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";
14 export class ReqAndCapabilitiesService {
16 private capabilityTypesList: CapabilityTypeModel[];
17 private relationshipTypesList: RelationshipTypeModel[];
18 private nodeTypesList: NodeTypeModel[];
19 private capabilitiesListUpdated: boolean = false;
20 private requirementsListUpdated: boolean = false;
21 private nodeTypeListUpdated: boolean = false;
23 readonly INPUTS_FOR_REQUIREMENTS: string = 'INPUTS_FOR_REQUIREMENTS';
24 readonly INPUTS_FOR_CAPABILITIES: string = 'INPUTS_FOR_CAPABILITIES';
27 private workspaceService: WorkspaceService,
28 private modalService: SdcUiServices.ModalService,
29 private loaderService: SdcUiServices.LoaderService,
30 private topologyTemplateService: TopologyTemplateService,
32 private toscaTypesServiceNg2: ToscaTypesServiceNg2){}
34 public isViewOnly = (): boolean => {
35 return this.store.selectSnapshot((state) => state.workspace.isViewOnly);
38 public isDesigner = (): boolean => {
39 return this.store.selectSnapshot((state) => state.workspace.isDesigner);
42 public async initInputs(initInputsFor: string) {
44 if (!this.capabilitiesListUpdated){
45 // -- COMMON for both --
46 this.capabilityTypesList = [];
47 let capabilityTypesResult = await this.toscaTypesServiceNg2.fetchCapabilityTypes(this.workspaceService.metadata.model);
48 Object.keys(capabilityTypesResult).forEach(key => {this.capabilityTypesList.push(capabilityTypesResult[key])})
49 this.capabilitiesListUpdated = true;
52 if (initInputsFor === 'INPUTS_FOR_REQUIREMENTS') {
53 if (!this.requirementsListUpdated){
54 this.relationshipTypesList = [];
55 let relationshipTypesResult = await this.toscaTypesServiceNg2.fetchRelationshipTypes(this.workspaceService.metadata.model);
56 Object.keys(relationshipTypesResult).forEach(key => {this.relationshipTypesList.push(relationshipTypesResult[key])});
57 this.requirementsListUpdated = true;
60 if (!this.nodeTypeListUpdated){
61 this.nodeTypesList = [];
62 let nodeTypesResult = await this.toscaTypesServiceNg2.fetchNodeTypes();
63 Object.keys(nodeTypesResult).forEach(key => {this.nodeTypesList.push(nodeTypesResult[key])})
64 this.nodeTypeListUpdated = true;
69 getCapabilityTypesList() {
70 return this.capabilityTypesList;
73 getRelationsShipeTypeList() {
74 return this.relationshipTypesList;
78 return this.nodeTypesList;