Merge pull request #6094 from nextcloud/sharedby-avatar

Show avatar instead of username for shared files
This commit is contained in:
Jan-Christoph Borchardt 2017-11-02 14:51:17 +01:00 committed by GitHub
commit 4a3893b105
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 58 deletions

View File

@ -555,6 +555,10 @@ a.action > img {
#fileList a.action.action-share { #fileList a.action.action-share {
padding: 17px 14px; padding: 17px 14px;
} }
#fileList a.action.action-share .avatar {
display: inline-block;
vertical-align: middle;
}
#fileList a.action.action-menu { #fileList a.action.action-menu {
padding-top: 17px; padding-top: 17px;
@ -590,8 +594,12 @@ a.action > img {
max-width: 70px; max-width: 70px;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
vertical-align: bottom; vertical-align: middle;
padding-left: 6px; margin-left: 6px;
}
#fileList .remoteAddress .userDomain {
margin-left: 0 !important;
} }
#fileList .favorite-mark.permanent { #fileList .favorite-mark.permanent {

View File

@ -145,7 +145,7 @@ describe('OCA.Sharing.Util tests', function() {
}]); }]);
$tr = fileList.$el.find('tbody tr:first'); $tr = fileList.$el.find('tbody tr:first');
$action = $tr.find('.action-share'); $action = $tr.find('.action-share');
expect($action.find('>span').text().trim()).toEqual('User One'); expect($action.find('>span').text().trim()).toEqual('Shared by User One');
expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
expect($action.find('.icon').hasClass('icon-public')).toEqual(false); expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg'); expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg');
@ -166,7 +166,7 @@ describe('OCA.Sharing.Util tests', function() {
}]); }]);
$tr = fileList.$el.find('tbody tr:first'); $tr = fileList.$el.find('tbody tr:first');
$action = $tr.find('.action-share'); $action = $tr.find('.action-share');
expect($action.find('>span').text().trim()).toEqual('Shared with User One, User Two'); expect($action.text().trim()).toEqual('Shared with User One Shared with User Two');
expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
expect($action.find('.icon').hasClass('icon-public')).toEqual(false); expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg'); expect(OC.basename(getImageUrl($tr.find('.filename .thumbnail')))).toEqual('folder-shared.svg');
@ -273,7 +273,7 @@ describe('OCA.Sharing.Util tests', function() {
expect($tr.attr('data-share-recipients')).toEqual('Group One, Group Two, User One, User Two'); expect($tr.attr('data-share-recipients')).toEqual('Group One, Group Two, User One, User Two');
expect($action.find('>span').text().trim()).toEqual('Shared with Group One, Group Two, User One, User Two'); expect($action.text().trim()).toEqual('Shared with Group One Shared with Group Two Shared with User One Shared with User Two');
expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
expect($action.find('.icon').hasClass('icon-public')).toEqual(false); expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
}); });
@ -306,7 +306,7 @@ describe('OCA.Sharing.Util tests', function() {
expect($tr.attr('data-share-recipients')).toEqual('User One, User Three, User Two'); expect($tr.attr('data-share-recipients')).toEqual('User One, User Three, User Two');
expect($action.find('>span').text().trim()).toEqual('Shared with User One, User Three, User Two'); expect($action.text().trim()).toEqual('Shared with User One Shared with User Three Shared with User Two');
expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
expect($action.find('.icon').hasClass('icon-public')).toEqual(false); expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
}); });
@ -362,7 +362,7 @@ describe('OCA.Sharing.Util tests', function() {
expect($tr.attr('data-share-recipients')).toEqual('User Two'); expect($tr.attr('data-share-recipients')).toEqual('User Two');
expect($action.find('>span').text().trim()).toEqual('User One'); expect($action.find('>span').text().trim()).toEqual('Shared by User One');
expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
expect($action.find('.icon').hasClass('icon-public')).toEqual(false); expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
}); });
@ -393,7 +393,7 @@ describe('OCA.Sharing.Util tests', function() {
expect($tr.attr('data-share-recipients')).not.toBeDefined(); expect($tr.attr('data-share-recipients')).not.toBeDefined();
expect($action.find('>span').text().trim()).toEqual('User One'); expect($action.find('>span').text().trim()).toEqual('Shared by User One');
expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); expect($action.find('.icon').hasClass('icon-shared')).toEqual(true);
expect($action.find('.icon').hasClass('icon-public')).toEqual(false); expect($action.find('.icon').hasClass('icon-public')).toEqual(false);
}); });

