2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 import { Component, Input } from '@angular/core';
21 import { Store } from '@ngxs/store';
23 Component as TopologyTemplate,
24 FullComponentInstance,
28 import { SUBSTITUTION_FILTER_EVENTS } from 'app/utils/constants';
29 import { ComponentMetadata } from '../../../../../../models/component-metadata';
30 import { ServiceInstanceObject } from '../../../../../../models/service-instance-properties-and-interfaces';
31 import { EventListenerService } from '../../../../../../services/event-listener-service';
32 import { ConstraintObject } from '../../../../../components/logic/service-dependencies/service-dependencies.component';
33 import { TopologyTemplateService } from '../../../../../services/component-services/topology-template.service';
34 import { ComponentGenericResponse } from '../../../../../services/responses/component-generic-response';
35 import { WorkspaceService } from '../../../../workspace/workspace.service';
36 import { SelectedComponentType } from '../../../common/store/graph.actions';
37 import { CompositionService } from '../../../composition.service';
40 selector: 'substitution-filter-tab',
41 templateUrl: 'substitution-filter-tab.component.html',
42 styleUrls: ['substitution-filter-tab.component.less']
44 export class SubstitutionFilterTabComponent {
45 isComponentInstanceSelected: boolean;
47 selectedInstanceSiblings: ServiceInstanceObject[];
48 componentInstancesConstraints: any[];
49 selectedInstanceConstraints: ConstraintObject[];
50 selectedInstanceProperties: PropertyBEModel[];
51 componentInstanceProperties: PropertiesGroup;
52 metaData: ComponentMetadata;
54 @Input() isViewOnly: boolean;
55 @Input() componentType: SelectedComponentType;
56 @Input() component: FullComponentInstance | TopologyTemplate;
59 constructor(private store: Store,
60 private topologyTemplateService: TopologyTemplateService,
61 private workspaceService: WorkspaceService,
62 private compositionService: CompositionService,
63 private eventListenerService: EventListenerService) {
67 this.metaData = this.workspaceService.metadata;
68 this.isComponentInstanceSelected = this.componentType === SelectedComponentType.COMPONENT_INSTANCE;
69 this.initInstancesWithProperties();
72 public loadConstraints = (): void => {
73 this.topologyTemplateService.getSubstitutionFilterConstraints(this.metaData.componentType, this.metaData.uniqueId).subscribe((response) => {
74 this.componentInstancesConstraints = response.substitutionFilterForTopologyTemplate;
78 public notifyDependencyEventsObserver = (isChecked: boolean): void => {
79 this.eventListenerService.notifyObservers(SUBSTITUTION_FILTER_EVENTS.ON_SUBSTITUTION_FILTER_CHANGE, isChecked);
82 public updateSelectedInstanceConstraints = (constraintsList:Array<ConstraintObject>):void => {
83 this.componentInstancesConstraints[this.component.uniqueId].properties = constraintsList;
84 this.selectedInstanceConstraints = this.componentInstancesConstraints[this.component.uniqueId].properties;
87 private initInstancesWithProperties = (): void => {
88 this.topologyTemplateService.getComponentPropertiesSubstitutionFilter(this.metaData.componentType, this.metaData.uniqueId).subscribe((genericResponse: ComponentGenericResponse) => {
89 this.selectedInstanceProperties = genericResponse.properties;
90 this.updateInstanceAttributes();
94 private updateInstanceAttributes = (): void => {
95 if (this.isComponentInstanceSelected && this.componentInstanceProperties) {
96 const instancesMappedList = this.compositionService.componentInstances.map((coInstance) => new ServiceInstanceObject({
97 id: coInstance.uniqueId,
98 name: coInstance.name,
99 properties: this.componentInstanceProperties[coInstance.uniqueId] || []
101 this.selectedInstanceProperties = this.componentInstanceProperties[this.component.uniqueId];
102 this.selectedInstanceSiblings = instancesMappedList.filter((coInstance) => coInstance.id !== this.component.uniqueId);