Skip to content
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

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
49 changes: 41 additions & 8 deletions library.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
} else {
callback(null, text.replace(/\r\n/g, "<br />"));
}

};

Widget.renderRecentViewWidget = function(widget, callback) {
Expand All @@ -86,6 +87,14 @@
};

Widget.renderActiveUsersWidget = function(widget, callback) {
function generateHtml(users) {
html = templates.parse(html, {
active_users: users,
relative_path: nconf.get('relative_path')
});
return html;
}

function getUserData(err, uids) {
if (err) {
return callback(err);
Expand All @@ -98,18 +107,43 @@
return callback(err);
}

html = templates.parse(html, {
active_users: users,
relative_path: nconf.get('relative_path')
});
html = generateHtml(users);

callback(err, html);
});
}

var count = Math.max(1, widget.data.numUsers || 24);
var html = Widget.templates['widgets/activeusers.tpl'], cidOrtid;
var match;
if (widget.data.cid) {
if (!!widget.data.global) {
async.parallel({
users: function(next) {
user.getUsersFromSet('users:online', widget.uid, 0, 49, next);
},
isAdministrator: function(next) {
user.isAdministrator(widget.uid, next);
}
}, function(err, results) {
if (err) {
return callback(err);
}

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

results.users = results.users.map(function(a) {
return {'uid': a.uid, 'username': a.username, 'userslug': a.userslug, 'picture': a.picture};
});

html = generateHtml(results.users);

callback(null, html);
});
} else if (widget.data.cid) {
cidOrtid = widget.data.cid;
categories.getActiveUsers(cidOrtid, getUserData);
} else if (widget.area.url.startsWith('topic')) {
Expand Down Expand Up @@ -187,7 +221,7 @@
if (err) {
return callback(err);
}
app.render('widgets/recentposts', {posts: posts, numPosts: numPosts, cid: cid}, function(err, html) {
app.render('widgets/recentposts', {posts: posts, numPosts: numPosts, cid: cid, relative_path: nconf.get('relative_path')}, function(err, html) {
translator.translate(html, function(translatedHTML) {
callback(err, translatedHTML);
});
Expand Down Expand Up @@ -457,6 +491,5 @@
callback(null, widgets);
};


module.exports = Widget;
}(module));
}(module));
9 changes: 6 additions & 3 deletions public/templates/admin/activeusers.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<label>Amount of Users to display:</label>
<input type="text" class="form-control" name="numUsers" placeholder="4" />
<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" />
<input type="text" class="form-control" name="cid" placeholder="0" />