Add settings page to control watched categories (#6648)
* Add settings page to control watched categories * Fix passing undefined to pushUnreadCountv1.18.x
parent
f5f3da12e7
commit
523a2dc54c
@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
define('forum/account/categories', ['forum/account/header'], function (header) {
|
||||
var Categories = {};
|
||||
|
||||
Categories.init = function () {
|
||||
header.init();
|
||||
|
||||
ajaxify.data.categories.forEach(function (category) {
|
||||
handleIgnoreWatch(category.cid);
|
||||
});
|
||||
};
|
||||
|
||||
function handleIgnoreWatch(cid) {
|
||||
var category = $('[data-cid="' + cid + '"]');
|
||||
category.find('[component="category/watching"], [component="category/ignoring"]').on('click', function () {
|
||||
var $this = $(this);
|
||||
var command = $this.attr('component') === 'category/watching' ? 'watch' : 'ignore';
|
||||
|
||||
socket.emit('categories.' + command, cid, function (err, modified_cids) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
modified_cids.forEach(function (cid) {
|
||||
var category = $('[data-cid="' + cid + '"]');
|
||||
category.find('[component="category/watching/menu"]').toggleClass('hidden', command !== 'watch');
|
||||
category.find('[component="category/watching/check"]').toggleClass('fa-check', command === 'watch');
|
||||
|
||||
category.find('[component="category/ignoring/menu"]').toggleClass('hidden', command !== 'ignore');
|
||||
category.find('[component="category/ignoring/check"]').toggleClass('fa-check', command === 'ignore');
|
||||
});
|
||||
|
||||
app.alertSuccess('[[category:' + command + '.message]]');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return Categories;
|
||||
});
|
@ -0,0 +1,70 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
|
||||
var user = require('../../user');
|
||||
var categories = require('../../categories');
|
||||
var accountHelpers = require('./helpers');
|
||||
|
||||
var categoriesController = {};
|
||||
|
||||
|
||||
categoriesController.get = function (req, res, callback) {
|
||||
var userData;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
|
||||
},
|
||||
function (_userData, next) {
|
||||
userData = _userData;
|
||||
if (!userData) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
ignored: function (next) {
|
||||
user.getIgnoredCategories(userData.uid, next);
|
||||
},
|
||||
all: function (next) {
|
||||
categories.getCategoriesByPrivilege('cid:0:children', userData.uid, 'find', next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
flattenArray(results);
|
||||
userData.categories = results.all;
|
||||
next();
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
userData.title = '[[pages:account/watched_categories]]';
|
||||
res.render('account/categories', userData);
|
||||
});
|
||||
};
|
||||
|
||||
function moveChildrenToRoot(child) {
|
||||
this.results.all.splice(this.i + this.results.j, 0, child);
|
||||
this.results.j = this.results.j + 1;
|
||||
}
|
||||
|
||||
function flattenArray(results) {
|
||||
for (var i = 0; i < results.all.length; i++) {
|
||||
var category = results.all[i];
|
||||
|
||||
category.isIgnored = false;
|
||||
if (results.ignored.includes(category.cid)) {
|
||||
category.isIgnored = true;
|
||||
}
|
||||
|
||||
if (!!category.children && !!category.children.length) {
|
||||
results.j = 1;
|
||||
category.children.forEach(moveChildrenToRoot, { i: i, results: results });
|
||||
category.children = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = categoriesController;
|
Loading…
Reference in New Issue