45 lines
1021 B
TypeScript
45 lines
1021 B
TypeScript
|
|
import { Maybe } from '@/core';
|
||
|
|
import { Component, Input, signal } from '@angular/core';
|
||
|
|
import { FormControl } from '@angular/forms';
|
||
|
|
|
||
|
|
export interface ISelectItem {
|
||
|
|
id: number;
|
||
|
|
name: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Component({
|
||
|
|
selector: 'abstract-select-field',
|
||
|
|
template: '',
|
||
|
|
})
|
||
|
|
export abstract class AbstractSelectComponent<T = ISelectItem> {
|
||
|
|
@Input() control!: FormControl<Maybe<number | T>>;
|
||
|
|
@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);
|
||
|
|
|
||
|
|
abstract getData(): void;
|
||
|
|
// abstract getLabel(): string;
|
||
|
|
|
||
|
|
refresh() {
|
||
|
|
this.getData();
|
||
|
|
}
|
||
|
|
|
||
|
|
onOpenForm() {
|
||
|
|
// Override in subclass if needed
|
||
|
|
}
|
||
|
|
|
||
|
|
get selectOptionValue() {
|
||
|
|
if (!this.control) return undefined;
|
||
|
|
if (this.isFullDataOptionValue) {
|
||
|
|
return undefined;
|
||
|
|
}
|
||
|
|
return this.optionValue;
|
||
|
|
}
|
||
|
|
}
|