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 * Created by rc2122 on 5/16/2017.
24 import * as _ from "lodash";
25 import {Component, Input, Output, EventEmitter, ViewChild} from '@angular/core';
26 import {ButtonModel, ButtonsModelMap, FilterPropertiesAssignmentData} from "app/models";
27 import * as sdcConfig from "../../../../../../configurations/dev"
28 import {PopoverComponent} from "../../ui/popover/popover.component";
31 selector: 'filter-properties-assignment',
32 templateUrl: './filter-properties-assignment.component.html',
33 styleUrls: ['./filter-properties-assignment.component.less']
36 export class FilterPropertiesAssignmentComponent {
37 @Input() componentType: string;
38 @Output() searchProperties: EventEmitter<FilterPropertiesAssignmentData> = new EventEmitter<FilterPropertiesAssignmentData>();
39 footerButtons:ButtonsModelMap = {};
40 typesOptions:Array<string>;//All optional types
41 selectedTypes:Object = {};
42 allSelected:boolean = false;//if all option selected
43 filterData:FilterPropertiesAssignmentData = new FilterPropertiesAssignmentData();
44 @ViewChild('filterPopover') filterPopover: PopoverComponent;
47 this.footerButtons['Apply'] = new ButtonModel('Apply', 'blue', this.search, this.someTypesSelectedAndThereIsPropertyName);
48 this.footerButtons['Close'] = new ButtonModel('Close', 'grey', this.close);
49 this.componentType = this.componentType.toLocaleLowerCase();
50 this.typesOptions = sdcConfig.resourceTypesFilter[this.componentType];
54 _.forEach(this.typesOptions, (type) => {
55 this.selectedTypes[type] = this.allSelected;
59 onTypeSelected = (type:string) => {
60 if(!this.selectedTypes[type]){
61 this.allSelected = false;//unselected 'All'
66 console.log('search props');
67 this.filterData.selectedTypes = [];
68 _.forEach(sdcConfig.resourceTypesFilter[this.componentType], (type) => {
69 if(this.selectedTypes[type]){
70 this.filterData.selectedTypes.push(type);
73 this.searchProperties.emit(this.filterData);
74 this.filterPopover.hide();
78 this.filterPopover.hide();
81 someTypesSelectedAndThereIsPropertyName = ():boolean => {
82 if( _.find(Object.keys(this.selectedTypes),(key) => {
83 return this.selectedTypes[key];
84 }) && this.filterData.propertyName ){
90 clearAll = ():void => {
91 this.filterData.propertyName = "";
92 _.forEach(this.selectedTypes,(value, key) => {
93 this.selectedTypes[key] = false;
95 this.allSelected = false;