diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2017-11-27 16:46:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-27 16:46:11 +0100 |
commit | f700cd14fa4f094b7822edcf2e1a74b7f44ae32b (patch) | |
tree | df62e15e70eee968b6863b441ffa08efdd22636e /apps/files_sharing | |
parent | 4a63727ed989818eaca85dea113e8e0b075b1c07 (diff) | |
parent | 134192d76cf27bee9549710a1eac40db3ef1edf1 (diff) | |
download | nextcloud-server-f700cd14fa4f094b7822edcf2e1a74b7f44ae32b.tar.gz nextcloud-server-f700cd14fa4f094b7822edcf2e1a74b7f44ae32b.zip |
Merge pull request #7222 from nextcloud/fix-filerow-avatars
Fix filerow avatars
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/js/share.js | 50 | ||||
-rw-r--r-- | apps/files_sharing/js/sharedfilelist.js | 47 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/shareSpec.js | 89 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/sharedfilelistSpec.js | 4 |
4 files changed, 80 insertions, 110 deletions
diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index 5cd04ece446..aa0803c491b 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -46,13 +46,14 @@ tr.attr('data-share-permissions', sharePermissions); if (fileData.shareOwner) { tr.attr('data-share-owner', fileData.shareOwner); + tr.attr('data-share-owner-id', fileData.shareOwnerId); // user should always be able to rename a mount point if (fileData.mountType === 'shared-root') { tr.attr('data-permissions', fileData.permissions | OC.PERMISSION_UPDATE); } } - if (fileData.recipientsDisplayName) { - tr.attr('data-share-recipients', fileData.recipientsDisplayName); + if (fileData.recipientData && !_.isEmpty(fileData.recipientData)) { + tr.attr('data-share-recipient-data', JSON.stringify(fileData.recipientData)); } if (fileData.shareTypes) { tr.attr('data-share-types', fileData.shareTypes.join(',')); @@ -67,8 +68,7 @@ fileInfo.shareOwner = $el.attr('data-share-owner') || undefined; if( $el.attr('data-share-types')){ - var shareTypes = $el.attr('data-share-types').split(','); - fileInfo.shareTypes = shareTypes; + fileInfo.shareTypes = $el.attr('data-share-types').split(','); } if( $el.attr('data-expiration')){ @@ -77,8 +77,6 @@ fileInfo.shares.push({expiration: expirationTimestamp}); } - fileInfo.recipientsDisplayName = $el.attr('data-share-recipients') || undefined; - return fileInfo; }; @@ -218,10 +216,13 @@ var recipients = _.pluck(shareModel.get('shares'), 'share_with_displayname'); // note: we only update the data attribute because updateIcon() if (recipients.length) { - $tr.attr('data-share-recipients', OCA.Sharing.Util.formatRecipients(recipients)); + var recipientData = _.mapObject(shareModel.get('shares'), function (share) { + return {shareWith: share.share_with, shareWithDisplayName: share.share_with_displayname}; + }); + $tr.attr('data-share-recipient-data', JSON.stringify(recipientData)); } else { - $tr.removeAttr('data-share-recipients'); + $tr.removeAttr('data-share-recipient-data'); } }, @@ -229,15 +230,15 @@ * Update the file action share icon for the given file * * @param $tr file element of the file to update - * @param {bool} hasUserShares true if a user share exists - * @param {bool} hasLinkShare true if a link share exists + * @param {boolean} hasUserShares true if a user share exists + * @param {boolean} hasLinkShare true if a link share exists * - * @return {bool} true if the icon was set, false otherwise + * @return {boolean} true if the icon was set, false otherwise */ _updateFileActionIcon: function($tr, hasUserShares, hasLinkShare) { // if the statuses are loaded already, use them for the icon // (needed when scrolling to the next page) - if (hasUserShares || hasLinkShare || $tr.attr('data-share-recipients') || $tr.attr('data-share-owner')) { + if (hasUserShares || hasLinkShare || $tr.attr('data-share-recipient-data') || $tr.attr('data-share-owner')) { OC.Share.markFileAsShared($tr, true, hasLinkShare); return true; } @@ -245,31 +246,6 @@ }, /** - * Formats a recipients array to be displayed. - * The first four recipients will be shown and the - * other ones will be shown as "+x" where "x" is the number of - * remaining recipients. - * - * @param {Array.<String>} recipients recipients array - * @param {int} count optional total recipients count (in case the array was shortened) - * @return {String} formatted recipients display text - */ - formatRecipients: function(recipients, count) { - var maxRecipients = 4; - var text; - if (!_.isNumber(count)) { - count = recipients.length; - } - // TODO: use natural sort - recipients = _.first(recipients, maxRecipients).sort(); - text = recipients.join(', '); - if (count > maxRecipients) { - text += ', +' + (count - maxRecipients); - } - return text; - }, - - /** * @param {Array} fileData * @returns {String} */ diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js index b11b302c6c2..ad818d91413 100644 --- a/apps/files_sharing/js/sharedfilelist.js +++ b/apps/files_sharing/js/sharedfilelist.js @@ -153,6 +153,27 @@ // storage info like free space / used space }, + updateRow: function($tr, fileInfo, options) { + if(!fileInfo instanceof OCA.Sharing.SharedFileInfo) { + // recycle SharedFileInfo values if something tries to overwrite it + var oldModel = this.getModelForFile($tr); + + if(_.isUndefined(fileInfo.recipientData) && oldModel.recipientData) { + fileInfo.recipientData = oldModel.recipientData; + } + if(_.isUndefined(fileInfo.recipients) && oldModel.recipientData) { + fileInfo.recipientData = oldModel.recipientData; + } + if(_.isUndefined(fileInfo.shares) && oldModel.shares) { + fileInfo.shares = oldModel.shares; + } + if(_.isUndefined(fileInfo.shareOwner) && oldModel.shareOwner) { + fileInfo.shareOwner = oldModel.shareOwner; + } + } + OCA.Files.FileList.prototype._createRow.updateRow(this, arguments); + }, + reload: function() { this.showMask(); if (this._reloadCall) { @@ -225,7 +246,6 @@ }, _makeFilesFromRemoteShares: function(data) { - var self = this; var files = data; files = _.chain(files) @@ -297,6 +317,7 @@ }; if (self._sharedWithUser) { file.shareOwner = share.displayname_owner; + file.shareOwnerId = share.uid_owner; file.name = OC.basename(share.file_target); file.path = OC.dirname(share.file_target); file.permissions = share.permissions; @@ -307,6 +328,7 @@ else { if (share.share_type !== OC.Share.SHARE_TYPE_LINK) { file.share.targetDisplayName = share.share_with_displayname; + file.share.targetShareWithId = share.share_with; } file.name = OC.basename(share.path); file.path = OC.dirname(share.path); @@ -325,12 +347,14 @@ .reduce(function(memo, file) { var data = memo[file.id]; var recipient = file.share.targetDisplayName; + var recipientId = file.share.targetShareWithId; if (!data) { data = memo[file.id] = file; data.shares = [file.share]; // using a hash to make them unique, // this is only a list to be displayed data.recipients = {}; + data.recipientData = {}; // share types data.shareTypes = {}; // counter is cheaper than calling _.keys().length @@ -351,6 +375,10 @@ // only store the first ones, they will be the only ones // displayed data.recipients[recipient] = true; + data.recipientData[data.recipientsCount] = { + 'shareWith': recipientId, + 'shareWithDisplayName': recipient + }; } data.recipientsCount++; } @@ -367,11 +395,6 @@ // convert the recipients map to a flat // array of sorted names data.mountType = 'shared'; - data.recipients = _.keys(data.recipients); - data.recipientsDisplayName = OCA.Sharing.Util.formatRecipients( - data.recipients, - data.recipientsCount - ); delete data.recipientsCount; if (self._sharedWithUser) { // only for outgoing shres @@ -405,7 +428,16 @@ * @property {int} stime share timestamp in milliseconds * @property {String} [targetDisplayName] display name of the recipient * (only when shared with others) + * @property {String} [targetShareWithId] id of the recipient + * + */ + + /** + * Recipient attributes * + * @typedef {Object} OCA.Sharing.RecipientInfo + * @property {String} shareWith the id of the recipient + * @property {String} shareWithDisplayName the display name of the recipient */ /** @@ -419,7 +451,8 @@ * @property {String} shareOwner name of the share owner * @property {Array.<String>} recipients name of the first 4 recipients * (this is mostly for display purposes) - * @property {String} recipientsDisplayName display name + * @property {Object.<OCA.Sharing.RecipientInfo>} recipientData (as object for easier + * passing to HTML data attributes with jQuery) */ OCA.Sharing.FileList = FileList; diff --git a/apps/files_sharing/tests/js/shareSpec.js b/apps/files_sharing/tests/js/shareSpec.js index 5b0a78c9c64..893525f7566 100644 --- a/apps/files_sharing/tests/js/shareSpec.js +++ b/apps/files_sharing/tests/js/shareSpec.js @@ -140,6 +140,7 @@ describe('OCA.Sharing.Util tests', function() { size: 12, permissions: OC.PERMISSION_ALL, shareOwner: 'User One', + shareOwnerId: 'User One', etag: 'abc', shareTypes: [] }]); @@ -161,6 +162,16 @@ describe('OCA.Sharing.Util tests', function() { size: 12, permissions: OC.PERMISSION_ALL, recipientsDisplayName: 'User One, User Two', + recipientData: { + 0: { + shareWith: 'User One', + shareWithDisplayName: 'User One' + }, + 1: { + shareWith: 'User Two', + shareWithDisplayName: 'User Two' + } + }, etag: 'abc', shareTypes: [OC.Share.SHARE_TYPE_USER] }]); @@ -264,15 +275,13 @@ describe('OCA.Sharing.Util tests', function() { // simulate updating shares shareTab._dialog.model.set({ shares: [ - {share_with_displayname: 'User One'}, - {share_with_displayname: 'User Two'}, - {share_with_displayname: 'Group One'}, - {share_with_displayname: 'Group Two'} + {share_with_displayname: 'User One', share_with: 'User One'}, + {share_with_displayname: 'User Two', share_with: 'User Two'}, + {share_with_displayname: 'Group One', share_with: 'Group One'}, + {share_with_displayname: 'Group Two', share_with: 'Group Two'} ] }); - expect($tr.attr('data-share-recipients')).toEqual('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-public')).toEqual(false); @@ -298,14 +307,12 @@ describe('OCA.Sharing.Util tests', function() { // simulate updating shares shareTab._dialog.model.set({ shares: [ - {share_with_displayname: 'User One'}, - {share_with_displayname: 'User Two'}, - {share_with_displayname: 'User Three'} + {share_with_displayname: 'User One', share_with: 'User One'}, + {share_with_displayname: 'User Two', share_with: 'User Two'}, + {share_with_displayname: 'User Three', share_with: 'User Three'} ] }); - expect($tr.attr('data-share-recipients')).toEqual('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-public')).toEqual(false); @@ -334,7 +341,7 @@ describe('OCA.Sharing.Util tests', function() { shares: [] }); - expect($tr.attr('data-share-recipients')).not.toBeDefined(); + expect($tr.attr('data-share-recipient-data')).not.toBeDefined(); }); it('keep share text after updating reshare', function() { var $action, $tr; @@ -348,7 +355,8 @@ describe('OCA.Sharing.Util tests', function() { size: 12, permissions: OC.PERMISSION_ALL, etag: 'abc', - shareOwner: 'User One' + shareOwner: 'User One', + shareOwnerId: 'User One' }]); $action = fileList.$el.find('tbody tr:first .action-share'); $tr = fileList.$el.find('tr:first'); @@ -360,8 +368,6 @@ describe('OCA.Sharing.Util tests', function() { shares: [{share_with_displayname: 'User Two'}] }); - expect($tr.attr('data-share-recipients')).toEqual('User Two'); - 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-public')).toEqual(false); @@ -379,7 +385,9 @@ describe('OCA.Sharing.Util tests', function() { permissions: OC.PERMISSION_ALL, etag: 'abc', shareOwner: 'User One', - recipients: 'User Two' + shareOwnerId: 'User One', + recipients: 'User Two', + recipientData: {'User Two': 'User Two'} }]); $action = fileList.$el.find('tbody tr:first .action-share'); $tr = fileList.$el.find('tr:first'); @@ -391,60 +399,13 @@ describe('OCA.Sharing.Util tests', function() { shares: [] }); - expect($tr.attr('data-share-recipients')).not.toBeDefined(); + expect($tr.attr('data-share-recipient-data')).not.toBeDefined(); 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-public')).toEqual(false); }); }); - describe('formatRecipients', function() { - it('returns a single recipient when one passed', function() { - expect(OCA.Sharing.Util.formatRecipients(['User one'])) - .toEqual('User one'); - }); - it('returns two recipients when two passed', function() { - expect(OCA.Sharing.Util.formatRecipients(['User one', 'User two'])) - .toEqual('User one, User two'); - }); - it('returns four recipients with plus when five passed', function() { - var recipients = [ - 'User one', - 'User two', - 'User three', - 'User four', - 'User five' - ]; - expect(OCA.Sharing.Util.formatRecipients(recipients)) - .toEqual('User four, User one, User three, User two, +1'); - }); - it('returns four recipients with plus when ten passed', function() { - var recipients = [ - 'User one', - 'User two', - 'User three', - 'User four', - 'User five', - 'User six', - 'User seven', - 'User eight', - 'User nine', - 'User ten' - ]; - expect(OCA.Sharing.Util.formatRecipients(recipients)) - .toEqual('User four, User one, User three, User two, +6'); - }); - it('returns four recipients with plus when four passed with counter', function() { - var recipients = [ - 'User one', - 'User two', - 'User three', - 'User four' - ]; - expect(OCA.Sharing.Util.formatRecipients(recipients, 10)) - .toEqual('User four, User one, User three, User two, +6'); - }); - }); describe('Excluded lists', function() { function createListThenAttach(listId) { var fileActions = new OCA.Files.FileActions(); diff --git a/apps/files_sharing/tests/js/sharedfilelistSpec.js b/apps/files_sharing/tests/js/sharedfilelistSpec.js index 3efbb8fcea3..903234947bd 100644 --- a/apps/files_sharing/tests/js/sharedfilelistSpec.js +++ b/apps/files_sharing/tests/js/sharedfilelistSpec.js @@ -628,7 +628,7 @@ describe('OCA.Sharing.FileList tests', function() { expect($tr.attr('data-permissions')).toEqual('31'); // read and delete expect($tr.attr('data-mime')).toEqual('text/plain'); expect($tr.attr('data-mtime')).toEqual('11111000'); - expect($tr.attr('data-share-recipients')).not.toBeDefined(); + expect($tr.attr('data-share-recipient-data')).not.toBeDefined(); expect($tr.attr('data-share-owner')).not.toBeDefined(); expect($tr.attr('data-share-id')).toEqual('7'); expect($tr.attr('data-favorite')).toEqual('true'); @@ -681,7 +681,7 @@ describe('OCA.Sharing.FileList tests', function() { expect($tr.attr('data-permissions')).toEqual('31'); // read and delete expect($tr.attr('data-mime')).toEqual('text/plain'); expect($tr.attr('data-mtime')).toEqual('11111000'); - expect($tr.attr('data-share-recipients')).not.toBeDefined(); + expect($tr.attr('data-share-recipient-data')).not.toBeDefined(); expect($tr.attr('data-share-owner')).not.toBeDefined(); expect($tr.attr('data-share-id')).toEqual('7'); expect($tr.attr('data-favorite')).toEqual('true'); |