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";
10 export class CompositionService extends CommonGraphDataService{
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;
20 //---------------------------- COMPONENT INSTANCES ------------------------------------//
22 public getOriginComponentById = (uniqueId:string):Component => {
23 return this.originComponents && this.originComponents.find(instance => instance.uniqueId === uniqueId);
26 public addOriginComponent = (originComponent:Component) => {
27 if(!this.originComponents) this.originComponents = [];
28 if(!this.getOriginComponentById(originComponent.uniqueId)){
29 this.originComponents.push(originComponent);
34 public updateGroup = (instance: GroupInstance) => {
35 this.groupInstances = this.groupInstances.map(group => instance.uniqueId === group.uniqueId? instance : group);
38 public updatePolicy = (instance: PolicyInstance) => {
39 this.policies = this.policies.map(policy => instance.uniqueId === policy.uniqueId? instance : policy);
42 //---------------------------- POLICIES---------------------------------//
43 public addPolicyInstance = (instance: PolicyInstance) => {
44 return this.policies.push(instance);
48 //---------------------------- POLICIES---------------------------------//
49 public addGroupInstance = (instance: GroupInstance) => {
50 return this.groupInstances.push(instance);
54 //----------------------------SELECTED COMPONENT -----------------------//
56 public setSelectedComponentType = (selectedType: SelectedComponentType) => {
57 this.selectedComponentType = selectedType;