import '@material/mwc-dialog'; import '@material/mwc-fab'; import collect from 'collect.js'; import {Children} from 'mithril'; import {Model} from '../../Models'; import DataTable from '../DataTable/DataTable.jsx'; import TableBody from '../DataTable/TableBody.jsx'; import TableCell from '../DataTable/TableCell.jsx'; import TableHead from '../DataTable/TableHead.jsx'; import TableHeadCell from '../DataTable/TableHeadCell.jsx'; import TableHeadRow from '../DataTable/TableHeadRow.jsx'; import TableRow from '../DataTable/TableRow.jsx'; import Mdi from '../Mdi.jsx'; import Page from '../Page.jsx'; export type ColumnT = { id?: string, title: string, type?: 'checkbox' | 'numeric' } /** * @abstract */ export default class RecordsPage extends Page { columns: {[string]: [string]} | {[string]: ColumnT} | ColumnT[]; rows: string[][] = []; dialogs: Children[]; model: Model; tableColumns(): Children { return collect(this.columns) .map( (column: ColumnT | string, id: string) => ( {typeof column === 'string' ? column : column.title} ) ) .toArray(); } tableRows(): Children { if (this.rows.length === 0) { return ( {this.__('Non sono presenti dati')} ); } return this.rows.map((row, index) => ( {row.map((cell, index_) => {cell})} )); } view(vnode) { return ( <>

{this.title}

{this.tableColumns()} {this.tableRows()} {this.dialogs} ); } oncreate(vnode) { super.oncreate(vnode); $('mwc-fab#add-record') .on('click', function () { $(this) .next('mwc-dialog#add-record-dialog') .get(0) .open(); }); } }