aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pages/composition/composition.service.ts
blob: e5e9d2dca8f1d186993c71acf19c53bbfb0b113f (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
import {Injectable} from "@angular/core";
import 'rxjs/add/observable/forkJoin';
import {Component, PropertiesGroup, AttributesGroup, PolicyInstance} from "app/models";
import {GroupInstance} from "app/models/graph/zones/group-instance";
import {CommonGraphDataService} from "./common/common-graph-data.service";
import {ForwardingPath} from "../../../models/forwarding-path";
import {SelectedComponentType} from "./common/store/graph.actions";

@Injectable()
export class CompositionService extends CommonGraphDataService{

    public originComponents: Array<Component>; //This contains the full data set after specifically requesting it. The uniqueId matches the 'componentUid' in the componentInstances array
    public componentInstancesProperties:PropertiesGroup;
    public componentInstancesAttributes:AttributesGroup;
    public groupInstances: GroupInstance[];
    public policies: PolicyInstance[];
    public forwardingPaths:  { [key:string]:ForwardingPath };
    public selectedComponentType: SelectedComponentType;

    //---------------------------- COMPONENT INSTANCES ------------------------------------//

    public getOriginComponentById = (uniqueId:string):Component => {
        return this.originComponents && this.originComponents.find(instance => instance.uniqueId === uniqueId);
    }

    public addOriginComponent = (originComponent:Component) => {
        if(!this.originComponents) this.originComponents = [];
        if(!this.getOriginComponentById(originComponent.uniqueId)){
            this.originComponents.push(originComponent);
        }
    }


    public updateGroup = (instance: GroupInstance) => {
        this.groupInstances = this.groupInstances.map(group => instance.uniqueId === group.uniqueId? instance : group);
    }

    public updatePolicy = (instance: PolicyInstance) => {
        this.policies = this.policies.map(policy => instance.uniqueId === policy.uniqueId? instance : policy);
    }

    //---------------------------- POLICIES---------------------------------//
    public addPolicyInstance = (instance: PolicyInstance) => {
        return this.policies.push(instance);
    }


    //---------------------------- POLICIES---------------------------------//
    public addGroupInstance = (instance: GroupInstance) => {
        return this.groupInstances.push(instance);
    }


   //----------------------------SELECTED COMPONENT -----------------------//

    public setSelectedComponentType = (selectedType: SelectedComponentType) => {
        this.selectedComponentType = selectedType;
    }
}