Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.DS_Store
._.DS_Store
._*
lib

# Logs
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ specific method documentation for each public view function.
## Overriding templates

See also the `ViewController` templates documentation.
Assuming your `opts.prefix`/`opts.templatePrefix` is `my-module`, the following templates are registered with default implementations:
Assuming your `opts.prefix`/`opts.templatePrefix` is `my-module`, the following templates are registered with default implementations:

- `my-module-create`
- `my-module-edit`
Expand Down
68 changes: 37 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "nxus-web",
"version": "4.1.13",
"version": "4.2.0-2",
"description": "Base theme, template, and MVC support for Nxus applications",
"main": "lib",
"scripts": {
"preversion": "npm test",
"postversion": "npm run build-docs && git push && git push --tags",
"test": "NODE_ENV=test mocha --compilers js:babel-core/register -R spec src/test/*.js src/modules/**/test/*.js",
"compile": "rm -rf lib/; babel src --out-dir lib --ignore src/modules/web-theme-default/assets; cp -r src/modules/web-theme-default/assets lib/modules/web-theme-default/; cp -r src/modules/web-theme-default/partials lib/modules/web-theme-default/; cp -r src/modules/web-theme-default/layouts lib/modules/web-theme-default/; npm run copyTemplates",
"compile": "rm -rf lib/; babel src --out-dir lib --ignore src/modules/web-theme-default/assets; cp -r src/modules/web-theme-default/assets lib/modules/web-theme-default/; cp -r src/modules/web-theme-default/partials lib/modules/web-theme-default/; cp -r src/modules/web-theme-default/layouts lib/modules/web-theme-default/; cp -r src/assets lib; npm run copyTemplates",
"copyTemplates": "cp -r src/templates lib/; for each in `ls src/modules/`; do if [ -d src/modules/$each/templates ]; then cp -r src/modules/$each/templates lib/modules/$each; fi; done;",
"prepublish": "npm run compile",
"postpublish": "npm run build-docs && npm run publish-docs",
Expand Down
41 changes: 24 additions & 17 deletions src/EditController.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ViewController from './ViewController'

/**
* A base class for CRUD routes and templates for a model
*
*
* # Parameters
* See Controller docs
*
Expand All @@ -19,17 +19,17 @@ import ViewController from './ViewController'
* * `redirectAfterCreate` - path suffix to routePrefix after route
* * `redirectAfterEdit` - path suffix to routePrefix after route
* * `redirectAfterDelete` - path suffix to routePrefix after route
*
*
*
*
* # Implement Routes
*
*
* The default implementation of the routes handles querying for the
* model instance, pagination, and the template rendering. See the
* specific method documentation for each public view function.
*
*
* # Overriding templates
* See also the `ViewController` templates documentation.
* Assuming your `opts.prefix`/`opts.templatePrefix` is `my-module`, the following templates are registered with default implementations:
* Assuming your `opts.prefix`/`opts.templatePrefix` is `my-module`, the following templates are registered with default implementations:
* * `my-module-create`
* * `my-module-edit`
*
Expand All @@ -40,7 +40,7 @@ class EditController extends ViewController {
super(options)

this.routeDetail = '/edit'

let routePrefix = this.routePrefix
router.route(routePrefix+"/create", ::this._create)
router.route(routePrefix+"/edit/:id", ::this._edit)
Expand All @@ -53,7 +53,6 @@ class EditController extends ViewController {
this.redirectAfterCreate = options.redirectAfterCreate || ""
this.redirectAfterEdit = options.redirectAfterEdit || ""
this.redirectAfterDelete = options.redirectAfterDelete || ""

// Yes, these should be __dirname not local to the subclass
// Subclass templates are expected to be loaded by MVCModule or manually?
templater.default().template(__dirname+"/templates/web-controller-form.ejs", this.pageTemplate, this.templatePrefix+"-create")
Expand All @@ -70,7 +69,7 @@ class EditController extends ViewController {
_.each(params, (val, key) => { route = route.replace(":" + key, val) })
return route
}

/*
* Override to modify the routes used for redirects, links.
* Useful to replace extra route `:params` in `this.routePrefix`.
Expand All @@ -85,7 +84,7 @@ class EditController extends ViewController {
routeForRequest(req, route, inst) {
return route
}

defaultContext(req, related=false) {
return super.defaultContext(req, related).then((ret) => {
ret.instanceUrl = this.routeForRequest(req, this.routePrefix+this.routeDetail)
Expand All @@ -111,7 +110,11 @@ class EditController extends ViewController {
return this.edit(req, res, finder).then((context) => {
return Object.assign(defaultContext, context)
})
}).then((context) => {
}).then(async (context) => {
let templates = await templater.getTemplates()
context.checkTemplate = (template) => {
return templates["web-form-input-"+template]
}
return templater.render(this.templatePrefix+"-edit", context).then(::res.send)
})
}
Expand All @@ -136,8 +139,12 @@ class EditController extends ViewController {
return Promise.all([
this.create(req, res, {}),
this.defaultContext(req, true)
]).spread((context, defaultContext) => {
]).spread(async (context, defaultContext) => {
context = Object.assign(defaultContext, context)
let templates = await templater.getTemplates()
context.checkTemplate = (template) => {
return templates["web-form-input-"+template]
}
return templater.render(this.templatePrefix+"-create", context).then(::res.send)
})
}
Expand All @@ -149,7 +156,7 @@ class EditController extends ViewController {
* @param {object} object An empty object for setting defaults for the template
* @returns {object} The context for template rendering.
*/

create(req, res, object) {
return {title: "Create " + this.displayName, object}
}
Expand Down Expand Up @@ -202,7 +209,7 @@ class EditController extends ViewController {
return inst
}


/**
* Override to perform custom remove logic
* @param {id} id ID to remove
Expand Down Expand Up @@ -237,7 +244,7 @@ class EditController extends ViewController {
this.log.error(e.toString())
req.flash('error', "Error saving "+this.displayName+": "+e)
}

if (this.redirect) {
res.redirect(this.routeForRequest(req,
this.routePrefix + (id ? this.redirectAfterEdit : this.redirectAfterCreate),
Expand Down Expand Up @@ -267,7 +274,7 @@ class EditController extends ViewController {
return [values, relatedValues]
})
}

async remove(req, res) {
let inst
try {
Expand All @@ -282,7 +289,7 @@ class EditController extends ViewController {
this.routePrefix + this.redirectAfterDelete,
inst))
}
}
}
}

export default EditController
2 changes: 2 additions & 0 deletions src/assets/datetimepicker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
node_modules
7 changes: 7 additions & 0 deletions src/assets/datetimepicker/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- "8"
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start
Loading