|
|
@@ -19,6 +19,7 @@
|
|
|
import {Component, OnInit, OnDestroy, Input, ViewChild, ElementRef, forwardRef} from '@angular/core';
|
|
|
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
|
|
|
import {Subject} from 'rxjs/Subject';
|
|
|
+import {CommonEntry} from '@app/models/common-entry.model';
|
|
|
import {UtilsService} from '@app/services/utils.service';
|
|
|
|
|
|
@Component({
|
|
|
@@ -48,6 +49,7 @@ export class SearchBoxComponent implements OnInit, OnDestroy, ControlValueAccess
|
|
|
this.parameterInput.addEventListener('blur', this.onParameterInputBlur);
|
|
|
this.valueInput.addEventListener('blur', this.onValueInputBlur);
|
|
|
this.parameterNameChangeSubject.subscribe(this.onParameterNameChange);
|
|
|
+ this.parameterAddSubject.subscribe(this.onParameterAdd);
|
|
|
}
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
@@ -57,6 +59,7 @@ export class SearchBoxComponent implements OnInit, OnDestroy, ControlValueAccess
|
|
|
this.parameterInput.removeEventListener('blur', this.onParameterInputBlur);
|
|
|
this.valueInput.removeEventListener('blur', this.onValueInputBlur);
|
|
|
this.parameterNameChangeSubject.unsubscribe();
|
|
|
+ this.parameterAddSubject.unsubscribe();
|
|
|
}
|
|
|
|
|
|
private currentId: number = 0;
|
|
|
@@ -74,22 +77,25 @@ export class SearchBoxComponent implements OnInit, OnDestroy, ControlValueAccess
|
|
|
currentValue: string;
|
|
|
|
|
|
@Input()
|
|
|
- items: any[] = [];
|
|
|
+ items: CommonEntry[] = [];
|
|
|
|
|
|
@Input()
|
|
|
parameterNameChangeSubject: Subject<any> = this.defaultSubject;
|
|
|
|
|
|
+ @Input()
|
|
|
+ parameterAddSubject: Subject<any> = this.defaultSubject;
|
|
|
+
|
|
|
@ViewChild('parameterInput')
|
|
|
parameterInputRef: ElementRef;
|
|
|
|
|
|
@ViewChild('valueInput')
|
|
|
valueInputRef: ElementRef;
|
|
|
|
|
|
- rootElement: HTMLElement;
|
|
|
+ private rootElement: HTMLElement;
|
|
|
|
|
|
- parameterInput: HTMLElement;
|
|
|
+ private parameterInput: HTMLElement;
|
|
|
|
|
|
- valueInput: HTMLElement;
|
|
|
+ private valueInput: HTMLElement;
|
|
|
|
|
|
activeItem?: any;
|
|
|
|
|
|
@@ -127,13 +133,17 @@ export class SearchBoxComponent implements OnInit, OnDestroy, ControlValueAccess
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ private getItem(name: string): CommonEntry {
|
|
|
+ return this.items.find(field => field.value === name);
|
|
|
+ }
|
|
|
+
|
|
|
clear(): void {
|
|
|
this.isActive = false;
|
|
|
this.activeItem = null;
|
|
|
this.currentValue = null;
|
|
|
}
|
|
|
|
|
|
- itemsListFormatter(item: any): string {
|
|
|
+ itemsListFormatter(item: CommonEntry): string {
|
|
|
return item.name;
|
|
|
}
|
|
|
|
|
|
@@ -142,8 +152,7 @@ export class SearchBoxComponent implements OnInit, OnDestroy, ControlValueAccess
|
|
|
}
|
|
|
|
|
|
onParameterNameChange = (options: any): void => {
|
|
|
- this.activeItem = typeof options.item === 'string' ?
|
|
|
- this.items.find(field => field.value === options.item) : options.item;
|
|
|
+ this.activeItem = typeof options.item === 'string' ? this.getItem(options.item) : options.item;
|
|
|
this.isExclude = options.isExclude;
|
|
|
this.isActive = true;
|
|
|
this.isParameterInput = false;
|
|
|
@@ -168,6 +177,18 @@ export class SearchBoxComponent implements OnInit, OnDestroy, ControlValueAccess
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ onParameterAdd = (options: any): void => {
|
|
|
+ const item = this.getItem(options.name);
|
|
|
+ this.parameters.push({
|
|
|
+ id: this.currentId++,
|
|
|
+ name: options.name,
|
|
|
+ label: item.name,
|
|
|
+ value: options.value,
|
|
|
+ isExclude: options.isExclude
|
|
|
+ });
|
|
|
+ this.updateValue();
|
|
|
+ }
|
|
|
+
|
|
|
removeParameter(event: MouseEvent, id: number): void {
|
|
|
this.parameters = this.parameters.filter(parameter => parameter.id !== id);
|
|
|
this.updateValue();
|