Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-manager

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-manager - npm Package Compare versions

Comparing version 0.1.2 to 0.1.4

lib/search.js

8

example/app.js

@@ -14,3 +14,9 @@ var Admin = require('../lib/admin').Admin,

},
require('./models/Label').Label,
{
model: require('./models/Label').Label,
fields: [
'name',
'creationDate'
]
},
require('./models/Record').Record

@@ -17,0 +23,0 @@ ];

@@ -7,3 +7,15 @@ var mongoose = require('mongoose');

LabelSchema.virtual('creationDate').get(function () {
return this._id.getTimestamp();
});
LabelSchema.virtual('virtualAttr').get(function () {
return true;
});
LabelSchema.virtual('virtualAttr').set(function (value) {
console.log("Setting virtual attribute to " + value);
});
var Label = mongoose.model('Label', LabelSchema);
exports.Label = Label;

25

lib/admin.js

@@ -46,7 +46,18 @@ var express = require('express'),

Admin.prototype.getFields = function getFields(modelName, limit){
var fields = _.values(this.models[modelName].model.schema.paths);
fields = fields.map(function(field){
return field.path;
});
fields = _.without(fields, '_id', '__v');
var paths = this.models[modelName].model.schema.paths,
virtuals = this.models[modelName].model.schema.virtuals;
var fields = Object.keys(paths).map(function(k){
return paths[k].path;
}).filter(function(p){
return p != '_id' && p != '__v';
});
fields = fields.concat(Object.keys(virtuals).map(function(k){
return virtuals[k].path;
}).filter(function(p){
return p != 'id';
}));
if (limit) {

@@ -73,6 +84,2 @@ fields = fields.slice(0, Math.min(limit, fields.length));

app.use(express.session());
app.use(function(req, res, next){
res.locals.errors = {};
next();
});
app.use(require('../views/helpers').init(this));

@@ -79,0 +86,0 @@ app.use(app.router);

@@ -1,3 +0,4 @@

var async = require('async'),
utils = require('../utils');
var utils = require('../utils'),
_ = require('underscore'),
Search = require('../search').Search;

@@ -10,41 +11,11 @@ exports.init = function(admin){

function loadDocuments(req, res, next){
var pageSize = res.locals.pageSize = admin.options.pageSize,
model = res.locals.model = admin.getModel(req.params.model),
page = res.locals.page = parseInt(req.query.page, 10) || 1,
skip = res.locals.skip = (page - 1) * pageSize,
q = res.locals.q = req.query.q,
where = res.locals.where = req.query.where,
fields = res.locals.fields = admin.getListFields(req.params.model);
var model = res.locals.model = admin.getModel(req.params.model),
fields = res.locals.fields = admin.getListFields(req.params.model),
search = new Search(admin.options, model, fields, req.query);
try {
var parsed = JSON.parse(where || '{}');
} catch(e) {
res.locals.errors.where = 'Could not parse where clause. It must be valid JSON.';
return res.render('list');
}
async.parallel([
function(cb){
model.count(parsed, cb);
},
function(cb){
model.find(parsed).limit(pageSize).skip(skip).exec(function(err, documents){
if (err) return cb(err);
var fieldsToPopulate = fields.filter(function(f){
var field = utils.getField(model, f);
return field.options && 'ref' in field.options;
});
model.populate(documents, fieldsToPopulate, function(){
cb(err, documents);
});
});
}
], function(err, results){
search.execute(function(err){
if (err) return next(err);
res.render('list', {
documents : results[1],
count : results[0],
search: search,
actions: admin.getActions(req.params.model)

@@ -71,2 +42,1 @@ });

};

@@ -8,2 +8,6 @@ exports.url = function(req){

return document.schema.paths[fieldName] || document.schema.virtuals[fieldName];
};
exports.isVirtual = function(document, fieldName) {
return fieldName in document.schema.virtuals;
};
{
"name": "mongoose-manager",
"version": "0.1.2",
"version": "0.1.4",
"scripts": {

@@ -5,0 +5,0 @@ "example": "supervisor --force-watch -i public,views example/app.js"

@@ -34,2 +34,6 @@ $(function(){

}
$(document).on('click', '[href^="#advanced-search"]', function(){
return false;
});
});

@@ -1,2 +0,4 @@

var moment = require('moment');
var moment = require('moment'),
_ = require('underscore'),
ejs = require('ejs');

@@ -15,1 +17,31 @@ exports.empty = function(str) {

};
/**
* Creates the query string corresponding to the passed criteria.
*
* @param search the criteria to output the query string for.
* @returns {string}
*/
exports.queryString = function(search) {
var params = [];
_.each(search.criteria, function(value, key){
params.push(key + '=' + encodeURIComponent(value));
});
return '?' + params.join('&');
};
var inputTpl = ejs.compile('<input type="hidden" name="<%= key %>" value="<%= value %>">');
/**
* Creates the hidden inputs string corresponding to the passed criteria.
*
* @param search the criteria to output the hidden input fields for.
* @returns {string}
*/
exports.formInput = function(search) {
var inputs = [];
_.each(search.criteria, function(value, key){
inputs.push(inputTpl({key: key, value: value}));
});
return inputs.join('\n');
};

@@ -24,3 +24,12 @@ var moment = require('moment'),

res.locals.getField = require('../lib/utils').getField;
res.locals.isVirtual = require('../lib/utils').isVirtual;
res.locals.readOnly = function(model, fieldName){
if (!utils.isVirtual(model, fieldName)){
return false;
}
var field = utils.getField(model, fieldName);
return (!field.setters || !field.setters.length);
};
res.locals.req = req;

@@ -27,0 +36,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc