2025-12-10 16:54:25 +03:30
|
|
|
import { Maybe } from '@/core';
|
2025-12-15 18:00:45 +03:30
|
|
|
import { Component, Input, model, signal } from '@angular/core';
|
2025-12-10 16:54:25 +03:30
|
|
|
import { FormControl } from '@angular/forms';
|
|
|
|
|
|
|
|
|
|
export interface ISelectItem {
|
|
|
|
|
id: number;
|
|
|
|
|
name: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'abstract-select-field',
|
|
|
|
|
template: '',
|
|
|
|
|
})
|
|
|
|
|
export abstract class AbstractSelectComponent<T = ISelectItem> {
|
2025-12-15 18:00:45 +03:30
|
|
|
@Input() control = new FormControl<Maybe<number | T>>(null);
|
2025-12-10 16:54:25 +03:30
|
|
|
@Input() canInsert: boolean = false;
|
|
|
|
|
@Input() showLabel: boolean = true;
|
|
|
|
|
@Input() showErrors: boolean = true;
|
|
|
|
|
@Input() isFullDataOptionValue: boolean = false;
|
|
|
|
|
@Input() optionValue = 'id';
|
|
|
|
|
|
|
|
|
|
loading = signal(false);
|
|
|
|
|
items = signal<Maybe<T[]>>(null);
|
|
|
|
|
isOpenFormDialog = signal(false);
|
2025-12-15 18:00:45 +03:30
|
|
|
value = model<Maybe<T>>(null);
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
if (this.value()) {
|
|
|
|
|
this.control.setValue(this.value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.control.valueChanges.subscribe((val) => {
|
|
|
|
|
this.value.set(val as Maybe<T>);
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-12-10 16:54:25 +03:30
|
|
|
|
|
|
|
|
abstract getData(): void;
|
|
|
|
|
|
|
|
|
|
refresh() {
|
|
|
|
|
this.getData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onOpenForm() {
|
2025-12-15 18:00:45 +03:30
|
|
|
this.isOpenFormDialog.set(true);
|
2025-12-10 16:54:25 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get selectOptionValue() {
|
|
|
|
|
if (this.isFullDataOptionValue) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
return this.optionValue;
|
|
|
|
|
}
|
|
|
|
|
}
|