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';
22 import {Component as TopologyTemplate, FullComponentInstance, InputBEModel, PropertiesGroup, PropertyBEModel,} from 'app/models';
23 import {SUBSTITUTION_FILTER_EVENTS} from 'app/utils/constants';
24 import {ComponentMetadata} from '../../../../../../models/component-metadata';
25 import {ServiceInstanceObject} from '../../../../../../models/service-instance-properties-and-interfaces';
26 import {EventListenerService} from '../../../../../../services/event-listener-service';
27 import {TopologyTemplateService} from '../../../../../services/component-services/topology-template.service';
28 import {ComponentGenericResponse} from '../../../../../services/responses/component-generic-response';
29 import {WorkspaceService} from '../../../../workspace/workspace.service';
30 import {SelectedComponentType} from '../../../common/store/graph.actions';
31 import {CompositionService} from '../../../composition.service';
32 import {FilterConstraint} from "../../../../../../models/filter-constraint";
35 selector: 'substitution-filter-tab',
36 templateUrl: 'substitution-filter-tab.component.html',
37 styleUrls: ['substitution-filter-tab.component.less']
39 export class SubstitutionFilterTabComponent {
40 isComponentInstanceSelected: boolean;
42 selectedInstanceSiblings: ServiceInstanceObject[];
43 componentInstancesConstraints: any[];
44 selectedInstanceConstraints: FilterConstraint[];
45 parentServiceProperties: PropertyBEModel[];
46 parentServiceInputs: InputBEModel[];
47 componentInstanceProperties: PropertiesGroup;
48 metaData: ComponentMetadata;
50 @Input() isViewOnly: boolean;
51 @Input() componentType: SelectedComponentType;
52 @Input() component: FullComponentInstance | TopologyTemplate;
55 constructor(private store: Store,
56 private topologyTemplateService: TopologyTemplateService,
57 private workspaceService: WorkspaceService,
58 private compositionService: CompositionService,
59 private eventListenerService: EventListenerService) {
63 this.metaData = this.workspaceService.metadata;
64 this.isComponentInstanceSelected = this.componentType === SelectedComponentType.COMPONENT_INSTANCE;
65 this.initInstancesWithProperties();
68 public loadConstraints = (): void => {
69 this.topologyTemplateService.getSubstitutionFilterConstraints(this.metaData.componentType, this.metaData.uniqueId).subscribe((response) => {
70 this.componentInstancesConstraints = response.substitutionFilters;
74 public notifyDependencyEventsObserver = (isChecked: boolean): void => {
75 this.eventListenerService.notifyObservers(SUBSTITUTION_FILTER_EVENTS.ON_SUBSTITUTION_FILTER_CHANGE, isChecked);
78 public updateSelectedInstanceConstraints = (constraintsList:Array<FilterConstraint>):void => {
79 this.componentInstancesConstraints[this.component.uniqueId].properties = constraintsList;
80 this.selectedInstanceConstraints = this.componentInstancesConstraints[this.component.uniqueId].properties;
83 private initInstancesWithProperties = (): void => {
84 this.topologyTemplateService.getComponentPropertiesAndInputsForSubstitutionFilter(this.metaData.componentType, this.metaData.uniqueId)
85 .subscribe((genericResponse: ComponentGenericResponse) => {
86 this.parentServiceProperties = genericResponse.properties;
87 this.parentServiceInputs = genericResponse.inputs;