UNPKG

stackpress

Version:

Incept is a content management framework.

46 lines (45 loc) 1.64 kB
export default function AdminCreatePageFactory(model) { return async function AdminCreatePage(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 || [] }); if (req.method === 'POST') { const response = await ctx.resolve(`${model.dash}-create`, req, res); if (res.code !== 200) { return; } const ids = model.ids.map(column => (response.results || {})[column.name]).filter(Boolean); const base = admin.base || '/admin'; res.redirect(`${base}/${model.dash}/detail/${ids.join('/')}`); } }; } ;