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-17 14:25:01 +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>
|
2023-02-20 15:59:07 +01:00
|
|
|
<div class="uk-width-auto filters-toggle">
|
|
|
|
<ng-content select="[filters-toggle]"></ng-content>
|
|
|
|
</div>
|
|
|
|
<div class="uk-width-auto" [class.uk-flex-first]="iconPosition === 'left'">
|
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>;
|
2023-02-20 15:59:07 +01:00
|
|
|
@Input() iconPosition: 'left' | 'right' = 'right';
|
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-17 14:25:01 +02:00
|
|
|
@HostListener('window:keydown.enter', ['$event'])
|
|
|
|
enter(event: KeyboardEvent) {
|
2022-04-19 01:09:42 +02:00
|
|
|
let input: InputComponent = this.inputs.toArray().find(input => input.focused && input.type !== 'select');
|
2022-04-17 14:25:01 +02:00
|
|
|
if (input) {
|
2022-04-19 01:09:42 +02:00
|
|
|
input.focus(false, event);
|
2022-04-17 14:25:01 +02:00
|
|
|
event.preventDefault();
|
|
|
|
this.searchEmitter.emit();
|
2022-04-07 17:17:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-04 10:06:34 +02:00
|
|
|
constructor() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterContentInit() {
|
2024-05-22 11:42:21 +02:00
|
|
|
this.init();
|
|
|
|
this.inputs.changes.subscribe(input => {
|
|
|
|
this.init();
|
2022-04-04 10:06:34 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
}
|
2024-05-22 11:42:21 +02:00
|
|
|
|
|
|
|
init() {
|
|
|
|
this.inputs.forEach(input => {
|
|
|
|
input.inputClass = 'advanced-search';
|
|
|
|
input.selectArrow = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-06-01 15:28:44 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|