43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
// list-data.ts - definition and methods of the List component
|
|
|
|
export function List(name: string, conf: any): object {
|
|
const domain = conf.domain || this.conf.domain
|
|
const comp = {
|
|
state: {
|
|
id: this.conf.itemid,
|
|
mode: 'view'
|
|
},
|
|
name: name, // also used as class of incoming/outgoing message
|
|
action: conf.action, // (default) action of outgoing message
|
|
domain: domain, // domain of incoming/outgoing message
|
|
data: [], // model = list of rows
|
|
meta: {}, // metadata (params) for each field (table column)
|
|
handle, // handle incoming messages
|
|
initField // initialize field (= @mounted)
|
|
}
|
|
this.components[name] = comp
|
|
this.sendMsg([domain, 'query', name], {})
|
|
return comp
|
|
}
|
|
|
|
// Data methods
|
|
|
|
function handle(domain, action, class_, item: string, payload) {
|
|
if (action == 'list') {
|
|
const rows = payload.split('\n')
|
|
this.data.length = 0
|
|
for (const row of rows) {
|
|
this.data.push(JSON.parse(row))
|
|
}
|
|
console.log('data: ', this.data)
|
|
}
|
|
}
|
|
|
|
function initField(name: string, meta: any) {
|
|
if (meta.defexpr) {
|
|
meta.default = eval(meta.defexpr)
|
|
}
|
|
this.data[name] = meta.default || ""
|
|
this.meta[name] = meta
|
|
}
|
|
|