Comparing version 0.0.13 to 0.0.14
@@ -129,3 +129,4 @@ /** | ||
res.locals.opts = this.opts; | ||
res.locals.schema = this._getSchema(); | ||
var entity = new this.Entity(); | ||
res.locals.schema = entity.getSchema(); | ||
res.locals.currentUser = req.user; | ||
@@ -140,26 +141,2 @@ // all template functions | ||
/** | ||
* Add fields required for the views to render properly. | ||
* | ||
* Render at first runtime and serve cached afterwards. | ||
* | ||
* @return {Object} An extended mongoose schema. | ||
*/ | ||
CrudCtrl.prototype._getSchema = function() { | ||
if (this._schemaViews) { | ||
return this._schemaViews; | ||
} | ||
var entity = new this.Entity(); | ||
var schemaViews = this._schemaViews = Object.create(entity.Model.schema.paths); | ||
__.forIn(schemaViews, function(schemaItem, path) { | ||
schemaViews[path]._viewData = { | ||
canShow: tplHelpers.canShow(schemaItem, this.opts), | ||
name: tplHelpers.getName(path, this.opts), | ||
}; | ||
}, this); | ||
return schemaViews; | ||
}; | ||
/** | ||
* Process incoming POST vars, we will: | ||
@@ -166,0 +143,0 @@ * * Remove all vars starting with underscore ( _ ). |
{ | ||
"name": "crude", | ||
"description": "Seamless CRUD control operations for node.", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"homepage": "https://github.com/talksession/node-crude", | ||
@@ -40,3 +40,4 @@ "author": { | ||
"middlewarify": "~0.0.4", | ||
"node-entity": "0.0.5" | ||
"node-entity": "0.0.7", | ||
"mschema": "~0.5.2" | ||
}, | ||
@@ -43,0 +44,0 @@ "devDependencies": { |
@@ -15,2 +15,4 @@ /** | ||
var val = item[paths.shift()]; | ||
// mongoose may have nested objects, take care of that | ||
if (0 < paths.length) { | ||
@@ -25,44 +27,11 @@ paths.forEach(function(p){ | ||
/** | ||
* Return a proper label for the path. | ||
* Return the string with the first char capitalized. | ||
* | ||
* @param {string} path The full path name. | ||
* @param {Object} opts The CRUD-controller options object. | ||
* @return {[type]} [description] | ||
* @param {string} name The string. | ||
* @return {string} Return the string with the first char capitalized. | ||
*/ | ||
tplHelpers.getName = function(path, opts) { | ||
var name; | ||
if (opts.expandPaths) { | ||
name = path; | ||
} else { | ||
name = path.split('.').pop(); | ||
} | ||
tplHelpers.capitaliseFirstChar = function(name) { | ||
return name.charAt(0).toUpperCase() + name.slice(1); | ||
}; | ||
/** | ||
* Determine if this schema item should be publicly displayed. | ||
* | ||
* @param {Object} schemaItem A single schema item (a column). | ||
* @param {Object} opts The CRUD-controller options object. | ||
* @return {boolean} true to show. | ||
*/ | ||
tplHelpers.canShow = function(schemaItem, opts) { | ||
// check for custom excluded paths | ||
if (opts.viewExcludePaths.length) { | ||
if (0 <= opts.viewExcludePaths.indexOf(schemaItem.path)) { | ||
return false; | ||
} | ||
} | ||
// check for private vars (starting with underscore) | ||
if ('_' === schemaItem.path.charAt(0)) { | ||
if (opts.showId && '_id' === schemaItem.path) { | ||
return true; | ||
} | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
}; | ||
tplHelpers.formAttrs = function() { | ||
@@ -69,0 +38,0 @@ return { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29496
9
735
+ Addedmschema@~0.5.2
+ Addedmschema@0.5.6(transitive)
+ Addednode-entity@0.0.7(transitive)
- Removednode-entity@0.0.5(transitive)
Updatednode-entity@0.0.7