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, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
23 import { DerivedFEProperty, InstanceFePropertiesMap, PropertyFEModel } from 'app/models';
24 import { InstanceFeDetails } from '../../../../models/instance-fe-details';
25 import { PropertiesService } from '../../../services/properties.service';
26 import { ModalService } from '../../../services/modal.service';
29 selector: 'properties-table',
30 templateUrl: './properties-table.component.html',
31 styleUrls: ['./properties-table.component.less']
33 export class PropertiesTableComponent implements OnChanges {
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
49 @Output() updateCheckedChildPropertyCount: EventEmitter<boolean> = new EventEmitter<boolean>();//only for hasDeclareListOption
50 @Output() deleteProperty: EventEmitter<PropertyFEModel> = new EventEmitter<PropertyFEModel>();
51 private selectedPropertyToDelete: PropertyFEModel;
58 readonly ascUpperLettersFirst = 1;
59 readonly descLowerLettersFirst = -1;
61 constructor(private propertiesService: PropertiesService, private modalService: ModalService ) {
64 ngOnChanges(changes: SimpleChanges): void {
65 if (changes.fePropertiesMap) {
72 this.reverse = (this.sortBy === sortBy) ? !this.reverse : true;
73 this.direction = this.reverse ? this.ascUpperLettersFirst : this.descLowerLettersFirst;
75 this.path = sortBy.split('.');
78 onPropertyChanged = (property) => {
79 this.emitter.emit(property);
82 // Click on main row (row of propertyFEModel)
83 onClickPropertyRow = (property: PropertyFEModel, instanceName: string, event?) => {
84 // event && event.stopPropagation();
85 this.selectedPropertyId = property.name;
86 const propertyRowSelectedEvent: PropertyRowSelectedEvent = new PropertyRowSelectedEvent(property, instanceName);
87 this.selectPropertyRow.emit(propertyRowSelectedEvent);
90 // Click on inner row (row of DerivedFEProperty)
91 onClickPropertyInnerRow = (property: DerivedFEProperty, instanceName: string) => {
92 const propertyRowSelectedEvent: PropertyRowSelectedEvent = new PropertyRowSelectedEvent(property, instanceName);
93 this.selectPropertyRow.emit(propertyRowSelectedEvent);
96 propertyChecked = (prop: PropertyFEModel, childPropName?: string) => {
97 const isChecked: boolean = (!childPropName) ? prop.isSelected : prop.flattenedChildren.find((prop) => prop.propertiesName == childPropName).isSelected;
100 this.propertiesService.undoDisableRelatedProperties(prop, childPropName);
102 this.propertiesService.disableRelatedProperties(prop, childPropName);
104 this.updateCheckedPropertyCount.emit(isChecked);
107 let isCount: boolean = (isChecked)? true : false ;
108 this.updateCheckedChildPropertyCount.emit(isCount);
112 onDeleteProperty = () => {
113 this.deleteProperty.emit(this.selectedPropertyToDelete);
114 this.modalService.closeCurrentModal();
117 openDeleteModal = (property:PropertyFEModel) => {
118 this.selectedPropertyToDelete = property;
119 this.modalService.createActionModal("Delete Property", "Are you sure you want to delete this property?",
120 "Delete", this.onDeleteProperty, "Close").instance.open();
125 export class PropertyRowSelectedEvent {
126 propertyModel: PropertyFEModel | DerivedFEProperty;
127 instanceName: string;
128 constructor( propertyModel: PropertyFEModel | DerivedFEProperty, instanceName: string ) {
129 this.propertyModel = propertyModel;
130 this.instanceName = instanceName;