mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
fix(types): Fix tipi model
This commit is contained in:
@@ -14,7 +14,6 @@ import type {
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
IModel,
|
IModel,
|
||||||
IndexedModel,
|
|
||||||
Model
|
Model
|
||||||
} from '../../Models';
|
} from '../../Models';
|
||||||
import type {
|
import type {
|
||||||
@@ -36,7 +35,7 @@ export type ColumnT = {
|
|||||||
id?: string
|
id?: string
|
||||||
title: string
|
title: string
|
||||||
type?: 'checkbox' | 'numeric'
|
type?: 'checkbox' | 'numeric'
|
||||||
valueModifier?: (instance: IModel<IndexedModel>, property: string) => any
|
valueModifier?: (instance: IModel, property: string) => any
|
||||||
};
|
};
|
||||||
export type SectionT = {
|
export type SectionT = {
|
||||||
id?: string
|
id?: string
|
||||||
@@ -49,7 +48,7 @@ export type SectionT = {
|
|||||||
| Record<string, TextFieldT | TextAreaT | SelectT>
|
| Record<string, TextFieldT | TextAreaT | SelectT>
|
||||||
};
|
};
|
||||||
export type ColumnsT = Record<string, string | ColumnT>;
|
export type ColumnsT = Record<string, string | ColumnT>;
|
||||||
export type RowsT = Collection<IModel<IndexedModel>>;
|
export type RowsT = Collection<IModel>;
|
||||||
export type SectionsT = Record<string, SectionT> | SectionT[];
|
export type SectionsT = Record<string, SectionT> | SectionT[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,7 +62,7 @@ export class RecordsPage extends Page {
|
|||||||
recordDialogMaxWidth: string | number = 'auto';
|
recordDialogMaxWidth: string | number = 'auto';
|
||||||
model: typeof Model;
|
model: typeof Model;
|
||||||
customSetter: (
|
customSetter: (
|
||||||
model: IModel<IndexedModel>,
|
model: IModel,
|
||||||
fields: Collection<File | string>
|
fields: Collection<File | string>
|
||||||
) => void;
|
) => void;
|
||||||
|
|
||||||
@@ -133,7 +132,7 @@ export class RecordsPage extends Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return this.rows
|
return this.rows
|
||||||
.map((instance: IModel<IndexedModel>, index: string) => (
|
.map((instance: IModel, index: string) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={index}
|
key={index}
|
||||||
data-model-id={instance.getId()}
|
data-model-id={instance.getId()}
|
||||||
@@ -154,7 +153,7 @@ export class RecordsPage extends Page {
|
|||||||
async updateRecord(id: number) {
|
async updateRecord(id: number) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const response = await this.model.find(id);
|
const response = await this.model.find(id);
|
||||||
const instance = response.getData() as IModel<IndexedModel>;
|
const instance = response.getData() as IModel;
|
||||||
const dialog = $('mwc-dialog#add-record-dialog');
|
const dialog = $('mwc-dialog#add-record-dialog');
|
||||||
|
|
||||||
dialog
|
dialog
|
||||||
@@ -334,7 +333,7 @@ export class RecordsPage extends Page {
|
|||||||
if (isFormValid(form)) {
|
if (isFormValid(form)) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
// eslint-disable-next-line new-cap
|
// eslint-disable-next-line new-cap
|
||||||
const instance = new this.model() as IModel<IndexedModel>;
|
const instance = new this.model() as IModel;
|
||||||
|
|
||||||
if (this.customSetter) {
|
if (this.customSetter) {
|
||||||
this.customSetter(instance, collect(getFormData(form)));
|
this.customSetter(instance, collect(getFormData(form)));
|
||||||
@@ -358,7 +357,7 @@ export class RecordsPage extends Page {
|
|||||||
if (dialogElement) {
|
if (dialogElement) {
|
||||||
(dialogElement as MWCDialog).close();
|
(dialogElement as MWCDialog).close();
|
||||||
}
|
}
|
||||||
this.rows.put((model as IndexedModel).getId(), model);
|
this.rows.put((model as Model).getId(), model);
|
||||||
m.redraw();
|
m.redraw();
|
||||||
await showSnackbar(__('Record salvato'), 4000);
|
await showSnackbar(__('Record salvato'), 4000);
|
||||||
}
|
}
|
||||||
@@ -369,7 +368,7 @@ export class RecordsPage extends Page {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getModelValue(model: IndexedModel, field: string): any {
|
getModelValue(model: IModel, field: string): any {
|
||||||
const column = this.columns[field];
|
const column = this.columns[field];
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
let value: any = model[field];
|
let value: any = model[field];
|
||||||
|
@@ -4,21 +4,18 @@ import {
|
|||||||
} from 'coloquent';
|
} from 'coloquent';
|
||||||
import {snakeCase} from 'lodash';
|
import {snakeCase} from 'lodash';
|
||||||
|
|
||||||
export interface IndexedModel extends Model {
|
export interface InstantiableModel<T extends Model> {
|
||||||
[prop: string]: any;
|
new (): Model | T;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InstantiableModel<T extends IndexedModel> {
|
export type IModel<T extends Model = Model> = InstanceType<InstantiableModel<T>>;
|
||||||
new (): T;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type IModel<T extends IndexedModel> = InstanceType<InstantiableModel<T>>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base model for all models.
|
* The base model for all models.
|
||||||
*/
|
*/
|
||||||
export abstract class Model extends BaseModel {
|
export abstract class Model extends BaseModel {
|
||||||
jsonApiType: string = '';
|
jsonApiType: string = '';
|
||||||
|
[prop: string]: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
Reference in New Issue
Block a user