diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-10-30 17:26:53 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-11-06 00:53:59 +0100 |
commit | 5d2c89ca6c1e99d38fd12d5fddaa7370d863750c (patch) | |
tree | fb11bcbb09a09bd86ee18f860d195c794081d16e /apps/files_sharing/src | |
parent | eebcf890917ca17f9e3bd00a792b89f841c824da (diff) | |
download | nextcloud-server-5d2c89ca6c1e99d38fd12d5fddaa7370d863750c.tar.gz nextcloud-server-5d2c89ca6c1e99d38fd12d5fddaa7370d863750c.zip |
Fix sharing breadcrumbs
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files_sharing/src')
-rw-r--r-- | apps/files_sharing/src/share.js | 163 | ||||
-rw-r--r-- | apps/files_sharing/src/sharebreadcrumbview.js | 31 |
2 files changed, 161 insertions, 33 deletions
diff --git a/apps/files_sharing/src/share.js b/apps/files_sharing/src/share.js index 9c63b9a9884..a59cfda4b12 100644 --- a/apps/files_sharing/src/share.js +++ b/apps/files_sharing/src/share.js @@ -20,10 +20,31 @@ if (!OCA.Sharing) { OCA.Sharing = {} } + + OC.Share = _.extend(OC.Share || {}, { + SHARE_TYPE_USER: 0, + SHARE_TYPE_GROUP: 1, + SHARE_TYPE_LINK: 3, + SHARE_TYPE_EMAIL: 4, + SHARE_TYPE_REMOTE: 6, + SHARE_TYPE_CIRCLE: 7, + SHARE_TYPE_GUEST: 8, + SHARE_TYPE_REMOTE_GROUP: 9, + SHARE_TYPE_ROOM: 10 + }) + /** * @namespace */ OCA.Sharing.Util = { + + /** + * Regular expression for splitting parts of remote share owners: + * "user@example.com/path/to/owncloud" + * "user@anotherexample.com@example.com/path/to/owncloud + */ + _REMOTE_OWNER_REGEXP: new RegExp('^([^@]*)@(([^@]*)@)?([^/]*)([/](.*)?)?$'), + /** * Initialize the sharing plugin. * @@ -210,9 +231,7 @@ }) // register share breadcrumbs component - var shareTab = new OCA.Sharing.ShareTabView('sharing', {order: -20}) - - var breadCrumbSharingDetailView = new OCA.Sharing.ShareBreadCrumbView({ shareTab: shareTab }) + var breadCrumbSharingDetailView = new OCA.Sharing.ShareBreadCrumbView() fileList.registerBreadCrumbDetailView(breadCrumbSharingDetailView) }, @@ -313,9 +332,9 @@ // even if reshared, only show "Shared by" if (ownerId) { message = t('core', 'Shared by') - avatars = this._formatRemoteShare(ownerId, owner, message) + avatars = OCA.Sharing.Util._formatRemoteShare(ownerId, owner, message) } else if (recipients) { - avatars = this._formatShareList(recipients) + avatars = OCA.Sharing.Util._formatShareList(recipients) } action.html(avatars).prepend(icon) @@ -334,6 +353,140 @@ } icon.removeClass('icon-shared icon-public').addClass(iconClass) }, + /** + * Format a remote address + * + * @param {String} shareWith userid, full remote share, or whatever + * @param {String} shareWithDisplayName + * @param {String} message + * @returns {String} HTML code to display + */ + _formatRemoteShare: function(shareWith, shareWithDisplayName, message) { + var parts = OCA.Sharing.Util._REMOTE_OWNER_REGEXP.exec(shareWith) + if (!parts) { + // display avatar of the user + var avatar = '<span class="avatar" data-username="' + escapeHTML(shareWith) + '" title="' + message + ' ' + escapeHTML(shareWithDisplayName) + '"></span>' + var hidden = '<span class="hidden-visually">' + message + ' ' + escapeHTML(shareWithDisplayName) + '</span> ' + return avatar + hidden + } + + var userName = parts[1] + var userDomain = parts[3] + var server = parts[4] + var tooltip = message + ' ' + userName + if (userDomain) { + tooltip += '@' + userDomain + } + if (server) { + if (!userDomain) { + userDomain = '…' + } + tooltip += '@' + server + } + + var html = '<span class="remoteAddress" title="' + escapeHTML(tooltip) + '">' + html += '<span class="username">' + escapeHTML(userName) + '</span>' + if (userDomain) { + html += '<span class="userDomain">@' + escapeHTML(userDomain) + '</span>' + } + html += '</span> ' + return html + }, + /** + * Loop over all recipients in the list and format them using + * all kind of fancy magic. + * + * @param {Object} recipients array of all the recipients + * @returns {String[]} modified list of recipients + */ + _formatShareList: function(recipients) { + var _parent = this + recipients = _.toArray(recipients) + recipients.sort(function(a, b) { + return a.shareWithDisplayName.localeCompare(b.shareWithDisplayName) + }) + return $.map(recipients, function(recipient) { + return _parent._formatRemoteShare(recipient.shareWith, recipient.shareWithDisplayName, t('core', 'Shared with')) + }) + }, + + /** + * Marks/unmarks a given file as shared by changing its action icon + * and folder icon. + * + * @param $tr file element to mark as shared + * @param hasShares whether shares are available + * @param hasLink whether link share is available + */ + markFileAsShared: function($tr, hasShares, hasLink) { + var action = $tr.find('.fileactions .action[data-action="Share"]') + var type = $tr.data('type') + var icon = action.find('.icon') + var message, recipients, avatars + var ownerId = $tr.attr('data-share-owner-id') + var owner = $tr.attr('data-share-owner') + var mountType = $tr.attr('data-mounttype') + var shareFolderIcon + var iconClass = 'icon-shared' + action.removeClass('shared-style') + // update folder icon + if (type === 'dir' && (hasShares || hasLink || ownerId)) { + if (typeof mountType !== 'undefined' && mountType !== 'shared-root' && mountType !== 'shared') { + shareFolderIcon = OC.MimeType.getIconUrl('dir-' + mountType) + } else if (hasLink) { + shareFolderIcon = OC.MimeType.getIconUrl('dir-public') + } else { + shareFolderIcon = OC.MimeType.getIconUrl('dir-shared') + } + $tr.find('.filename .thumbnail').css('background-image', 'url(' + shareFolderIcon + ')') + $tr.attr('data-icon', shareFolderIcon) + } else if (type === 'dir') { + var isEncrypted = $tr.attr('data-e2eencrypted') + // FIXME: duplicate of FileList._createRow logic for external folder, + // need to refactor the icon logic into a single code path eventually + if (isEncrypted === 'true') { + shareFolderIcon = OC.MimeType.getIconUrl('dir-encrypted') + $tr.attr('data-icon', shareFolderIcon) + } else if (mountType && mountType.indexOf('external') === 0) { + shareFolderIcon = OC.MimeType.getIconUrl('dir-external') + $tr.attr('data-icon', shareFolderIcon) + } else { + shareFolderIcon = OC.MimeType.getIconUrl('dir') + // back to default + $tr.removeAttr('data-icon') + } + $tr.find('.filename .thumbnail').css('background-image', 'url(' + shareFolderIcon + ')') + } + // update share action text / icon + if (hasShares || ownerId) { + recipients = $tr.data('share-recipient-data') + action.addClass('shared-style') + + avatars = '<span>' + t('core', 'Shared') + '</span>' + // even if reshared, only show "Shared by" + if (ownerId) { + message = t('core', 'Shared by') + avatars = this._formatRemoteShare(ownerId, owner, message) + } else if (recipients) { + avatars = this._formatShareList(recipients) + } + action.html(avatars).prepend(icon) + + if (ownerId || recipients) { + var avatarElement = action.find('.avatar') + avatarElement.each(function() { + $(this).avatar($(this).data('username'), 32) + }) + action.find('span[title]').tooltip({ placement: 'top' }) + } + } else { + action.html('<span class="hidden-visually">' + t('core', 'Shared') + '</span>').prepend(icon) + } + if (hasLink) { + iconClass = 'icon-public' + } + icon.removeClass('icon-shared icon-public').addClass(iconClass) + }, /** * @param {Array} fileData diff --git a/apps/files_sharing/src/sharebreadcrumbview.js b/apps/files_sharing/src/sharebreadcrumbview.js index c712229b2ee..5c310501649 100644 --- a/apps/files_sharing/src/sharebreadcrumbview.js +++ b/apps/files_sharing/src/sharebreadcrumbview.js @@ -30,13 +30,6 @@ }, _dirInfo: undefined, - /** @type OCA.Sharing.ShareTabView */ - _shareTab: undefined, - - initialize: function(options) { - this._shareTab = options.shareTab - }, - render: function(data) { this._dirInfo = data.dirInfo || null @@ -72,28 +65,10 @@ dirInfo: self._dirInfo }) }) - this._shareTab.on('sharesChanged', function(shareModel) { - var shareTypes = [] - var shares = shareModel.getSharesWithCurrentItem() - for (var i = 0; i < shares.length; i++) { - if (shareTypes.indexOf(shares[i].share_type) === -1) { - shareTypes.push(shares[i].share_type) - } - } - - if (shareModel.hasLinkShares()) { - shareTypes.push(OC.Share.SHARE_TYPE_LINK) - } - - // Since the dirInfo isn't updated we need to do this dark hackery - self._dirInfo.shareTypes = shareTypes - - self.render({ - dirInfo: self._dirInfo - }) - }) - OCA.Files.App.fileList.showDetailsView(fileInfoModel, 'sharing') + var path = fileInfoModel.attributes.path + '/' + fileInfoModel.attributes.name + OCA.Files.Sidebar.file = path + OCA.Files.Sidebar.activeTab = 'sharing' } }) |