From 1f9e50086cc404d6dd46c5ae664f951faaf74c98 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 9 Jul 2018 13:04:09 +0200 Subject: [PATCH 01/10] Tiny start of the share overview Signed-off-by: Roeland Jago Douma --- apps/files_sharing/appinfo/app.php | 34 ++++--- apps/files_sharing/js/app.js | 36 ++++++++ apps/files_sharing/js/sharedfilelist.js | 117 ++++++++++++++++++------ 3 files changed, 148 insertions(+), 39 deletions(-) diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 4f5cf09bef..189c45426d 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -62,17 +62,6 @@ if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') { 'name' => $l->t('Shared with you'), ]; }); - - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N('files_sharing'); - return [ - 'id' => 'deletedshares', - 'appname' => 'files_sharing', - 'script' => 'list.php', - 'order' => 18, - 'name' => $l->t('Deleted shares'), - ]; - }); if (\OCP\Util::isSharingDisabledForUser() === false) { \OCA\Files\App::getNavigationManager()->add(function () { @@ -100,4 +89,27 @@ if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') { }); } } + + \OCA\Files\App::getNavigationManager()->add(function () { + $l = \OC::$server->getL10N('files_sharing'); + return [ + 'id' => 'shareoverview', + 'appname' => 'files_sharing', + 'script' => 'list.php', + 'order' => 18, + 'name' => $l->t('Share overview'), + ]; + }); + + + \OCA\Files\App::getNavigationManager()->add(function () { + $l = \OC::$server->getL10N('files_sharing'); + return [ + 'id' => 'deletedshares', + 'appname' => 'files_sharing', + 'script' => 'list.php', + 'order' => 19, + 'name' => $l->t('Deleted shares'), + ]; + }); } diff --git a/apps/files_sharing/js/app.js b/apps/files_sharing/js/app.js index f63410bc9b..ce16c1da92 100644 --- a/apps/files_sharing/js/app.js +++ b/apps/files_sharing/js/app.js @@ -21,6 +21,7 @@ OCA.Sharing.App = { _inFileList: null, _outFileList: null, + _overviewFileList: null, initSharingIn: function($el) { if (this._inFileList) { @@ -116,6 +117,28 @@ OCA.Sharing.App = { return this._deletedFileList; }, + initShareingOverview: function($el) { + if (this._overviewFileList) { + return this._overviewFileList; + } + this._overviewFileList = new OCA.Sharing.FileList( + $el, + { + id: 'shares.overview', + scrollContainer: $('#app-content'), + config: OCA.Files.App.getFilesConfig(), + isOverview: true + } + ); + + this._extendFileList(this._overviewFileList); + this._overviewFileList.appName = t('files_sharing', 'Share overview'); + this._overviewFileList.$el.find('#emptycontent').html('
' + + '

' + t('files_sharing', 'No shares') + '

' + + '

' + t('files_sharing', 'Shares will show up here') + '

'); + return this._overviewFileList; + }, + removeSharingIn: function() { if (this._inFileList) { this._inFileList.$fileList.empty(); @@ -140,6 +163,12 @@ OCA.Sharing.App = { } }, + removeSharingOverview: function() { + if (this._overviewFileList) { + this._overviewFileList.$fileList.empty(); + } + }, + /** * Destroy the app */ @@ -152,6 +181,7 @@ OCA.Sharing.App = { this._inFileList = null; this._outFileList = null; this._linkFileList = null; + this._overviewFileList = null; delete this._globalActionsInitialized; }, @@ -252,4 +282,10 @@ $(document).ready(function() { $('#app-content-deletedshares').on('hide', function() { OCA.Sharing.App.removeSharingDeleted(); }); + $('#app-content-shareoverview').on('show', function(e) { + OCA.Sharing.App.initShareingOverview($(e.target)); + }); + $('#app-content-shareoverview').on('hide', function() { + OCA.Sharing.App.removeSharingOverview(); + }); }); diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js index 973d2120b1..e89a061e99 100644 --- a/apps/files_sharing/js/sharedfilelist.js +++ b/apps/files_sharing/js/sharedfilelist.js @@ -40,6 +40,7 @@ _showDeleted: false, _clientSideSort: true, _allowSelection: false, + _isOverview: false, /** * @private @@ -60,6 +61,9 @@ if (options && options.showDeleted) { this._showDeleted = true; } + if (options && options.isOverview) { + this._isOverview = true; + } }, _renderRow: function() { @@ -191,39 +195,92 @@ // there is only root this._setCurrentDir('/', false); + if (!this._isOverview) { + if (this._showDeleted) { + var shares = $.ajax({ + url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'deletedshares', + /* jshint camelcase: false */ + data: { + format: 'json', + include_tags: true + }, + type: 'GET', + beforeSend: function (xhr) { + xhr.setRequestHeader('OCS-APIREQUEST', 'true'); + }, + }); + } else { + var shares = $.ajax({ + url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares', + /* jshint camelcase: false */ + data: { + format: 'json', + shared_with_me: !!this._sharedWithUser, + include_tags: true + }, + type: 'GET', + beforeSend: function (xhr) { + xhr.setRequestHeader('OCS-APIREQUEST', 'true'); + }, + }); + } + var promises = []; + promises.push(shares); - if (this._showDeleted) { - var shares = $.ajax({ - url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'deletedshares', - /* jshint camelcase: false */ - data: { - format: 'json', - include_tags: true - }, - type: 'GET', - beforeSend: function(xhr) { - xhr.setRequestHeader('OCS-APIREQUEST', 'true'); - }, - }); + if (!!this._sharedWithUser) { + var remoteShares = $.ajax({ + url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares', + /* jshint camelcase: false */ + data: { + format: 'json', + include_tags: true + }, + type: 'GET', + beforeSend: function (xhr) { + xhr.setRequestHeader('OCS-APIREQUEST', 'true'); + }, + }); + promises.push(remoteShares); + } else { + //Push empty promise so callback gets called the same way + promises.push($.Deferred().resolve()); + } + + this._reloadCall = $.when.apply($, promises); + var callBack = this.reloadCallback.bind(this); + return this._reloadCall.then(callBack, callBack); } else { - var shares = $.ajax({ + var promises = []; + var sharedWith = $.ajax({ url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares', /* jshint camelcase: false */ data: { format: 'json', - shared_with_me: !!this._sharedWithUser, + shared_with_me: true, include_tags: true }, type: 'GET', - beforeSend: function(xhr) { + beforeSend: function (xhr) { xhr.setRequestHeader('OCS-APIREQUEST', 'true'); }, }); - } - var promises = []; - promises.push(shares); + promises.push(sharedWith); + + var sharedBy = $.ajax({ + url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares', + /* jshint camelcase: false */ + data: { + format: 'json', + shared_with_me: false, + include_tags: true + }, + type: 'GET', + beforeSend: function (xhr) { + xhr.setRequestHeader('OCS-APIREQUEST', 'true'); + }, + }); + promises.push(sharedBy); - if (!!this._sharedWithUser) { var remoteShares = $.ajax({ url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares', /* jshint camelcase: false */ @@ -232,19 +289,23 @@ include_tags: true }, type: 'GET', - beforeSend: function(xhr) { + beforeSend: function (xhr) { xhr.setRequestHeader('OCS-APIREQUEST', 'true'); }, }); promises.push(remoteShares); - } else { - //Push empty promise so callback gets called the same way - promises.push($.Deferred().resolve()); - } - this._reloadCall = $.when.apply($, promises); - var callBack = this.reloadCallback.bind(this); - return this._reloadCall.then(callBack, callBack); + this._reloadCall = $.when.apply($, promises); + var callBack = this.reloadOverviewCallBack().bind(this); + return this._reloadCall.then(callBack, callBack, callBack); + } + }, + + reloadOverviewCallBack: function(sharedWith, sharedBy, remote) { + delete this._reloadCall; + this.hideMask(); + + alert('foo'); }, reloadCallback: function(shares, remoteShares) { From 6f45607f57c55550808824ffdeebbf10353a2554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Fri, 13 Jul 2018 09:33:57 +0200 Subject: [PATCH 02/10] Upgraded navigation submenu management and api + created sharing submenu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/files/appinfo/app.php | 41 +++++----- apps/files/appinfo/routes.php | 11 +-- apps/files/css/files.scss | 3 +- apps/files/js/navigation.js | 26 ++----- apps/files/lib/Controller/ApiController.php | 33 ++++----- apps/files/lib/Controller/ViewController.php | 55 ++++++++------ apps/files/templates/appnavigation.php | 21 ++++-- apps/files_sharing/appinfo/app.php | 78 ++++++++++---------- lib/private/NavigationManager.php | 4 +- 9 files changed, 135 insertions(+), 137 deletions(-) diff --git a/apps/files/appinfo/app.php b/apps/files/appinfo/app.php index fbe33fb54f..a7ce4e1830 100644 --- a/apps/files/appinfo/app.php +++ b/apps/files/appinfo/app.php @@ -39,24 +39,29 @@ $templateManager->registerTemplate('application/vnd.oasis.opendocument.presentat $templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'core/templates/filetemplates/template.odt'); $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods'); -\OCA\Files\App::getNavigationManager()->add(function () use ($l) { - return [ - 'id' => 'files', - 'appname' => 'files', - 'script' => 'list.php', - 'order' => 0, - 'name' => $l->t('All files'), - ]; -}); +\OCA\Files\App::getNavigationManager()->add([ + 'id' => 'files', + 'appname' => 'files', + 'script' => 'list.php', + 'order' => 0, + 'name' => $l->t('All files'), +]); -\OCA\Files\App::getNavigationManager()->add(function () use ($l) { - return [ - 'id' => 'recent', - 'appname' => 'files', - 'script' => 'recentlist.php', - 'order' => 2, - 'name' => $l->t('Recent'), - ]; -}); +\OCA\Files\App::getNavigationManager()->add([ + 'id' => 'recent', + 'appname' => 'files', + 'script' => 'recentlist.php', + 'order' => 2, + 'name' => $l->t('Recent'), +]); + +\OCA\Files\App::getNavigationManager()->add([ + 'id' => 'favorites', + 'appname' => 'files', + 'script' => 'simplelist.php', + 'order' => 5, + 'name' => $l->t('Favorites'), + 'expandedState' => 'show_Quick_Access' +]); \OCP\Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig'); diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index a9d8ba0a1b..44663d185d 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -77,14 +77,9 @@ $application->registerRoutes( 'verb' => 'GET', ], [ - 'name' => 'API#showQuickAccess', - 'url' => '/api/v1/quickaccess/set/showList', - 'verb' => 'GET', - ], - [ - 'name' => 'API#getShowQuickAccess', - 'url' => '/api/v1/quickaccess/get/showList', - 'verb' => 'GET', + 'name' => 'API#toggleShowFolder', + 'url' => '/api/v1/toggleShowFolder/{key}', + 'verb' => 'POST' ], [ 'name' => 'API#getShowQuickaccessSettings', diff --git a/apps/files/css/files.scss b/apps/files/css/files.scss index 24ecbf399e..79dc2a26eb 100644 --- a/apps/files/css/files.scss +++ b/apps/files/css/files.scss @@ -93,7 +93,8 @@ background-image: url('../img/star.svg?v=1'); } .nav-icon-sharingin, -.nav-icon-sharingout { +.nav-icon-sharingout, +.nav-icon-shareoverview { background-image: url('../img/share.svg?v=1'); } .nav-icon-sharinglinks { diff --git a/apps/files/js/navigation.js b/apps/files/js/navigation.js index d4fa06cb45..8ce976a6f5 100644 --- a/apps/files/js/navigation.js +++ b/apps/files/js/navigation.js @@ -172,30 +172,18 @@ */ _onClickMenuButton: function (ev) { var $target = $(ev.target); + var $menu = $target.parent('li'); var itemId = $target.closest('button').attr('id'); var collapsibleToggles = []; var dotmenuToggles = []; - // The collapsibleToggles-Array consists of a list of Arrays. Every subarray must contain the Button to listen to at the 0th index, - // and the parent, which should be toggled at the first arrayindex. - collapsibleToggles.push(["#button-collapse-favorites", "#button-collapse-parent-favorites"]); - - // The dotmenuToggles-Array consists of a list of Arrays. Every subarray must contain the Button to listen to at the 0th index, - // and the parent, which should be toggled at the first arrayindex. - dotmenuToggles.push(["#dotmenu-button-favorites", "dotmenu-content-favorites"]); - - collapsibleToggles.forEach(function foundToggle (item) { - if (item[0] === ("#" + itemId)) { - $(item[1]).toggleClass('open'); - var show = 1; - if (!$(item[1]).hasClass('open')) { - show = 0; - } - $.get(OC.generateUrl("/apps/files/api/v1/quickaccess/set/showList"), {show: show}, function (data, status) { - }); - } - }); + if ($menu.hasClass('collapsible') && $menu.data('expandedstate')) { + $menu.toggleClass('open'); + var show = $menu.hasClass('open') ? 1 : 0; + var key = $menu.data('expandedstate'); + $.post(OC.generateUrl("/apps/files/api/v1/toggleShowFolder/" + key), {show: show}); + } dotmenuToggles.forEach(function foundToggle (item) { if (item[0] === ("#" + itemId)) { diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index aae1bec2e7..fd63d54515 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -291,29 +291,28 @@ class ApiController extends Controller { } /** - * Toggle default for showing/hiding QuickAccess folder + * Toggle default for showing/hiding xxx folder * * @NoAdminRequired * - * @param bool $show + * @param bool $show + * @param bool $key the key of the folder * * @return Response */ - public function showQuickAccess($show) { - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', (int)$show); - return new Response(); - } - - /** - * Toggle default for showing/hiding QuickAccess folder - * - * @NoAdminRequired - * - * @return String - */ - public function getShowQuickAccess() { - - return $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', 0); + public function toggleShowFolder(int $show, string $key) { + // ensure the edited key exists + $navItems = \OCA\Files\App::getNavigationManager()->getAll(); + foreach ($navItems as $item) { + // check if data is valid + if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) { + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int)$show); + return new Response(); + } + } + $response = new Response(); + $response->setStatus(Http::STATUS_FORBIDDEN); + return $response; } /** diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index f240e04c72..063d16c62d 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -156,6 +156,7 @@ class ViewController extends Controller { $user = $this->userSession->getUser()->getUID(); + // Get all the user favorites to create a submenu try { $favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID()); } catch (\RuntimeException $e) { @@ -193,27 +194,20 @@ class ViewController extends Controller { } - // show_Quick_Access stored as string - $defaultExpandedState = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', '0') === '1'; - - \OCA\Files\App::getNavigationManager()->add( - [ - 'id' => 'favorites', - 'appname' => 'files', - 'script' => 'simplelist.php', - 'classes' => $collapseClasses, - 'order' => 5, - 'name' => $this->l10n->t('Favorites'), - 'sublist' => $favoritesSublistArray, - 'defaultExpandedState' => $defaultExpandedState, - 'enableMenuButton' => 0, - ] - ); - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); - usort($navItems, function ($item1, $item2) { - return $item1['order'] - $item2['order']; - }); + + // transform the favorites entry in menu + $navItems['favorites']['sublist'] = $favoritesSublistArray; + $navItems['favorites']['classes'] = $collapseClasses; + + + // parse every menu and add the expandedState user value + foreach ($navItems as $key => $item) { + if (isset($item['expandedState'])) { + $defaultValue = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1'; + $navItems[$key]['defaultExpandedState'] = $defaultValue; + } + } $nav->assign('navigationItems', $navItems); @@ -235,10 +229,23 @@ class ViewController extends Controller { if (isset($item['script'])) { $content = $this->renderScript($item['appname'], $item['script']); } - $contentItem = []; - $contentItem['id'] = $item['id']; - $contentItem['content'] = $content; - $contentItems[] = $contentItem; + // parse submenus + if (isset($item['sublist'])) { + foreach ($item['sublist'] as $subitem) { + $subcontent = ''; + if (isset($subitem['script'])) { + $subcontent = $this->renderScript($subitem['appname'], $subitem['script']); + } + $contentItems[$subitem['id']] = [ + 'id' => $subitem['id'], + 'content' =>$subcontent + ]; + } + } + $contentItems[$item['id']] = [ + 'id' => $item['id'], + 'content' =>$content + ]; } $event = new GenericEvent(null, ['hiddenFields' => []]); diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php index 0b9ac66590..04bcc57700 100644 --- a/apps/files/templates/appnavigation.php +++ b/apps/files/templates/appnavigation.php @@ -66,21 +66,26 @@ function NavigationListElements($item, $l, $pinned) { strpos($item['classes'], 'pinned') !== false ? $pinned++ : ''; ?> -
  • id="button-collapse-parent-" - data-id="" data-dir="" data-view="" - class="nav- open" +
  • data-dir="" + data-view="" + data-expandedstate="" + class="nav- + + + open" folderposition="" > + class="nav-icon- svg"> - +
      style="display: none"> + class="app-navigation-entry-utils" style="display: none">
      • diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 189c45426d..b7459d999d 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -50,56 +50,54 @@ $eventDispatcher->addListener( $config = \OC::$server->getConfig(); $shareManager = \OC::$server->getShareManager(); $userSession = \OC::$server->getUserSession(); +$l = \OC::$server->getL10N('files_sharing'); if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') { - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N('files_sharing'); - return [ - 'id' => 'sharingin', - 'appname' => 'files_sharing', - 'script' => 'list.php', - 'order' => 15, - 'name' => $l->t('Shared with you'), - ]; - }); + + $sharingSublistArray = []; + + array_push($sharingSublistArray, [ + 'id' => 'sharingin', + 'appname' => 'files_sharing', + 'script' => 'list.php', + 'order' => 15, + 'name' => $l->t('Shared with you'), + ]); if (\OCP\Util::isSharingDisabledForUser() === false) { - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N('files_sharing'); - return [ - 'id' => 'sharingout', - 'appname' => 'files_sharing', - 'script' => 'list.php', - 'order' => 16, - 'name' => $l->t('Shared with others'), - ]; - }); + array_push($sharingSublistArray, [ + 'id' => 'sharingout', + 'appname' => 'files_sharing', + 'script' => 'list.php', + 'order' => 16, + 'name' => $l->t('Shared with others'), + ]); // Check if sharing by link is enabled if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N('files_sharing'); - return [ - 'id' => 'sharinglinks', - 'appname' => 'files_sharing', - 'script' => 'list.php', - 'order' => 17, - 'name' => $l->t('Shared by link'), - ]; - }); + array_push($sharingSublistArray, [ + 'id' => 'sharinglinks', + 'appname' => 'files_sharing', + 'script' => 'list.php', + 'order' => 17, + 'name' => $l->t('Shared by link'), + ]); } } - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N('files_sharing'); - return [ - 'id' => 'shareoverview', - 'appname' => 'files_sharing', - 'script' => 'list.php', - 'order' => 18, - 'name' => $l->t('Share overview'), - ]; - }); + // show_Quick_Access stored as string + $defaultExpandedState = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_sharing_menu', '0') === '1'; + + \OCA\Files\App::getNavigationManager()->add([ + 'id' => 'shareoverview', + 'appname' => 'files_sharing', + 'script' => 'list.php', + 'order' => 18, + 'name' => $l->t('Share overview'), + 'classes' => 'collapsible', + 'sublist' => $sharingSublistArray, + 'expandedState' => 'show_sharing_menu' + ]); \OCA\Files\App::getNavigationManager()->add(function () { diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php index 1c764f9c1f..1874cd0e4f 100644 --- a/lib/private/NavigationManager.php +++ b/lib/private/NavigationManager.php @@ -100,7 +100,7 @@ class NavigationManager implements INavigationManager { if(!isset($entry['type'])) { $entry['type'] = 'link'; } - $this->entries[] = $entry; + $this->entries[$entry['id']] = $entry; } /** @@ -133,7 +133,7 @@ class NavigationManager implements INavigationManager { * @return array */ private function proceedNavigation(array $list): array { - usort($list, function($a, $b) { + uasort($list, function($a, $b) { if (isset($a['order']) && isset($b['order'])) { return ($a['order'] < $b['order']) ? -1 : 1; } else if (isset($a['order']) || isset($b['order'])) { From e1a2bb9d69bf1aeba6362672c6b161bb96ad8a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Fri, 13 Jul 2018 09:57:54 +0200 Subject: [PATCH 03/10] Fix fav quickaccess ressource addition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/files/appinfo/app.php | 26 ++-- apps/files/js/tagsplugin.js | 33 ++--- apps/files/lib/Controller/ViewController.php | 123 +++++++++---------- 3 files changed, 87 insertions(+), 95 deletions(-) diff --git a/apps/files/appinfo/app.php b/apps/files/appinfo/app.php index a7ce4e1830..dfff7f6f46 100644 --- a/apps/files/appinfo/app.php +++ b/apps/files/appinfo/app.php @@ -40,27 +40,27 @@ $templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'c $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods'); \OCA\Files\App::getNavigationManager()->add([ - 'id' => 'files', + 'id' => 'files', 'appname' => 'files', - 'script' => 'list.php', - 'order' => 0, - 'name' => $l->t('All files'), + 'script' => 'list.php', + 'order' => 0, + 'name' => $l->t('All files') ]); \OCA\Files\App::getNavigationManager()->add([ - 'id' => 'recent', + 'id' => 'recent', 'appname' => 'files', - 'script' => 'recentlist.php', - 'order' => 2, - 'name' => $l->t('Recent'), + 'script' => 'recentlist.php', + 'order' => 2, + 'name' => $l->t('Recent') ]); \OCA\Files\App::getNavigationManager()->add([ - 'id' => 'favorites', - 'appname' => 'files', - 'script' => 'simplelist.php', - 'order' => 5, - 'name' => $l->t('Favorites'), + 'id' => 'favorites', + 'appname' => 'files', + 'script' => 'simplelist.php', + 'order' => 5, + 'name' => $l->t('Favorites'), 'expandedState' => 'show_Quick_Access' ]); diff --git a/apps/files/js/tagsplugin.js b/apps/files/js/tagsplugin.js index bc1396b510..4ce6604384 100644 --- a/apps/files/js/tagsplugin.js +++ b/apps/files/js/tagsplugin.js @@ -68,29 +68,22 @@ * @param {String} appfolder folder to be removed */ function removeFavoriteFromList (appfolder) { - var quickAccessList = 'sublist-favorites'; - var collapsibleButtonId = 'button-collapse-favorites'; var listULElements = document.getElementById(quickAccessList); if (!listULElements) { return; } - var listLIElements = listULElements.getElementsByTagName('li'); var apppath=appfolder; if(appfolder.startsWith("//")){ apppath=appfolder.substring(1, appfolder.length); } - for (var i = 0; i <= listLIElements.length - 1; i++) { - if (listLIElements[i].getElementsByTagName('a')[0].href.endsWith("dir=" + apppath)) { - listLIElements[i].remove(); - } - } + $(listULElements).find('[data-dir="' + apppath + '"]').remove(); if (listULElements.childElementCount === 0) { - var collapsibleButton = document.getElementById("button-collapse-favorites"); - collapsibleButton.style.display = 'none'; + var collapsibleButton = $(listULElements).parent().find('button.collapse'); + collapsibleButton.hide(); $("#button-collapse-parent-favorites").removeClass('collapsible'); } } @@ -102,7 +95,6 @@ */ function addFavoriteToList (appfolder) { var quickAccessList = 'sublist-favorites'; - var collapsibleButtonId = 'button-collapse-favorites'; var listULElements = document.getElementById(quickAccessList); if (!listULElements) { return; @@ -110,13 +102,13 @@ var listLIElements = listULElements.getElementsByTagName('li'); var appName = appfolder.substring(appfolder.lastIndexOf("/") + 1, appfolder.length); - var apppath=appfolder; + var apppath = appfolder; if(appfolder.startsWith("//")){ - apppath=appfolder.substring(1, appfolder.length); + apppath = appfolder.substring(1, appfolder.length); } - var url=OC.generateUrl('/apps/files/?dir=')+apppath; - + var url = OC.generateUrl('/apps/files/?dir=' + apppath + '&view=files'); + var innerTagA = document.createElement('A'); innerTagA.setAttribute("href", url); @@ -125,7 +117,9 @@ var length = listLIElements.length + 1; var innerTagLI = document.createElement('li'); - innerTagLI.setAttribute("data-id", url); + innerTagLI.setAttribute("data-id", apppath.replace('/', '-')); + innerTagLI.setAttribute("data-dir", apppath); + innerTagLI.setAttribute("data-view", 'files'); innerTagLI.setAttribute("class", "nav-" + appName); innerTagLI.setAttribute("folderpos", length.toString()); innerTagLI.appendChild(innerTagA); @@ -134,10 +128,9 @@ if (data === "dir") { if (listULElements.childElementCount <= 0) { listULElements.appendChild(innerTagLI); - var collapsibleButton = document.getElementById(collapsibleButtonId); - collapsibleButton.style.display = ''; - - $("#button-collapse-parent-favorites").addClass('collapsible'); + var collapsibleButton = $(listULElements).parent().find('button.collapse'); + collapsibleButton.show(); + $(listULElements).parent().addClass('collapsible'); } else { listLIElements[listLIElements.length - 1].after(innerTagLI); } diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 063d16c62d..0a13af3233 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -33,6 +33,8 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; +use OCP\App\IAppManager; +use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\IConfig; @@ -41,8 +43,6 @@ use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUserSession; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use OCP\Files\Folder; -use OCP\App\IAppManager; use Symfony\Component\EventDispatcher\GenericEvent; /** @@ -73,27 +73,27 @@ class ViewController extends Controller { protected $activityHelper; public function __construct(string $appName, - IRequest $request, - IURLGenerator $urlGenerator, - IL10N $l10n, - IConfig $config, - EventDispatcherInterface $eventDispatcherInterface, - IUserSession $userSession, - IAppManager $appManager, - IRootFolder $rootFolder, - Helper $activityHelper + IRequest $request, + IURLGenerator $urlGenerator, + IL10N $l10n, + IConfig $config, + EventDispatcherInterface $eventDispatcherInterface, + IUserSession $userSession, + IAppManager $appManager, + IRootFolder $rootFolder, + Helper $activityHelper ) { parent::__construct($appName, $request); - $this->appName = $appName; - $this->request = $request; - $this->urlGenerator = $urlGenerator; - $this->l10n = $l10n; - $this->config = $config; + $this->appName = $appName; + $this->request = $request; + $this->urlGenerator = $urlGenerator; + $this->l10n = $l10n; + $this->config = $config; $this->eventDispatcher = $eventDispatcherInterface; - $this->userSession = $userSession; - $this->appManager = $appManager; - $this->rootFolder = $rootFolder; - $this->activityHelper = $activityHelper; + $this->userSession = $userSession; + $this->appManager = $appManager; + $this->rootFolder = $rootFolder; + $this->activityHelper = $activityHelper; } /** @@ -102,8 +102,8 @@ class ViewController extends Controller { * @return string */ protected function renderScript($appName, $scriptName) { - $content = ''; - $appPath = \OC_App::getAppPath($appName); + $content = ''; + $appPath = \OC_App::getAppPath($appName); $scriptPath = $appPath . '/' . $scriptName; if (file_exists($scriptPath)) { // TODO: sanitize path / script name ? @@ -112,6 +112,7 @@ class ViewController extends Controller { $content = ob_get_contents(); @ob_end_clean(); } + return $content; } @@ -123,6 +124,7 @@ class ViewController extends Controller { */ protected function getStorageInfo() { $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false); + return \OC_Helper::getStorageInfo('/', $dirInfo); } @@ -171,21 +173,21 @@ class ViewController extends Controller { $favoritesSublistArray = Array(); $navBarPositionPosition = 6; - $currentCount = 0; + $currentCount = 0; foreach ($favElements['folders'] as $dir) { - $id = substr($dir, strrpos($dir, '/') + 1, strlen($dir)); - $link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']); + $id = substr($dir, strrpos($dir, '/') + 1, strlen($dir)); + $link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']); $sortingValue = ++$currentCount; - $element = [ - 'id' => str_replace('/', '-', $dir), - 'view' => 'files', - 'href' => $link, - 'dir' => $dir, - 'order' => $navBarPositionPosition, - 'folderPosition' => $sortingValue, - 'name' => $id, - 'icon' => 'files', + $element = [ + 'id' => str_replace('/', '-', $dir), + 'view' => 'files', + 'href' => $link, + 'dir' => $dir, + 'order' => $navBarPositionPosition, + 'folderPosition' => $sortingValue, + 'name' => $id, + 'icon' => 'files', 'quickaccesselement' => 'true' ]; @@ -193,19 +195,16 @@ class ViewController extends Controller { $navBarPositionPosition++; } - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); - // transform the favorites entry in menu + // add the favorites entry in menu $navItems['favorites']['sublist'] = $favoritesSublistArray; $navItems['favorites']['classes'] = $collapseClasses; - // parse every menu and add the expandedState user value foreach ($navItems as $key => $item) { if (isset($item['expandedState'])) { - $defaultValue = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1'; - $navItems[$key]['defaultExpandedState'] = $defaultValue; + $navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1'; } } @@ -237,34 +236,34 @@ class ViewController extends Controller { $subcontent = $this->renderScript($subitem['appname'], $subitem['script']); } $contentItems[$subitem['id']] = [ - 'id' => $subitem['id'], - 'content' =>$subcontent + 'id' => $subitem['id'], + 'content' => $subcontent ]; } } $contentItems[$item['id']] = [ - 'id' => $item['id'], - 'content' =>$content + 'id' => $item['id'], + 'content' => $content ]; } $event = new GenericEvent(null, ['hiddenFields' => []]); $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts', $event); - $params = []; - $params['usedSpacePercent'] = (int)$storageInfo['relative']; - $params['owner'] = $storageInfo['owner']; - $params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; - $params['isPublic'] = false; - $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); - $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); + $params = []; + $params['usedSpacePercent'] = (int) $storageInfo['relative']; + $params['owner'] = $storageInfo['owner']; + $params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; + $params['isPublic'] = false; + $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); + $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); - $showHidden = (bool)$this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); - $params['showHiddenFiles'] = $showHidden ? 1 : 0; - $params['fileNotFound'] = $fileNotFound ? 1 : 0; - $params['appNavigation'] = $nav; - $params['appContents'] = $contentItems; - $params['hiddenFields'] = $event->getArgument('hiddenFields'); + $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); + $params['showHiddenFiles'] = $showHidden ? 1 : 0; + $params['fileNotFound'] = $fileNotFound ? 1 : 0; + $params['appNavigation'] = $nav; + $params['appContents'] = $contentItems; + $params['hiddenFields'] = $event->getArgument('hiddenFields'); $response = new TemplateResponse( $this->appName, @@ -275,7 +274,6 @@ class ViewController extends Controller { $policy->addAllowedFrameDomain('\'self\''); $response->setContentSecurityPolicy($policy); - return $response; } @@ -287,14 +285,14 @@ class ViewController extends Controller { * @throws \OCP\Files\NotFoundException */ private function showFile($fileId) { - $uid = $this->userSession->getUser()->getUID(); + $uid = $this->userSession->getUser()->getUID(); $baseFolder = $this->rootFolder->getUserFolder($uid); - $files = $baseFolder->getById($fileId); - $params = []; + $files = $baseFolder->getById($fileId); + $params = []; if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { - $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); - $files = $baseFolder->getById($fileId); + $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); + $files = $baseFolder->getById($fileId); $params['view'] = 'trashbin'; } @@ -309,6 +307,7 @@ class ViewController extends Controller { // and scroll to the entry $params['scrollto'] = $file->getName(); } + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); } throw new \OCP\Files\NotFoundException(); From 34368cc031a069cf16dfd770d59b8f4912c2ba68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Fri, 13 Jul 2018 11:45:50 +0200 Subject: [PATCH 04/10] Fixed sharing coding style and display - Added all shares overview MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) Fixed if condition Signed-off-by: John Molakvoæ (skjnldsv) --- apps/files_sharing/js/sharedfilelist.js | 181 +++++++++--------------- 1 file changed, 70 insertions(+), 111 deletions(-) diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js index e89a061e99..914bfd6ae1 100644 --- a/apps/files_sharing/js/sharedfilelist.js +++ b/apps/files_sharing/js/sharedfilelist.js @@ -195,120 +195,70 @@ // there is only root this._setCurrentDir('/', false); - if (!this._isOverview) { - if (this._showDeleted) { - var shares = $.ajax({ - url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'deletedshares', - /* jshint camelcase: false */ - data: { - format: 'json', - include_tags: true - }, - type: 'GET', - beforeSend: function (xhr) { - xhr.setRequestHeader('OCS-APIREQUEST', 'true'); - }, - }); - } else { - var shares = $.ajax({ - url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares', - /* jshint camelcase: false */ - data: { - format: 'json', - shared_with_me: !!this._sharedWithUser, - include_tags: true - }, - type: 'GET', - beforeSend: function (xhr) { - xhr.setRequestHeader('OCS-APIREQUEST', 'true'); - }, - }); - } - var promises = []; - promises.push(shares); + var promises = []; - if (!!this._sharedWithUser) { - var remoteShares = $.ajax({ - url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares', - /* jshint camelcase: false */ - data: { - format: 'json', - include_tags: true - }, - type: 'GET', - beforeSend: function (xhr) { - xhr.setRequestHeader('OCS-APIREQUEST', 'true'); - }, - }); - promises.push(remoteShares); - } else { - //Push empty promise so callback gets called the same way - promises.push($.Deferred().resolve()); - } + var deletedShares = { + url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'deletedshares', + /* jshint camelcase: false */ + data: { + format: 'json', + include_tags: true + }, + type: 'GET', + beforeSend: function (xhr) { + xhr.setRequestHeader('OCS-APIREQUEST', 'true'); + }, + }; - this._reloadCall = $.when.apply($, promises); - var callBack = this.reloadCallback.bind(this); - return this._reloadCall.then(callBack, callBack); + var shares = { + url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares', + /* jshint camelcase: false */ + data: { + format: 'json', + shared_with_me: this._sharedWithUser !== false, + include_tags: true + }, + type: 'GET', + beforeSend: function (xhr) { + xhr.setRequestHeader('OCS-APIREQUEST', 'true'); + }, + }; + + var remoteShares = { + url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares', + /* jshint camelcase: false */ + data: { + format: 'json', + include_tags: true + }, + type: 'GET', + beforeSend: function (xhr) { + xhr.setRequestHeader('OCS-APIREQUEST', 'true'); + }, + }; + + // Add the proper ajax requests to the list and run them + // and make sure we have 2 promises + if (this._showDeleted) { + promises.push($.ajax(deletedShares)); } else { - var promises = []; - var sharedWith = $.ajax({ - url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares', - /* jshint camelcase: false */ - data: { - format: 'json', - shared_with_me: true, - include_tags: true - }, - type: 'GET', - beforeSend: function (xhr) { - xhr.setRequestHeader('OCS-APIREQUEST', 'true'); - }, - }); - promises.push(sharedWith); + promises.push($.ajax(shares)); - var sharedBy = $.ajax({ - url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares', - /* jshint camelcase: false */ - data: { - format: 'json', - shared_with_me: false, - include_tags: true - }, - type: 'GET', - beforeSend: function (xhr) { - xhr.setRequestHeader('OCS-APIREQUEST', 'true'); - }, - }); - promises.push(sharedBy); - - var remoteShares = $.ajax({ - url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares', - /* jshint camelcase: false */ - data: { - format: 'json', - include_tags: true - }, - type: 'GET', - beforeSend: function (xhr) { - xhr.setRequestHeader('OCS-APIREQUEST', 'true'); - }, - }); - promises.push(remoteShares); - - this._reloadCall = $.when.apply($, promises); - var callBack = this.reloadOverviewCallBack().bind(this); - return this._reloadCall.then(callBack, callBack, callBack); + if (this._sharedWithUser !== false || this._isOverview) { + promises.push($.ajax(remoteShares)); + } + if (this._isOverview) { + shares.data.shared_with_me = !shares.data.shared_with_me + promises.push($.ajax(shares)); + } } + + this._reloadCall = $.when.apply($, promises); + var callBack = this.reloadCallback.bind(this); + return this._reloadCall.then(callBack, callBack); }, - reloadOverviewCallBack: function(sharedWith, sharedBy, remote) { - delete this._reloadCall; - this.hideMask(); - - alert('foo'); - }, - - reloadCallback: function(shares, remoteShares) { + reloadCallback: function(shares, remoteShares, additionnalShares) { delete this._reloadCall; this.hideMask(); @@ -318,12 +268,21 @@ var files = []; - if (shares[0].ocs && shares[0].ocs.data) { - files = files.concat(this._makeFilesFromShares(shares[0].ocs.data)); + // make sure to use the same format + if(shares[0] && shares[0].ocs) { + shares = shares[0]; } - if (remoteShares && remoteShares[0].ocs && remoteShares[0].ocs.data) { - files = files.concat(this._makeFilesFromRemoteShares(remoteShares[0].ocs.data)); + if (shares.ocs && shares.ocs.data) { + files = files.concat(this._makeFilesFromShares(shares.ocs.data)); + } + + if (remoteShares && remoteShares.ocs && remoteShares.ocs.data) { + files = files.concat(this._makeFilesFromRemoteShares(remoteShares.ocs.data)); + } + + if (additionnalShares && additionnalShares[0] && additionnalShares[0].ocs && additionnalShares[0].ocs.data) { + files = files.concat(this._makeFilesFromShares(additionnalShares[0].ocs.data)); } this.setFiles(files); From a349f2a9f5c851dcbcadca203d2ffc4635706400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Fri, 13 Jul 2018 14:47:00 +0200 Subject: [PATCH 05/10] Fixed phpunit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- .../tests/Controller/ViewControllerTest.php | 84 +---- tests/lib/NavigationManagerTest.php | 315 ++++++++++-------- 2 files changed, 193 insertions(+), 206 deletions(-) diff --git a/apps/files/tests/Controller/ViewControllerTest.php b/apps/files/tests/Controller/ViewControllerTest.php index 8f07764580..674d4a9542 100644 --- a/apps/files/tests/Controller/ViewControllerTest.php +++ b/apps/files/tests/Controller/ViewControllerTest.php @@ -145,7 +145,7 @@ class ViewControllerTest extends TestCase { $nav->assign('total_space', '100 B'); //$nav->assign('webdavurl', ''); $nav->assign('navigationItems', [ - [ + 'files' => [ 'id' => 'files', 'appname' => 'files', 'script' => 'list.php', @@ -156,7 +156,7 @@ class ViewControllerTest extends TestCase { 'type' => 'link', 'classes' => '', ], - [ + 'recent' => [ 'id' => 'recent', 'appname' => 'files', 'script' => 'recentlist.php', @@ -167,65 +167,21 @@ class ViewControllerTest extends TestCase { 'type' => 'link', 'classes' => '', ], - [ + 'favorites' => [ 'id' => 'favorites', 'appname' => 'files', 'script' => 'simplelist.php', 'order' => 5, - 'name' => null, + 'name' => \OC::$server->getL10N('files')->t('Favorites'), 'active' => false, 'icon' => '', 'type' => 'link', 'classes' => '', 'sublist' => [], 'defaultExpandedState' => false, - 'enableMenuButton' => 0, + 'expandedState' => 'show_Quick_Access' ], - [ - 'id' => 'sharingin', - 'appname' => 'files_sharing', - 'script' => 'list.php', - 'order' => 15, - 'name' => \OC::$server->getL10N('files_sharing')->t('Shared with you'), - 'active' => false, - 'icon' => '', - 'type' => 'link', - 'classes' => '', - ], - [ - 'id' => 'sharingout', - 'appname' => 'files_sharing', - 'script' => 'list.php', - 'order' => 16, - 'name' => \OC::$server->getL10N('files_sharing')->t('Shared with others'), - 'active' => false, - 'icon' => '', - 'type' => 'link', - 'classes' => '', - ], - [ - 'id' => 'sharinglinks', - 'appname' => 'files_sharing', - 'script' => 'list.php', - 'order' => 17, - 'name' => \OC::$server->getL10N('files_sharing')->t('Shared by link', []), - 'active' => false, - 'icon' => '', - 'type' => 'link', - 'classes' => '', - ], - [ - 'id' => 'deletedshares', - 'appname' => 'files_sharing', - 'script' => 'list.php', - 'order' => 18, - 'name' => \OC::$server->getL10N('files_sharing')->t('Deleted shares'), - 'active' => false, - 'icon' => '', - 'type' => 'link', - 'classes' => '', - ], - [ + 'systemtagsfilter' => [ 'id' => 'systemtagsfilter', 'appname' => 'systemtags', 'script' => 'list.php', @@ -236,7 +192,7 @@ class ViewControllerTest extends TestCase { 'type' => 'link', 'classes' => '', ], - [ + 'trashbin' => [ 'id' => 'trashbin', 'appname' => 'files_trashbin', 'script' => 'list.php', @@ -264,39 +220,23 @@ class ViewControllerTest extends TestCase { 'allowShareWithLink' => 'yes', 'appNavigation' => $nav, 'appContents' => [ - [ + 'files' => [ 'id' => 'files', 'content' => null, ], - [ + 'recent' => [ 'id' => 'recent', 'content' => null, ], - [ + 'favorites' => [ 'id' => 'favorites', 'content' => null, ], - [ - 'id' => 'sharingin', - 'content' => null, - ], - [ - 'id' => 'sharingout', - 'content' => null, - ], - [ - 'id' => 'sharinglinks', - 'content' => null, - ], - [ - 'id' => 'deletedshares', - 'content' => null, - ], - [ + 'systemtagsfilter' => [ 'id' => 'systemtagsfilter', 'content' => null, ], - [ + 'trashbin' => [ 'id' => 'trashbin', 'content' => null, ], diff --git a/tests/lib/NavigationManagerTest.php b/tests/lib/NavigationManagerTest.php index b34ecca946..8bc1c372ac 100644 --- a/tests/lib/NavigationManagerTest.php +++ b/tests/lib/NavigationManagerTest.php @@ -12,10 +12,6 @@ namespace Test; -use OC\App\AppManager; -use OC\Group\Manager; -use OC\NavigationManager; -use OC\SubAdmin; use OCP\IConfig; use OCP\IGroupManager; use OCP\IL10N; @@ -23,6 +19,10 @@ use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserSession; use OCP\L10N\IFactory; +use OC\App\AppManager; +use OC\Group\Manager; +use OC\NavigationManager; +use OC\SubAdmin; class NavigationManagerTest extends TestCase { /** @var AppManager|\PHPUnit_Framework_MockObject_MockObject */ @@ -44,12 +44,12 @@ class NavigationManagerTest extends TestCase { protected function setUp() { parent::setUp(); - $this->appManager = $this->createMock(AppManager::class); - $this->urlGenerator = $this->createMock(IURLGenerator::class); - $this->l10nFac = $this->createMock(IFactory::class); - $this->userSession = $this->createMock(IUserSession::class); - $this->groupManager = $this->createMock(Manager::class); - $this->config = $this->createMock(IConfig::class); + $this->appManager = $this->createMock(AppManager::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->l10nFac = $this->createMock(IFactory::class); + $this->userSession = $this->createMock(IUserSession::class); + $this->groupManager = $this->createMock(Manager::class); + $this->config = $this->createMock(IConfig::class); $this->navigationManager = new NavigationManager( $this->appManager, $this->urlGenerator, @@ -65,46 +65,46 @@ class NavigationManagerTest extends TestCase { public function addArrayData() { return [ [ - [ - 'id' => 'entry id', - 'name' => 'link text', - 'order' => 1, - 'icon' => 'optional', - 'href' => 'url', - 'type' => 'settings', - 'classes' => '', - ], - [ - 'id' => 'entry id', - 'name' => 'link text', - 'order' => 1, - 'icon' => 'optional', - 'href' => 'url', - 'active' => false, - 'type' => 'settings', - 'classes' => '', + 'entry id' => [ + 'id' => 'entry id', + 'name' => 'link text', + 'order' => 1, + 'icon' => 'optional', + 'href' => 'url', + 'type' => 'settings', + 'classes' => '' ], + 'entry id2' => [ + 'id' => 'entry id', + 'name' => 'link text', + 'order' => 1, + 'icon' => 'optional', + 'href' => 'url', + 'active' => false, + 'type' => 'settings', + 'classes' => '' + ] ], [ - [ - 'id' => 'entry id', - 'name' => 'link text', - 'order' => 1, + 'entry id' => [ + 'id' => 'entry id', + 'name' => 'link text', + 'order' => 1, //'icon' => 'optional', - 'href' => 'url', - 'active' => true, + 'href' => 'url', + 'active' => true ], - [ - 'id' => 'entry id', - 'name' => 'link text', - 'order' => 1, - 'icon' => '', - 'href' => 'url', - 'active' => false, - 'type' => 'link', - 'classes' => '', - ], - ], + 'entry id2' => [ + 'id' => 'entry id', + 'name' => 'link text', + 'order' => 1, + 'icon' => '', + 'href' => 'url', + 'active' => false, + 'type' => 'link', + 'classes' => '' + ] + ] ]; } @@ -120,7 +120,7 @@ class NavigationManagerTest extends TestCase { $navigationEntries = $this->navigationManager->getAll('all'); $this->assertCount(1, $navigationEntries, 'Expected that 1 navigation entry exists'); - $this->assertEquals($expectedEntry, $navigationEntries[0]); + $this->assertEquals($expectedEntry, $navigationEntries['entry id']); $this->navigationManager->clear(false); $this->assertEmpty($this->navigationManager->getAll('all'), 'Expected no navigation entry exists after clear()'); @@ -148,12 +148,12 @@ class NavigationManagerTest extends TestCase { $navigationEntries = $this->navigationManager->getAll('all'); $this->assertEquals(1, $testAddClosureNumberOfCalls, 'Expected that the closure is called by getAll()'); $this->assertCount(1, $navigationEntries, 'Expected that 1 navigation entry exists'); - $this->assertEquals($expectedEntry, $navigationEntries[0]); + $this->assertEquals($expectedEntry, $navigationEntries['entry id']); $navigationEntries = $this->navigationManager->getAll('all'); $this->assertEquals(1, $testAddClosureNumberOfCalls, 'Expected that the closure is only called once for getAll()'); $this->assertCount(1, $navigationEntries, 'Expected that 1 navigation entry exists'); - $this->assertEquals($expectedEntry, $navigationEntries[0]); + $this->assertEquals($expectedEntry, $navigationEntries['entry id']); $this->navigationManager->clear(false); $this->assertEmpty($this->navigationManager->getAll('all'), 'Expected no navigation entry exists after clear()'); @@ -161,11 +161,11 @@ class NavigationManagerTest extends TestCase { public function testAddArrayClearGetAll() { $entry = [ - 'id' => 'entry id', - 'name' => 'link text', - 'order' => 1, - 'icon' => 'optional', - 'href' => 'url', + 'id' => 'entry id', + 'name' => 'link text', + 'order' => 1, + 'icon' => 'optional', + 'href' => 'url' ]; $this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists'); @@ -178,11 +178,11 @@ class NavigationManagerTest extends TestCase { $this->assertEmpty($this->navigationManager->getAll(), 'Expected no navigation entry exists'); $entry = [ - 'id' => 'entry id', - 'name' => 'link text', - 'order' => 1, - 'icon' => 'optional', - 'href' => 'url', + 'id' => 'entry id', + 'name' => 'link text', + 'order' => 1, + 'icon' => 'optional', + 'href' => 'url' ]; global $testAddClosureNumberOfCalls; @@ -208,36 +208,36 @@ class NavigationManagerTest extends TestCase { public function testWithAppManager($expected, $navigation, $isAdmin = false) { $l = $this->createMock(IL10N::class); - $l->expects($this->any())->method('t')->willReturnCallback(function($text, $parameters = []) { + $l->expects($this->any())->method('t')->willReturnCallback(function ($text, $parameters = []) { return vsprintf($text, $parameters); }); $this->appManager->expects($this->once())->method('getAppInfo')->with('test')->willReturn($navigation); $this->l10nFac->expects($this->any())->method('get')->willReturn($l); - $this->urlGenerator->expects($this->any())->method('imagePath')->willReturnCallback(function($appName, $file) { + $this->urlGenerator->expects($this->any())->method('imagePath')->willReturnCallback(function ($appName, $file) { return "/apps/$appName/img/$file"; }); - $this->urlGenerator->expects($this->any())->method('linkToRoute')->willReturnCallback(function() { - return "/apps/test/"; + $this->urlGenerator->expects($this->any())->method('linkToRoute')->willReturnCallback(function () { + return '/apps/test/'; }); $this->urlGenerator - ->expects($this->once()) - ->method('linkToRouteAbsolute') - ->with( - 'core.login.logout', - [ - 'requesttoken' => \OCP\Util::callRegister(), - ] - ) - ->willReturn('https://example.com/logout'); + ->expects($this->once()) + ->method('linkToRouteAbsolute') + ->with( + 'core.login.logout', + [ + 'requesttoken' => \OCP\Util::callRegister() + ] + ) + ->willReturn('https://example.com/logout'); $user = $this->createMock(IUser::class); $user->expects($this->any())->method('getUID')->willReturn('user001'); $this->userSession->expects($this->any())->method('getUser')->willReturn($user); $this->userSession->expects($this->any())->method('isLoggedIn')->willReturn(true); $this->appManager->expects($this->once()) - ->method('getEnabledAppsForUser') - ->with($user) - ->willReturn(['test']); + ->method('getEnabledAppsForUser') + ->with($user) + ->willReturn(['test']); $this->groupManager->expects($this->any())->method('isAdmin')->willReturn($isAdmin); $subadmin = $this->createMock(SubAdmin::class); $subadmin->expects($this->any())->method('isSubAdmin')->with($user)->willReturn(false); @@ -250,72 +250,119 @@ class NavigationManagerTest extends TestCase { public function providesNavigationConfig() { $apps = [ - [ - 'id' => 'core_apps', - 'order' => 3, - 'href' => '/apps/test/', - 'icon' => '/apps/settings/img/apps.svg', - 'name' => 'Apps', - 'active' => false, - 'type' => 'settings', - 'classes' => '', + 'core_apps' => [ + 'id' => 'core_apps', + 'order' => 3, + 'href' => '/apps/test/', + 'icon' => '/apps/settings/img/apps.svg', + 'name' => 'Apps', + 'active' => false, + 'type' => 'settings', + 'classes' => '' ] ]; $defaults = [ - [ - 'id' => 'settings', - 'order' => 1, - 'href' => '/apps/test/', - 'icon' => '/apps/settings/img/admin.svg', - 'name' => 'Settings', - 'active' => false, - 'type' => 'settings', - 'classes' => '', - ], - [ - 'id' => 'logout', - 'order' => 99999, - 'href' => 'https://example.com/logout', - 'icon' => '/apps/core/img/actions/logout.svg', - 'name' => 'Log out', - 'active' => false, - 'type' => 'settings', - 'classes' => '', + 'settings' => [ + 'id' => 'settings', + 'order' => 1, + 'href' => '/apps/test/', + 'icon' => '/apps/settings/img/admin.svg', + 'name' => 'Settings', + 'active' => false, + 'type' => 'settings', + 'classes' => '' ], + 'logout' => [ + 'id' => 'logout', + 'order' => 99999, + 'href' => 'https://example.com/logout', + 'icon' => '/apps/core/img/actions/logout.svg', + 'name' => 'Log out', + 'active' => false, + 'type' => 'settings', + 'classes' => '' + ] ]; + return [ - 'minimalistic' => [array_merge([$defaults[0]], [[ - 'id' => 'test', - 'order' => 100, - 'href' => '/apps/test/', - 'icon' => '/apps/test/img/app.svg', - 'name' => 'Test', - 'active' => false, - 'type' => 'link', - 'classes' => '', - ]], [$defaults[1]]), ['navigations' => [['route' => 'test.page.index', 'name' => 'Test']]]], - 'minimalistic-settings' => [array_merge([$defaults[0]], [[ - 'id' => 'test', - 'order' => 100, - 'href' => '/apps/test/', - 'icon' => '/apps/test/img/app.svg', - 'name' => 'Test', - 'active' => false, - 'type' => 'settings', - 'classes' => '', - ]], [$defaults[1]]), ['navigations' => [['route' => 'test.page.index', 'name' => 'Test', 'type' => 'settings']]]], - 'admin' => [array_merge([$defaults[0]], $apps, [[ - 'id' => 'test', - 'order' => 100, - 'href' => '/apps/test/', - 'icon' => '/apps/test/img/app.svg', - 'name' => 'Test', - 'active' => false, - 'type' => 'link', - 'classes' => '', - ]], [$defaults[1]]), ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test']]], true], - 'no name' => [array_merge([$defaults[0]], $apps, [$defaults[1]]), ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index']]], true], - 'no admin' => [$defaults, ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test']]]] + 'minimalistic' => [ + array_merge( + ['settings' => $defaults['settings']], + ['test' => [ + 'id' => 'test', + 'order' => 100, + 'href' => '/apps/test/', + 'icon' => '/apps/test/img/app.svg', + 'name' => 'Test', + 'active' => false, + 'type' => 'link', + 'classes' => '' + ]], + ['logout' => $defaults['logout']] + ), + ['navigations' => [ + ['route' => 'test.page.index', 'name' => 'Test'] + ]] + ], + 'minimalistic-settings' => [ + array_merge( + ['settings' => $defaults['settings']], + ['test' => [ + 'id' => 'test', + 'order' => 100, + 'href' => '/apps/test/', + 'icon' => '/apps/test/img/app.svg', + 'name' => 'Test', + 'active' => false, + 'type' => 'settings', + 'classes' => '' + ]], + ['logout' => $defaults['logout']] + ), + ['navigations' => [ + ['route' => 'test.page.index', 'name' => 'Test', 'type' => 'settings'] + ] + ]], + 'admin' => [ + array_merge( + ['settings' => $defaults['settings']], + $apps, + ['test' => [ + 'id' => 'test', + 'order' => 100, + 'href' => '/apps/test/', + 'icon' => '/apps/test/img/app.svg', + 'name' => 'Test', + 'active' => false, + 'type' => 'link', + 'classes' => '' + ]], + ['logout' => $defaults['logout']] + ), + ['navigations' => [ + ['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test'] + ]], + true + ], + 'no name' => [ + array_merge( + ['settings' => $defaults['settings']], + $apps, + ['logout' => $defaults['logout']] + ), + ['navigations' => [ + ['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index'] + ]], + true + ], + 'no admin' => [ + $defaults, + ['navigations' => [[ + '@attributes' => ['role' => 'admin'], + 'route' => 'test.page.index', + 'name' => 'Test' + ]]] + ] ]; } } From 18790858caea8f20f09ade8c7e3039da6dd1483b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Sat, 14 Jul 2018 12:14:21 +0200 Subject: [PATCH 06/10] Fix share by/with check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/files_sharing/js/sharedfilelist.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js index 914bfd6ae1..6c0aae1eb1 100644 --- a/apps/files_sharing/js/sharedfilelist.js +++ b/apps/files_sharing/js/sharedfilelist.js @@ -274,7 +274,7 @@ } if (shares.ocs && shares.ocs.data) { - files = files.concat(this._makeFilesFromShares(shares.ocs.data)); + files = files.concat(this._makeFilesFromShares(shares.ocs.data, this._sharedWithUser)); } if (remoteShares && remoteShares.ocs && remoteShares.ocs.data) { @@ -282,7 +282,7 @@ } if (additionnalShares && additionnalShares[0] && additionnalShares[0].ocs && additionnalShares[0].ocs.data) { - files = files.concat(this._makeFilesFromShares(additionnalShares[0].ocs.data)); + files = files.concat(this._makeFilesFromShares(additionnalShares[0].ocs.data, !this._sharedWithUser)); } this.setFiles(files); @@ -323,7 +323,7 @@ * @param {Array} data OCS API share array * @return {Array.} array of shared file info */ - _makeFilesFromShares: function(data) { + _makeFilesFromShares: function(data, sharedWithUser) { /* jshint camelcase: false */ var self = this; var files = data; @@ -359,7 +359,7 @@ stime: share.stime * 1000, expiration: share.expiration, }; - if (self._sharedWithUser) { + if (sharedWithUser) { file.shareOwner = share.displayname_owner; file.shareOwnerId = share.uid_owner; file.name = OC.basename(share.file_target); From 98cf2bab488af7cf64399bbe43560c9b68d50f47 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 16 Jul 2018 16:26:39 +0200 Subject: [PATCH 07/10] Rename "Shares overview" to "Shares" Signed-off-by: Morris Jobke --- apps/files_sharing/appinfo/app.php | 2 +- apps/files_sharing/js/app.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index b7459d999d..443d9e0201 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -93,7 +93,7 @@ if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') { 'appname' => 'files_sharing', 'script' => 'list.php', 'order' => 18, - 'name' => $l->t('Share overview'), + 'name' => $l->t('Shares'), 'classes' => 'collapsible', 'sublist' => $sharingSublistArray, 'expandedState' => 'show_sharing_menu' diff --git a/apps/files_sharing/js/app.js b/apps/files_sharing/js/app.js index ce16c1da92..76d52cfe9e 100644 --- a/apps/files_sharing/js/app.js +++ b/apps/files_sharing/js/app.js @@ -132,7 +132,7 @@ OCA.Sharing.App = { ); this._extendFileList(this._overviewFileList); - this._overviewFileList.appName = t('files_sharing', 'Share overview'); + this._overviewFileList.appName = t('files_sharing', 'Shares'); this._overviewFileList.$el.find('#emptycontent').html('
        ' + '

        ' + t('files_sharing', 'No shares') + '

        ' + '

        ' + t('files_sharing', 'Shares will show up here') + '

        '); From c0fcc0e45c19b2c7876bd0cd7620a763a8151238 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 16 Jul 2018 16:28:57 +0200 Subject: [PATCH 08/10] Make section "deleted shares" a subsection of "shares" Signed-off-by: Morris Jobke --- apps/files_sharing/appinfo/app.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 443d9e0201..d50da0285a 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -85,6 +85,14 @@ if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') { } } + array_push($sharingSublistArray, [ + 'id' => 'deletedshares', + 'appname' => 'files_sharing', + 'script' => 'list.php', + 'order' => 19, + 'name' => $l->t('Deleted shares'), + ]); + // show_Quick_Access stored as string $defaultExpandedState = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_sharing_menu', '0') === '1'; @@ -98,16 +106,4 @@ if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') { 'sublist' => $sharingSublistArray, 'expandedState' => 'show_sharing_menu' ]); - - - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N('files_sharing'); - return [ - 'id' => 'deletedshares', - 'appname' => 'files_sharing', - 'script' => 'list.php', - 'order' => 19, - 'name' => $l->t('Deleted shares'), - ]; - }); } From 92e30698bb3f1387e883e2075360a796b9df996f Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 16 Jul 2018 16:29:17 +0200 Subject: [PATCH 09/10] Reorder position of "Shared by me" and "Shared with me" Signed-off-by: Morris Jobke --- apps/files_sharing/appinfo/app.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index d50da0285a..567b1a16ba 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -56,6 +56,16 @@ if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') { $sharingSublistArray = []; + if (\OCP\Util::isSharingDisabledForUser() === false) { + array_push($sharingSublistArray, [ + 'id' => 'sharingout', + 'appname' => 'files_sharing', + 'script' => 'list.php', + 'order' => 16, + 'name' => $l->t('Shared with others'), + ]); + } + array_push($sharingSublistArray, [ 'id' => 'sharingin', 'appname' => 'files_sharing', @@ -65,14 +75,6 @@ if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') { ]); if (\OCP\Util::isSharingDisabledForUser() === false) { - array_push($sharingSublistArray, [ - 'id' => 'sharingout', - 'appname' => 'files_sharing', - 'script' => 'list.php', - 'order' => 16, - 'name' => $l->t('Shared with others'), - ]); - // Check if sharing by link is enabled if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { array_push($sharingSublistArray, [ From cdb42432c3a58efc24f59d9a4bb453288f346eab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Tue, 17 Jul 2018 12:26:57 +0200 Subject: [PATCH 10/10] Jsuinit fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/files_sharing/js/sharedfilelist.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js index 6c0aae1eb1..7119249714 100644 --- a/apps/files_sharing/js/sharedfilelist.js +++ b/apps/files_sharing/js/sharedfilelist.js @@ -269,9 +269,15 @@ var files = []; // make sure to use the same format - if(shares[0] && shares[0].ocs) { + if (shares[0] && shares[0].ocs) { shares = shares[0]; } + if (remoteShares && remoteShares[0] && remoteShares[0].ocs) { + remoteShares = remoteShares[0]; + } + if (additionnalShares && additionnalShares[0] && additionnalShares[0].ocs) { + additionnalShares = additionnalShares[0]; + } if (shares.ocs && shares.ocs.data) { files = files.concat(this._makeFilesFromShares(shares.ocs.data, this._sharedWithUser)); @@ -281,10 +287,11 @@ files = files.concat(this._makeFilesFromRemoteShares(remoteShares.ocs.data)); } - if (additionnalShares && additionnalShares[0] && additionnalShares[0].ocs && additionnalShares[0].ocs.data) { - files = files.concat(this._makeFilesFromShares(additionnalShares[0].ocs.data, !this._sharedWithUser)); + if (additionnalShares && additionnalShares && additionnalShares.ocs && additionnalShares.ocs.data) { + files = files.concat(this._makeFilesFromShares(additionnalShares.ocs.data, !this._sharedWithUser)); } + this.setFiles(files); return true; },