formatting remote sharer should take protocol, path into account
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
921f9441d3
commit
8e8861f716
|
@ -34,7 +34,7 @@ import escapeHTML from 'escape-html'
|
||||||
* "user@example.com/path/to/owncloud"
|
* "user@example.com/path/to/owncloud"
|
||||||
* "user@anotherexample.com@example.com/path/to/owncloud
|
* "user@anotherexample.com@example.com/path/to/owncloud
|
||||||
*/
|
*/
|
||||||
_REMOTE_OWNER_REGEXP: new RegExp('^(([^@]*)@(([^@^/^\\s]*)@)?)([^[\\s/]*)([/](.*))?$'),
|
_REMOTE_OWNER_REGEXP: new RegExp('^(([^@]*)@(([^@^/\\s]*)@)?)((https://)?[^[\\s/]*)([/](.*))?$'),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the sharing plugin.
|
* Initialize the sharing plugin.
|
||||||
|
@ -343,137 +343,140 @@ import escapeHTML from 'escape-html'
|
||||||
}
|
}
|
||||||
icon.removeClass('icon-shared icon-public').addClass(iconClass)
|
icon.removeClass('icon-shared icon-public').addClass(iconClass)
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Format a remote address
|
* Format a remote address
|
||||||
*
|
*
|
||||||
* @param {String} shareWith userid, full remote share, or whatever
|
* @param {String} shareWith userid, full remote share, or whatever
|
||||||
* @param {String} shareWithDisplayName
|
* @param {String} shareWithDisplayName
|
||||||
* @param {String} message
|
* @param {String} message
|
||||||
* @returns {String} HTML code to display
|
* @returns {String} HTML code to display
|
||||||
*/
|
*/
|
||||||
_formatRemoteShare: function(shareWith, shareWithDisplayName, message) {
|
_formatRemoteShare: function(shareWith, shareWithDisplayName, message) {
|
||||||
var parts = OCA.Sharing.Util._REMOTE_OWNER_REGEXP.exec(shareWith)
|
var parts = OCA.Sharing.Util._REMOTE_OWNER_REGEXP.exec(shareWith)
|
||||||
if (!parts || !parts[6]) {
|
console.error(parts);
|
||||||
// display avatar of the user
|
if (!parts || !parts[7]) {
|
||||||
var avatar = '<span class="avatar" data-username="' + escapeHTML(shareWith) + '" title="' + message + ' ' + escapeHTML(shareWithDisplayName) + '"></span>'
|
// display avatar of the user
|
||||||
var hidden = '<span class="hidden-visually">' + message + ' ' + escapeHTML(shareWithDisplayName) + '</span> '
|
var avatar = '<span class="avatar" data-username="' + escapeHTML(shareWith) + '" title="' + message + ' ' + escapeHTML(shareWithDisplayName) + '"></span>'
|
||||||
return avatar + hidden
|
var hidden = '<span class="hidden-visually">' + message + ' ' + escapeHTML(shareWithDisplayName) + '</span> '
|
||||||
}
|
return avatar + hidden
|
||||||
|
}
|
||||||
|
|
||||||
var userName = parts[2]
|
var userName = parts[2]
|
||||||
var userDomain = parts[4]
|
var userDomain = parts[4]
|
||||||
var server = parts[5]
|
var server = parts[5]
|
||||||
|
var protocol = parts[6]
|
||||||
|
var serverPath = parts[8] ? parts[7] : ''; // no trailing slash on root
|
||||||
|
|
||||||
var tooltip = message + ' ' + userName
|
var tooltip = message + ' ' + userName
|
||||||
if (userDomain) {
|
if (userDomain) {
|
||||||
tooltip += '@' + userDomain
|
tooltip += '@' + userDomain
|
||||||
}
|
}
|
||||||
if (server) {
|
if (server) {
|
||||||
tooltip += '@' + server
|
tooltip += '@' + server.replace(protocol, '') + serverPath
|
||||||
}
|
}
|
||||||
|
|
||||||
var html = '<span class="remoteAddress" title="' + escapeHTML(tooltip) + '">'
|
var html = '<span class="remoteAddress" title="' + escapeHTML(tooltip) + '">'
|
||||||
html += '<span class="username">' + escapeHTML(userName) + '</span>'
|
html += '<span class="username">' + escapeHTML(userName) + '</span>'
|
||||||
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
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Loop over all recipients in the list and format them using
|
* Loop over all recipients in the list and format them using
|
||||||
* all kind of fancy magic.
|
* all kind of fancy magic.
|
||||||
*
|
*
|
||||||
* @param {Object} recipients array of all the recipients
|
* @param {Object} recipients array of all the recipients
|
||||||
* @returns {String[]} modified list of recipients
|
* @returns {String[]} modified list of recipients
|
||||||
*/
|
*/
|
||||||
_formatShareList: function(recipients) {
|
_formatShareList: function(recipients) {
|
||||||
var _parent = this
|
var _parent = this
|
||||||
recipients = _.toArray(recipients)
|
recipients = _.toArray(recipients)
|
||||||
recipients.sort(function(a, b) {
|
recipients.sort(function(a, b) {
|
||||||
return a.shareWithDisplayName.localeCompare(b.shareWithDisplayName)
|
return a.shareWithDisplayName.localeCompare(b.shareWithDisplayName)
|
||||||
})
|
})
|
||||||
return $.map(recipients, function(recipient) {
|
return $.map(recipients, function(recipient) {
|
||||||
return _parent._formatRemoteShare(recipient.shareWith, recipient.shareWithDisplayName, t('core', 'Shared with'))
|
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"
|
* Marks/unmarks a given file as shared by changing its action icon
|
||||||
if (ownerId) {
|
* and folder icon.
|
||||||
message = t('core', 'Shared by')
|
*
|
||||||
avatars = this._formatRemoteShare(ownerId, owner, message)
|
* @param $tr file element to mark as shared
|
||||||
} else if (recipients) {
|
* @param hasShares whether shares are available
|
||||||
avatars = this._formatShareList(recipients)
|
* @param hasLink whether link share is available
|
||||||
}
|
*/
|
||||||
action.html(avatars).prepend(icon)
|
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')
|
||||||
|
|
||||||
if (ownerId || recipients) {
|
avatars = '<span>' + t('core', 'Shared') + '</span>'
|
||||||
var avatarElement = action.find('.avatar')
|
// even if reshared, only show "Shared by"
|
||||||
avatarElement.each(function() {
|
if (ownerId) {
|
||||||
$(this).avatar($(this).data('username'), 32)
|
message = t('core', 'Shared by')
|
||||||
})
|
avatars = this._formatRemoteShare(ownerId, owner, message)
|
||||||
action.find('span[title]').tooltip({ placement: 'top' })
|
} else if (recipients) {
|
||||||
}
|
avatars = this._formatShareList(recipients)
|
||||||
} else {
|
}
|
||||||
action.html('<span class="hidden-visually">' + t('core', 'Shared') + '</span>').prepend(icon)
|
action.html(avatars).prepend(icon)
|
||||||
}
|
|
||||||
if (hasLink) {
|
if (ownerId || recipients) {
|
||||||
iconClass = 'icon-public'
|
var avatarElement = action.find('.avatar')
|
||||||
}
|
avatarElement.each(function() {
|
||||||
icon.removeClass('icon-shared icon-public').addClass(iconClass)
|
$(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)
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue