Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / pages / composition / composition.service.ts
1 import {Injectable} from "@angular/core";
2 import 'rxjs/add/observable/forkJoin';
3 import {Component, PropertiesGroup, AttributesGroup, PolicyInstance} from "app/models";
4 import {GroupInstance} from "app/models/graph/zones/group-instance";
5 import {CommonGraphDataService} from "./common/common-graph-data.service";
6 import {ForwardingPath} from "../../../models/forwarding-path";
7 import {SelectedComponentType} from "./common/store/graph.actions";
8
9 @Injectable()
10 export class CompositionService extends CommonGraphDataService{
11
12     public originComponents: Array<Component>; //This contains the full data set after specifically requesting it. The uniqueId matches the 'componentUid' in the componentInstances array
13     public componentInstancesProperties:PropertiesGroup;
14     public componentInstancesAttributes:AttributesGroup;
15     public groupInstances: GroupInstance[];
16     public policies: PolicyInstance[];
17     public forwardingPaths:  { [key:string]:ForwardingPath };
18     public selectedComponentType: SelectedComponentType;
19
20     //---------------------------- COMPONENT INSTANCES ------------------------------------//
21
22     public getOriginComponentById = (uniqueId:string):Component => {
23         return this.originComponents && this.originComponents.find(instance => instance.uniqueId === uniqueId);
24     }
25
26     public addOriginComponent = (originComponent:Component) => {
27         if(!this.originComponents) this.originComponents = [];
28         if(!this.getOriginComponentById(originComponent.uniqueId)){
29             this.originComponents.push(originComponent);
30         }
31     }
32
33
34     public updateGroup = (instance: GroupInstance) => {
35         this.groupInstances = this.groupInstances.map(group => instance.uniqueId === group.uniqueId? instance : group);
36     }
37
38     public updatePolicy = (instance: PolicyInstance) => {
39         this.policies = this.policies.map(policy => instance.uniqueId === policy.uniqueId? instance : policy);
40     }
41
42     //---------------------------- POLICIES---------------------------------//
43     public addPolicyInstance = (instance: PolicyInstance) => {
44         return this.policies.push(instance);
45     }
46
47
48     //---------------------------- POLICIES---------------------------------//
49     public addGroupInstance = (instance: GroupInstance) => {
50         return this.groupInstances.push(instance);
51     }
52
53
54    //----------------------------SELECTED COMPONENT -----------------------//
55
56     public setSelectedComponentType = (selectedType: SelectedComponentType) => {
57         this.selectedComponentType = selectedType;
58     }
59 }