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';
25 Component as TopologyTemplate,
27 FullComponentInstance,
34 import { SUBSTITUTION_FILTER_EVENTS } from 'app/utils/constants';
35 import { ComponentMetadata } from '../../../../../../models/component-metadata';
36 import { ServiceInstanceObject } from '../../../../../../models/service-instance-properties-and-interfaces';
37 import { EventListenerService } from '../../../../../../services/event-listener-service';
38 import { ConstraintObject } from '../../../../../components/logic/service-dependencies/service-dependencies.component';
39 import { TopologyTemplateService } from '../../../../../services/component-services/topology-template.service';
40 import { ComponentGenericResponse } from '../../../../../services/responses/component-generic-response';
41 import { WorkspaceService } from '../../../../workspace/workspace.service';
42 import { SelectedComponentType } from '../../../common/store/graph.actions';
43 import { CompositionService } from '../../../composition.service';
46 selector: 'substitution-filter-tab',
47 templateUrl: 'substitution-filter-tab.component.html',
48 styleUrls: ['substitution-filter-tab.component.less']
50 export class SubstitutionFilterTabComponent {
51 isComponentInstanceSelected: boolean;
53 selectedInstanceSiblings: ServiceInstanceObject[];
54 componentInstancesConstraints: any[];
55 selectedInstanceConstraints: ConstraintObject[];
56 selectedInstanceProperties: PropertyBEModel[];
57 componentInstanceProperties: PropertiesGroup;
58 metaData: ComponentMetadata;
60 @Input() isViewOnly: boolean;
61 @Input() componentType: SelectedComponentType;
62 @Input() component: FullComponentInstance | TopologyTemplate;
65 constructor(private store: Store,
66 private topologyTemplateService: TopologyTemplateService,
67 private workspaceService: WorkspaceService,
68 private compositionService: CompositionService,
69 private eventListenerService: EventListenerService) {
73 this.metaData = this.workspaceService.metadata;
74 this.isComponentInstanceSelected = this.componentType === SelectedComponentType.COMPONENT_INSTANCE;
75 this.initInstancesWithProperties();
76 this.loadConstraints();
77 this.initInstancesWithProperties();
80 public loadConstraints = (): void => {
81 this.topologyTemplateService.getSubstitutionFilterConstraints(this.metaData.componentType, this.metaData.uniqueId).subscribe((response) => {
82 this.componentInstancesConstraints = response.substitutionFilterForTopologyTemplate;
86 public notifyDependencyEventsObserver = (isChecked: boolean): void => {
87 this.eventListenerService.notifyObservers(SUBSTITUTION_FILTER_EVENTS.ON_SUBSTITUTION_FILTER_CHANGE, isChecked);
90 public updateSelectedInstanceConstraints = (constraintsList:Array<ConstraintObject>):void => {
91 this.componentInstancesConstraints[this.component.uniqueId].properties = constraintsList;
92 this.selectedInstanceConstraints = this.componentInstancesConstraints[this.component.uniqueId].properties;
95 private initInstancesWithProperties = (): void => {
96 this.topologyTemplateService.getComponentInstanceProperties(this.metaData.componentType, this.metaData.uniqueId).subscribe((genericResponse: ComponentGenericResponse) => {
97 this.componentInstanceProperties = genericResponse.componentInstancesProperties;
98 this.updateInstanceAttributes();
103 private updateInstanceAttributes = (): void => {
104 if (this.isComponentInstanceSelected && this.componentInstanceProperties) {
105 const instancesMappedList = this.compositionService.componentInstances.map((coInstance) => new ServiceInstanceObject({
106 id: coInstance.uniqueId,
107 name: coInstance.name,
108 properties: this.componentInstanceProperties[coInstance.uniqueId] || []
110 this.selectedInstanceProperties = this.componentInstanceProperties[this.component.uniqueId];
111 this.selectedInstanceSiblings = instancesMappedList.filter((coInstance) => coInstance.id !== this.component.uniqueId);