Added some quick filters, #5232

v1.18.x
Julian Lam 8 years ago
parent b7217e8841
commit 8e1d441e20

@ -1,5 +1,4 @@
{ {
"quick-filters": "Quick Filters",
"state": "State", "state": "State",
"reporter": "Reporter", "reporter": "Reporter",
"reported-at": "Reported At", "reported-at": "Reported At",
@ -9,11 +8,15 @@
"update": "Update", "update": "Update",
"updated": "Updated", "updated": "Updated",
"quick-filters": "Quick Filters",
"filter-active": "There are one or more filters active in this list of flags",
"filter-reset": "Remove Filters",
"filters": "Filter Options", "filters": "Filter Options",
"filter-reporterId": "Reporter UID", "filter-reporterId": "Reporter UID",
"filter-type": "Flag Type", "filter-type": "Flag Type",
"filter-type-all": "All Content", "filter-type-all": "All Content",
"filter-type-post": "Post", "filter-type-post": "Post",
"filter-quick-mine": "Assigned to me",
"apply-filters": "Apply Filters", "apply-filters": "Apply Filters",
"notes": "Flag Notes", "notes": "Flag Notes",

@ -12,6 +12,11 @@ define('forum/flags/list', ['components'], function (components) {
Flags.enableFilterForm = function () { Flags.enableFilterForm = function () {
var filtersEl = components.get('flags/filters'); var filtersEl = components.get('flags/filters');
// Parse ajaxify data to set form values to reflect current filters
for(var filter in ajaxify.data.filters) {
filtersEl.find('[name="' + filter + '"]').val(ajaxify.data.filters[filter]);
}
filtersEl.find('button').on('click', function () { filtersEl.find('button').on('click', function () {
var payload = filtersEl.serializeArray(); var payload = filtersEl.serializeArray();
var qs = payload.map(function (filter) { var qs = payload.map(function (filter) {

@ -26,7 +26,7 @@ modsController.flags.list = function (req, res, next) {
} }
// Parse query string params for filters // Parse query string params for filters
var valid = ['reporterId', 'type']; var valid = ['reporterId', 'type', 'quick'];
var filters = valid.reduce(function (memo, cur) { var filters = valid.reduce(function (memo, cur) {
if (req.query.hasOwnProperty(cur)) { if (req.query.hasOwnProperty(cur)) {
memo[cur] = req.query[cur]; memo[cur] = req.query[cur];
@ -35,13 +35,15 @@ modsController.flags.list = function (req, res, next) {
return memo; return memo;
}, {}); }, {});
flags.list(filters, function (err, flags) { flags.list(filters, req.uid, function (err, flags) {
if (err) { if (err) {
return next(err); return next(err);
} }
res.render('flags/list', { res.render('flags/list', {
flags: flags flags: flags,
hasFilter: !!Object.keys(filters).length,
filters: filters
}); });
}); });
}); });

@ -47,7 +47,7 @@ Flags.get = function (flagId, callback) {
], callback); ], callback);
}; };
Flags.list = function (filters, callback) { Flags.list = function (filters, uid, callback) {
if (typeof filters === 'function' && !callback) { if (typeof filters === 'function' && !callback) {
callback = filters; callback = filters;
filters = {}; filters = {};
@ -64,16 +64,23 @@ Flags.list = function (filters, callback) {
case 'reporterId': case 'reporterId':
sets.push('flags:byReporter:' + filters[type]); sets.push('flags:byReporter:' + filters[type]);
break; break;
case 'quick':
switch (filters.quick) {
case 'mine':
sets.push('flags:byAssignee:' + uid);
break;
}
break;
} }
} }
} }
sets = sets.length ? sets : ['flags:datetime']; // No filter default sets = sets.length ? sets : ['flags:datetime']; // No filter default
async.waterfall([ async.waterfall([
function (next) { function (next) {
if (sets.length === 1) { if (sets.length === 1) {
db.getSortedSetRevRange(sets[0], 0, 19, next); db.getSortedSetRevRange(sets[0], 0, -1, next);
} else { } else {
db.getSortedSetRevIntersect({sets: sets, start: 0, stop: -1, aggregate: 'MAX'}, next); db.getSortedSetRevIntersect({sets: sets, start: 0, stop: -1, aggregate: 'MAX'}, next);
} }
@ -316,6 +323,8 @@ Flags.update = function (flagId, uid, changeset, callback) {
// Retrieve existing flag data to compare for history-saving purposes // Retrieve existing flag data to compare for history-saving purposes
var fields = ['state', 'assignee']; var fields = ['state', 'assignee'];
var history = []; var history = [];
var tasks = [];
var now = Date.now();
async.waterfall([ async.waterfall([
async.apply(db.getObjectFields.bind(db), 'flag:' + flagId, fields), async.apply(db.getObjectFields.bind(db), 'flag:' + flagId, fields),
@ -325,6 +334,18 @@ Flags.update = function (flagId, uid, changeset, callback) {
if (current[prop] === changeset[prop]) { if (current[prop] === changeset[prop]) {
delete changeset[prop]; delete changeset[prop];
} else { } else {
// Add tasks as necessary
switch (prop) {
case 'state':
tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byState:' + changeset[prop], now, flagId));
tasks.push(async.apply(db.sortedSetRemove.bind(db), 'flags:byState:' + current[prop], flagId));
break;
case 'assignee':
tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byAssignee:' + changeset[prop], now, flagId));
break;
}
// Append to history payload // Append to history payload
history.push(prop + ':' + changeset[prop]); history.push(prop + ':' + changeset[prop]);
} }
@ -336,12 +357,12 @@ Flags.update = function (flagId, uid, changeset, callback) {
return next(); return next();
} }
async.parallel([ // Save new object to db (upsert)
// Save new object to db (upsert) tasks.push(async.apply(db.setObject, 'flag:' + flagId, changeset));
async.apply(db.setObject, 'flag:' + flagId, changeset), // Append history
// Append history tasks.push(async.apply(Flags.appendHistory, flagId, uid, history))
async.apply(Flags.appendHistory, flagId, uid, history)
], function (err, data) { async.parallel(tasks, function (err, data) {
return next(err); return next(err);
}); });
} }

Loading…
Cancel
Save