aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pages/composition/common/common-graph-data.service.ts
diff options
context:
space:
mode:
authorys9693 <ys9693@att.com>2020-01-19 13:50:02 +0200
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-01-22 12:33:31 +0000
commit16a9fce0e104a38371a9e5a567ec611ae3fc7f33 (patch)
tree03a2aff3060ddb5bc26a90115805a04becbaffc9 /catalog-ui/src/app/ng2/pages/composition/common/common-graph-data.service.ts
parentaa83a2da4f911c3ac89318b8e9e8403b072942e1 (diff)
Catalog alignment
Issue-ID: SDC-2724 Signed-off-by: ys9693 <ys9693@att.com> Change-Id: I52b4aacb58cbd432ca0e1ff7ff1f7dd52099c6fe
Diffstat (limited to 'catalog-ui/src/app/ng2/pages/composition/common/common-graph-data.service.ts')
-rw-r--r--catalog-ui/src/app/ng2/pages/composition/common/common-graph-data.service.ts64
1 files changed, 64 insertions, 0 deletions
diff --git a/catalog-ui/src/app/ng2/pages/composition/common/common-graph-data.service.ts b/catalog-ui/src/app/ng2/pages/composition/common/common-graph-data.service.ts
new file mode 100644
index 0000000000..d4caa5e9ed
--- /dev/null
+++ b/catalog-ui/src/app/ng2/pages/composition/common/common-graph-data.service.ts
@@ -0,0 +1,64 @@
+import {Injectable} from "@angular/core";
+import 'rxjs/add/observable/forkJoin';
+import {ComponentInstance} from "../../../../models/componentsInstances/componentInstance";
+import {SelectedComponentType} from "./store/graph.actions";
+import {RelationshipModel} from "../../../../models/graph/relationship";
+
+@Injectable()
+export class CommonGraphDataService {
+
+ public componentInstances: Array<ComponentInstance>;
+ public componentInstancesRelations: RelationshipModel[];
+ public selectedComponentType: SelectedComponentType;
+
+ constructor() {
+ }
+
+ //------------------------ RELATIONS ---------------------------------//
+ public setRelations = (componentInstancesRelations: RelationshipModel[]) => {
+ this.componentInstancesRelations = this.componentInstancesRelations;
+ }
+
+ public getRelations = (): RelationshipModel[] => {
+ return this.componentInstancesRelations;
+ }
+
+ public addRelation = (componentInstancesRelations: RelationshipModel) => {
+ this.componentInstancesRelations.push(componentInstancesRelations);
+ }
+
+ public deleteRelation(relationToDelete: RelationshipModel) {
+ this.componentInstancesRelations = _.filter(this.componentInstancesRelations, (relationship: RelationshipModel) => {
+ return relationship.relationships[0].relation.id !== relationToDelete.relationships[0].relation.id;
+ });
+ }
+
+ //---------------------------- COMPONENT INSTANCES ------------------------------------//
+ public getComponentInstances = (): Array<ComponentInstance> => {
+ return this.componentInstances;
+ }
+
+ public addComponentInstance = (instance: ComponentInstance) => {
+ return this.componentInstances.push(instance);
+ }
+
+ public updateComponentInstances = (componentInstances: ComponentInstance[]) => {
+ _.unionBy(this.componentInstances, componentInstances, 'uniqueId');
+ }
+
+ public updateInstance = (instance: ComponentInstance) => {
+ this.componentInstances = this.componentInstances.map(componentInstance => instance.uniqueId === componentInstance.uniqueId? instance : componentInstance);
+ }
+
+ public deleteComponentInstance(instanceToDelete: string) {
+ this.componentInstances = _.filter(this.componentInstances, (instance: ComponentInstance) => {
+ return instance.uniqueId !== instanceToDelete;
+ });
+ }
+
+ //----------------------------SELECTED COMPONENT -----------------------//
+
+ public setSelectedComponentType = (selectedType: SelectedComponentType) => {
+ this.selectedComponentType = selectedType;
+ }
+}