import { AfterContentInit, Component, ContentChildren, EventEmitter, HostListener, Input, OnDestroy, Output, QueryList } from "@angular/core"; import {InputComponent} from "../input/input.component"; import {EntitiesSelectionComponent} from "../../searchPages/searchUtils/entitiesSelection.component"; @Component({ selector: 'advanced-search-input', template: `
` }) export class AdvancedSearchInputComponent implements AfterContentInit, OnDestroy { @ContentChildren(InputComponent) inputs: QueryList; @ContentChildren(EntitiesSelectionComponent) entities: QueryList; @Input() iconPosition: 'left' | 'right' = 'right'; @Input() disabled: boolean = false; @Input() searchInputClass: string = 'inner'; @Input() dark: boolean; @Input() smallVertical: boolean = false; @Output() searchEmitter: EventEmitter = new EventEmitter(); @HostListener('window:keydown.enter', ['$event']) enter(event: KeyboardEvent) { let input: InputComponent = this.inputs.toArray().find(input => input.focused && input.type !== 'select'); if (input) { input.focus(false, event); event.preventDefault(); this.searchEmitter.emit(); } } constructor() { } ngAfterContentInit() { this.init(); this.inputs.changes.subscribe(input => { this.init(); }); } ngOnDestroy() { } init() { this.inputs.forEach(input => { input.inputClass = 'advanced-search'; }); } focusNext(input: InputComponent | EntitiesSelectionComponent, event: any = null) { if(!event || !event.init) { setTimeout(() => { if(input instanceof InputComponent) { input.focus(true); } else { input.input.focus(true); } }, 100); } } get length() { return this.inputs.length + this.entities.length; } }