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",
"reporter": "Reporter",
"reported-at": "Reported At",
@ -9,11 +8,15 @@
"update": "Update",
"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",
"filter-reporterId": "Reporter UID",
"filter-type": "Flag Type",
"filter-type-all": "All Content",
"filter-type-post": "Post",
"filter-quick-mine": "Assigned to me",
"apply-filters": "Apply Filters",
"notes": "Flag Notes",

@ -12,6 +12,11 @@ define('forum/flags/list', ['components'], function (components) {
Flags.enableFilterForm = function () {
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 () {
var payload = filtersEl.serializeArray();
var qs = payload.map(function (filter) {

@ -26,7 +26,7 @@ modsController.flags.list = function (req, res, next) {
}
// Parse query string params for filters
var valid = ['reporterId', 'type'];
var valid = ['reporterId', 'type', 'quick'];
var filters = valid.reduce(function (memo, cur) {
if (req.query.hasOwnProperty(cur)) {
memo[cur] = req.query[cur];
@ -35,13 +35,15 @@ modsController.flags.list = function (req, res, next) {
return memo;
}, {});
flags.list(filters, function (err, flags) {
flags.list(filters, req.uid, function (err, flags) {
if (err) {
return next(err);
}
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);
};
Flags.list = function (filters, callback) {
Flags.list = function (filters, uid, callback) {
if (typeof filters === 'function' && !callback) {
callback = filters;
filters = {};
@ -64,16 +64,23 @@ Flags.list = function (filters, callback) {
case 'reporterId':
sets.push('flags:byReporter:' + filters[type]);
break;
case 'quick':
switch (filters.quick) {
case 'mine':
sets.push('flags:byAssignee:' + uid);
break;
}
break;
}
}
}
sets = sets.length ? sets : ['flags:datetime']; // No filter default
async.waterfall([
function (next) {
if (sets.length === 1) {
db.getSortedSetRevRange(sets[0], 0, 19, next);
db.getSortedSetRevRange(sets[0], 0, -1, next);
} else {
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
var fields = ['state', 'assignee'];
var history = [];
var tasks = [];
var now = Date.now();
async.waterfall([
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]) {
delete changeset[prop];
} 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
history.push(prop + ':' + changeset[prop]);
}
@ -336,12 +357,12 @@ Flags.update = function (flagId, uid, changeset, callback) {
return next();
}
async.parallel([
// Save new object to db (upsert)
async.apply(db.setObject, 'flag:' + flagId, changeset),
// Append history
async.apply(Flags.appendHistory, flagId, uid, history)
], function (err, data) {
// Save new object to db (upsert)
tasks.push(async.apply(db.setObject, 'flag:' + flagId, changeset));
// Append history
tasks.push(async.apply(Flags.appendHistory, flagId, uid, history))
async.parallel(tasks, function (err, data) {
return next(err);
});
}

Loading…
Cancel
Save