2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation
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, Inject, OnInit} from '@angular/core';
21 import {IStepComponent} from "../../../../../../models/wizard-step";
22 import {ConnectionWizardService} from "../connection-wizard.service";
23 import {Component as IComponent} from "../../../../../../models/components/component";
24 import {ComponentServiceNg2} from "../../../../../services/component-services/component.service";
25 import {Observable} from "rxjs";
26 import {Operation} from "../create-interface-operation/model/operation";
29 selector: 'app-relationship-operations-step',
30 templateUrl: './relationship-operations-step.component.html',
31 styleUrls: ['./relationship-operations-step.component.less']
33 export class RelationshipOperationsStepComponent implements OnInit, IStepComponent {
35 private connectionWizardService: ConnectionWizardService;
36 private componentService: ComponentServiceNg2;
37 interfaceTypeMap: Map<string, Array<string>>;
38 component: IComponent;
39 operationList: Array<Operation>;
40 operationList$: Observable<Array<Operation>>;
41 enableAddOperation: boolean;
43 constructor(@Inject('$stateParams') private stateParams,
44 connectionWizardService: ConnectionWizardService,
45 componentService: ComponentServiceNg2) {
46 this.component = stateParams.component;
47 this.componentService = componentService;
48 this.connectionWizardService = connectionWizardService;
49 this.interfaceTypeMap = new Map<string, Array<string>>();
53 this.loadOperationList();
54 this.loadInterfaceTypeMap();
57 private loadOperationList(): void {
58 if (this.connectionWizardService.selectedMatch.operations) {
59 this.operationList = this.connectionWizardService.selectedMatch.operations.slice();
61 this.operationList = new Array<Operation>();
63 this.operationList$ = Observable.of(this.operationList);
66 private loadInterfaceTypeMap(): void {
67 this.componentService.getInterfaceTypes(null).subscribe(response => {
68 for (const interfaceType in response) {
69 let operationList = response[interfaceType];
70 //ignore interfaceTypes that doesn't contain operations
71 if (operationList && operationList.length > 0) {
72 //remove operations already on the list
73 const existingOperations =
74 this.operationList.filter(operation => operation.interfaceType === interfaceType);
75 operationList = operationList
76 .filter(operationType => !existingOperations.find(operation => operation.operationType === operationType));
77 if (operationList && operationList.length > 0) {
79 this.interfaceTypeMap.set(interfaceType, operationList);
86 preventBack(): boolean {
90 preventNext(): boolean {
95 this.enableAddOperation = !this.enableAddOperation;
98 operationAdded(operation: Operation) {
99 this.enableAddOperation = false;
101 const foundOperation = this.operationList
102 .find(operation1 => operation1.interfaceType === operation.interfaceType
103 && operation1.operationType === operation.operationType);
104 if (foundOperation) {
107 this.operationList.push(operation);
108 this.operationList = this.operationList.slice();
109 this.connectionWizardService.selectedMatch.addToOperations(operation);
110 this.removeFromInterfaceMap(operation);
114 onRemoveOperation(operation: Operation) {
115 if (!this.operationList) {
118 const index = this.operationList.indexOf(operation);
120 this.operationList.splice(index, 1);
121 this.operationList = this.operationList.slice();
122 this.connectionWizardService.selectedMatch.removeFromOperations(operation);
123 this.addToInterfaceMap(operation);
127 private removeFromInterfaceMap(operation: Operation) {
128 if (!this.interfaceTypeMap.has(operation.interfaceType)) {
131 const operationList = this.interfaceTypeMap.get(operation.interfaceType);
132 if (!operationList) {
136 const index = operationList.indexOf(operation.operationType);
138 operationList.splice(index, 1);
140 if (operationList.length == 0) {
141 this.interfaceTypeMap.delete(operation.interfaceType);
143 this.interfaceTypeMap.set(operation.interfaceType, operationList);
147 private addToInterfaceMap(operation: Operation) {
148 if (!this.interfaceTypeMap.has(operation.interfaceType)) {
149 this.interfaceTypeMap.set(operation.interfaceType, new Array<string>(operation.operationType));
153 const operationList = this.interfaceTypeMap.get(operation.interfaceType);
154 if (!operationList) {
155 this.interfaceTypeMap.set(operation.interfaceType, new Array<string>(operation.operationType));
158 operationList.push(operation.operationType);
159 operationList.sort();
160 this.interfaceTypeMap.set(operation.interfaceType, operationList);