2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 import { IWorkspaceViewModelScope } from "app/view-models/workspace/workspace-view-model";
23 import { PropertyModel } from "app/models";
24 import { ModalsHandler } from "app/utils";
25 import { ComponentGenericResponse } from "../../../../ng2/services/responses/component-generic-response";
26 import { ComponentServiceNg2 } from "../../../../ng2/services/component-services/component.service";
27 import { SdcUiCommon, SdcUiServices, SdcUiComponents } from "onap-ui-angular";
29 interface IPropertiesViewModelScope extends IWorkspaceViewModelScope {
30 tableHeadersList:Array<any>;
33 filteredProperties:Array<PropertyModel>;
35 addOrUpdateProperty(property?:PropertyModel):void;
36 delete(property:PropertyModel):void;
37 sort(sortBy:string):void;
40 export class PropertiesViewModel {
46 'ComponentServiceNg2',
51 constructor(private $scope:IPropertiesViewModelScope,
52 private $filter:ng.IFilterService,
53 private ModalsHandler:ModalsHandler,
54 private ComponentServiceNg2:ComponentServiceNg2,
55 private modalService: SdcUiServices.ModalService) {
56 this.initComponentProperties();
59 private initComponentProperties = ():void => {
61 if(!this.$scope.component.properties) {
62 this.$scope.isLoading = true;
63 this.ComponentServiceNg2.getComponentProperties(this.$scope.component).subscribe((response:ComponentGenericResponse) => {
64 this.$scope.component.properties = response.properties;
66 this.$scope.isLoading = false;
68 this.$scope.isLoading = false;
75 private openEditPropertyModal = (property:PropertyModel):void => {
76 this.ModalsHandler.openEditPropertyModal(property, this.$scope.component, this.$scope.filteredProperties, false, 'component', this.$scope.component.uniqueId).then((updatedProperty:PropertyModel) => {
77 //property = updatedProperty;
81 private initScope = ():void => {
84 this.$scope.filteredProperties = this.$scope.component.properties;
85 this.$scope.sortBy = 'name';
86 this.$scope.reverse = false;
87 this.$scope.setValidState(true);
88 this.$scope.tableHeadersList = [
89 {title: 'Name', property: 'name'},
90 {title: 'Type', property: 'type'},
91 {title: 'Schema', property: 'schema.property.type'},
92 {title: 'Description', property: 'description'},
94 this.$scope.sort = (sortBy:string):void => {
95 this.$scope.reverse = (this.$scope.sortBy === sortBy) ? !this.$scope.reverse : false;
96 this.$scope.sortBy = sortBy;
100 this.$scope.addOrUpdateProperty = (property?:PropertyModel):void => {
101 this.openEditPropertyModal(property ? property : new PropertyModel());
104 this.$scope.delete = (property:PropertyModel):void => {
106 let onOk: Function = ():void => {
107 this.$scope.component.deleteProperty(property.uniqueId);
109 let title:string = this.$filter('translate')("PROPERTY_VIEW_DELETE_MODAL_TITLE");
110 let message:string = this.$filter('translate')("PROPERTY_VIEW_DELETE_MODAL_TEXT", "{'name': '" + property.name + "'}");
111 const okButton = {testId: "OK", text: "OK", type: SdcUiCommon.ButtonType.info, callback: onOk, closeModal: true} as SdcUiComponents.ModalButtonComponent;
112 this.modalService.openInfoModal(title, message, 'delete-modal', [okButton]);