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 {COMPONENT_FIELDS} from "../../../../utils/constants";
26 import {ComponentGenericResponse} from "../../../../ng2/services/responses/component-generic-response";
27 import {ComponentServiceNg2} from "../../../../ng2/services/component-services/component.service";
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 {
50 constructor(private $scope:IPropertiesViewModelScope,
51 private $filter:ng.IFilterService,
52 private ModalsHandler:ModalsHandler,
53 private ComponentServiceNg2:ComponentServiceNg2) {
54 this.initComponentProperties();
57 private initComponentProperties = ():void => {
59 if(!this.$scope.component.properties) {
60 this.$scope.isLoading = true;
61 this.ComponentServiceNg2.getComponentProperties(this.$scope.component).subscribe((response:ComponentGenericResponse) => {
62 this.$scope.component.properties = response.properties;
64 this.$scope.isLoading = false;
66 this.$scope.isLoading = false;
73 private openEditPropertyModal = (property:PropertyModel):void => {
74 this.ModalsHandler.openEditPropertyModal(property, this.$scope.component, this.$scope.filteredProperties, false, 'component', this.$scope.component.uniqueId).then((updatedProperty:PropertyModel) => {
75 //property = updatedProperty;
79 private initScope = ():void => {
82 this.$scope.filteredProperties = this.$scope.component.properties;
83 this.$scope.sortBy = 'name';
84 this.$scope.reverse = false;
85 this.$scope.setValidState(true);
86 this.$scope.tableHeadersList = [
87 {title: 'Name', property: 'name'},
88 {title: 'Type', property: 'type'},
89 {title: 'Schema', property: 'schema.property.type'},
90 {title: 'Description', property: 'description'},
92 this.$scope.sort = (sortBy:string):void => {
93 this.$scope.reverse = (this.$scope.sortBy === sortBy) ? !this.$scope.reverse : false;
94 this.$scope.sortBy = sortBy;
98 this.$scope.addOrUpdateProperty = (property?:PropertyModel):void => {
99 this.openEditPropertyModal(property ? property : new PropertyModel());
102 this.$scope.delete = (property:PropertyModel):void => {
104 let onOk = ():void => {
105 this.$scope.component.deleteProperty(property.uniqueId);
107 let title:string = this.$filter('translate')("PROPERTY_VIEW_DELETE_MODAL_TITLE");
108 let message:string = this.$filter('translate')("PROPERTY_VIEW_DELETE_MODAL_TEXT", "{'name': '" + property.name + "'}");
109 this.ModalsHandler.openConfirmationModal(title, message, false).then(onOk);