2022-01-06 15:45:35 +01:00
|
|
|
import '@maicol07/mwc-layout-grid';
|
|
|
|
import '@material/mwc-dialog';
|
|
|
|
import '@material/mwc-fab';
|
|
|
|
import '@material/mwc-snackbar';
|
|
|
|
|
|
|
|
import type {Dialog as MWCDialog} from '@material/mwc-dialog';
|
|
|
|
import type {Cash} from 'cash-dom';
|
|
|
|
import collect, {type Collection} from 'collect.js';
|
2022-01-26 11:43:14 +01:00
|
|
|
import {
|
|
|
|
ToManyRelation,
|
|
|
|
ToOneRelation
|
|
|
|
} from 'coloquent';
|
2022-01-27 10:10:45 +01:00
|
|
|
import {capitalize} from 'lodash-es';
|
2022-01-06 15:45:35 +01:00
|
|
|
import type {
|
|
|
|
Children,
|
|
|
|
Vnode,
|
|
|
|
VnodeDOM
|
|
|
|
} from 'mithril';
|
2022-01-18 20:52:22 +01:00
|
|
|
import {sync as render} from 'mithril-node-render';
|
2022-01-06 15:45:35 +01:00
|
|
|
|
2022-01-07 14:22:14 +01:00
|
|
|
import {
|
|
|
|
IModel,
|
2022-01-26 11:43:14 +01:00
|
|
|
InstantiableModel,
|
2022-01-07 14:22:14 +01:00
|
|
|
Model
|
|
|
|
} from '../../Models';
|
2022-01-06 15:45:35 +01:00
|
|
|
import type {
|
|
|
|
FieldT,
|
|
|
|
SelectT,
|
|
|
|
TextAreaT,
|
|
|
|
TextFieldT
|
2022-01-26 16:24:20 +01:00
|
|
|
} from '../../typings';
|
2022-01-26 11:43:14 +01:00
|
|
|
import {
|
|
|
|
getFormData,
|
|
|
|
isFormValid,
|
|
|
|
showSnackbar
|
|
|
|
} from '../../utils';
|
2022-01-06 15:45:35 +01:00
|
|
|
import DataTable from '../DataTable/DataTable';
|
|
|
|
import TableCell from '../DataTable/TableCell';
|
|
|
|
import TableColumn from '../DataTable/TableColumn';
|
|
|
|
import TableRow from '../DataTable/TableRow';
|
|
|
|
import LoadingButton from '../LoadingButton';
|
|
|
|
import Mdi from '../Mdi';
|
|
|
|
import Page from '../Page';
|
|
|
|
|
|
|
|
export type ColumnT = {
|
|
|
|
id?: string
|
|
|
|
title: string
|
|
|
|
type?: 'checkbox' | 'numeric'
|
2022-01-27 10:08:23 +01:00
|
|
|
valueModifier?: (value: any, field: string, model: IModel) => any
|
2022-01-06 15:45:35 +01:00
|
|
|
};
|
|
|
|
export type SectionT = {
|
|
|
|
heading?: string
|
|
|
|
columns?: number
|
2022-01-24 15:39:41 +01:00
|
|
|
fields: Record<string, TextFieldT | TextAreaT | SelectT>
|
2022-01-06 15:45:35 +01:00
|
|
|
};
|
|
|
|
export type ColumnsT = Record<string, string | ColumnT>;
|
2022-01-07 16:04:50 +01:00
|
|
|
export type RowsT = Collection<IModel>;
|
2022-01-24 15:39:41 +01:00
|
|
|
export type SectionsT = Record<string, SectionT>;
|
2022-01-06 15:45:35 +01:00
|
|
|
|
2022-01-26 16:24:20 +01:00
|
|
|
const FIELDS: string = 'text-field, text-area, material-select';
|
|
|
|
|
2022-01-06 15:45:35 +01:00
|
|
|
/**
|
|
|
|
* @abstract
|
|
|
|
*/
|
|
|
|
export class RecordsPage extends Page {
|
|
|
|
columns: ColumnsT;
|
|
|
|
rows: RowsT = collect({});
|
|
|
|
sections: SectionsT;
|
|
|
|
dialogs: Children[];
|
|
|
|
recordDialogMaxWidth: string | number = 'auto';
|
|
|
|
model: typeof Model;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* What fields should take precedence when saving the record
|
|
|
|
*/
|
|
|
|
fieldsPrecedence: string[] = [];
|
|
|
|
|
|
|
|
async oninit(vnode: Vnode) {
|
|
|
|
super.oninit(vnode);
|
2022-01-10 16:01:09 +01:00
|
|
|
// @ts-ignore
|
|
|
|
const response = await this.model.with(this.model.relationships).get();
|
2022-01-06 15:45:35 +01:00
|
|
|
const data = response.getData() as Model[];
|
|
|
|
|
|
|
|
if (data.length > 0) {
|
|
|
|
for (const record of data) {
|
|
|
|
this.rows.put(record.getId(), record);
|
|
|
|
}
|
|
|
|
|
|
|
|
m.redraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onupdate(vnode: VnodeDOM) {
|
|
|
|
const rows: Cash = $('.mdc-data-table__row[data-model-id]');
|
|
|
|
|
|
|
|
if (rows.length > 0) {
|
|
|
|
rows.on('click', async (event: PointerEvent) => {
|
|
|
|
const cell = event.target as HTMLElement;
|
|
|
|
if (cell.tagName === 'MWC-CHECKBOX') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await this.updateRecord($(cell).parent('tr').data('model-id') as number);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tableColumns(): JSX.Element[] {
|
|
|
|
return collect(this.columns)
|
|
|
|
// @ts-ignore
|
|
|
|
.map((column: ColumnT | string, id: string) => (
|
|
|
|
<TableColumn
|
|
|
|
id={id}
|
|
|
|
key={id}
|
|
|
|
{...(typeof column === 'object' ? column : {})}
|
|
|
|
sortable
|
|
|
|
filterable
|
|
|
|
>
|
|
|
|
{typeof column === 'string' ? column : column.title}
|
|
|
|
</TableColumn>
|
|
|
|
))
|
|
|
|
.toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
tableRows(): Children {
|
|
|
|
if (this.rows.isEmpty()) {
|
|
|
|
return (
|
|
|
|
<TableRow key="no-data">
|
|
|
|
<TableCell
|
|
|
|
colspan={collect(this.columns).count()}
|
|
|
|
style="text-align: center;"
|
|
|
|
>
|
|
|
|
{__('Non sono presenti dati')}
|
|
|
|
</TableCell>
|
|
|
|
</TableRow>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.rows
|
2022-01-07 16:04:50 +01:00
|
|
|
.map((instance: IModel, index: string) => (
|
2022-01-06 15:45:35 +01:00
|
|
|
<TableRow
|
|
|
|
key={index}
|
|
|
|
data-model-id={instance.getId()}
|
|
|
|
style="cursor: pointer"
|
|
|
|
>
|
|
|
|
{collect(this.columns)
|
|
|
|
.map((column, index_: string) => (
|
|
|
|
<TableCell key={index_}>
|
2022-01-27 11:25:15 +01:00
|
|
|
{this.getModelValue(instance, (column as ColumnT).id ?? index_, true)}
|
2022-01-06 15:45:35 +01:00
|
|
|
</TableCell>
|
|
|
|
))
|
|
|
|
.toArray()}
|
|
|
|
</TableRow>
|
|
|
|
))
|
|
|
|
.toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateRecord(id: number) {
|
|
|
|
// @ts-ignore
|
2022-01-10 16:01:09 +01:00
|
|
|
const response = await this.model.with(this.model.relationships).find(id);
|
2022-01-07 16:04:50 +01:00
|
|
|
const instance = response.getData() as IModel;
|
2022-01-26 22:12:03 +01:00
|
|
|
const dialog: MWCDialog | null = document.querySelector('mwc-dialog#add-record-dialog');
|
2022-01-06 15:45:35 +01:00
|
|
|
|
2022-01-26 22:12:03 +01:00
|
|
|
if (dialog) {
|
|
|
|
for (const field of dialog.querySelectorAll(FIELDS)) {
|
|
|
|
const value = this.getModelValue(instance, field.id) as string;
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
field.innerHTML = await this.getFieldBody(field as HTMLFormElement, value);
|
2022-01-06 15:45:35 +01:00
|
|
|
|
2022-01-26 22:12:03 +01:00
|
|
|
(field as HTMLInputElement).value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(dialog)
|
|
|
|
.find('mwc-button#delete-button')
|
|
|
|
.show()
|
|
|
|
.on('click', () => {
|
|
|
|
const confirmDialog = $('mwc-dialog#confirm-delete-record-dialog');
|
|
|
|
const confirmButton = confirmDialog.find('mwc-button#confirm-button');
|
|
|
|
const loading: Cash = confirmButton.find('mwc-circular-progress');
|
|
|
|
confirmButton.on('click', async () => {
|
|
|
|
loading.show();
|
|
|
|
await instance.delete();
|
|
|
|
// noinspection JSUnresolvedVariable
|
|
|
|
this.rows.forget(instance.getId());
|
|
|
|
m.redraw();
|
|
|
|
await showSnackbar(__('Record eliminato!'), 4000);
|
|
|
|
});
|
|
|
|
loading.hide();
|
|
|
|
(confirmDialog.get(0) as MWCDialog).show();
|
2022-01-06 15:45:35 +01:00
|
|
|
});
|
2022-01-26 22:12:03 +01:00
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
}
|
2022-01-06 15:45:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
recordDialog() {
|
|
|
|
return (
|
|
|
|
<mwc-dialog
|
|
|
|
id="add-record-dialog"
|
|
|
|
className="record-dialog"
|
|
|
|
heading={__('Aggiungi nuovo record')}
|
|
|
|
// @ts-ignore
|
|
|
|
style={`--mdc-dialog-max-width: ${this.recordDialogMaxWidth}`}
|
|
|
|
>
|
|
|
|
<form>
|
|
|
|
<text-field
|
|
|
|
id="id"
|
|
|
|
name="id"
|
|
|
|
// @ts-ignore
|
|
|
|
style="display: none;"
|
|
|
|
data-default-value=""
|
|
|
|
/>
|
|
|
|
{(() => {
|
|
|
|
const sections = collect(this.sections);
|
|
|
|
return sections
|
2022-01-24 15:39:41 +01:00
|
|
|
.map((section, id: string) => (
|
2022-01-06 15:45:35 +01:00
|
|
|
<>
|
2022-01-24 15:39:41 +01:00
|
|
|
<div id={id}>
|
2022-01-06 15:45:35 +01:00
|
|
|
<h4 class="mdc-typography--overline">{section.heading}</h4>
|
|
|
|
<mwc-layout-grid>
|
|
|
|
{(() => {
|
|
|
|
const fields = collect(section.fields);
|
|
|
|
return fields
|
|
|
|
.map((field: TextFieldT | TextAreaT | SelectT, fieldIndex: string) => (
|
|
|
|
<mwc-layout-grid-cell
|
|
|
|
key={fieldIndex}
|
|
|
|
span={12 / (section.columns ?? 3)}
|
|
|
|
>
|
|
|
|
{m(
|
|
|
|
(field.elementType)
|
|
|
|
?? this.getElementFromType(field.type as string),
|
|
|
|
{
|
|
|
|
...field,
|
|
|
|
id: field.id ?? fieldIndex,
|
|
|
|
name: field.name ?? field.id ?? fieldIndex,
|
|
|
|
'data-default-value':
|
|
|
|
field.value ?? (field as SelectT).selected ?? ''
|
2022-01-18 20:52:22 +01:00
|
|
|
}
|
2022-01-06 15:45:35 +01:00
|
|
|
)}
|
|
|
|
</mwc-layout-grid-cell>
|
|
|
|
))
|
|
|
|
.toArray();
|
|
|
|
})()}
|
|
|
|
</mwc-layout-grid>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
))
|
|
|
|
.toArray();
|
|
|
|
})()}
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<LoadingButton
|
|
|
|
type="submit"
|
|
|
|
slot="primaryAction"
|
|
|
|
label={__('Conferma')}
|
|
|
|
/>
|
|
|
|
<mwc-button slot="secondaryAction" dialogAction="cancel">
|
|
|
|
{__('Annulla')}
|
|
|
|
</mwc-button>
|
|
|
|
<mwc-button
|
|
|
|
id="delete-button"
|
|
|
|
slot="secondaryAction"
|
|
|
|
label={__('Elimina')}
|
|
|
|
style="--mdc-theme-primary: var(--mdc-theme-error, red); float: left; display: none;"
|
|
|
|
>
|
|
|
|
<Mdi icon="delete-outline" slot="icon" />
|
|
|
|
</mwc-button>
|
|
|
|
</mwc-dialog>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteRecordDialog(): Children {
|
|
|
|
return (
|
|
|
|
<mwc-dialog id="confirm-delete-record-dialog">
|
|
|
|
<p>{__('Sei sicuro di voler eliminare questo record?')}</p>
|
|
|
|
<LoadingButton
|
|
|
|
id="confirm-button"
|
|
|
|
slot="primaryAction"
|
|
|
|
label={__('Sì')}
|
|
|
|
/>
|
|
|
|
<mwc-button
|
|
|
|
slot="secondaryAction"
|
|
|
|
dialogAction="discard"
|
|
|
|
label={__('No')}
|
|
|
|
/>
|
|
|
|
</mwc-dialog>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
view(vnode: Vnode) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<h2>{this.title}</h2>
|
|
|
|
<DataTable checkable paginated>
|
|
|
|
{this.tableColumns()}
|
|
|
|
{this.tableRows()}
|
|
|
|
</DataTable>
|
|
|
|
|
|
|
|
<mwc-fab id="add-record" label={__('Aggiungi')} className="sticky">
|
|
|
|
<Mdi icon="plus" slot="icon" />
|
|
|
|
</mwc-fab>
|
|
|
|
{this.recordDialog()}
|
|
|
|
{this.deleteRecordDialog()}
|
|
|
|
{this.dialogs}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
oncreate(vnode: VnodeDOM) {
|
|
|
|
super.oncreate(vnode);
|
|
|
|
|
|
|
|
const fab: Cash = $('mwc-fab#add-record');
|
|
|
|
const dialog: Cash = fab.next('mwc-dialog#add-record-dialog');
|
|
|
|
const form: Cash = dialog.find('form');
|
|
|
|
|
|
|
|
// Open "New record" dialog
|
2022-01-25 19:53:44 +01:00
|
|
|
fab.on('click', this.openNewRecordDialog.bind(this, form, dialog));
|
2022-01-06 15:45:35 +01:00
|
|
|
|
|
|
|
const button = dialog.find('mwc-button[type="submit"]');
|
2022-01-25 19:53:44 +01:00
|
|
|
button.on('click', () => form.trigger('submit'));
|
|
|
|
form.on('submit', this.submitForm.bind(this, button, dialog, form));
|
|
|
|
}
|
2022-01-06 15:45:35 +01:00
|
|
|
|
2022-01-25 19:53:44 +01:00
|
|
|
openNewRecordDialog(form: Cash, dialog: Cash) {
|
|
|
|
form
|
2022-01-26 16:24:20 +01:00
|
|
|
// eslint-disable-next-line unicorn/no-array-callback-reference
|
|
|
|
.find(FIELDS)
|
2022-01-25 19:53:44 +01:00
|
|
|
.each(async (index, field) => {
|
|
|
|
field.innerHTML = await this.getFieldBody(field as HTMLFormElement);
|
|
|
|
(field as HTMLInputElement).value = $(field)
|
|
|
|
.data('default-value') as string;
|
|
|
|
});
|
|
|
|
dialog.find('mwc-button[type="submit"] mwc-circular-progress').hide();
|
|
|
|
dialog.find('mwc-button#delete-button').hide();
|
|
|
|
const dialogElement: HTMLElement & Partial<MWCDialog> | undefined = dialog.get(0);
|
|
|
|
if (dialogElement) {
|
|
|
|
(dialogElement as MWCDialog).show();
|
|
|
|
}
|
|
|
|
}
|
2022-01-06 15:45:35 +01:00
|
|
|
|
2022-01-25 19:53:44 +01:00
|
|
|
async submitForm(button: Cash, dialog: Cash, form: Cash, event: SubmitEvent) {
|
|
|
|
event.preventDefault();
|
|
|
|
const loading: Cash = button.find('mwc-circular-progress');
|
|
|
|
loading.show();
|
2022-01-06 15:45:35 +01:00
|
|
|
|
2022-01-25 19:53:44 +01:00
|
|
|
if (isFormValid(form)) {
|
|
|
|
const data = collect(getFormData(form));
|
|
|
|
// @ts-ignore
|
|
|
|
const instance = this.rows.get(data.get('id'), new this.model() as IModel) as IModel;
|
2022-01-10 17:07:00 +01:00
|
|
|
|
2022-01-25 19:53:44 +01:00
|
|
|
const modelId = await this.setter(instance, data);
|
2022-01-06 15:45:35 +01:00
|
|
|
|
2022-01-25 19:53:44 +01:00
|
|
|
if (modelId) {
|
|
|
|
// @ts-ignore
|
|
|
|
const newResponse = await this.model.with(this.model.relationships)
|
|
|
|
.find(modelId);
|
|
|
|
const model = newResponse.getData() as IModel;
|
2022-01-10 17:07:00 +01:00
|
|
|
|
2022-01-25 19:53:44 +01:00
|
|
|
const dialogElement = dialog.get(0);
|
|
|
|
if (dialogElement) {
|
|
|
|
(dialogElement as MWCDialog).close();
|
2022-01-06 15:45:35 +01:00
|
|
|
}
|
2022-01-25 19:53:44 +01:00
|
|
|
|
|
|
|
this.rows.put(model.getId(), model);
|
2022-01-06 15:45:35 +01:00
|
|
|
loading.hide();
|
2022-01-25 19:53:44 +01:00
|
|
|
m.redraw();
|
|
|
|
await showSnackbar(__('Record salvato'), 4000);
|
2022-01-06 15:45:35 +01:00
|
|
|
}
|
2022-01-25 19:53:44 +01:00
|
|
|
} else {
|
|
|
|
loading.hide();
|
|
|
|
await showSnackbar(__('Campi non validi. Controlla i dati inseriti'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async setter(model: IModel, data: Collection<File | string>) {
|
2022-01-26 12:31:39 +01:00
|
|
|
const firstFields = data.only(this.fieldsPrecedence);
|
|
|
|
const fields = data.except(this.fieldsPrecedence);
|
|
|
|
|
|
|
|
firstFields.each((currentItem, key) => {
|
|
|
|
fields.put(key, currentItem);
|
|
|
|
});
|
2022-01-25 19:53:44 +01:00
|
|
|
|
2022-01-26 11:43:14 +01:00
|
|
|
const relations: Record<string, IModel> = {};
|
|
|
|
|
2022-01-26 12:31:39 +01:00
|
|
|
data.each((value, field) => {
|
|
|
|
if (typeof field === 'string' && field.includes(':')) {
|
2022-01-26 11:43:14 +01:00
|
|
|
const [relation, fieldName] = field.split(':');
|
2022-01-26 17:36:56 +01:00
|
|
|
const relationModel = this.getRelation(model, relation, true);
|
|
|
|
if (relationModel) {
|
|
|
|
relationModel[fieldName] = value;
|
|
|
|
relations[relation] = relationModel;
|
|
|
|
}
|
2022-01-26 11:43:14 +01:00
|
|
|
} else {
|
2022-01-26 12:31:39 +01:00
|
|
|
model[field as string] = value;
|
2022-01-26 11:43:14 +01:00
|
|
|
}
|
2022-01-06 15:45:35 +01:00
|
|
|
});
|
2022-01-25 19:53:44 +01:00
|
|
|
|
2022-01-26 11:43:14 +01:00
|
|
|
// Save relations
|
|
|
|
for (const [relation, relatedModel] of Object.entries(relations)) {
|
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
const response = await relatedModel.save();
|
|
|
|
if (response.getModelId) {
|
|
|
|
model.setRelation(relation, response.getModelId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-25 19:53:44 +01:00
|
|
|
const response = await model.save();
|
|
|
|
return response.getModelId();
|
2022-01-06 15:45:35 +01:00
|
|
|
}
|
|
|
|
|
2022-01-26 15:38:44 +01:00
|
|
|
getRelation(model: IModel, relation: string, createIfNotExists = false) {
|
|
|
|
const relationModel = (model[`get${capitalize(relation)}`] as Function)() as IModel;
|
2022-01-26 11:43:14 +01:00
|
|
|
if (relationModel) {
|
|
|
|
return relationModel;
|
|
|
|
}
|
|
|
|
|
2022-01-26 20:20:56 +01:00
|
|
|
const relationship = (model[relation] as Function)() as
|
|
|
|
ToOneRelation<IModel> | ToManyRelation<IModel>;
|
2022-01-26 15:38:44 +01:00
|
|
|
const RelationshipModel = relationship.getType() as InstantiableModel;
|
|
|
|
return createIfNotExists ? new RelationshipModel() : undefined;
|
2022-01-26 11:43:14 +01:00
|
|
|
}
|
|
|
|
|
2022-01-27 11:25:15 +01:00
|
|
|
getModelValue(model: IModel, field: string, useValueModifier = false, raw = false): any {
|
2022-01-06 15:45:35 +01:00
|
|
|
const column = this.columns[field];
|
2022-01-26 15:38:44 +01:00
|
|
|
let value: unknown;
|
|
|
|
if (field.includes(':')) {
|
|
|
|
const [relation, fieldName] = field.split(':');
|
|
|
|
const relationModel = this.getRelation(model, relation);
|
|
|
|
value = relationModel?.[fieldName];
|
|
|
|
} else {
|
|
|
|
value = model[field];
|
|
|
|
}
|
2022-01-06 15:45:35 +01:00
|
|
|
|
2022-01-27 11:25:15 +01:00
|
|
|
if (useValueModifier && typeof column === 'object' && column.valueModifier) {
|
2022-01-27 10:08:23 +01:00
|
|
|
value = column.valueModifier(value, field, model);
|
2022-01-06 15:45:35 +01:00
|
|
|
}
|
|
|
|
|
2022-01-10 17:07:00 +01:00
|
|
|
return (value || raw) ? value : '';
|
2022-01-06 15:45:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getElementFromType(type: string) {
|
|
|
|
switch (type) {
|
|
|
|
case 'text':
|
|
|
|
return 'text-field';
|
|
|
|
|
|
|
|
case 'textarea':
|
|
|
|
return 'text-area';
|
|
|
|
|
|
|
|
case 'select':
|
|
|
|
return 'material-select';
|
|
|
|
|
|
|
|
/* Case 'checkbox':
|
|
|
|
case 'radio':
|
|
|
|
return Radio; */
|
|
|
|
default:
|
|
|
|
return 'text-field';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-26 22:12:03 +01:00
|
|
|
async getFieldBody(field: HTMLFormElement & FieldT, value?: string) {
|
2022-01-06 15:45:35 +01:00
|
|
|
const list = [];
|
|
|
|
|
2022-01-18 20:52:22 +01:00
|
|
|
switch (field.type ?? field.getAttribute('type')) {
|
2022-01-26 16:24:20 +01:00
|
|
|
case 'select': {
|
|
|
|
const section = collect(this.sections)
|
2022-01-26 19:54:28 +01:00
|
|
|
// (temporary) .first((s) => field.id in s.fields);
|
|
|
|
.filter((s) => field.id in s.fields)
|
|
|
|
.first();
|
2022-01-24 15:39:41 +01:00
|
|
|
let {options} = section.fields[field.id] as SelectT;
|
2022-01-18 20:52:22 +01:00
|
|
|
if (options instanceof Promise) {
|
|
|
|
options = await options;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options) {
|
|
|
|
for (const option of options) {
|
|
|
|
list.push(render(
|
2022-01-26 22:12:03 +01:00
|
|
|
<mwc-list-item key={option.value} value={option.value}
|
|
|
|
selected={option.value === value} activated={option.value === value}>
|
2022-01-18 20:52:22 +01:00
|
|
|
{option.label}
|
|
|
|
</mwc-list-item>
|
|
|
|
));
|
|
|
|
}
|
2022-01-06 15:45:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2022-01-26 16:24:20 +01:00
|
|
|
}
|
2022-01-06 15:45:35 +01:00
|
|
|
case 'checkbox':
|
|
|
|
return '';
|
|
|
|
case 'radio':
|
|
|
|
return '';
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
2022-01-26 16:24:20 +01:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
|
|
const {icon} = field;
|
2022-01-26 20:23:16 +01:00
|
|
|
if (icon) {
|
2022-01-26 16:24:20 +01:00
|
|
|
list.push(render(<Mdi icon={icon} slot="icon"/>));
|
2022-01-06 15:45:35 +01:00
|
|
|
}
|
|
|
|
|
2022-01-18 20:52:22 +01:00
|
|
|
return list.join('');
|
2022-01-06 15:45:35 +01:00
|
|
|
}
|
|
|
|
}
|