2 * Created by rc2122 on 5/16/2017.
4 import {Component, Input, Output, EventEmitter, ViewChild} from '@angular/core';
5 import {ButtonModel, ButtonsModelMap, FilterPropertiesAssignmentData} from "app/models";
6 import {PopoverComponent} from "../popover/popover.component";
7 import * as sdcConfig from "../../../../../configurations/dev"
10 selector: 'filter-properties-assignment',
11 templateUrl: './filter-properties-assignment.component.html',
12 styleUrls: ['./filter-properties-assignment.component.less']
15 export class FilterPropertiesAssignmentComponent {
16 @Input() componentType: string;
17 @Output() searchProperties: EventEmitter<FilterPropertiesAssignmentData> = new EventEmitter<FilterPropertiesAssignmentData>();
18 footerButtons:ButtonsModelMap = {};
19 typesOptions:Array<string>;//All optional types
20 selectedTypes:Object = {};
21 allSelected:boolean = false;//if all option selected
22 filterData:FilterPropertiesAssignmentData = new FilterPropertiesAssignmentData();
23 @ViewChild('filterPopover') filterPopover: PopoverComponent;
26 this.footerButtons['Apply'] = new ButtonModel('Apply', 'blue', this.search, this.someTypesSelectedAndThereIsPropertyName);
27 this.footerButtons['Close'] = new ButtonModel('Close', 'grey', this.close);
28 this.componentType = this.componentType.toLocaleLowerCase();
29 this.typesOptions = sdcConfig.resourceTypesFilter[this.componentType];
33 _.forEach(this.typesOptions, (type) => {
34 this.selectedTypes[type] = this.allSelected;
38 onTypeSelected = (type:string) => {
39 if(!this.selectedTypes[type]){
40 this.allSelected = false;//unselected 'All'
45 console.log('search props');
46 this.filterData.selectedTypes = [];
47 _.forEach(sdcConfig.resourceTypesFilter[this.componentType], (type) => {
48 if(this.selectedTypes[type]){
49 this.filterData.selectedTypes.push(type);
52 this.searchProperties.emit(this.filterData);
53 this.filterPopover.hide();
57 this.filterPopover.hide();
60 someTypesSelectedAndThereIsPropertyName = ():boolean => {
61 if( _.find(Object.keys(this.selectedTypes),(key) => {
62 return this.selectedTypes[key];
63 }) && this.filterData.propertyName ){
69 clearAll = ():void => {
70 this.filterData.propertyName = "";
71 _.forEach(this.selectedTypes,(value, key) => {
72 this.selectedTypes[key] = false;
74 this.allSelected = false;