Skip to content

Avatars in share dialog #13866

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

Merged
merged 6 commits into from
Feb 17, 2015
Merged
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
6 changes: 6 additions & 0 deletions core/css/share.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
overflow: hidden;
vertical-align: middle;
}
#shareWithList .avatar {
margin-right: 2px;
display: inline-block;
overflow: hidden;
vertical-align: middle;
}
#shareWithList li label{
margin-right: 8px;
}
Expand Down
1 change: 1 addition & 0 deletions core/js/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
'session_keepalive' => \OCP\Config::getSystemValue('session_keepalive', true),
'version' => implode('.', OC_Util::getVersion()),
'versionstring' => OC_Util::getVersionString(),
'enable_avatars' => \OC::$server->getConfig()->getSystemValue('enable_avatars', true),
)
),
"oc_appconfig" => json_encode(
Expand Down
3 changes: 2 additions & 1 deletion core/js/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"libraries": [
"jquery-showpassword.js",
"jquery-tipsy.js"
"jquery-tipsy.js",
"jquery.avatar.js"
],
"modules": [
"compatibility.js",
Expand Down
28 changes: 26 additions & 2 deletions core/js/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,17 @@ OC.Share={
var html = '<div id="dropdown" class="drop shareDropDown" data-item-type="'+itemType+'" data-item-source="'+itemSource+'">';
if (data !== false && data.reshare !== false && data.reshare.uid_owner !== undefined) {
if (data.reshare.share_type == OC.Share.SHARE_TYPE_GROUP) {
html += '<span class="reshare">'+t('core', 'Shared with you and the group {group} by {owner}', {group: data.reshare.share_with, owner: data.reshare.displayname_owner})+'</span>';
html += '<span class="reshare">'+t('core', 'Shared with you and the group {group} by {owner}', {group: data.reshare.share_with, owner: data.reshare.displayname_owner});
if (oc_config.enable_avatars === true) {
html += ' <div id="avatar-share-owner" style="display: inline-block"></div>';
}
html += '</span>';
} else {
html += '<span class="reshare">'+t('core', 'Shared with you by {owner}', {owner: data.reshare.displayname_owner})+'</span>';
html += '<span class="reshare">'+t('core', 'Shared with you by {owner}', {owner: data.reshare.displayname_owner});
if (oc_config.enable_avatars === true) {
html += ' <div id="avatar-share-owner" style="display: inline-block"></div>';
}
html += '</span>';
}
html += '<br />';
// reduce possible permissions to what the original share allowed
Expand Down Expand Up @@ -437,6 +445,12 @@ OC.Share={
html += '</div>';
dropDownEl = $(html);
dropDownEl = dropDownEl.appendTo(appendTo);

//Get owner avatars
if (oc_config.enable_avatars === true && data !== false && data.reshare !== false && data.reshare.uid_owner !== undefined) {
$('#avatar-share-owner').avatar(data.reshare.uid_owner, 32);
}

// Reset item shares
OC.Share.itemShares = [];
OC.Share.currentShares = {};
Expand Down Expand Up @@ -650,6 +664,13 @@ OC.Share={
var html = '<li style="clear: both;" data-share-type="'+escapeHTML(shareType)+'" data-share-with="'+escapeHTML(shareWith)+'" title="' + escapeHTML(shareWith) + '">';
var showCrudsButton;
html += '<a href="#" class="unshare"><img class="svg" alt="'+t('core', 'Unshare')+'" title="'+t('core', 'Unshare')+'" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>';
if (oc_config.enable_avatars === true) {
if (shareType === OC.Share.SHARE_TYPE_USER) {
html += '<div id="avatar-' + escapeHTML(shareWith) + '" class="avatar"></div>';
} else {
html += '<div class="avatar" style="padding-right: 32px"></div>';
}
}
html += '<span class="username">' + escapeHTML(shareWithDisplayName) + '</span>';
var mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val();
if (mailNotificationEnabled === 'yes' && shareType !== OC.Share.SHARE_TYPE_REMOTE) {
Expand Down Expand Up @@ -681,6 +702,9 @@ OC.Share={
html += '</div>';
html += '</li>';
html = $(html).appendTo('#shareWithList');
if (oc_config.enable_avatars === true && shareType === OC.Share.SHARE_TYPE_USER) {
$('#avatar-' + escapeHTML(shareWith)).avatar(escapeHTML(shareWith), 32);
}
// insert cruds button into last label element
var lastLabel = html.find('>label:last');
if (lastLabel.exists()){
Expand Down
82 changes: 82 additions & 0 deletions core/js/tests/specs/shareSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ describe('OC.Share tests', function() {
var oldAppConfig;
var loadItemStub;
var autocompleteStub;
var oldEnableAvatars;
var avatarStub;

beforeEach(function() {
$('#testArea').append($('<div id="shareContainer"></div>'));
Expand Down Expand Up @@ -54,13 +56,19 @@ describe('OC.Share tests', function() {
var $el = $('<div></div>').data('ui-autocomplete', {});
return $el;
});

oldEnableAvatars = oc_config.enable_avatars;
oc_config.enable_avatars = false;
avatarStub = sinon.stub($.fn, 'avatar');
});
afterEach(function() {
/* jshint camelcase:false */
oc_appconfig.core = oldAppConfig;
loadItemStub.restore();

autocompleteStub.restore();
avatarStub.restore();
oc_config.enable_avatars = oldEnableAvatars;
$('#dropdown').remove();
});
it('calls loadItem with the correct arguments', function() {
Expand Down Expand Up @@ -405,6 +413,80 @@ describe('OC.Share tests', function() {
});
});
});
describe('check for avatar', function() {
beforeEach(function() {
loadItemStub.returns({
reshare: [],
shares: [{
id: 100,
item_source: 123,
permissions: 31,
share_type: OC.Share.SHARE_TYPE_USER,
share_with: 'user1',
share_with_displayname: 'User One'
},{
id: 101,
item_source: 123,
permissions: 31,
share_type: OC.Share.SHARE_TYPE_GROUP,
share_with: 'group',
share_with_displayname: 'group'
}]
});
});

describe('avatars enabled', function() {
beforeEach(function() {
oc_config.enable_avatars = true;
OC.Share.showDropDown(
'file',
123,
$container,
true,
31,
'shared_file_name.txt'
);
});

afterEach(function() {
oc_config.enable_avatars = false;
});

it('test correct function call', function() {
expect(avatarStub.calledOnce).toEqual(true);
var args = avatarStub.getCall(0).args;


expect($('#shareWithList').children().length).toEqual(2);

expect($('#avatar-user1').length).toEqual(1);
expect(args.length).toEqual(2);
expect(args[0]).toEqual('user1');
});

it('test no avatar for groups', function() {
expect($('#shareWithList').children().length).toEqual(2);
expect($('#shareWithList li:nth-child(2) .avatar').attr('id')).not.toBeDefined();
});
});

describe('avatars disabled', function() {
beforeEach(function() {
OC.Share.showDropDown(
'file',
123,
$container,
true,
31,
'shared_file_name.txt'
);
});

it('no avatar classes', function() {
expect($('.avatar').length).toEqual(0);
});
});
});
describe('"sharesChanged" event', function() {
var autocompleteOptions;
var handler;
Expand Down