sails-hook-adminx
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -18,5 +18,6 @@ /** | ||
_.each(sails.models, function (item, index) { | ||
if (!item.meta.junctionTable) { //TODO: is this the best way to know if a model is a junctionTable? | ||
if (!item.meta.junctionTable && index !== 'archive') { //TODO: is this the best way to know if a model is a junctionTable? | ||
var schema = { | ||
key: index, | ||
primaryKey: item.primaryKey, | ||
name: prepareSchemaName(item, index), | ||
@@ -39,5 +40,10 @@ attrs: prepareSchemaAttributes(item), | ||
var page = parseInt(req.param('page')) - 1 || 0; | ||
var limit = parseInt(req.param('limit')) || 10; | ||
sails.log('limit', limit); | ||
var limit = parseInt(req.param('limit')) || sails.config.adminx.defaults.listLimit || 10; | ||
sails.log.verbose('sails-hook-adminx:', 'schema', schema); | ||
sails.log.verbose('sails-hook-adminx:', 'search', search); | ||
sails.log.verbose('sails-hook-adminx:', 'sort', sort); | ||
sails.log.verbose('sails-hook-adminx:', 'page', page); | ||
sails.log.verbose('sails-hook-adminx:', 'limit', limit); | ||
// Validation | ||
@@ -49,3 +55,3 @@ if (!model) return res.badRequest('schema doesn\'t exist'); | ||
if(sort) criteria.sort = sort; | ||
sails.log(criteria); | ||
sails.log.verbose('sails-hook-adminx:', 'criteria', JSON.stringify(criteria)); | ||
@@ -61,3 +67,3 @@ model.find(criteria) | ||
items: items, | ||
pageIndex: (page - 1) * limit, | ||
pageIndex: page * limit, | ||
pageTotal: Math.ceil(count / limit) | ||
@@ -211,11 +217,3 @@ }; | ||
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') { | ||
if (type === 'string') { | ||
o[index] = { contains: query }; | ||
@@ -230,2 +228,17 @@ where.or.push(o); | ||
function prepareListDefaultSort (schema) { | ||
var model = sails.models[schema]; | ||
var attrs = prepareSchemaAttributes(model); | ||
// Search attribute displayed in the list | ||
var attr = _.find(attrs, { list: true, type: string }); | ||
// Use id | ||
if(!attr) { | ||
attr = _.find(attrs, { primaryKey: true }); | ||
} | ||
return attr; | ||
} | ||
function resultFilterAll (object) { | ||
@@ -232,0 +245,0 @@ //_.clone(value, [isDeep], [customizer], [thisArg]) |
60
index.js
@@ -24,3 +24,7 @@ const adminxHeaderAuth = require('./api/policies/adminxHeaderAuth'); | ||
authEnabled: true, | ||
dataAuthToken: null | ||
dataAuthToken: null, | ||
defaults: { | ||
listLimit: 10 | ||
}, | ||
}, | ||
@@ -43,31 +47,3 @@ routes: adminxRoutes.routes | ||
configure: function () { | ||
/*// Load policies under ./api/policies and config under ./config | ||
// https://github.com/leeroybrun/sails-util-mvcsloader#loading-config--policies | ||
loader.configure({ | ||
policies: __dirname + '/api/policies',// Path to the policies to load | ||
config: __dirname + '/config' // Path to the config to load | ||
});*/ | ||
//SAILS BUG: It seems sails OPTIONS requests don't return the headers configured on a per-route basis | ||
//SOLUTION: Modify sails.config.headers on the fly to add ours | ||
/*var headerName = 'adminx-data-auth-token'; | ||
if (sails.config.cors.allowRequestHeaders.indexOf(headerName) === -1) { | ||
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]); | ||
}*/ | ||
sails.log('sails-hook-adminx:', 'Configured'); | ||
}, | ||
@@ -89,14 +65,13 @@ | ||
//TODO: check if sails has enabled an ORM or throw an Error/Warning | ||
sails.log('sails-hook-adminx:', 'Waiting for orm'); | ||
/*// Load controllers under ./api/controllers and services under ./services | ||
// https://github.com/leeroybrun/sails-util-mvcsloader#loading-models--controllers--services | ||
loader.inject({ | ||
controllers: __dirname + '/api/controllers', // Path to the controllers to load | ||
// services: __dirname + '/api/services' // Path to the services to load | ||
}, function(err) { | ||
// Signal that initialization of this hook is complete | ||
// by calling the callback. | ||
return cb(err); | ||
});*/ | ||
cb(); | ||
var eventsToWaitFor = ['hook:orm:loaded']; | ||
sails.after(eventsToWaitFor, function() { | ||
// Finish initializing custom hook | ||
sails.log('sails-hook-adminx:', 'Initialized'); | ||
// Then call cb() | ||
return cb(); | ||
}); | ||
}, | ||
@@ -112,3 +87,4 @@ | ||
registerActions: function (cb) { | ||
sails.log('No actions registered'); | ||
sails.log('sails-hook-adminx:', 'Registered actions'); | ||
cb(); | ||
}, | ||
@@ -115,0 +91,0 @@ |
{ | ||
"name": "sails-hook-adminx", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "AdminX hook for Sails.js. AdminX is a sleek admin panel that integrates with any database, without coding.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -5,3 +5,2 @@ # sails-hook-adminx | ||
[![npm version](https://badge.fury.io/js/sails-hook-adminx.svg)](https://badge.fury.io/js/sails-hook-adminx) | ||
[![Known Vulnerabilities](https://snyk.io/test/npm/sails-hook-adminx/badge.svg)](https://snyk.io/test/npm/sails-hook-adminx) | ||
[![Join the chat at https://gitter.im/adminxhq/sails-hook-adminx](https://badges.gitter.im/adminxhq/sails-hook-adminx.svg)](https://gitter.im/adminxhq/sails-hook-adminx?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
@@ -22,4 +21,3 @@ [![Twitter Follow](https://img.shields.io/twitter/follow/adminxhq.svg?style=social&maxAge=3600)](https://twitter.com/adminxhq) | ||
### Requirements | ||
- for sails 1.0 use sails-hook-adminx@0.1 | ||
- for sails 0.12 use sails-hook-adminx@0.0 | ||
- Sails >0.12 or >1.0 | ||
- Waterline: this integrations requires you to use the default Sails ORM | ||
@@ -37,3 +35,5 @@ | ||
# npm install sails-hook-adminx --save | ||
yarn add sails-hook-adminx | ||
yarn add sails-hook-adminx@^0.1.2 # Sails 1.0 | ||
# or | ||
yarn add sails-hook-adminx@^0.0.10 # Sails 0.12 | ||
``` | ||
@@ -40,0 +40,0 @@ |
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
96470
698