From c5597baf88c3f7bcea9c03a3fa35e1dc81e12bd5 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Tue, 4 Oct 2016 12:56:04 +0200 Subject: show whether the current folder was shared or not Signed-off-by: Christoph Wurst --- apps/files/js/breadcrumb.js | 23 ++++++++++++ apps/files/js/filelist.js | 10 +++++ apps/files_sharing/appinfo/app.php | 1 + apps/files_sharing/js/share.js | 3 ++ apps/files_sharing/js/sharebreadcrumbview.js | 56 ++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 apps/files_sharing/js/sharebreadcrumbview.js diff --git a/apps/files/js/breadcrumb.js b/apps/files/js/breadcrumb.js index 98de7aa374c..ff9700456da 100644 --- a/apps/files/js/breadcrumb.js +++ b/apps/files/js/breadcrumb.js @@ -45,6 +45,7 @@ if (options.getCrumbUrl) { this.getCrumbUrl = options.getCrumbUrl; } + this._detailViews = []; }; /** * @memberof OCA.Files @@ -52,6 +53,7 @@ BreadCrumb.prototype = { $el: null, dir: null, + dirInfo: null, /** * Total width of all breadcrumbs @@ -79,6 +81,20 @@ } }, + setDirectoryInfo: function(dirInfo) { + if (dirInfo !== this.dirInfo) { + this.dirInfo = dirInfo; + this.render(); + } + }, + + /** + * @param {Backbone.View} detailView + */ + addDetailView: function(detailView) { + this._detailViews.push(detailView); + }, + /** * Returns the full URL to the given directory * @@ -122,6 +138,13 @@ } $crumb.addClass('last'); + _.each(this._detailViews, function(view) { + view.render({ + dirInfo: this.dirInfo + }); + $crumb.append(view.$el); + }, this); + // in case svg is not supported by the browser we need to execute the fallback mechanism if (!OC.Util.hasSVGSupport()) { OC.Util.replaceSVG(this.$el); diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 18534db3ee9..8d0e492643f 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1646,6 +1646,7 @@ // first entry is the root this.dirInfo = result.shift(); + this.breadcrumb.setDirectoryInfo(this.dirInfo); if (this.dirInfo.permissions) { this.setDirectoryPermissions(this.dirInfo.permissions); @@ -2954,6 +2955,15 @@ if (this._detailsView) { this._detailsView.addDetailView(detailView); } + }, + + /** + * Register a view to be added to the breadcrumb view + */ + registerBreadCrumbDetailView: function(detailView) { + if (this.breadcrumb) { + this.breadcrumb.addDetailView(detailView); + } } }; diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 7da295afddd..06f4a41ac14 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -42,6 +42,7 @@ $eventDispatcher->addListener( function() { \OCP\Util::addScript('files_sharing', 'share'); \OCP\Util::addScript('files_sharing', 'sharetabview'); + \OCP\Util::addScript('files_sharing', 'sharebreadcrumbview'); \OCP\Util::addStyle('files_sharing', 'sharetabview'); } ); diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index 64fc7ef7296..7629124ec44 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -185,6 +185,9 @@ } }); fileList.registerTabView(shareTab); + + var breadCrumbSharingDetailView = new OCA.Sharing.ShareBreadCrumbView(); + fileList.registerBreadCrumbDetailView(breadCrumbSharingDetailView); }, /** diff --git a/apps/files_sharing/js/sharebreadcrumbview.js b/apps/files_sharing/js/sharebreadcrumbview.js new file mode 100644 index 00000000000..c469fd252aa --- /dev/null +++ b/apps/files_sharing/js/sharebreadcrumbview.js @@ -0,0 +1,56 @@ +/* global Handlebars, OC */ + +/** + * @copyright 2016 Christoph Wurst + * + * @author 2016 Christoph Wurst + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +(function() { + 'use strict'; + + var TEMPLATE = '{{#if isShared}}' + + 'Shared!' + + '{{else}}' + + 'Not shared!' + + '{{/if}}'; + + var BreadCrumbView = OC.Backbone.View.extend({ + tagName: 'span', + _template: undefined, + template: function(data) { + if (!this._template) { + this._template = Handlebars.compile(TEMPLATE); + } + return this._template(data); + }, + render: function(data) { + var isShared = data.dirInfo && data.dirInfo.shareTypes && data.dirInfo.shareTypes.length > 0; + + this.$el.html(this.template({ + isShared: isShared + })); + + return this; + } + }); + + OCA.Sharing.ShareBreadCrumbView = BreadCrumbView; +})(); + -- cgit v1.2.3 From bc1cb8a6d09d97df93b7914e020759eb7df73df1 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Tue, 4 Oct 2016 19:08:08 +0200 Subject: let users share the curren folder Signed-off-by: Christoph Wurst --- apps/files/js/filelist.js | 11 +++++++---- apps/files_sharing/js/sharebreadcrumbview.js | 12 ++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 8d0e492643f..5bdb1a8999d 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -518,13 +518,16 @@ OC.Apps.showAppSidebar(this._detailsView.$el); } - var $tr = this.findFileEl(fileName); - var model = this.getModelForFile($tr); + if (_.isObject(fileName)) { + var model = new OCA.Files.FileInfoModel(fileName); + } else { + var $tr = this.findFileEl(fileName); + var model = this.getModelForFile($tr); + $tr.addClass('highlighted'); + } this._currentFileModel = model; - $tr.addClass('highlighted'); - this._detailsView.setFileInfo(model); this._detailsView.$el.scrollTop(0); }, diff --git a/apps/files_sharing/js/sharebreadcrumbview.js b/apps/files_sharing/js/sharebreadcrumbview.js index c469fd252aa..7e659768304 100644 --- a/apps/files_sharing/js/sharebreadcrumbview.js +++ b/apps/files_sharing/js/sharebreadcrumbview.js @@ -33,6 +33,10 @@ var BreadCrumbView = OC.Backbone.View.extend({ tagName: 'span', + events: { + click: '_onClick' + }, + _dirInfo: undefined, _template: undefined, template: function(data) { if (!this._template) { @@ -41,13 +45,21 @@ return this._template(data); }, render: function(data) { + this._dirInfo = data.dirInfo; + var isShared = data.dirInfo && data.dirInfo.shareTypes && data.dirInfo.shareTypes.length > 0; this.$el.html(this.template({ isShared: isShared })); + this.delegateEvents(); return this; + }, + _onClick: function(e) { + e.preventDefault(); + + OCA.Files.App.fileList.showDetailsView(this._dirInfo, 'shareTabView'); } }); -- cgit v1.2.3 From 9e5e120ef9869b7c52d90e85782ec83a9217275d Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Mon, 10 Oct 2016 10:15:42 +0200 Subject: refactor share permission logic into own method to reuse it for the share tab Signed-off-by: Christoph Wurst --- apps/files_sharing/js/share.js | 35 ++++++++++++++++++++++------------- apps/files_sharing/js/sharetabview.js | 4 ++++ tests/karma.config.js | 2 +- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index 7629124ec44..2119db0b71e 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -36,19 +36,7 @@ var oldCreateRow = fileList._createRow; fileList._createRow = function(fileData) { var tr = oldCreateRow.apply(this, arguments); - var sharePermissions = fileData.permissions; - if (fileData.mountType && fileData.mountType === "external-root"){ - // for external storages we can't use the permissions of the mountpoint - // instead we show all permissions and only use the share permissions from the mountpoint to handle resharing - sharePermissions = sharePermissions | (OC.PERMISSION_ALL & ~OC.PERMISSION_SHARE); - } - if (fileData.type === 'file') { - // files can't be shared with delete permissions - sharePermissions = sharePermissions & ~OC.PERMISSION_DELETE; - - // create permissions don't mean anything for files - sharePermissions = sharePermissions & ~OC.PERMISSION_CREATE; - } + var sharePermissions = OCA.Sharing.Util.getSharePermissions(fileData); tr.attr('data-share-permissions', sharePermissions); if (fileData.shareOwner) { tr.attr('data-share-owner', fileData.shareOwner); @@ -251,6 +239,27 @@ text += ', +' + (count - maxRecipients); } return text; + }, + + /** + * @param {Array} fileData + * @returns {String} + */ + getSharePermissions: function(fileData) { + var sharePermissions = fileData.permissions; + if (fileData.mountType && fileData.mountType === "external-root"){ + // for external storages we can't use the permissions of the mountpoint + // instead we show all permissions and only use the share permissions from the mountpoint to handle resharing + sharePermissions = sharePermissions | (OC.PERMISSION_ALL & ~OC.PERMISSION_SHARE); + } + if (fileData.type === 'file') { + // files can't be shared with delete permissions + sharePermissions = sharePermissions & ~OC.PERMISSION_DELETE; + + // create permissions don't mean anything for files + sharePermissions = sharePermissions & ~OC.PERMISSION_CREATE; + } + return sharePermissions; } }; })(); diff --git a/apps/files_sharing/js/sharetabview.js b/apps/files_sharing/js/sharetabview.js index 2c7070aa3d5..7bb1f1229d0 100644 --- a/apps/files_sharing/js/sharetabview.js +++ b/apps/files_sharing/js/sharetabview.js @@ -50,6 +50,10 @@ if (this.model) { this.$el.html(this.template()); + if (_.isUndefined(this.model.get('sharePermissions'))) { + this.model.set('sharePermissions', OCA.Sharing.Util.getSharePermissions(this.model.attributes)); + } + // TODO: the model should read these directly off the passed fileInfoModel var attributes = { itemType: this.model.isDirectory() ? 'folder' : 'file', diff --git a/tests/karma.config.js b/tests/karma.config.js index 111af7a1559..d80b5bbd759 100644 --- a/tests/karma.config.js +++ b/tests/karma.config.js @@ -54,7 +54,7 @@ module.exports = function(config) { 'apps/files_sharing/js/app.js', 'apps/files_sharing/js/sharedfilelist.js', 'apps/files_sharing/js/share.js', - 'apps/files_sharing/js/external.js', + 'apps/files_sharing/js/sharebreadcrumbview.js', 'apps/files_sharing/js/public.js', 'apps/files_sharing/js/sharetabview.js' ], -- cgit v1.2.3 From 5bf7e5533d79c98d720d92ecee0125938805ff0f Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Mon, 10 Oct 2016 11:14:51 +0200 Subject: visually reflect sharing state of current folder Signed-off-by: Christoph Wurst --- apps/files_sharing/appinfo/app.php | 1 + apps/files_sharing/css/sharebreadcrumb.css | 33 ++++++++++++++++++++++++++++ apps/files_sharing/js/sharebreadcrumbview.js | 6 +---- core/css/styles.css | 5 ++++- 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 apps/files_sharing/css/sharebreadcrumb.css diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 06f4a41ac14..850c2c05977 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -44,6 +44,7 @@ $eventDispatcher->addListener( \OCP\Util::addScript('files_sharing', 'sharetabview'); \OCP\Util::addScript('files_sharing', 'sharebreadcrumbview'); \OCP\Util::addStyle('files_sharing', 'sharetabview'); + \OCP\Util::addStyle('files_sharing', 'sharebreadcrumb'); } ); diff --git a/apps/files_sharing/css/sharebreadcrumb.css b/apps/files_sharing/css/sharebreadcrumb.css new file mode 100644 index 00000000000..054c6bd66bf --- /dev/null +++ b/apps/files_sharing/css/sharebreadcrumb.css @@ -0,0 +1,33 @@ +/** + * @copyright 2016 Christoph Wurst + * + * @author 2016 Christoph Wurst + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +div.crumb span.icon-share { + display: inline-block; + width: 32px; + vertical-align: sub; + cursor: pointer; + opacity: 0.2; +} + +div.crumb span.icon-share.shared { + opacity: 0.7; +} diff --git a/apps/files_sharing/js/sharebreadcrumbview.js b/apps/files_sharing/js/sharebreadcrumbview.js index 7e659768304..9803c8f6dea 100644 --- a/apps/files_sharing/js/sharebreadcrumbview.js +++ b/apps/files_sharing/js/sharebreadcrumbview.js @@ -25,11 +25,7 @@ (function() { 'use strict'; - var TEMPLATE = '{{#if isShared}}' - + 'Shared!' - + '{{else}}' - + 'Not shared!' - + '{{/if}}'; + var TEMPLATE = ''; var BreadCrumbView = OC.Backbone.View.extend({ tagName: 'span', diff --git a/core/css/styles.css b/core/css/styles.css index d94a31c4cf1..6923ea42fc0 100644 --- a/core/css/styles.css +++ b/core/css/styles.css @@ -894,12 +894,15 @@ div.crumb.hidden { display: none; } div.crumb a, -div.crumb span { +div.crumb > span { position: relative; top: 12px; padding: 14px 24px 14px 17px; color: #555; } +div.crumb.last a { + padding-right: 14px; +} div.crumb:first-child a { position: relative; top: 13px; -- cgit v1.2.3 From 36cf77914069cd63b4d70d2ca0658f9000cddf78 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Mon, 10 Oct 2016 11:57:16 +0200 Subject: the root folder must not be shared Signed-off-by: Christoph Wurst --- apps/files_sharing/js/sharebreadcrumbview.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/apps/files_sharing/js/sharebreadcrumbview.js b/apps/files_sharing/js/sharebreadcrumbview.js index 9803c8f6dea..c6bf365ba07 100644 --- a/apps/files_sharing/js/sharebreadcrumbview.js +++ b/apps/files_sharing/js/sharebreadcrumbview.js @@ -43,12 +43,17 @@ render: function(data) { this._dirInfo = data.dirInfo; - var isShared = data.dirInfo && data.dirInfo.shareTypes && data.dirInfo.shareTypes.length > 0; - - this.$el.html(this.template({ - isShared: isShared - })); - this.delegateEvents(); + if (this._dirInfo !== null && (this._dirInfo.path !== '/' || this._dirInfo.name !== '')) { + var isShared = data.dirInfo && data.dirInfo.shareTypes && data.dirInfo.shareTypes.length > 0; + this.$el.html(this.template({ + isShared: isShared + })); + this.$el.show(); + this.delegateEvents(); + } else { + this.$el.empty(); + this.$el.hide(); + } return this; }, -- cgit v1.2.3 From c55718ae5e6eb3ebde519e3a4954e8b339734067 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Mon, 10 Oct 2016 17:35:11 +0200 Subject: update breadcrumb view whenever the share information on the directory info model changes Signed-off-by: Christoph Wurst --- apps/files/js/filelist.js | 10 +++++----- apps/files_sharing/js/sharebreadcrumbview.js | 12 ++++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 5bdb1a8999d..c53fa4f3d66 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -473,7 +473,7 @@ * Displays the details view for the given file and * selects the given tab * - * @param {string} fileName file name for which to show details + * @param {string|OCA.Files.FileInfoModel} fileName file name or FileInfoModel for which to show details * @param {string} [tabId] optional tab id to select */ showDetailsView: function(fileName, tabId) { @@ -487,7 +487,7 @@ /** * Update the details view to display the given file * - * @param {string} fileName file name from the current list + * @param {string|OCA.Files.FileInfoModel} fileName file name from the current list or a FileInfoModel object * @param {boolean} [show=true] whether to open the sidebar if it was closed */ _updateDetailsView: function(fileName, show) { @@ -518,8 +518,8 @@ OC.Apps.showAppSidebar(this._detailsView.$el); } - if (_.isObject(fileName)) { - var model = new OCA.Files.FileInfoModel(fileName); + if (fileName instanceof OCA.Files.FileInfoModel) { + var model = fileName; } else { var $tr = this.findFileEl(fileName); var model = this.getModelForFile($tr); @@ -2025,7 +2025,7 @@ function updateInList(fileInfo) { self.updateRow(tr, fileInfo); - self._updateDetailsView(fileInfo.name, false); + self._updateDetailsView(fileInfo, false); } // TODO: too many nested blocks, move parts into functions diff --git a/apps/files_sharing/js/sharebreadcrumbview.js b/apps/files_sharing/js/sharebreadcrumbview.js index c6bf365ba07..d29ba9d05dc 100644 --- a/apps/files_sharing/js/sharebreadcrumbview.js +++ b/apps/files_sharing/js/sharebreadcrumbview.js @@ -41,7 +41,7 @@ return this._template(data); }, render: function(data) { - this._dirInfo = data.dirInfo; + this._dirInfo = data.dirInfo || null; if (this._dirInfo !== null && (this._dirInfo.path !== '/' || this._dirInfo.name !== '')) { var isShared = data.dirInfo && data.dirInfo.shareTypes && data.dirInfo.shareTypes.length > 0; @@ -60,7 +60,15 @@ _onClick: function(e) { e.preventDefault(); - OCA.Files.App.fileList.showDetailsView(this._dirInfo, 'shareTabView'); + var fileInfoModel = new OCA.Files.FileInfoModel(this._dirInfo); + var self = this; + fileInfoModel.on('change', function() { + console.log('CHANGE'); + self.render({ + dirInfo: self._dirInfo + }); + }); + OCA.Files.App.fileList.showDetailsView(fileInfoModel, 'shareTabView'); } }); -- cgit v1.2.3 From 1190ce1dd5530865c6a5465e1e93a64002bcda47 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 14 Oct 2016 11:21:40 +0200 Subject: Listen to sharetab changes Signed-off-by: Roeland Jago Douma --- apps/files_sharing/js/share.js | 2 +- apps/files_sharing/js/sharebreadcrumbview.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index 2119db0b71e..073cc77e5aa 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -174,7 +174,7 @@ }); fileList.registerTabView(shareTab); - var breadCrumbSharingDetailView = new OCA.Sharing.ShareBreadCrumbView(); + var breadCrumbSharingDetailView = new OCA.Sharing.ShareBreadCrumbView({shareTab: shareTab}); fileList.registerBreadCrumbDetailView(breadCrumbSharingDetailView); }, diff --git a/apps/files_sharing/js/sharebreadcrumbview.js b/apps/files_sharing/js/sharebreadcrumbview.js index d29ba9d05dc..e8357bcbdef 100644 --- a/apps/files_sharing/js/sharebreadcrumbview.js +++ b/apps/files_sharing/js/sharebreadcrumbview.js @@ -34,6 +34,14 @@ }, _dirInfo: undefined, _template: undefined, + + /** @type OCA.Sharing.ShareTabView */ + _shareTab: undefined, + + initialize: function(options) { + this._shareTab = options.shareTab; + }, + template: function(data) { if (!this._template) { this._template = Handlebars.compile(TEMPLATE); @@ -68,6 +76,9 @@ dirInfo: self._dirInfo }); }); + this._shareTab.on('sharesChanged', function(shareModel) { + alert('aaoobb'); + }); OCA.Files.App.fileList.showDetailsView(fileInfoModel, 'shareTabView'); } }); -- cgit v1.2.3 From 8de4d4f76e524893409ada59ca01dfde1f371241 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Tue, 18 Oct 2016 10:50:39 +0200 Subject: detail fixes for share current folder Signed-off-by: Jan-Christoph Borchardt --- apps/files_sharing/css/sharebreadcrumb.css | 1 - apps/files_sharing/js/sharebreadcrumbview.js | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/files_sharing/css/sharebreadcrumb.css b/apps/files_sharing/css/sharebreadcrumb.css index 054c6bd66bf..b31b01540cd 100644 --- a/apps/files_sharing/css/sharebreadcrumb.css +++ b/apps/files_sharing/css/sharebreadcrumb.css @@ -22,7 +22,6 @@ div.crumb span.icon-share { display: inline-block; - width: 32px; vertical-align: sub; cursor: pointer; opacity: 0.2; diff --git a/apps/files_sharing/js/sharebreadcrumbview.js b/apps/files_sharing/js/sharebreadcrumbview.js index e8357bcbdef..dde044be35a 100644 --- a/apps/files_sharing/js/sharebreadcrumbview.js +++ b/apps/files_sharing/js/sharebreadcrumbview.js @@ -25,7 +25,7 @@ (function() { 'use strict'; - var TEMPLATE = ''; + var TEMPLATE = ''; var BreadCrumbView = OC.Backbone.View.extend({ tagName: 'span', @@ -85,4 +85,3 @@ OCA.Sharing.ShareBreadCrumbView = BreadCrumbView; })(); - -- cgit v1.2.3 From b39a17e49969a626ba561917dc24cfb76b9fcdbc Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 7 Nov 2016 11:27:15 +0100 Subject: Actually update the state Signed-off-by: Roeland Jago Douma --- apps/files_sharing/js/sharebreadcrumbview.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/js/sharebreadcrumbview.js b/apps/files_sharing/js/sharebreadcrumbview.js index dde044be35a..6f1e0f5ee1b 100644 --- a/apps/files_sharing/js/sharebreadcrumbview.js +++ b/apps/files_sharing/js/sharebreadcrumbview.js @@ -77,7 +77,25 @@ }); }); this._shareTab.on('sharesChanged', function(shareModel) { - alert('aaoobb'); + 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.hasLinkShare()) { + 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, 'shareTabView'); } -- cgit v1.2.3 From 07d027feebb90ea6b93a4ca3df82ec3a86f6d495 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 7 Nov 2016 15:33:30 +0100 Subject: Show link icon when shared by link Signed-off-by: Roeland Jago Douma --- apps/files_sharing/js/sharebreadcrumbview.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/apps/files_sharing/js/sharebreadcrumbview.js b/apps/files_sharing/js/sharebreadcrumbview.js index 6f1e0f5ee1b..3492259c0c8 100644 --- a/apps/files_sharing/js/sharebreadcrumbview.js +++ b/apps/files_sharing/js/sharebreadcrumbview.js @@ -25,15 +25,12 @@ (function() { 'use strict'; - var TEMPLATE = ''; - var BreadCrumbView = OC.Backbone.View.extend({ tagName: 'span', events: { click: '_onClick' }, _dirInfo: undefined, - _template: undefined, /** @type OCA.Sharing.ShareTabView */ _shareTab: undefined, @@ -42,24 +39,26 @@ this._shareTab = options.shareTab; }, - template: function(data) { - if (!this._template) { - this._template = Handlebars.compile(TEMPLATE); - } - return this._template(data); - }, render: function(data) { this._dirInfo = data.dirInfo || null; if (this._dirInfo !== null && (this._dirInfo.path !== '/' || this._dirInfo.name !== '')) { var isShared = data.dirInfo && data.dirInfo.shareTypes && data.dirInfo.shareTypes.length > 0; - this.$el.html(this.template({ - isShared: isShared - })); + this.$el.removeClass('shared icon-public icon-share'); + if (isShared) { + this.$el.addClass('shared'); + if (data.dirInfo.shareTypes.indexOf(OC.Share.SHARE_TYPE_LINK) !== -1) { + this.$el.addClass('icon-public'); + } else { + this.$el.addClass('icon-share'); + } + } else { + this.$el.addClass('icon-share'); + } this.$el.show(); this.delegateEvents(); } else { - this.$el.empty(); + this.$el.removeClass('shared icon-public icon-share'); this.$el.hide(); } -- cgit v1.2.3 From 0c1fd16d54b47bd0333c435a31becf30347b516f Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 7 Nov 2016 20:57:45 +0100 Subject: Add tests Signed-off-by: Roeland Jago Douma --- .../tests/js/sharedbreadcrumviewSpec.js | 224 +++++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 apps/files_sharing/tests/js/sharedbreadcrumviewSpec.js diff --git a/apps/files_sharing/tests/js/sharedbreadcrumviewSpec.js b/apps/files_sharing/tests/js/sharedbreadcrumviewSpec.js new file mode 100644 index 00000000000..b2193f4458b --- /dev/null +++ b/apps/files_sharing/tests/js/sharedbreadcrumviewSpec.js @@ -0,0 +1,224 @@ +/** + * @copyright 2016, Roeland Jago Douma + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +describe('OCA.Sharing.ShareBreadCrumbView tests', function() { + var BreadCrumb = OCA.Files.BreadCrumb; + var SharedBreadCrum = OCA.Sharing.ShareBreadCrumbView; + + describe('Rendering', function() { + var bc; + var sbc; + var shareTab; + beforeEach(function() { + bc = new BreadCrumb({ + getCrumbUrl: function(part, index) { + // for testing purposes + return part.dir + '#' + index; + } + }); + shareTab = new OCA.Sharing.ShareTabView(); + sbc = new SharedBreadCrum({ + shareTab: shareTab + }); + bc.addDetailView(sbc); + }); + afterEach(function() { + bc = null; + sbc = null; + shareModel = null; + }); + it('Do not render in root', function() { + var dirInfo = new OC.Files.FileInfo({ + id: 42, + path: '/', + type: 'dir', + name: '' + }); + bc.setDirectoryInfo(dirInfo); + bc.setDirectory(''); + bc.render(); + expect(bc.$el.hasClass('breadcrumb')).toEqual(true); + expect(bc.$el.find('.icon-share').length).toEqual(0); + expect(bc.$el.find('.shared').length).toEqual(0); + expect(bc.$el.find('.icon-public').length).toEqual(0); + }); + it('Render in dir', function() { + var dirInfo = new OC.Files.FileInfo({ + id: 42, + path: '/foo', + type: 'dir' + }); + bc.setDirectoryInfo(dirInfo); + bc.setDirectory('/foo'); + bc.render(); + expect(bc.$el.hasClass('breadcrumb')).toEqual(true); + expect(bc.$el.find('.icon-share').length).toEqual(1); + expect(bc.$el.find('.shared').length).toEqual(0); + expect(bc.$el.find('.icon-public').length).toEqual(0); + }); + it('Render shared if dir is shared with user', function() { + var dirInfo = new OC.Files.FileInfo({ + id: 42, + path: '/foo', + type: 'dir', + shareTypes: [OC.Share.SHARE_TYPE_USER] + }); + bc.setDirectoryInfo(dirInfo); + bc.setDirectory('/foo'); + bc.render(); + expect(bc.$el.hasClass('breadcrumb')).toEqual(true); + expect(bc.$el.find('.icon-share').length).toEqual(1); + expect(bc.$el.find('.shared').length).toEqual(1); + expect(bc.$el.find('.icon-public').length).toEqual(0); + }); + it('Render shared if dir is shared with group', function() { + var dirInfo = new OC.Files.FileInfo({ + id: 42, + path: '/foo', + type: 'dir', + shareTypes: [OC.Share.SHARE_TYPE_GROUP] + }); + bc.setDirectoryInfo(dirInfo); + bc.setDirectory('/foo'); + bc.render(); + expect(bc.$el.hasClass('breadcrumb')).toEqual(true); + expect(bc.$el.find('.icon-share').length).toEqual(1); + expect(bc.$el.find('.shared').length).toEqual(1); + expect(bc.$el.find('.icon-public').length).toEqual(0); + }); + it('Render shared if dir is shared by link', function() { + var dirInfo = new OC.Files.FileInfo({ + id: 42, + path: '/foo', + type: 'dir', + shareTypes: [OC.Share.SHARE_TYPE_LINK] + }); + bc.setDirectoryInfo(dirInfo); + bc.setDirectory('/foo'); + bc.render(); + expect(bc.$el.hasClass('breadcrumb')).toEqual(true); + expect(bc.$el.find('.icon-share').length).toEqual(0); + expect(bc.$el.find('.shared').length).toEqual(1); + expect(bc.$el.find('.icon-public').length).toEqual(1); + }); + it('Render shared if dir is shared with remote', function() { + var dirInfo = new OC.Files.FileInfo({ + id: 42, + path: '/foo', + type: 'dir', + shareTypes: [OC.Share.SHARE_TYPE_REMOTE] + }); + bc.setDirectoryInfo(dirInfo); + bc.setDirectory('/foo'); + bc.render(); + expect(bc.$el.hasClass('breadcrumb')).toEqual(true); + expect(bc.$el.find('.icon-share').length).toEqual(1); + expect(bc.$el.find('.shared').length).toEqual(1); + expect(bc.$el.find('.icon-public').length).toEqual(0); + }); + it('Render link shared if at least one is a link share', function() { + var dirInfo = new OC.Files.FileInfo({ + id: 42, + path: '/foo', + type: 'dir', + shareTypes: [ + OC.Share.SHARE_TYPE_USER, + OC.Share.SHARE_TYPE_GROUP, + OC.Share.SHARE_TYPE_LINK, + OC.Share.SHARE_TYPE_EMAIL, + OC.Share.SHARE_TYPE_REMOTE + ] + }); + bc.setDirectoryInfo(dirInfo); + bc.setDirectory('/foo'); + bc.render(); + expect(bc.$el.hasClass('breadcrumb')).toEqual(true); + expect(bc.$el.find('.icon-share').length).toEqual(0); + expect(bc.$el.find('.shared').length).toEqual(1); + expect(bc.$el.find('.icon-public').length).toEqual(1); + }); + it('Remove shared status from user share', function() { + var dirInfo = new OC.Files.FileInfo({ + id: 42, + path: '/foo', + type: 'dir', + shareTypes: [OC.Share.SHARE_TYPE_USER] + }); + + bc.setDirectory('/foo'); + bc.setDirectoryInfo(dirInfo); + bc.render(); + + var mock = sinon.createStubInstance(OCA.Files.FileList); + mock.showDetailsView = function() { }; + OCA.Files.App.fileList = mock; + var spy = sinon.spy(mock, 'showDetailsView'); + bc.$el.find('.icon-share').click(); + + expect(spy.calledOnce).toEqual(true); + + var model = sinon.createStubInstance(OC.Share.ShareItemModel); + model.getSharesWithCurrentItem = function() { return [] }; + model.hasLinkShare = function() { return false; }; + + shareTab.trigger('sharesChanged', model); + + expect(bc.$el.hasClass('breadcrumb')).toEqual(true); + expect(bc.$el.find('.icon-share').length).toEqual(1); + expect(bc.$el.find('.shared').length).toEqual(0); + expect(bc.$el.find('.icon-public').length).toEqual(0); + }); + it('Add link share to user share', function() { + var dirInfo = new OC.Files.FileInfo({ + id: 42, + path: '/foo', + type: 'dir', + shareTypes: [OC.Share.SHARE_TYPE_USER] + }); + + bc.setDirectory('/foo'); + bc.setDirectoryInfo(dirInfo); + bc.render(); + + var mock = sinon.createStubInstance(OCA.Files.FileList); + mock.showDetailsView = function() { }; + OCA.Files.App.fileList = mock; + var spy = sinon.spy(mock, 'showDetailsView'); + bc.$el.find('.icon-share').click(); + + expect(spy.calledOnce).toEqual(true); + + var model = sinon.createStubInstance(OC.Share.ShareItemModel); + model.getSharesWithCurrentItem = function() { return [ + {share_type: OC.Share.SHARE_TYPE_USER} + ] }; + model.hasLinkShare = function() { return true; }; + + shareTab.trigger('sharesChanged', model); + + expect(bc.$el.hasClass('breadcrumb')).toEqual(true); + expect(bc.$el.find('.icon-share').length).toEqual(0); + expect(bc.$el.find('.shared').length).toEqual(1); + expect(bc.$el.find('.icon-public').length).toEqual(1); + }); + }); +}); -- cgit v1.2.3 From 6c323496ab02f7ac71bc46bcf1272408f4b8c739 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Tue, 8 Nov 2016 10:35:48 +0100 Subject: fix share icon position and remove debug log --- apps/files_sharing/css/sharebreadcrumb.css | 1 - apps/files_sharing/js/sharebreadcrumbview.js | 1 - 2 files changed, 2 deletions(-) diff --git a/apps/files_sharing/css/sharebreadcrumb.css b/apps/files_sharing/css/sharebreadcrumb.css index b31b01540cd..2339fc8ffc3 100644 --- a/apps/files_sharing/css/sharebreadcrumb.css +++ b/apps/files_sharing/css/sharebreadcrumb.css @@ -22,7 +22,6 @@ div.crumb span.icon-share { display: inline-block; - vertical-align: sub; cursor: pointer; opacity: 0.2; } diff --git a/apps/files_sharing/js/sharebreadcrumbview.js b/apps/files_sharing/js/sharebreadcrumbview.js index 3492259c0c8..36bbddfaec4 100644 --- a/apps/files_sharing/js/sharebreadcrumbview.js +++ b/apps/files_sharing/js/sharebreadcrumbview.js @@ -70,7 +70,6 @@ var fileInfoModel = new OCA.Files.FileInfoModel(this._dirInfo); var self = this; fileInfoModel.on('change', function() { - console.log('CHANGE'); self.render({ dirInfo: self._dirInfo }); -- cgit v1.2.3 From 742ece8b7a054ce16152d721f91936d04b5d22c2 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 8 Nov 2016 11:14:36 +0100 Subject: Fix styling of the breadcrumbs icon * properly center share icon * also apply styles for public share icon Signed-off-by: Morris Jobke --- apps/files_sharing/css/sharebreadcrumb.css | 7 +++++-- core/css/styles.css | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/css/sharebreadcrumb.css b/apps/files_sharing/css/sharebreadcrumb.css index 2339fc8ffc3..792c8a31b7c 100644 --- a/apps/files_sharing/css/sharebreadcrumb.css +++ b/apps/files_sharing/css/sharebreadcrumb.css @@ -20,12 +20,15 @@ * */ -div.crumb span.icon-share { +div.crumb span.icon-share, +div.crumb span.icon-public { display: inline-block; cursor: pointer; opacity: 0.2; + margin-right: 6px; } -div.crumb span.icon-share.shared { +div.crumb span.icon-share.shared, +div.crumb span.icon-public.shared { opacity: 0.7; } diff --git a/core/css/styles.css b/core/css/styles.css index 6923ea42fc0..84d3229bda9 100644 --- a/core/css/styles.css +++ b/core/css/styles.css @@ -901,7 +901,7 @@ div.crumb > span { color: #555; } div.crumb.last a { - padding-right: 14px; + padding-right: 0px; } div.crumb:first-child a { position: relative; -- cgit v1.2.3