1 import {Injectable} from "@angular/core";
2 import 'rxjs/add/observable/forkJoin';
3 import {ComponentInstance} from "../../../../models/componentsInstances/componentInstance";
4 import {SelectedComponentType} from "./store/graph.actions";
5 import {RelationshipModel} from "../../../../models/graph/relationship";
8 export class CommonGraphDataService {
10 public componentInstances: Array<ComponentInstance>;
11 public componentInstancesRelations: RelationshipModel[];
12 public selectedComponentType: SelectedComponentType;
17 //------------------------ RELATIONS ---------------------------------//
18 public setRelations = (componentInstancesRelations: RelationshipModel[]) => {
19 this.componentInstancesRelations = this.componentInstancesRelations;
22 public getRelations = (): RelationshipModel[] => {
23 return this.componentInstancesRelations;
26 public addRelation = (componentInstancesRelations: RelationshipModel) => {
27 this.componentInstancesRelations.push(componentInstancesRelations);
30 public deleteRelation(relationToDelete: RelationshipModel) {
31 this.componentInstancesRelations = _.filter(this.componentInstancesRelations, (relationship: RelationshipModel) => {
32 return relationship.relationships[0].relation.id !== relationToDelete.relationships[0].relation.id;
36 //---------------------------- COMPONENT INSTANCES ------------------------------------//
37 public getComponentInstances = (): Array<ComponentInstance> => {
38 return this.componentInstances;
41 public addComponentInstance = (instance: ComponentInstance) => {
42 return this.componentInstances.push(instance);
45 public updateComponentInstances = (componentInstances: ComponentInstance[]) => {
46 _.unionBy(this.componentInstances, componentInstances, 'uniqueId');
49 public updateInstance = (instance: ComponentInstance) => {
50 this.componentInstances = this.componentInstances.map(componentInstance => instance.uniqueId === componentInstance.uniqueId? instance : componentInstance);
53 public deleteComponentInstance(instanceToDelete: string) {
54 this.componentInstances = _.filter(this.componentInstances, (instance: ComponentInstance) => {
55 return instance.uniqueId !== instanceToDelete;
59 //----------------------------SELECTED COMPONENT -----------------------//
61 public setSelectedComponentType = (selectedType: SelectedComponentType) => {
62 this.selectedComponentType = selectedType;