Skip to content

Added option to have active users similar to standard forum software #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions library.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
var templatesToLoad = [
"recentreplies.tpl", "activeusers.tpl", "moderators.tpl", "forumstats.tpl", "recentposts.tpl", "recenttopics.tpl",
"categories.tpl", "populartags.tpl",
"admin/categorywidget.tpl", "admin/forumstats.tpl", "admin/html.tpl", "admin/text.tpl", "admin/recentposts.tpl",
"admin/categorywidget.tpl", "admin/activeusers.tpl", "admin/forumstats.tpl", "admin/html.tpl", "admin/text.tpl", "admin/recentposts.tpl",
"admin/recenttopics.tpl", "admin/defaultwidget.tpl", "admin/categorieswidget.tpl", "admin/populartags.tpl"
];

Expand Down Expand Up @@ -101,8 +101,31 @@
}

var html = Widget.templates['activeusers.tpl'], cidOrtid;

var match;
if (widget.data.cid) {
if (widget.data.global) {
async.parallel({
users: function(next) {
user.getUsersFromSet('users:online', 0, 49, next);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this already returns a list of user objects so no need to call getUserData again

},
isAdministrator: function(next) {
user.isAdministrator(widget.uid, next);
}
}, function(err, results) {
if (err) {
return getUserData(err);
}

if (!results.isAdministrator) {
results.users = results.users.filter(function(user) {
return user && user.status !== 'offline';
});
}

results.users = results.users.map(function(a) { return a.uid; });
getUserData(err, results.users);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to call this again since the results.users is an array of full user objects. can remove this line and the map above it and call

callback(null, templates.parse(html, {active_users: results.users});

});
} else if (widget.data.cid) {
cidOrtid = widget.data.cid;
categories.getActiveUsers(cidOrtid, getUserData);
} else if (widget.area.url.indexOf('topic') === 0) {
Expand Down Expand Up @@ -214,8 +237,8 @@
{
widget: "activeusers",
name: "Active Users",
description: "List of active users in a category.",
content: Widget.templates['admin/categorywidget.tpl']
description: "List of active users, optionally in a category.",
content: Widget.templates['admin/activeusers.tpl']
},
{
widget: "moderators",
Expand Down Expand Up @@ -264,6 +287,5 @@
callback(null, widgets);
};


module.exports = Widget;
}(module));
}(module));
10 changes: 10 additions & 0 deletions public/templates/admin/activeusers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<label>
Include All Users: <input name="global" type="checkbox"><br />
<small>Active users will include all online users(regardless of current category).</small>
</label>
<br />
<label>
Custom Category:<br />
<small>Leave blank to to dynamically pull from current category</small>
</label>
<input type="text" class="form-control" name="cid" placeholder="0" />