const app = require('../../app')
const {editIcon, createIcon} = require('../../assets')
const list = ({
typeName,
typePlural,
camelName,
camelPlural,
paramName,
paramPlural,
apiPrefix,
appPrefix,
columns
}) => {
const defaultHeader = column => html`
${column.fieldName} | `
const defaultCell = column => html`{{${raw(camelName)}.${raw(column.camelName)}}} | `
app.component(`app${typePlural}Page`, {
template: html`
${typePlural}
${columns.map(c => c.header || defaultHeader(c))}
| Actions |
${columns.map(c => c.cell || defaultCell(c))}
|
Edit
|
`,
controllerAs: 'ctrl',
controller: function(api) {
const crud = api.crud(apiPrefix)
this.selected = []
this.data = []
this.getRecords = () => {
this.promise = crud.list().then(data => {
this.data = data
})
}
this.getRecords()
}
})
}
module.exports = list