summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/services/modules.service.ts
blob: 857f0718d6b1c93e47d3e05d97b8953b7e5f855f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import {Inject, Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {ISdcConfig, SdcConfigToken} from "../config/sdc-config.config";
import {DisplayModule, Module} from "../../models/modules/base-module";
import {Observable} from "rxjs/Observable";
import {ServerTypeUrl} from "../../utils/constants";

@Injectable()
export class ModulesService {

    protected baseUrl;

    constructor(private http: HttpClient, @Inject(SdcConfigToken) sdcConfig: ISdcConfig) {
        this.baseUrl = sdcConfig.api.root + sdcConfig.api.component_api_root;
    }

    getComponentInstanceModule = (topologyTemplateType: string, topologyTemplateId: string, componentInstanceId: string, moduleId: string):Observable<DisplayModule> => {
        return this.http.get<DisplayModule>(this.baseUrl + ServerTypeUrl.toServerTypeUrl(topologyTemplateType) + "/" + topologyTemplateId + "/resourceInstance/" + componentInstanceId + "/groupInstance/" + moduleId)
            .map((response) => {
                return new DisplayModule(response);
            })
    };

    getModuleForDisplay = (topologyTemplateType: string, topologyTemplateId: string, moduleId: string):Observable<DisplayModule> => {
        return this.http.get<DisplayModule>(this.baseUrl + ServerTypeUrl.toServerTypeUrl(topologyTemplateType) + "/" + topologyTemplateId + "/groups/" + moduleId)
            .map((response) => {
                return new DisplayModule(response);
            })
    };

    public updateModuleMetadata = (topologyTemplateType: string, topologyTemplateId: string, module: Module):Observable<Module> => {
        return this.http.put<Module>(this.baseUrl + ServerTypeUrl.toServerTypeUrl(topologyTemplateType) + "/" + topologyTemplateId + "/groups/" + module.uniqueId + "/metadata", module)
    }
}