e7b39c0a8451984c9c84db90fdf5e54d3d3d7837
[sdc.git] / catalog-ui / src / app / ng2 / pages / workspace / req-and-capabilities / req-and-capabilities.service.ts
1 import { Injectable } from "@angular/core";
2 import { TopologyTemplateService } from "../../../services/component-services/topology-template.service";
3 import { Store } from "@ngxs/store";
4 import { SdcUiServices } from "onap-ui-angular";
5 import { CapabilityTypeModel } from "../../../../models/capability-types";
6 import { RelationshipTypeModel } from "../../../../models/relationship-types";
7 import { NodeTypeModel } from "../../../../models/node-types";
8 import { WorkspaceService } from "../workspace.service";
9 import { ToscaTypesServiceNg2 } from "../../../services/tosca-types.service";
10
11
12
13 @Injectable()
14 export class ReqAndCapabilitiesService {
15
16     private capabilityTypesList: CapabilityTypeModel[];
17     private relationshipTypesList: RelationshipTypeModel[];
18     private nodeTypesList: NodeTypeModel[];
19
20     readonly INPUTS_FOR_REQUIREMENTS: string = 'INPUTS_FOR_REQUIREMENTS';
21     readonly INPUTS_FOR_CAPABILITIES: string = 'INPUTS_FOR_CAPABILITIES';
22
23     constructor(
24         private workspaceService: WorkspaceService,
25         private modalService: SdcUiServices.ModalService,
26         private loaderService: SdcUiServices.LoaderService,
27         private topologyTemplateService: TopologyTemplateService,
28         private store: Store,
29         private toscaTypesServiceNg2: ToscaTypesServiceNg2){}
30
31     public isViewOnly = (): boolean => {
32         return this.store.selectSnapshot((state) => state.workspace.isViewOnly);
33     }
34
35     public isDesigner = (): boolean => {
36         return this.store.selectSnapshot((state) => state.workspace.isDesigner);
37     }
38
39     public async initInputs(initInputsFor: string) {
40
41         // -- COMMON for both --
42         this.capabilityTypesList = [];
43         let capabilityTypesResult = await this.toscaTypesServiceNg2.fetchCapabilityTypes(this.workspaceService.metadata.model);
44         Object.keys(capabilityTypesResult).forEach(key => {this.capabilityTypesList.push(capabilityTypesResult[key])})
45
46         if (initInputsFor === 'INPUTS_FOR_REQUIREMENTS') {
47             this.relationshipTypesList = [];
48             let relationshipTypesResult = await this.toscaTypesServiceNg2.fetchRelationshipTypes(this.workspaceService.metadata.model);
49             Object.keys(relationshipTypesResult).forEach(key => {this.relationshipTypesList.push(relationshipTypesResult[key])});
50
51             this.nodeTypesList = [];
52             let nodeTypesResult = await this.toscaTypesServiceNg2.fetchNodeTypes(this.workspaceService.metadata.model);
53             Object.keys(nodeTypesResult).forEach(key => {this.nodeTypesList.push(nodeTypesResult[key])})
54         }
55     }
56
57     getCapabilityTypesList() {
58         return this.capabilityTypesList;
59     }
60
61     getRelationsShipeTypeList() {
62         return this.relationshipTypesList;
63     }
64
65     getNodeTypesList() {
66         return this.nodeTypesList;
67     }
68 }