2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2022 Nordix Foundation. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
21 import {Component, Input, Inject, ComponentRef} from '@angular/core';
22 import {Component as IComponent } from 'app/models/components/component';
24 import { SdcConfigToken, ISdcConfig } from "app/ng2/config/sdc-config.config";
25 import {TranslateService } from "app/ng2/shared/translator/translate.service";
27 import { ModalComponent } from 'app/ng2/components/ui/modal/modal.component';
28 import {ModalService } from 'app/ng2/services/modal.service';
33 ButtonModel, ModalModel
36 import {ComponentServiceNg2 } from 'app/ng2/services/component-services/component.service';
38 import { SdcUiServices } from 'onap-ui-angular';
39 import {TopologyTemplateService} from "../../services/component-services/topology-template.service";
40 import {InputOperationParameter, InterfaceOperationModel} from "../../../models/interfaceOperation";
41 import {PropertyParamRowComponent} from "../composition/interface-operatons/operation-creator/property-param-row/property-param-row.component";
42 import {InterfaceOperationHandlerComponent} from "../composition/interface-operatons/operation-creator/interface-operation-handler.component";
43 import {DropdownValue} from "../../components/ui/form-components/dropdown/ui-element-dropdown.component";
45 export class UIOperationModel extends OperationModel {
46 isCollapsed: boolean = true;
50 constructor(operation: OperationModel) {
53 if (!operation.description) {
54 this.description = '';
57 if (this.description.length > this.MAX_LENGTH) {
58 this.isEllipsis = true;
60 this.isEllipsis = false;
64 getDescriptionEllipsis(): string {
65 if (this.isCollapsed && this.description.length > this.MAX_LENGTH) {
66 return this.description.substr(0, this.MAX_LENGTH - 3) + '...';
68 return this.description;
73 this.isCollapsed = !this.isCollapsed;
77 // tslint:disable-next-line:max-classes-per-file
78 class ModalTranslation {
82 CANCEL_BUTTON: string;
84 CREATE_BUTTON: string;
85 DELETE_BUTTON: string;
88 constructor(private TranslateService: TranslateService) {
89 this.TranslateService.languageChangedObservable.subscribe(lang => {
90 this.CREATE_TITLE = this.TranslateService.translate("INTERFACE_CREATE_TITLE");
91 this.EDIT_TITLE = this.TranslateService.translate('INTERFACE_EDIT_TITLE');
92 this.DELETE_TITLE = this.TranslateService.translate("INTERFACE_DELETE_TITLE");
93 this.CANCEL_BUTTON = this.TranslateService.translate("INTERFACE_CANCEL_BUTTON");
94 this.SAVE_BUTTON = this.TranslateService.translate("INTERFACE_SAVE_BUTTON");
95 this.CREATE_BUTTON = this.TranslateService.translate("INTERFACE_CREATE_BUTTON");
96 this.DELETE_BUTTON = this.TranslateService.translate("INTERFACE_DELETE_BUTTON");
97 this.deleteText = (operationName) => this.TranslateService.translate("INTERFACE_DELETE_TEXT", {operationName});
102 // tslint:disable-next-line:max-classes-per-file
103 export class UIInterfaceModel extends InterfaceModel {
104 isCollapsed: boolean = false;
106 constructor(interfaceData?: any) {
107 super(interfaceData);
108 this.operations = _.map(
110 (operation) => new UIOperationModel(operation)
115 this.isCollapsed = !this.isCollapsed;
119 // tslint:disable-next-line:max-classes-per-file
121 selector: 'interface-definition',
122 templateUrl: './interface-definition.page.component.html',
123 styleUrls: ['interface-definition.page.component.less'],
124 providers: [ModalService, TranslateService]
127 export class InterfaceDefinitionComponent {
129 modalInstance: ComponentRef<ModalComponent>;
130 interfaces: UIInterfaceModel[];
131 inputs: Array<InputOperationParameter> = [];
133 properties: Array<PropertyParamRowComponent> = [];
134 deploymentArtifactsFilePath: Array<DropdownValue> = [];
136 toscaArtifactTypes: Array<DropdownValue> = [];
139 interfaceTypes: { [interfaceType: string]: string[] };
140 modalTranslation: ModalTranslation;
142 capabilities: CapabilitiesGroup;
144 @Input() component: IComponent;
145 @Input() readonly: boolean;
146 @Input() enableMenuItems: Function;
147 @Input() disableMenuItems: Function;
150 @Inject(SdcConfigToken) private sdcConfig: ISdcConfig,
151 @Inject("$state") private $state: ng.ui.IStateService,
152 private translateService: TranslateService,
153 private componentServiceNg2: ComponentServiceNg2,
154 private modalServiceNg2: ModalService,
155 private modalServiceSdcUI: SdcUiServices.ModalService,
156 private topologyTemplateService: TopologyTemplateService
158 this.modalTranslation = new ModalTranslation(translateService);
163 this.initInterfaceDefinition();
167 private cancelAndCloseModal = () => {
168 return this.modalServiceNg2.closeCurrentModal();
171 private enableOrDisableSaveButton = (): boolean => {
175 onSelectInterfaceOperation(interfaceModel: UIInterfaceModel, operation: InterfaceOperationModel) {
176 const cancelButton: ButtonModel = new ButtonModel(this.modalTranslation.CANCEL_BUTTON, 'outline white', this.cancelAndCloseModal);
177 const saveButton: ButtonModel = new ButtonModel(this.modalTranslation.SAVE_BUTTON, 'blue', () =>
178 null, this.enableOrDisableSaveButton);
179 const interfaceDataModal: ModalModel =
180 new ModalModel('l', this.modalTranslation.EDIT_TITLE, '', [saveButton, cancelButton], 'custom');
181 this.modalInstance = this.modalServiceNg2.createCustomModal(interfaceDataModal);
183 this.modalServiceNg2.addDynamicContentToModal(
185 InterfaceOperationHandlerComponent,
187 deploymentArtifactsFilePath: this.deploymentArtifactsFilePath,
188 toscaArtifactTypes: this.toscaArtifactTypes,
189 selectedInterface: interfaceModel,
190 selectedInterfaceOperation: operation,
191 validityChangedCallback: this.enableOrDisableSaveButton,
195 this.modalInstance.instance.open();
198 private initInterfaceDefinition() {
199 this.isLoading = true;
200 this.interfaces = [];
201 this.topologyTemplateService.getComponentInterfaceOperations(this.component.componentType, this.component.uniqueId)
202 .subscribe((response) => {
203 if (response.interfaces) {
204 this.interfaces = _.map(response.interfaces, (interfaceModel) => new UIInterfaceModel(interfaceModel));
206 this.isLoading = false;
210 collapseAll(value: boolean = true): void {
211 _.forEach(this.interfaces, (interfaceData) => {
212 interfaceData.isCollapsed = value;
216 isAllCollapsed(): boolean {
217 return _.every(this.interfaces, (interfaceData) => interfaceData.isCollapsed);
220 isAllExpanded(): boolean {
221 return _.every(this.interfaces, (interfaceData) => !interfaceData.isCollapsed);
224 isInterfaceListEmpty(): boolean {
225 return this.interfaces.length === 0;
228 isOperationListEmpty(): boolean {
229 return _.filter(this.interfaces, (interfaceData) =>
230 interfaceData.operations && interfaceData.operations.length > 0).length > 0;