UNPKG

stackpress

Version:

Incept is a content management framework.

51 lines (50 loc) 1.81 kB
export default function AdminSearchPageFactory(model) { return async function AdminSearchPage(req, res, ctx) { if (res.body || (res.code && res.code !== 200)) { return; } const view = ctx.config.path('view', {}); const brand = ctx.config.path('brand', {}); const language = ctx.config.path('language', { key: 'locale', locale: 'en_US', languages: {} }); const admin = ctx.config.path('admin', {}); res.data.set('view', { base: view.base || '/', props: view.props || {} }); res.data.set('brand', { name: brand.name || 'Stackpress', logo: brand.logo || '/logo.png', icon: brand.icon || '/icon.png', favicon: brand.favicon || '/favicon.ico' }); res.data.set('language', { key: language.key || 'locale', locale: language.locale || 'en_US', languages: language.languages || {} }); res.data.set('admin', { name: admin.name || 'Admin', base: admin.base || '/admin', menu: admin.menu || [] }); let { q, filter, span, sort, skip, take, columns, } = req.data(); if (skip && !isNaN(Number(skip))) { skip = Number(skip); } if (take && !isNaN(Number(take))) { take = Number(take); } const response = await ctx.resolve(`${model.dash}-search`, { q, filter, span, sort, skip, take, columns }, res); if (res.code !== 200) { await ctx.emit('error', req, res); return; } const total = response.total; const rows = response.results; res.setRows(rows, total || rows.length); }; }