Code de-duplication of list and filter methods. The common functionality moved to table-helpers.js
This should make developing new table-based views easier.
This commit is contained in:
parent
c74232e9c5
commit
e5190c9b20
6 changed files with 137 additions and 421 deletions
|
@ -3,29 +3,12 @@
|
|||
let db = require('../db');
|
||||
let tools = require('../tools');
|
||||
let _ = require('../translate')._;
|
||||
let tableHelpers = require('../table-helpers');
|
||||
|
||||
let allowedKeys = ['description', 'editor_name', 'editor_data', 'html', 'text'];
|
||||
|
||||
module.exports.list = (start, limit, callback) => {
|
||||
db.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
connection.query('SELECT SQL_CALC_FOUND_ROWS * FROM templates ORDER BY name LIMIT ? OFFSET ?', [limit, start], (err, rows) => {
|
||||
if (err) {
|
||||
connection.release();
|
||||
return callback(err);
|
||||
}
|
||||
connection.query('SELECT FOUND_ROWS() AS total', (err, total) => {
|
||||
connection.release();
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
return callback(null, rows, total && total[0] && total[0].total);
|
||||
});
|
||||
});
|
||||
});
|
||||
tableHelpers.list('templates', 'name', start, limit, callback);
|
||||
};
|
||||
|
||||
module.exports.quicklist = callback => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue