2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2017 Huawei Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 import { Component, Input, Output, EventEmitter} from "@angular/core";
23 import {PropertyFEModel, DerivedFEProperty, InstanceFePropertiesMap} from "app/models";
24 import {PropertiesService} from "../../../services/properties.service";
25 import {ModalService} from "../../../services/modal.service";
26 import { InstanceFeDetails } from "../../../../models/instance-fe-details";
29 selector: 'properties-table',
30 templateUrl: './properties-table.component.html',
31 styleUrls: ['./properties-table.component.less']
33 export class PropertiesTableComponent {
35 @Input() fePropertiesMap: InstanceFePropertiesMap;
36 @Input() feInstanceNamesMap: Map<string, InstanceFeDetails>;
37 @Input() selectedPropertyId: string;
38 @Input() propertyNameSearchText:string;
39 @Input() searchTerm:string;
40 @Input() readonly:boolean;
41 @Input() isLoading:boolean;
42 @Input() hasDeclareOption:boolean;
43 @Input() hidePropertyType:boolean;
44 @Input() showDelete:boolean;
46 @Output('propertyChanged') emitter: EventEmitter<PropertyFEModel> = new EventEmitter<PropertyFEModel>();
47 @Output() selectPropertyRow: EventEmitter<PropertyRowSelectedEvent> = new EventEmitter<PropertyRowSelectedEvent>();
48 @Output() updateCheckedPropertyCount: EventEmitter<boolean> = new EventEmitter<boolean>();//only for hasDeclareOption and hasDeclareListOption
49 @Output() updateCheckedChildPropertyCount: EventEmitter<boolean> = new EventEmitter<boolean>();//only for hasDeclareListOption
50 @Output() deleteProperty: EventEmitter<PropertyFEModel> = new EventEmitter<PropertyFEModel>();
51 private selectedPropertyToDelete: PropertyFEModel;
59 this.reverse = (this.sortBy === sortBy) ? !this.reverse : true;
60 this.direction = this.reverse ? 1 : -1;
62 this.path = sortBy.split('.');
65 constructor (private propertiesService:PropertiesService, private modalService: ModalService){
71 onPropertyChanged = (property) => {
72 this.emitter.emit(property);
75 // Click on main row (row of propertyFEModel)
76 onClickPropertyRow = (property:PropertyFEModel, instanceName:string, event?) => {
77 //event && event.stopPropagation();
78 this.selectedPropertyId = property.name;
79 let propertyRowSelectedEvent:PropertyRowSelectedEvent = new PropertyRowSelectedEvent(property, instanceName);
80 this.selectPropertyRow.emit(propertyRowSelectedEvent);
83 // Click on inner row (row of DerivedFEProperty)
84 onClickPropertyInnerRow = (property:DerivedFEProperty, instanceName:string) => {
85 let propertyRowSelectedEvent:PropertyRowSelectedEvent = new PropertyRowSelectedEvent(property, instanceName);
86 this.selectPropertyRow.emit(propertyRowSelectedEvent);
89 propertyChecked = (prop: PropertyFEModel, childPropName?: string) => {
90 let isChecked: boolean = (!childPropName)? prop.isSelected : prop.flattenedChildren.find(prop => prop.propertiesName == childPropName).isSelected;
93 this.propertiesService.undoDisableRelatedProperties(prop, childPropName);
95 this.propertiesService.disableRelatedProperties(prop, childPropName);
97 this.updateCheckedPropertyCount.emit(isChecked);
100 let isCount: boolean = (isChecked)? true : false ;
101 this.updateCheckedChildPropertyCount.emit(isCount);
105 onDeleteProperty = () => {
106 this.deleteProperty.emit(this.selectedPropertyToDelete);
107 this.modalService.closeCurrentModal();
110 openDeleteModal = (property:PropertyFEModel) => {
111 this.selectedPropertyToDelete = property;
112 this.modalService.createActionModal("Delete Property", "Are you sure you want to delete this property?",
113 "Delete", this.onDeleteProperty, "Close").instance.open();
118 export class PropertyRowSelectedEvent {
119 propertyModel:PropertyFEModel | DerivedFEProperty;
121 constructor ( propertyModel:PropertyFEModel | DerivedFEProperty, instanceName:string ){
122 this.propertyModel = propertyModel;
123 this.instanceName = instanceName;