const app = require('../../app')
const { undoIcon} = require('../../assets')
/**
* @param {CrudPagesOptions} opts
*/
const list = (opts) => {
const defaultHeader = column => html`
${column.titleName} | `
const defaultCell = column => html`{{${raw(opts.camelName)}.${raw(column.camelName)}}} | `
console.log(`crud: app${opts.pascalPlural}TrashPage`)
app.component(`app${opts.pascalPlural}TrashPage`, {
template: html`
${opts.columns.filter(c => c.inList).map(c => c.header || defaultHeader(c))}
| Actions |
${opts.columns.filter(c => c.inList).map(c => c.cell || defaultCell(c))}
|
Undelete
|
`,
controllerAs: 'ctrl',
controller: function(api, $mdToast, $location, util, $routeParams) {
this.apiPrefix = util.fillPath(opts.apiPrefix, $routeParams)
this.appPrefix = util.fillPath(opts.appPrefix, $routeParams)
const crud = api.crud(this.apiPrefix)
this.selected = []
this.data = []
this.getRecords = () => {
this.promise = crud.trash().then(data => {
this.data = data
})
}
this.undelete = async rec => {
try {
await crud.undelete(rec.id)
$mdToast.showSimple(`${opts.titleName} undeleted.`)
$location.url(this.appPrefix)
} catch (err) {
console.error(err)
$mdToast.showSimple(`Could not undelete ${opts.titleName}: ${err.message || err}`)
}
}
this.getRecords()
}
})
}
module.exports = list