mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
feat: ✨ Retrieve automatico dei model in una select
This commit is contained in:
@@ -507,7 +507,15 @@ export class RecordsPage extends Page {
|
|||||||
// (temporary) .first((s) => field.id in s.fields);
|
// (temporary) .first((s) => field.id in s.fields);
|
||||||
.filter((s) => field.id in s.fields)
|
.filter((s) => field.id in s.fields)
|
||||||
.first();
|
.first();
|
||||||
let {options} = section.fields[field.id] as SelectT;
|
|
||||||
|
const select = section.fields[field.id] as SelectT;
|
||||||
|
let {options} = select;
|
||||||
|
const {model, labelAttribute} = select;
|
||||||
|
|
||||||
|
if (model && labelAttribute) {
|
||||||
|
options = this.getModelSelectOptions(model, labelAttribute);
|
||||||
|
}
|
||||||
|
|
||||||
if (options instanceof Promise) {
|
if (options instanceof Promise) {
|
||||||
options = await options;
|
options = await options;
|
||||||
}
|
}
|
||||||
@@ -541,7 +549,10 @@ export class RecordsPage extends Page {
|
|||||||
return list.join('');
|
return list.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
async getModelSelectOptions(model: typeof Model, labelAttribute: string): Promise<SelectOptionsT> {
|
async getModelSelectOptions(
|
||||||
|
model: typeof Model,
|
||||||
|
labelAttribute: string
|
||||||
|
): Promise<SelectOptionsT> {
|
||||||
const response = await model.all();
|
const response = await model.all();
|
||||||
const categories = response.getData();
|
const categories = response.getData();
|
||||||
|
|
||||||
|
@@ -6,6 +6,7 @@ import {
|
|||||||
} from '@material/mwc-textfield';
|
} from '@material/mwc-textfield';
|
||||||
|
|
||||||
import {MaterialIcons} from './icons';
|
import {MaterialIcons} from './icons';
|
||||||
|
import {Model} from '../Models';
|
||||||
|
|
||||||
export interface FieldT {
|
export interface FieldT {
|
||||||
id?: string
|
id?: string
|
||||||
@@ -85,5 +86,7 @@ export type SelectT = FieldT & {
|
|||||||
selected?: ListItemBase | null
|
selected?: ListItemBase | null
|
||||||
items?: ListItemBase[]
|
items?: ListItemBase[]
|
||||||
index?: number
|
index?: number
|
||||||
options?: SelectOptionsT | Promise<SelectOptionsT>
|
options?: SelectOptionsT | Promise<SelectOptionsT>,
|
||||||
|
model?: typeof Model,
|
||||||
|
labelAttribute?: string
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user