sails-hook-adminx
Advanced tools
Comparing version 0.1.1 to 0.1.2
/** | ||
* BackofficeController | ||
* AdminXController | ||
* | ||
* @description :: Server-side logic for managing users | ||
* @description :: Webhooks API for AdminX | ||
* @help :: See http://links.sailsjs.org/docs/controllers | ||
*/ | ||
var mergeWith = require('lodash.mergewith'); | ||
const numeral = require('numeral'); | ||
@@ -35,5 +36,6 @@ module.exports = { | ||
var search = req.param('search'); | ||
var sort = req.param('sort') || 'updatedAt desc'; | ||
var page = req.param('page') || 1; | ||
var limit = req.param('limit') || 10; | ||
var sort = req.param('sort'); | ||
var page = parseInt(req.param('page')) - 1 || 0; | ||
var limit = parseInt(req.param('limit')) || 10; | ||
sails.log('limit', limit); | ||
@@ -43,5 +45,10 @@ // Validation | ||
model.find() | ||
.where(prepareSearchWhere(schema, search)) | ||
.sort(sort) | ||
var criteria = {}; | ||
if(search) criteria.where = prepareSearchWhere(schema, search); | ||
if(sort) criteria.sort = sort; | ||
sails.log(criteria); | ||
model.find(criteria) | ||
// .where(prepareSearchWhere(schema, search)) | ||
// .sort(sort) | ||
.paginate(page, limit) | ||
@@ -194,16 +201,24 @@ .then(function (items) { | ||
var attrs = prepareSchemaAttributes(model); | ||
var where = { or: [] }; | ||
_.each(attrs, function (item, index) { | ||
// console.log(index); | ||
var type = item.type; | ||
var o = {}; | ||
// Make sure we don't search on dates | ||
if(type == 'number') { | ||
o[index] = query; | ||
where.or.push(o); | ||
} else if (type !== 'datetime') { | ||
o[index] = { contains: query }; | ||
where.or.push(o); | ||
} | ||
}); | ||
var where = {}; | ||
if (query && query.length > 0) { | ||
where.or = []; | ||
_.each(attrs, function (item, index) { | ||
// console.log(index); | ||
var type = item.type; | ||
var o = {}; | ||
// Make sure we don't search on dates | ||
/*if(type === 'number') { | ||
let number = numeral(query); | ||
if(!isNaN(number.value())) { | ||
o[index] = number.value(); | ||
where.or.push(o); | ||
} | ||
} else */ | ||
if (type !== 'datetime' && type !== 'number') { | ||
o[index] = { contains: query }; | ||
where.or.push(o); | ||
} | ||
}); | ||
} | ||
// console.log(where); | ||
@@ -210,0 +225,0 @@ return where; |
20
index.js
const adminxHeaderAuth = require('./api/policies/adminxHeaderAuth'); | ||
const adminxController = require('./api/controllers/AdminXController'); | ||
const adminxRoutes = require('./config/routes'); | ||
module.exports = function (sails) { | ||
// var loader = require('sails-util-mvcsloader')(sails); | ||
@@ -26,2 +26,4 @@ // Declare a var that will act as a reference to this hook. | ||
}, | ||
routes: adminxRoutes.routes | ||
//_hookTimeout: 20000 // wait 20 seconds before timing out | ||
@@ -53,3 +55,19 @@ }, | ||
sails.config.cors.allowRequestHeaders += ',' + headerName; | ||
} else { | ||
sails.log('No CORS configuration found in your project. AdminX needs to configure it.'); | ||
sails.log('AdminX can\'t modify sails.config.cors, you will have to configure CORS this manually.'); | ||
}*/ | ||
/* | ||
* | ||
*/ | ||
/*if(sails.config && sails.config.routes) { | ||
var key = '/adminx*'; | ||
// sails.config.routes[key] = _.merge(sails.config.routes[key], adminxRoutes.routes[key]); | ||
var routeCors = sails.config.routes[key].cors; | ||
if(routeCors) { | ||
} | ||
console.log(sails.config.routes[key]); | ||
}*/ | ||
}, | ||
@@ -56,0 +74,0 @@ |
{ | ||
"name": "sails-hook-adminx", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "AdminX hook for Sails.js. AdminX is a sleek admin panel that integrates with any database, without coding.", | ||
@@ -53,2 +53,3 @@ "keywords": [ | ||
"lodash.mergewith": "^4.6.0", | ||
"numeral": "^2.0.6", | ||
"sails-util-mvcsloader": "https://github.com/adminxhq/sails-util-mvcsloader" | ||
@@ -55,0 +56,0 @@ }, |
Sorry, the diff of this file is not supported yet
714
97484
3
14
+ Addednumeral@^2.0.6
+ Addednumeral@2.0.6(transitive)