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