2 import { Component, Input } from '@angular/core';
3 import { Store } from '@ngxs/store';
7 Component as TopologyTemplate,
15 import { ComponentMetadata } from '../../../../../../models/component-metadata';
16 import { ServiceInstanceObject } from '../../../../../../models/service-instance-properties-and-interfaces';
17 import { EventListenerService } from '../../../../../../services/event-listener-service';
18 import { TopologyTemplateService } from '../../../../../services/component-services/topology-template.service';
19 import { ComponentGenericResponse } from '../../../../../services/responses/component-generic-response';
20 import { WorkspaceService } from '../../../../workspace/workspace.service';
21 import { SelectedComponentType } from '../../../common/store/graph.actions';
22 import { CompositionService } from '../../../composition.service';
25 selector: 'service-consumption-tab',
26 templateUrl: './service-consumption-tab.component.html',
27 styleUrls: ['./service-consumption-tab.component.less'],
29 export class ServiceConsumptionTabComponent {
30 isComponentInstanceSelected: boolean;
32 instancesMappedList: ServiceInstanceObject[];
33 componentInstancesProperties: PropertiesGroup;
34 componentInstancesInputs: InputsGroup;
35 componentInstancesInterfaces: Map<string, InterfaceModel[]>;
36 componentInputs: InputBEModel[];
37 componentCapabilities: Capability[];
38 instancesCapabilitiesMap: Map<string, Capability[]>;
39 metadata: ComponentMetadata;
41 @Input() isViewOnly: boolean;
42 @Input() componentType: SelectedComponentType;
43 @Input() component: TopologyTemplate | FullComponentInstance;
46 constructor(private store: Store,
47 private topologyTemplateService: TopologyTemplateService,
48 private workspaceService: WorkspaceService,
49 private compositionService: CompositionService,
50 private eventListenerService: EventListenerService ) {}
52 this.metadata = this.workspaceService.metadata;
53 this.isComponentInstanceSelected = this.componentType === SelectedComponentType.COMPONENT_INSTANCE;
57 private initInstances = (): void => {
58 this.topologyTemplateService.getServiceConsumptionData(this.metadata.componentType, this.metadata.uniqueId).subscribe((genericResponse: ComponentGenericResponse) => {
59 this.componentInstancesProperties = genericResponse.componentInstancesProperties;
60 this.componentInstancesInputs = genericResponse.componentInstancesInputs;
61 this.componentInstancesInterfaces = genericResponse.componentInstancesInterfaces;
62 this.componentInputs = genericResponse.inputs;
63 this.buildInstancesCapabilitiesMap(genericResponse.componentInstances);
64 this.updateInstanceAttributes();
68 private buildInstancesCapabilitiesMap = (componentInstances: Array<ComponentInstance>): void => {
69 this.instancesCapabilitiesMap = new Map();
70 let flattenCapabilities = [];
71 _.forEach(componentInstances, (componentInstance) => {
72 flattenCapabilities = CapabilitiesGroup.getFlattenedCapabilities(componentInstance.capabilities);
73 this.instancesCapabilitiesMap[componentInstance.uniqueId] = _.filter(flattenCapabilities, cap => cap.properties && cap.ownerId === componentInstance.uniqueId);
77 private updateInstanceAttributes = (): void => {
78 if (this.isComponentInstanceSelected && this.componentInstancesProperties) {
79 this.instancesMappedList = this.compositionService.componentInstances.map((coInstance) => new ServiceInstanceObject({
80 id: coInstance.uniqueId,
81 name: coInstance.name,
82 properties: this.componentInstancesProperties[coInstance.uniqueId] || [],
83 inputs: this.componentInstancesInputs[coInstance.uniqueId] || [],
84 interfaces: this.componentInstancesInterfaces[coInstance.uniqueId] || []