Skip to content

Commit

Permalink
Sort User List to bring starred users at top.
Browse files Browse the repository at this point in the history
Split starred and unstarred users with a horizontal line.
  • Loading branch information
kartikmaji committed Aug 22, 2016
1 parent 802cd0e commit 681b057
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
23 changes: 21 additions & 2 deletions static/js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,21 @@ exports.update_users = function (user_list) {
};
}

var user_info = _.map(users, info_for);
function filter_starred_user(user) {
if (user.starred === true) {
return user;
}
}

// User info unsorted
var user_info_unsorted = _.map(users, info_for);

// Filtering out starred and unstarred users out of all users info
var starred_users = _.filter(user_info_unsorted, filter_starred_user);
var unstarred_users = _.difference(user_info_unsorted, starred_users);

// Concatenate starrred_users and unstarred_users with starred_users at top.
var user_info = starred_users.concat(unstarred_users);
if (user_list !== undefined) {
// Render right panel partially
$.each(user_info, function (index, user) {
Expand All @@ -261,7 +275,12 @@ exports.update_users = function (user_list) {
$('#user_presences li').eq(user_index).before(templates.render('user_presence_row', user));
});
} else {
$('#user_presences').html(templates.render('user_presence_rows', {users: user_info}));
var split_users = starred_users.length !== 0 && unstarred_users.length !== 0;
$('#user_presences').html(templates.render('user_presence_rows',
{starred_users: starred_users,
unstarred_users: unstarred_users,
split: split_users
}));
}

// Update user fading, if necessary.
Expand Down
6 changes: 5 additions & 1 deletion static/templates/user_presence_rows.handlebars
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{{! User Presence rows }}
{{#each users}}
{{#each starred_users}}
{{partial "user_presence_row"}}
{{/each}}
<hr>
{{#each unstarred_users}}
{{partial "user_presence_row"}}
{{/each}}

0 comments on commit 681b057

Please sign in to comment.