init
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { Maybe } from '@/core';
|
||||
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { Component, signal } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { IColumn } from '../components/pageDataList/page-data-list.component';
|
||||
|
||||
@Component({
|
||||
selector: 'abstract-list',
|
||||
template: '',
|
||||
})
|
||||
export abstract class AbstractList<ResponseModel, RequestParams = null> {
|
||||
columns = [] as IColumn[];
|
||||
loading = signal(false);
|
||||
items = signal<ResponseModel[]>([]);
|
||||
visibleForm = signal(false);
|
||||
requestPayload = signal<Maybe<RequestParams>>(null);
|
||||
selectedItemForEdit = signal<Maybe<ResponseModel>>(null);
|
||||
editMode = signal(false);
|
||||
|
||||
ngOnInit() {
|
||||
this.setColumns();
|
||||
this.getData();
|
||||
}
|
||||
|
||||
refresh() {
|
||||
this.getData();
|
||||
}
|
||||
|
||||
getData() {
|
||||
this.loading.set(true);
|
||||
this.getDataRequest(this.requestPayload())?.subscribe((res) => {
|
||||
this.loading.set(false);
|
||||
this.items.set(res.data);
|
||||
});
|
||||
}
|
||||
|
||||
openAddForm() {
|
||||
this.selectedItemForEdit.set(null);
|
||||
this.editMode.set(false);
|
||||
this.visibleForm.set(true);
|
||||
}
|
||||
|
||||
abstract getDataRequest(
|
||||
payload: Maybe<RequestParams>,
|
||||
): Observable<IPaginatedResponse<ResponseModel>> | void;
|
||||
|
||||
abstract setColumns(): void;
|
||||
|
||||
// constructor() {
|
||||
// if (this.editable) {
|
||||
// if (!this.ed) {
|
||||
// throw new Error('onEdit output must be bound when editable is true');
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
onEditClick(selectedItem: ResponseModel) {
|
||||
this.selectedItemForEdit.set(selectedItem);
|
||||
this.editMode.set(true);
|
||||
this.visibleForm.set(true);
|
||||
}
|
||||
onCloseEdit() {
|
||||
this.visibleForm.set(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user