nxus / admin

Admin screens for Nxus applications
1 stars 0 forks source link

Nxus 4 Approach #2

Closed mjreich closed 8 years ago

mjreich commented 8 years ago

@loppear writing this up to gut check approach with regards to re-use of nxus-web.

Features

admin.manage('my-model')

class MyModelAdmin extends AdminMVCModule {
  // Expects the same controller/templates structure as MVCModule
}
admin.page('My Page', '/my-page', ::this._adminPage)

admin.route('/my-route', ::this._adminRoute)

Questions

mjreich commented 8 years ago

Proposing a couple of API changes:

  1. Combine route/page:
//default partial version, wrapped in admin theme. Title is implicitly extracted from the last route segment using morph.
admin.page('/my-page', 'my-template-partial') 

//Specify opts, like title, menu.
admin.page('/my-page', {title: 'My Page Title', label: 'Menu Label'}, 'my-template-partial') 

//default handler version. If the return is a promise or a string, then the return is resolved rendered in the admin theme
admin.page('/my-page', () => {
  return template.render('my-template', opts)
})

//route version.  Next has to be explicitly called, or the res handled inside the handler.
admin.page('/my-route', {method: 'post'}, (req, res, next) => {
  //do something  
  res.redirect('/admin')
})
  1. Combine Actions?
loppear commented 8 years ago
  1. Approach: I expect AdminController to extend EditController, not MVCModule - these are model-specific.
    1. There might be a case for an AdminMVCModule as an alternative to admin.page(), but it feels like a mismatch still.
    2. Expect the same options object to be accepted by admin.manage() and new AdminController - upgrade to a class for custom model route handlers etc is just to move that options object to the constructor super() call.
    3. AdminController should mostly just need to set the routePrefix and templatePrefix and permissions-protected routes.
  2. Question responses:
    1. Class/instance actions are still to-do, still make sense for View/EditController to me.
    2. Not sure what theme support specifically is needed?
    3. N/A
    4. AdminController will have different routes (prefixed by adminBasePath as today), it's intended that you can have multiple View/Edit/AdminController subclasses for the same model.
  3. Routes & Pages - overall those changes look fine. I'm not sure about the handler version wrapping with the admin-template, and presumably that handler gets res/req?