2 import { Component, Input } from '@angular/core';
3 import { Store } from '@ngxs/store';
7 Component as TopologyTemplate,
16 import { DEPENDENCY_EVENTS } from 'app/utils/constants';
17 import { ComponentMetadata } from '../../../../../../models/component-metadata';
18 import { ServiceInstanceObject } from '../../../../../../models/service-instance-properties-and-interfaces';
19 import { EventListenerService } from '../../../../../../services/event-listener-service';
20 import { ConstraintObject } from '../../../../../components/logic/service-dependencies/service-dependencies.component';
21 import { TopologyTemplateService } from '../../../../../services/component-services/topology-template.service';
22 import { ComponentGenericResponse } from '../../../../../services/responses/component-generic-response';
23 import { WorkspaceService } from '../../../../workspace/workspace.service';
24 import { SelectedComponentType } from '../../../common/store/graph.actions';
25 import { CompositionService } from '../../../composition.service';
28 selector: 'service-dependencies-tab',
29 templateUrl: 'service-dependencies-tab.component.html',
30 styleUrls: ['service-dependencies-tab.component.less']
32 export class ServiceDependenciesTabComponent {
33 isComponentInstanceSelected: boolean;
35 selectedInstanceSiblings: ServiceInstanceObject[];
36 componentInstancesConstraints: any[];
37 selectedInstanceConstraints: ConstraintObject[];
38 selectedInstanceProperties: PropertyBEModel[];
39 componentInstanceProperties: PropertiesGroup;
40 metaData: ComponentMetadata;
42 @Input() isViewOnly: boolean;
43 @Input() componentType: SelectedComponentType;
44 @Input() component: FullComponentInstance | TopologyTemplate;
47 constructor(private store: Store,
48 private topologyTemplateService: TopologyTemplateService,
49 private workspaceService: WorkspaceService,
50 private compositionService: CompositionService,
51 private eventListenerService: EventListenerService) {
55 this.metaData = this.workspaceService.metadata;
56 this.isComponentInstanceSelected = this.componentType === SelectedComponentType.COMPONENT_INSTANCE;
57 this.initInstancesWithProperties();
58 this.loadConstraints();
59 this.initInstancesWithProperties();
62 public loadConstraints = (): void => {
63 this.topologyTemplateService.getServiceFilterConstraints(this.metaData.componentType, this.metaData.uniqueId).subscribe((response) => {
64 this.componentInstancesConstraints = response.nodeFilterData;
68 public notifyDependencyEventsObserver = (isChecked: boolean): void => {
69 this.eventListenerService.notifyObservers(DEPENDENCY_EVENTS.ON_DEPENDENCY_CHANGE, isChecked);
72 public updateSelectedInstanceConstraints = (constraintsList:Array<ConstraintObject>):void => {
73 this.componentInstancesConstraints[this.component.uniqueId].properties = constraintsList;
74 this.selectedInstanceConstraints = this.componentInstancesConstraints[this.component.uniqueId].properties;
77 private initInstancesWithProperties = (): void => {
78 this.topologyTemplateService.getComponentInstanceProperties(this.metaData.componentType, this.metaData.uniqueId).subscribe((genericResponse: ComponentGenericResponse) => {
79 this.componentInstanceProperties = genericResponse.componentInstancesProperties;
80 this.updateInstanceAttributes();
84 private updateInstanceAttributes = (): void => {
85 if (this.isComponentInstanceSelected && this.componentInstanceProperties) {
86 const instancesMappedList = this.compositionService.componentInstances.map((coInstance) => new ServiceInstanceObject({
87 id: coInstance.uniqueId,
88 name: coInstance.name,
89 properties: this.componentInstanceProperties[coInstance.uniqueId] || []
91 this.selectedInstanceProperties = this.componentInstanceProperties[this.component.uniqueId];
92 this.selectedInstanceSiblings = instancesMappedList.filter((coInstance) => coInstance.id !== this.component.uniqueId);