View File

@ -203,18 +203,19 @@ OC.Share = _.extend(OC.Share || {}, {
* @param {String} remoteAddress full remote share * @param {String} remoteAddress full remote share
* @return {String} HTML code to display * @return {String} HTML code to display
*/ */
_formatRemoteShare: function(remoteAddress) { _formatRemoteShare: function(remoteAddress, message) {
var parts = this._REMOTE_OWNER_REGEXP.exec(remoteAddress); var parts = this._REMOTE_OWNER_REGEXP.exec(remoteAddress);
if (!parts) { if (!parts) {
// display as is, most likely to be a simple owner name // display avatar of the user
return escapeHTML(remoteAddress); var avatar = '<span class="avatar" data-userName="' + escapeHTML(remoteAddress) + '" title="' + message + " " + escapeHTML(remoteAddress) + '"></span>';
var hidden = '<span class="hidden-visually">' + message + ' ' + escapeHTML(remoteAddress) + '</span> ';
return avatar + hidden;
} }
var userName = parts[1]; var userName = parts[1];
var userDomain = parts[3]; var userDomain = parts[3];
var server = parts[4]; var server = parts[4];
var dir = parts[6]; var tooltip = message + ' ' + userName;
var tooltip = userName;
if (userDomain) { if (userDomain) {
tooltip += '@' + userDomain; tooltip += '@' + userDomain;
} }
@ -230,7 +231,7 @@ OC.Share = _.extend(OC.Share || {}, {
if (userDomain) { if (userDomain) {
html += '<span class="userDomain">@' + escapeHTML(userDomain) + '</span>'; html += '<span class="userDomain">@' + escapeHTML(userDomain) + '</span>';
} }
html += '</span>'; html += '</span> ';
return html; return html;
}, },
/** /**
@ -243,7 +244,7 @@ OC.Share = _.extend(OC.Share || {}, {
_formatShareList: function(recipients) { _formatShareList: function(recipients) {
var _parent = this; var _parent = this;
return $.map(recipients, function(recipient) { return $.map(recipients, function(recipient) {
recipient = _parent._formatRemoteShare(recipient); recipient = _parent._formatRemoteShare(recipient, t('core', 'Shared with'));
return recipient; return recipient;
}); });
}, },
@ -259,8 +260,7 @@ OC.Share = _.extend(OC.Share || {}, {
var action = $tr.find('.fileactions .action[data-action="Share"]'); var action = $tr.find('.fileactions .action[data-action="Share"]');
var type = $tr.data('type'); var type = $tr.data('type');
var icon = action.find('.icon'); var icon = action.find('.icon');
var message; var message, recipients, avatars;
var recipients;
var owner = $tr.attr('data-share-owner'); var owner = $tr.attr('data-share-owner');
var shareFolderIcon; var shareFolderIcon;
var iconClass = 'icon-shared'; var iconClass = 'icon-shared';
@ -294,20 +294,23 @@ OC.Share = _.extend(OC.Share || {}, {
recipients = $tr.attr('data-share-recipients'); recipients = $tr.attr('data-share-recipients');
action.addClass('shared-style'); action.addClass('shared-style');
message = t('core', 'Shared'); avatars = '<span>' + t('core', 'Shared') + '</span>';
// even if reshared, only show "Shared by" // even if reshared, only show "Shared by"
if (owner) { if (owner) {
message = this._formatRemoteShare(owner); message = t('core', 'Shared by');
avatars = this._formatRemoteShare(owner, message);
} else if (recipients) {
avatars = this._formatShareList(recipients.split(', ')).join('');
} }
else if (recipients) { action.html(avatars).prepend(icon);
message = t('core', 'Shared with {recipients}', {recipients: this._formatShareList(recipients.split(", ")).join(", ")}, 0, {escape: false});
}
action.html('<span> ' + message + '</span>').prepend(icon);
if (owner || recipients) { if (owner || recipients) {
action.find('.remoteAddress').tooltip({placement: 'top'}); var avatarElement = action.find('.avatar');
avatarElement.avatar(avatarElement.data('username'), 32);
action.find('.icon-shared + span').tooltip({placement: 'top'});
} }
} } else {
else {
action.html('<span class="hidden-visually">' + t('core', 'Shared') + '</span>').prepend(icon); action.html('<span class="hidden-visually">' + t('core', 'Shared') + '</span>').prepend(icon);
} }
if (hasLink) { if (hasLink) {

View File

@ -47,7 +47,7 @@ describe('OC.Share tests', function() {
$file.attr('data-share-owner', input); $file.attr('data-share-owner', input);
OC.Share.markFileAsShared($file); OC.Share.markFileAsShared($file);
$action = $file.find('.action-share>span'); $action = $file.find('.action-share>span').parent();
expect($action.text().trim()).toEqual(output); expect($action.text().trim()).toEqual(output);
if (_.isString(title)) { if (_.isString(title)) {
expect($action.find('.remoteAddress').attr('title')).toEqual(title); expect($action.find('.remoteAddress').attr('title')).toEqual(title);
@ -58,41 +58,41 @@ describe('OC.Share tests', function() {
tooltipStub.reset(); tooltipStub.reset();
} }
it('displays the local share owner as is', function() { it('displays the local share owner with "Shared by" prefix', function() {
checkOwner('User One', 'User One', null); checkOwner('User One', 'Shared by User One', null);
}); });
it('displays the user name part of a remote share owner', function() { it('displays the user name part of a remote share owner', function() {
checkOwner( checkOwner(
'User One@someserver.com', 'User One@someserver.com',
'User One@…', 'User One@…',
'User One@someserver.com' 'Shared by User One@someserver.com'
); );
checkOwner( checkOwner(
'User One@someserver.com/', 'User One@someserver.com/',
'User One@…', 'User One@…',
'User One@someserver.com' 'Shared by User One@someserver.com'
); );
checkOwner( checkOwner(
'User One@someserver.com/root/of/owncloud', 'User One@someserver.com/root/of/owncloud',
'User One@…', 'User One@…',
'User One@someserver.com' 'Shared by User One@someserver.com'
); );
}); });
it('displays the user name part with domain of a remote share owner', function() { it('displays the user name part with domain of a remote share owner', function() {
checkOwner( checkOwner(
'User One@example.com@someserver.com', 'User One@example.com@someserver.com',
'User One@example.com', 'User One@example.com',
'User One@example.com@someserver.com' 'Shared by User One@example.com@someserver.com'
); );
checkOwner( checkOwner(
'User One@example.com@someserver.com/', 'User One@example.com@someserver.com/',
'User One@example.com', 'User One@example.com',
'User One@example.com@someserver.com' 'Shared by User One@example.com@someserver.com'
); );
checkOwner( checkOwner(
'User One@example.com@someserver.com/root/of/owncloud', 'User One@example.com@someserver.com/root/of/owncloud',
'User One@example.com', 'User One@example.com',
'User One@example.com@someserver.com' 'Shared by User One@example.com@someserver.com'
); );
}); });
}); });
@ -151,14 +151,14 @@ describe('OC.Share tests', function() {
}); });
}); });
describe('displaying the recipoients', function() { describe('displaying the recipients', function() {
function checkRecipients(input, output, title) { function checkRecipients(input, output, title) {
var $action; var $action;
$file.attr('data-share-recipients', input); $file.attr('data-share-recipients', input);
OC.Share.markFileAsShared($file, true); OC.Share.markFileAsShared($file, true);
$action = $file.find('.action-share>span'); $action = $file.find('.action-share>span').parent();
expect($action.text().trim()).toEqual(output); expect($action.text().trim()).toEqual(output);
if (_.isString(title)) { if (_.isString(title)) {
expect($action.find('.remoteAddress').attr('title')).toEqual(title); expect($action.find('.remoteAddress').attr('title')).toEqual(title);
@ -182,62 +182,61 @@ describe('OC.Share tests', function() {
it('displays the user name part of a remote recipient', function() { it('displays the user name part of a remote recipient', function() {
checkRecipients( checkRecipients(
'User One@someserver.com', 'User One@someserver.com',
'Shared with User One@…', 'User One@…',
'User One@someserver.com' 'Shared with User One@someserver.com'
); );
checkRecipients( checkRecipients(
'User One@someserver.com/', 'User One@someserver.com/',
'Shared with User One@…', 'User One@…',
'User One@someserver.com' 'Shared with User One@someserver.com'
); );
checkRecipients( checkRecipients(
'User One@someserver.com/root/of/owncloud', 'User One@someserver.com/root/of/owncloud',
'Shared with User One@…', 'User One@…',
'User One@someserver.com' 'Shared with User One@someserver.com'
); );
}); });
it('displays the user name part with domain of a remote share owner', function() { it('displays the user name part with domain of a remote share owner', function() {
checkRecipients( checkRecipients(
'User One@example.com@someserver.com', 'User One@example.com@someserver.com',
'Shared with User One@example.com', 'User One@example.com',
'User One@example.com@someserver.com' 'Shared with User One@example.com@someserver.com'
); );
checkRecipients( checkRecipients(
'User One@example.com@someserver.com/', 'User One@example.com@someserver.com/',
'Shared with User One@example.com', 'User One@example.com',
'User One@example.com@someserver.com' 'Shared with User One@example.com@someserver.com'
); );
checkRecipients( checkRecipients(
'User One@example.com@someserver.com/root/of/owncloud', 'User One@example.com@someserver.com/root/of/owncloud',
'Shared with User One@example.com', 'User One@example.com',
'User One@example.com@someserver.com' 'Shared with User One@example.com@someserver.com'
); );
}); });
it('display multiple remote recipients', function() { it('display multiple remote recipients', function() {
checkRecipients( checkRecipients(
'One@someserver.com, two@otherserver.com', 'One@someserver.com, two@otherserver.com',
'Shared with One@…, two@…', 'One@… two@…',
['One@someserver.com', 'two@otherserver.com'] ['Shared with One@someserver.com', 'Shared with two@otherserver.com']
); );
checkRecipients( checkRecipients(
'One@someserver.com/, two@otherserver.com', 'One@someserver.com/, two@otherserver.com',
'Shared with One@…, two@…', 'One@… two@…',
['One@someserver.com', 'two@otherserver.com'] ['Shared with One@someserver.com', 'Shared with two@otherserver.com']
); );
checkRecipients( checkRecipients(
'One@someserver.com/root/of/owncloud, two@otherserver.com', 'One@someserver.com/root/of/owncloud, two@otherserver.com',
'Shared with One@…, two@…', 'One@… two@…',
['One@someserver.com', 'two@otherserver.com'] ['Shared with One@someserver.com', 'Shared with two@otherserver.com']
); );
}); });
it('display mixed recipients', function() { it('display mixed recipients', function() {
checkRecipients( checkRecipients(
'One, two@otherserver.com', 'One, two@otherserver.com',
'Shared with One, two@…', 'Shared with One two@…',
['two@otherserver.com'] ['Shared with two@otherserver.com']
); );
}); });
}); });
}); });
}); });