The "Reports" feature seems functional.
Some small refactoring (column widths) of rendering tables in Lists, Templates, and Campaigns so that it is the same as Reports.
This commit is contained in:
parent
e7d12f1dbc
commit
8237dd5d77
22 changed files with 584 additions and 236 deletions
|
@ -19,7 +19,7 @@ let tableHelpers = require('../table-helpers');
|
|||
let allowedKeys = ['description', 'from', 'address', 'reply_to', 'subject', 'editor_name', 'editor_data', 'template', 'source_url', 'list', 'segment', 'html', 'text', 'tracking_disabled'];
|
||||
|
||||
module.exports.list = (start, limit, callback) => {
|
||||
tableHelpers.list('campaigns', ['*'], 'scheduled', start, limit, callback);
|
||||
tableHelpers.list('campaigns', ['*'], 'scheduled', null, start, limit, callback);
|
||||
};
|
||||
|
||||
module.exports.filter = (request, parent, callback) => {
|
||||
|
|
|
@ -10,7 +10,7 @@ let tableHelpers = require('../table-helpers');
|
|||
let allowedKeys = ['description', 'default_form', 'public_subscribe'];
|
||||
|
||||
module.exports.list = (start, limit, callback) => {
|
||||
tableHelpers.list('lists', ['*'], 'name', start, limit, callback);
|
||||
tableHelpers.list('lists', ['*'], 'name', null, start, limit, callback);
|
||||
};
|
||||
|
||||
module.exports.filter = (request, parent, callback) => {
|
||||
|
|
|
@ -8,7 +8,7 @@ const _ = require('../translate')._;
|
|||
const allowedKeys = ['name', 'description', 'mime_type', 'user_fields', 'js', 'hbs'];
|
||||
|
||||
module.exports.list = (start, limit, callback) => {
|
||||
tableHelpers.list('report_templates', ['*'], 'name', start, limit, callback);
|
||||
tableHelpers.list('report_templates', ['*'], 'name', null, start, limit, callback);
|
||||
};
|
||||
|
||||
module.exports.quicklist = callback => {
|
||||
|
|
|
@ -8,16 +8,29 @@ const tools = require('../tools');
|
|||
const _ = require('../translate')._;
|
||||
const log = require('npmlog');
|
||||
|
||||
const allowedKeys = ['name', 'description', 'report_template', 'params', 'filename'];
|
||||
const allowedKeys = ['name', 'description', 'report_template', 'params'];
|
||||
|
||||
const ReportState = {
|
||||
SCHEDULED: 0,
|
||||
PROCESSING: 1,
|
||||
FINISHED: 2,
|
||||
FAILED: 3
|
||||
};
|
||||
|
||||
module.exports.ReportState = ReportState;
|
||||
|
||||
module.exports.list = (start, limit, callback) => {
|
||||
tableHelpers.list('reports', ['*'], 'name', start, limit, callback);
|
||||
tableHelpers.list('reports', ['*'], 'name', null, start, limit, callback);
|
||||
};
|
||||
|
||||
module.exports.listWithState = (state, start, limit, callback) => {
|
||||
tableHelpers.list('reports', ['*'], 'name', { where: 'state=?', values: [state] }, start, limit, callback);
|
||||
}
|
||||
|
||||
module.exports.filter = (request, callback) => {
|
||||
tableHelpers.filter('reports JOIN report_templates ON reports.report_template = report_templates.id',
|
||||
['reports.id AS id', 'reports.name AS name', 'reports.description AS description', 'reports.state AS state', 'reports.filename AS filename', 'reports.report_template AS report_template', 'reports.params AS params', 'reports.created AS created', 'report_templates.name AS report_template_name', 'report_templates.mime_type AS mime_type' ],
|
||||
request, ['#', 'name', 'report_templates.name', 'description', 'created'], ['name'], 'created DESC', null, callback);
|
||||
['reports.id AS id', 'reports.name AS name', 'reports.description AS description', 'reports.state AS state', 'reports.report_template AS report_template', 'reports.params AS params', 'reports.last_run AS last_run', 'report_templates.name AS report_template_name', 'report_templates.mime_type AS mime_type' ],
|
||||
request, ['#', 'name', 'report_templates.name', 'description', 'last_run'], ['name'], 'name ASC', null, callback);
|
||||
};
|
||||
|
||||
module.exports.get = (id, callback) => {
|
||||
|
@ -60,29 +73,56 @@ module.exports.get = (id, callback) => {
|
|||
});
|
||||
};
|
||||
|
||||
module.exports.createOrUpdate = (createMode, data, callback) => {
|
||||
data = data || {};
|
||||
// This method is not supposed to be used for unsanitized inputs. It does not do any checks.
|
||||
module.exports.updateFields = (id, fieldValueMap, callback) => {
|
||||
db.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
const id = 'id' in data ? Number(data.id) : 0;
|
||||
const clauses = [];
|
||||
const values = [];
|
||||
for (let key of Object.keys(fieldValueMap)) {
|
||||
clauses.push(tools.toDbKey(key) + '=?');
|
||||
values.push(fieldValueMap[key]);
|
||||
}
|
||||
|
||||
values.push(id);
|
||||
|
||||
const query = 'UPDATE reports SET ' + clauses.join(', ') + ' WHERE id=? LIMIT 1';
|
||||
connection.query(query, values, (err, result) => {
|
||||
connection.release();
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
return callback(null, result && result.affectedRows || false)
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.createOrUpdate = (createMode, report, callback) => {
|
||||
report = report || {};
|
||||
|
||||
const id = 'id' in report ? Number(report.id) : 0;
|
||||
|
||||
if (!createMode && id < 1) {
|
||||
return callback(new Error(_('Missing report ID')));
|
||||
}
|
||||
|
||||
const template = tools.convertKeys(data);
|
||||
const name = (template.name || '').toString().trim();
|
||||
const name = (report.name || '').toString().trim();
|
||||
|
||||
if (!name) {
|
||||
return callback(new Error(_('Report name must be set')));
|
||||
}
|
||||
|
||||
const reportTemplateId = Number(template.reportTemplate);
|
||||
const reportTemplateId = Number(report.reportTemplate);
|
||||
reportTemplates.get(reportTemplateId, (err, reportTemplate) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
}
|
||||
|
||||
const params = data.paramsObject;
|
||||
const params = report.paramsObject;
|
||||
for (const spec of reportTemplate.userFieldsObject) {
|
||||
if (params[spec.id].length < spec.minOccurences) {
|
||||
return callback(new Error(_('At least ' + spec.minOccurences + ' rows in "' + spec.name + '" have to be selected.')));
|
||||
|
@ -97,8 +137,8 @@ module.exports.createOrUpdate = (createMode, data, callback) => {
|
|||
const values = [name, JSON.stringify(params)];
|
||||
|
||||
|
||||
Object.keys(template).forEach(key => {
|
||||
let value = typeof template[key] === 'number' ? template[key] : (template[key] || '').toString().trim();
|
||||
Object.keys(report).forEach(key => {
|
||||
let value = typeof report[key] === 'number' ? report[key] : (report[key] || '').toString().trim();
|
||||
key = tools.toDbKey(key);
|
||||
|
||||
if (key === 'description') {
|
||||
|
|
|
@ -21,7 +21,7 @@ module.exports.list = (listId, start, limit, callback) => {
|
|||
return callback(new Error('Missing List ID'));
|
||||
}
|
||||
|
||||
tableHelpers.list('subscription__' + listId, ['*'], 'email', start, limit, (err, rows, total) => {
|
||||
tableHelpers.list('subscription__' + listId, ['*'], 'email', null, start, limit, (err, rows, total) => {
|
||||
if (!err) {
|
||||
rows = rows.map(row => tools.convertKeys(row));
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ let tableHelpers = require('../table-helpers');
|
|||
let allowedKeys = ['description', 'editor_name', 'editor_data', 'html', 'text'];
|
||||
|
||||
module.exports.list = (start, limit, callback) => {
|
||||
tableHelpers.list('templates', ['*'], 'name', start, limit, callback);
|
||||
tableHelpers.list('templates', ['*'], 'name', null, start, limit, callback);
|
||||
};
|
||||
|
||||
module.exports.filter = (request, parent, callback) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue