2022-04-04 10:06:34 +02:00
|
|
|
import {
|
|
|
|
AfterContentInit,
|
|
|
|
Component,
|
|
|
|
ContentChildren,
|
2022-04-07 17:17:52 +02:00
|
|
|
EventEmitter, HostListener,
|
2022-04-04 10:06:34 +02:00
|
|
|
Input,
|
|
|
|
OnDestroy,
|
|
|
|
Output,
|
|
|
|
QueryList
|
|
|
|
} from "@angular/core";
|
|
|
|
import {InputComponent} from "../input/input.component";
|
2022-04-15 23:49:35 +02:00
|
|
|
import {EntitiesSelectionComponent} from "../../searchPages/searchUtils/entitiesSelection.component";
|
2022-04-04 10:06:34 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'advanced-search-input',
|
|
|
|
template: `
|
2022-04-15 23:49:35 +02:00
|
|
|
<div *ngIf="inputs.length > 0" class="search-input" [class.dark]="dark" [ngClass]="searchInputClass" [class.small-vertical]="smallVertical">
|
2022-04-07 17:17:52 +02:00
|
|
|
<div class="uk-flex uk-flex-middle">
|
2022-04-04 10:06:34 +02:00
|
|
|
<div class="uk-width-expand">
|
2022-04-15 23:49:35 +02:00
|
|
|
<div class="uk-grid uk-grid-collapse inputs" [ngClass]="'uk-child-width-1-' + length" uk-grid>
|
2022-04-04 10:06:34 +02:00
|
|
|
<ng-content></ng-content>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="uk-width-auto">
|
2022-04-06 17:24:14 +02:00
|
|
|
<div class="search-icon" [class.disabled]="disabled" (click)="searchEmitter.emit()">
|
|
|
|
<icon name="search" [flex]="true" ratio="1.3"></icon>
|
2022-04-04 10:06:34 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
export class AdvancedSearchInputComponent implements AfterContentInit, OnDestroy {
|
2022-04-05 14:33:38 +02:00
|
|
|
@ContentChildren(InputComponent) inputs: QueryList<InputComponent>;
|
2022-04-15 23:49:35 +02:00
|
|
|
@ContentChildren(EntitiesSelectionComponent) entities: QueryList<EntitiesSelectionComponent>;
|
2022-04-04 10:06:34 +02:00
|
|
|
@Input() disabled: boolean = false;
|
2022-04-15 23:49:35 +02:00
|
|
|
@Input() searchInputClass: string = 'inner';
|
|
|
|
@Input() dark: boolean;
|
2022-04-06 17:24:14 +02:00
|
|
|
@Input() smallVertical: boolean = false;
|
2022-04-04 10:06:34 +02:00
|
|
|
@Output() searchEmitter: EventEmitter<void> = new EventEmitter<void>();
|
|
|
|
|
2022-04-07 17:17:52 +02:00
|
|
|
@HostListener('window:keydown', ['$event'])
|
|
|
|
keyEvent(event: KeyboardEvent) {
|
2022-04-15 23:49:35 +02:00
|
|
|
let input: InputComponent | EntitiesSelectionComponent = this.inputs.toArray().find(input => input.focused);
|
|
|
|
if(!input) {
|
|
|
|
input = this.entities.toArray().find(input => input.input.focused);
|
|
|
|
}
|
2022-04-08 14:47:03 +02:00
|
|
|
if(input) {
|
2022-04-07 17:17:52 +02:00
|
|
|
if(event.code === 'Enter') {
|
2022-04-15 23:49:35 +02:00
|
|
|
if(input instanceof EntitiesSelectionComponent) {
|
|
|
|
input.input.focus(false, event);
|
|
|
|
} else {
|
|
|
|
input.focus(false, event);
|
|
|
|
}
|
2022-04-07 17:17:52 +02:00
|
|
|
event.preventDefault();
|
|
|
|
this.searchEmitter.emit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-04 10:06:34 +02:00
|
|
|
constructor() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterContentInit() {
|
|
|
|
this.inputs.forEach(input => {
|
2022-04-06 17:24:14 +02:00
|
|
|
input.inputClass = 'advanced-search';
|
2022-04-04 10:06:34 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
}
|
2022-04-15 23:49:35 +02:00
|
|
|
|
|
|
|
get length() {
|
|
|
|
return this.inputs.length + this.entities.length;
|
|
|
|
}
|
2022-04-04 10:06:34 +02:00
|
|
|
}
|