aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pages/workspace/req-and-capabilities/req-and-capabilities.service.ts
blob: 470aac75a611bc08cde2aa1730c648de086e69d9 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { Injectable } from "@angular/core";
import { TopologyTemplateService } from "../../../services/component-services/topology-template.service";
import { Store } from "@ngxs/store";
import { SdcUiServices } from "onap-ui-angular";
import { CapabilityTypeModel } from "../../../../models/capability-types";
import { RelationshipTypeModel } from "../../../../models/relationship-types";
import { NodeTypeModel } from "../../../../models/node-types";
import { WorkspaceService } from "../workspace.service";
import { ToscaTypesServiceNg2 } from "../../../services/tosca-types.service";



@Injectable()
export class ReqAndCapabilitiesService {

    private capabilityTypesList: CapabilityTypeModel[];
    private relationshipTypesList: RelationshipTypeModel[];
    private nodeTypesList: NodeTypeModel[];
    private capabilitiesListUpdated: boolean = false;
    private requirementsListUpdated: boolean = false;
    private nodeTypeListUpdated: boolean = false;

    readonly INPUTS_FOR_REQUIREMENTS: string = 'INPUTS_FOR_REQUIREMENTS';
    readonly INPUTS_FOR_CAPABILITIES: string = 'INPUTS_FOR_CAPABILITIES';

    constructor(
        private workspaceService: WorkspaceService,
        private modalService: SdcUiServices.ModalService,
        private loaderService: SdcUiServices.LoaderService,
        private topologyTemplateService: TopologyTemplateService,
        private store: Store,
        private toscaTypesServiceNg2: ToscaTypesServiceNg2){}

    public isViewOnly = (): boolean => {
        return this.store.selectSnapshot((state) => state.workspace.isViewOnly);
    }

    public isDesigner = (): boolean => {
        return this.store.selectSnapshot((state) => state.workspace.isDesigner);
    }

    public async initInputs(initInputsFor: string) {

        if (!this.capabilitiesListUpdated){
            // -- COMMON for both --
            this.capabilityTypesList = [];
            let capabilityTypesResult = await this.toscaTypesServiceNg2.fetchCapabilityTypes();
            Object.keys(capabilityTypesResult).forEach(key => {this.capabilityTypesList.push(capabilityTypesResult[key])})
            this.capabilitiesListUpdated = true;
        }

        if (initInputsFor === 'INPUTS_FOR_REQUIREMENTS') {
            if (!this.requirementsListUpdated){
                this.relationshipTypesList = [];
                let relationshipTypesResult = await this.toscaTypesServiceNg2.fetchRelationshipTypes();
                Object.keys(relationshipTypesResult).forEach(key => {this.relationshipTypesList.push(relationshipTypesResult[key])});
                this.requirementsListUpdated = true;
            }

            if (!this.nodeTypeListUpdated){
                this.nodeTypesList = [];
                let nodeTypesResult = await this.toscaTypesServiceNg2.fetchNodeTypes();
                Object.keys(nodeTypesResult).forEach(key => {this.nodeTypesList.push(nodeTypesResult[key])})
                this.nodeTypeListUpdated = true;
            }
        }
    }

    getCapabilityTypesList() {
        return this.capabilityTypesList;
    }

    getRelationsShipeTypeList() {
        return this.relationshipTypesList;
    }

    getNodeTypesList() {
        return this.nodeTypesList;
    }
}