Header: show editing users in format <username>(<opened browser tabs>)

This commit is contained in:
Julia Radzhabova 2018-06-05 11:54:49 +03:00
parent 71997cf64e
commit 8212070fa3
4 changed files with 43 additions and 61 deletions

View file

@ -61,12 +61,11 @@ define([
}, },
getEditingCount: function() { getEditingCount: function() {
var count = 0; return this.filter(function(item){return item.get('online') && !item.get('view')}).length;
this.each(function(user){ },
user.get('online') && !user.get('view') && ++count;
});
return count; getEditingOriginalCount: function() {
return this.chain().filter(function(item){return item.get('online') && !item.get('view')}).groupBy(function(item) {return item.get('idOriginal');}).size().value();
}, },
findUser: function(id) { findUser: function(id) {

View file

@ -691,7 +691,7 @@ define([
onUpdateUsers: function() { onUpdateUsers: function() {
var users = this.userCollection; var users = this.userCollection;
this.popoverChanges.each(function (model) { this.popoverChanges && this.popoverChanges.each(function (model) {
var user = users.findOriginalUser(model.get('userid')); var user = users.findOriginalUser(model.get('userid'));
model.set('usercolor', (user) ? user.get('color') : null); model.set('usercolor', (user) ? user.get('color') : null);
}); });

View file

@ -57,16 +57,18 @@ define([
var templateUserItem = var templateUserItem =
'<li id="<%= user.get("iid") %>" class="<% if (!user.get("online")) { %> offline <% } if (user.get("view")) {%> viewmode <% } %>">' + '<li id="<%= user.get("iid") %>" class="<% if (!user.get("online")) { %> offline <% } if (user.get("view")) {%> viewmode <% } %>">' +
'<div class="color" style="background-color: <%= user.get("color") %>;" >' + '<div class="user-name">' +
'<label class="name"><%= fnEncode(user.get("username")) %></label>' + '<div class="color" style="background-color: <%= user.get("color") %>;"></div>'+
'</div>' + '<label><%= fnEncode(user.get("username")) %></label>' +
'<% if (len>1) { %><label style="margin-left:3px;">(<%=len%>)</label><% } %>' +
'</div>'+
'</li>'; '</li>';
var templateUserList = _.template( var templateUserList = _.template(
'<ul>' + '<ul>' +
'<% _.each(users, function(item) { %>' + '<% for (originalId in users) { %>' +
'<%= usertpl({user: item, fnEncode: fnEncode}) %>' + '<%= usertpl({user: users[originalId][0], fnEncode: fnEncode, len: users[originalId].length}) %>' +
'<% }); %>' + '<% } %>' +
'</ul>'); '</ul>');
var templateRightBox = '<section>' + var templateRightBox = '<section>' +
@ -115,63 +117,37 @@ define([
'<label id="title-user-name" style="pointer-events: none;"></label>' + '<label id="title-user-name" style="pointer-events: none;"></label>' +
'</section>'; '</section>';
function onAddUser(model, collection, opts) {
if ( $userList ) {
var $ul = $userList.find('ul');
if ( !$ul.length ) {
$userList.html( templateUserList({
users: collection.models,
usertpl: _.template(templateUserItem),
fnEncode: Common.Utils.String.htmlEncode
})
);
} else {
$ul.append( _.template(templateUserItem)({
user: model,
fnEncode: Common.Utils.String.htmlEncode
}) );
}
$userList.scroller && $userList.scroller.update({minScrollbarLength : 40, alwaysVisibleY: true});
}
applyUsers( collection.getEditingCount() );
};
function onUsersChanged(model, collection) {
if (model.changed.online != undefined && $userList) {
$userList.find('#'+ model.get('iid'))[model.changed.online ? 'removeClass' : 'addClass']('offline');
$userList.scroller && $userList.scroller.update({minScrollbarLength : 40, alwaysVisibleY: true});
}
applyUsers(model.collection.getEditingCount());
};
function onResetUsers(collection, opts) { function onResetUsers(collection, opts) {
var usercount = collection.getEditingCount(); var usercount = collection.getEditingCount();
if ( $userList ) { if ( $userList ) {
if ( usercount > 1 || usercount > 0 && appConfig && !appConfig.isEdit && !appConfig.canComments) { if ( usercount > 1 || usercount > 0 && appConfig && !appConfig.isEdit && !appConfig.canComments) {
$userList.html(templateUserList({ $userList.html(templateUserList({
users: collection.models, users: collection.chain().filter(function(item){return item.get('online') && !item.get('view')}).groupBy(function(item) {return item.get('idOriginal');}).value(),
usertpl: _.template(templateUserItem), usertpl: _.template(templateUserItem),
fnEncode: Common.Utils.String.htmlEncode fnEncode: Common.Utils.String.htmlEncode
})); }));
$userList.scroller = new Common.UI.Scroller({ if (!$userList.scroller)
el: $userList.find('ul'), $userList.scroller = new Common.UI.Scroller({
useKeyboard: true, el: $userList.find('ul'),
minScrollbarLength: 40, useKeyboard: true,
alwaysVisibleY: true minScrollbarLength: 40,
}); alwaysVisibleY: true
});
$userList.scroller.update({minScrollbarLength : 40, alwaysVisibleY: true});
} else { } else {
$userList.empty(); $userList.empty();
} }
} }
applyUsers( usercount ); applyUsers( usercount, collection.getEditingOriginalCount() );
}; };
function applyUsers(count) { function onUsersChanged(model) {
onResetUsers(model.collection);
};
function applyUsers(count, originalCount) {
var has_edit_users = count > 1 || count > 0 && appConfig && !appConfig.isEdit && !appConfig.canComments; // has other user(s) who edit document var has_edit_users = count > 1 || count > 0 && appConfig && !appConfig.isEdit && !appConfig.canComments; // has other user(s) who edit document
if ( has_edit_users ) { if ( has_edit_users ) {
$btnUsers $btnUsers
@ -192,7 +168,7 @@ define([
$btnUsers.find('.caption') $btnUsers.find('.caption')
.css({'font-size': ((has_edit_users) ? '12px' : '14px'), .css({'font-size': ((has_edit_users) ? '12px' : '14px'),
'margin-top': ((has_edit_users) ? '0' : '-1px')}) 'margin-top': ((has_edit_users) ? '0' : '-1px')})
.html((has_edit_users) ? count : '&plus;'); .html((has_edit_users) ? originalCount : '&plus;');
var usertip = $btnUsers.data('bs.tooltip'); var usertip = $btnUsers.data('bs.tooltip');
if ( usertip ) { if ( usertip ) {
@ -393,7 +369,7 @@ define([
storeUsers = this.options.storeUsers; storeUsers = this.options.storeUsers;
storeUsers.bind({ storeUsers.bind({
add : onAddUser, add : onUsersChanged,
change : onUsersChanged, change : onUsersChanged,
reset : onResetUsers reset : onResetUsers
}); });

View file

@ -233,15 +233,22 @@
display: inline-block; display: inline-block;
vertical-align: middle; vertical-align: middle;
border: 1px solid @gray-dark; border: 1px solid @gray-dark;
margin: 0 5px 1px 0;
} }
.name { .user-name {
display: block; color: @gray-deep;
padding-left: 16px; font-size: 12px;
margin-top: -5px; font-weight: bold;
white-space: nowrap; white-space: nowrap;
text-overflow: ellipsis; cursor: default;
vertical-align: middle;
label {
overflow: hidden;
text-overflow: ellipsis;
vertical-align: middle;
max-width: 200px;
}
} }
} }
} }