From 72ace9697c0951b3379a88c3cb639e1c9abe0170 Mon Sep 17 00:00:00 2001 From: fnuesse Date: Fri, 1 Jun 2018 20:29:43 +0200 Subject: [PATCH 01/19] Added FavoritesQuickaccess-Sidebar Added FavoritesQuickaccess-Sidebar Added Files-FavoritesQuickaccess-Toggle Fixed CSS for SpacerElement Removed Unnessessary Alerts and added Translations Tried fixing initial Quick-Access Checkboxstate Signed-off-by: fnuesse Tried fixing initial Quick-Access Checkboxstate Changed double-Quotes to single-Quotes Revert webdavurl which was changed by mistake Revert quota-icon which was changed by mistake Changed the Folderhandling from custom-designed to nextcloud-NavigationManager-handling Signed-off-by: fnuesse Moved CSS-Spacerclass to apps.scss for global usage Signed-off-by: fnuesse Renamed settings-caption in apps.scss to app-navigation-caption Signed-off-by: fnuesse Removed old input-tag for showQuickAccess-state Signed-off-by: fnuesse Removed old spacer element in files.scss Signed-off-by: fnuesse Changed style of favorites-sublist and disabled the ability to disable files-quickaccess Signed-off-by: fnuesse --- apps/files/appinfo/routes.php | 10 ++++ apps/files/js/app.js | 40 +++++++++++++- apps/files/lib/Controller/ApiController.php | 28 ++++++++++ apps/files/lib/Controller/ViewController.php | 58 +++++++++++++++++--- apps/files/templates/appnavigation.php | 28 ++++++---- core/css/apps.scss | 36 ++++++++++++ 6 files changed, 181 insertions(+), 19 deletions(-) diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index 0d1449ff35..3273d6d97d 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -76,6 +76,16 @@ $application->registerRoutes( 'url' => '/ajax/getstoragestats.php', 'verb' => 'GET', ], + [ + 'name' => 'API#showQuickAccess', + 'url' => '/api/v1/showquickaccess', + 'verb' => 'GET', + ], + [ + 'name' => 'API#hideQuickAccess', + 'url' => '/api/v1/hidequickaccess', + 'verb' => 'GET', + ], ] ] ); diff --git a/apps/files/js/app.js b/apps/files/js/app.js index 6a21bce975..97b8b630f7 100644 --- a/apps/files/js/app.js +++ b/apps/files/js/app.js @@ -53,12 +53,19 @@ this.$showHiddenFiles = $('input#showhiddenfilesToggle'); var showHidden = $('#showHiddenFiles').val() === "1"; this.$showHiddenFiles.prop('checked', showHidden); + + this.$showQuickAccess = $('input#showfavoritequickaccessToggle'); + var showQuickAccess = $('#showFavoriteQuickAccess').val() === "1"; + this.$showQuickAccess.prop('checked', showQuickAccess); + + if ($('#fileNotFound').val() === "1") { OC.Notification.show(t('files', 'File could not be found'), {type: 'error'}); } this._filesConfig = new OC.Backbone.Model({ - showhidden: showHidden + showhidden: showHidden, + showQuickAccess: showQuickAccess }); var urlParams = OC.Util.History.parseUrlQuery(); @@ -131,6 +138,7 @@ }); this._debouncedPersistShowHiddenFilesState = _.debounce(this._persistShowHiddenFilesState, 1200); + this._debouncedPersistShowQuickAccessState = _.debounce(this._persistShowQuickAccessState, 1200); }, /** @@ -205,6 +213,7 @@ $('#app-navigation').on('itemChanged', _.bind(this._onNavigationChanged, this)); this.$showHiddenFiles.on('change', _.bind(this._onShowHiddenFilesChange, this)); + this.$showQuickAccess.on('change', _.bind(this._onShowQuickAccessChange, this)); }, /** @@ -230,6 +239,35 @@ }); }, + + /** + * Toggle showing hidden files according to the settings checkbox + * + * @returns {undefined} + */ + _onShowQuickAccessChange: function() { + var qa = this.$showQuickAccess.is(':checked'); + this._filesConfig.set('show_quick_access', qa); + this._debouncedPersistShowQuickAccessState(); + }, + + /** + * Persist show hidden preference on ther server + * + * @returns {undefined} + */ + _persistShowQuickAccessState: function() { + var qa = this._filesConfig.get('show_quick_access'); + var url="/apps/files/api/v1/hidequickaccess"; + if(qa){ + url="/apps/files/api/v1/showquickaccess"; + } + + $.get(OC.generateUrl(url),function(data, status){ + }); + }, + + /** * Event handler for when the current navigation item has changed */ diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index a66b1b4d56..b1af121ed6 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -265,4 +265,32 @@ class ApiController extends Controller { return new Response(); } + /** + * Toggle default for showing/hiding QuickAccess folder + * + * @NoAdminRequired + * + * @param int $value + * @return Response + */ + public function showQuickAccess() { + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', 1); + return new Response(); + } + + /** + * Toggle default for showing/hiding QuickAccess folder + * + * @NoAdminRequired + * + * @param int $value + * @return Response + */ + public function hideQuickAccess() { + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', 0); + return new Response(); + } + + + } diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 7cb0f112f7..54602839eb 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -159,6 +159,7 @@ class ViewController extends Controller { // FIXME: Make non static $storageInfo = $this->getStorageInfo(); + \OCA\Files\App::getNavigationManager()->add( [ 'id' => 'favorites', @@ -169,18 +170,59 @@ class ViewController extends Controller { ] ); + + + $user = $this->userSession->getUser()->getUID(); + + $tagger=\OC::$server->getTagManager(); + + + $helper= new \OCA\Files\Activity\Helper($tagger); + $favElements = $helper->getFavoriteFilePaths($this->userSession->getUser()->getUID()); + $favItems = $favElements['items']; + + $key='show_Quick_Access'; + + if($this->config->getUserValue($user,$this->appName,$key,true) && sizeof($favElements['folders'])>0){ + /*$nav->assign('showQuickAccess', 1); + \OCA\Files\App::getNavigationManager()->add( + [ + 'id' => 'Spacer', + 'classes' => 'app-navigation-caption', + 'order' => 6, + 'name' => $this->l10n->t('Quick-Access') + ] + );*/ + + $i=0; + foreach($favElements['folders'] as $elem){ + + \OCA\Files\App::getNavigationManager()->add( + [ + 'id' => substr( $elem, strrpos($elem,'/')+1, strlen($elem)), + 'href' => \OC::$WEBROOT.'/index.php/apps/files/?dir='.$elem, + 'order' => 7+$i, + 'classes' => 'app-navigation-subelement', + 'name' => substr( $elem, strrpos($elem,'/')+1, strlen($elem)), + 'icon' => 'files' + ] + ); + $i++; + } + } + + + $navItems = \OCA\Files\App::getNavigationManager()->getAll(); usort($navItems, function($item1, $item2) { return $item1['order'] - $item2['order']; }); - $nav->assign('navigationItems', $navItems); - $webdavurl = $this->urlGenerator->linkTo('', 'remote.php') . - '/dav/files/' . - $this->userSession->getUser()->getUID() . - '/'; - $webdavurl = $this->urlGenerator->getAbsoluteURL($webdavurl); - $nav->assign('webdavurl', $webdavurl); + + + + + $nav->assign('navigationItems', $navItems); $nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used'])); if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) { @@ -215,7 +257,6 @@ class ViewController extends Controller { $params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; $params['isPublic'] = false; $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); - $user = $this->userSession->getUser()->getUID(); $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); @@ -234,6 +275,7 @@ class ViewController extends Controller { $policy->addAllowedFrameDomain('\'self\''); $response->setContentSecurityPolicy($policy); + return $response; } diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php index c811ace8ab..749f36a44e 100644 --- a/apps/files/templates/appnavigation.php +++ b/apps/files/templates/appnavigation.php @@ -1,19 +1,21 @@ + + - + t('Use this address to access your Files via WebDAV', array(link_to_docs('user-webdav'))));?> + diff --git a/core/css/apps.scss b/core/css/apps.scss index 13b4c7eb9f..2e3ab7b1a2 100644 --- a/core/css/apps.scss +++ b/core/css/apps.scss @@ -584,6 +584,41 @@ kbd { .app-navigation-entry-menu ul { list-style-type: none; } + + .app-navigation-caption { + font-weight: bold; + line-height: 44px; + white-space: nowrap; + text-overflow: ellipsis; + float: left; + margin-left:10px; + margin-top:10px; + margin-bottom:10px; + //Make the Link in the spacer not selectable and prevent mouseevents + -moz-user-select: -moz-none; + -khtml-user-select: none; + -webkit-user-select: none; + -o-user-select: none; + user-select: none; + pointer-events:none; + } + + .app-navigation-subelement { + line-height: 24px; + white-space: nowrap; + text-overflow: ellipsis; + float: left; + padding-left: 14px; + & a { + //Overrides normal size for smaller subelements + line-height: 24px; + min-height: 24px; + //Removes the double border on the a element + &:visited { box-shadow:none;} + &:hover { box-shadow:none;} + &:active {box-shadow:none; } + } + } } /* APP-CONTENT ---------------------------------------------------------------*/ @@ -691,6 +726,7 @@ kbd { background-color: var(--color-main-background); } + .settings-button { display: block; height: 44px; From fc4baed6e5e862492ac1e2f12a408971d8ee6a26 Mon Sep 17 00:00:00 2001 From: fnuesse Date: Sat, 16 Jun 2018 22:44:18 +0200 Subject: [PATCH 02/19] Added toggleable QuickAccess Signed-off-by: fnuesse Deleted wrongly commited File Signed-off-by: fnuesse Added quickaccess-state persistence Signed-off-by: fnuesse Started implementing sorting-algorithm for proper alphabetical display Signed-off-by: fnuesse Finished Sorting of Quickaccess elements Signed-off-by: fnuesse Implemented persistence for reverse-list and sorting-strategy Signed-off-by: fnuesse Implemented initial sorting for reverse-list and sorting-strategy Signed-off-by: fnuesse Refactored Code Signed-off-by: fnuesse Refactored Code Signed-off-by: fnuesse Refactored Code Signed-off-by: fnuesse --- apps/files/appinfo/routes.php | 20 ++ apps/files/js/app.js | 40 +--- apps/files/js/navigation.js | 195 ++++++++++++++++++- apps/files/lib/Controller/ApiController.php | 56 +++++- apps/files/lib/Controller/ViewController.php | 83 ++++---- apps/files/templates/appnavigation.php | 56 +++++- core/css/apps.scss | 17 -- 7 files changed, 357 insertions(+), 110 deletions(-) diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index 3273d6d97d..ed2373149f 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -86,6 +86,26 @@ $application->registerRoutes( 'url' => '/api/v1/hidequickaccess', 'verb' => 'GET', ], + [ + 'name' => 'API#setSortingStrategy', + 'url' => '/api/v1/setsortingstrategy', + 'verb' => 'GET', + ], + [ + 'name' => 'API#setReverseQuickaccess', + 'url' => '/api/v1/setreversequickaccess', + 'verb' => 'GET', + ], + [ + 'name' => 'API#getSortingStrategy', + 'url' => '/api/v1/getsortingstrategy', + 'verb' => 'GET', + ], + [ + 'name' => 'API#getReverseQuickaccess', + 'url' => '/api/v1/getreversequickaccess', + 'verb' => 'GET', + ] ] ] ); diff --git a/apps/files/js/app.js b/apps/files/js/app.js index 97b8b630f7..ec223e418b 100644 --- a/apps/files/js/app.js +++ b/apps/files/js/app.js @@ -54,18 +54,13 @@ var showHidden = $('#showHiddenFiles').val() === "1"; this.$showHiddenFiles.prop('checked', showHidden); - this.$showQuickAccess = $('input#showfavoritequickaccessToggle'); - var showQuickAccess = $('#showFavoriteQuickAccess').val() === "1"; - this.$showQuickAccess.prop('checked', showQuickAccess); - if ($('#fileNotFound').val() === "1") { OC.Notification.show(t('files', 'File could not be found'), {type: 'error'}); } this._filesConfig = new OC.Backbone.Model({ - showhidden: showHidden, - showQuickAccess: showQuickAccess + showhidden: showHidden }); var urlParams = OC.Util.History.parseUrlQuery(); @@ -138,7 +133,6 @@ }); this._debouncedPersistShowHiddenFilesState = _.debounce(this._persistShowHiddenFilesState, 1200); - this._debouncedPersistShowQuickAccessState = _.debounce(this._persistShowQuickAccessState, 1200); }, /** @@ -213,7 +207,6 @@ $('#app-navigation').on('itemChanged', _.bind(this._onNavigationChanged, this)); this.$showHiddenFiles.on('change', _.bind(this._onShowHiddenFilesChange, this)); - this.$showQuickAccess.on('change', _.bind(this._onShowQuickAccessChange, this)); }, /** @@ -228,7 +221,7 @@ }, /** - * Persist show hidden preference on ther server + * Persist show hidden preference on the server * * @returns {undefined} */ @@ -239,35 +232,6 @@ }); }, - - /** - * Toggle showing hidden files according to the settings checkbox - * - * @returns {undefined} - */ - _onShowQuickAccessChange: function() { - var qa = this.$showQuickAccess.is(':checked'); - this._filesConfig.set('show_quick_access', qa); - this._debouncedPersistShowQuickAccessState(); - }, - - /** - * Persist show hidden preference on ther server - * - * @returns {undefined} - */ - _persistShowQuickAccessState: function() { - var qa = this._filesConfig.get('show_quick_access'); - var url="/apps/files/api/v1/hidequickaccess"; - if(qa){ - url="/apps/files/api/v1/showquickaccess"; - } - - $.get(OC.generateUrl(url),function(data, status){ - }); - }, - - /** * Event handler for when the current navigation item has changed */ diff --git a/apps/files/js/navigation.js b/apps/files/js/navigation.js index d213d0467b..cf4de7d61e 100644 --- a/apps/files/js/navigation.js +++ b/apps/files/js/navigation.js @@ -4,6 +4,8 @@ * @author Vincent Petry * @copyright 2014 Vincent Petry * + * Edited by: Felix Nüsse 2018 + * * This file is licensed under the Affero General Public License version 3 * or later. * @@ -38,6 +40,10 @@ */ $currentContent: null, + /** + * Strategy by which the quickaccesslist is sorted + */ + $sortingStrategy: 'alphabet', /** * Initializes the navigation from the given container * @@ -49,13 +55,16 @@ this._activeItem = null; this.$currentContent = null; this._setupEvents(); + this.initialSort(); }, /** * Setup UI events */ _setupEvents: function() { - this.$el.on('click', 'li a', _.bind(this._onClickItem, this)); + this.$el.on('click', 'li a', _.bind(this._onClickItem, this)) + this.$el.on('click', 'li button', _.bind(this._onClickMenuButton, this)); + this.$el.on('click', 'li input', _.bind(this._onClickMenuItem, this)); }, /** @@ -127,9 +136,193 @@ this.setActiveItem(itemId); } ev.preventDefault(); + }, + /** + * Event handler for when clicking on an three-dot-menu. + */ + _onClickMenuButton: function(ev) { + var $target = $(ev.target); + var itemId = $target.closest('button').attr('id'); + if(itemId==='button-favorites'){ + document.getElementById('menu-favorites').classList.toggle('open'); + } + ev.preventDefault(); + }, + + /** + * Event handler for when clicking on a menuitem. + */ + _onClickMenuItem: function(ev) { + + var qaSelector= '#quickaccess-list'; + var qaKey= 'quickaccess-list'; + + var itemId = $(ev.target).closest('input').attr('id'); + var list = document.getElementById(qaKey).getElementsByTagName('li'); + + if(itemId==='enableQuickAccess'){ + $.get(OC.generateUrl("/apps/files/api/v1/showquickaccess"), {show: document.getElementById('enableQuickAccess').checked}, function(data, status){ + }); + $(qaSelector ).toggle(); + document.getElementById('menu-favorites').classList.toggle('open'); + } + + if(itemId==='sortByAlphabet'){ + //Prevents deselecting Group-Item + if(!document.getElementById('sortByAlphabet').checked){ + ev.preventDefault(); + return; + } + this.sortingStrategy='alphabet'; + document.getElementById('sortByDate').checked=false; + $.get(OC.generateUrl("/apps/files/api/v1/setsortingstrategy"), {strategy: this.sortingStrategy}, function(data, status){}); + this.QuickSort(list, 0, list.length - 1); + document.getElementById('menu-favorites').classList.toggle('open'); + } + + if(itemId==='sortByDate'){ + //Prevents deselecting Group-Item + if(!document.getElementById('sortByDate').checked){ + ev.preventDefault(); + return; + } + this.sortingStrategy='date'; + document.getElementById('sortByAlphabet').checked=false; + $.get(OC.generateUrl("/apps/files/api/v1/setsortingstrategy"), {strategy: this.sortingStrategy}, function(data, status){}); + this.QuickSort(list, 0, list.length - 1); + document.getElementById('menu-favorites').classList.toggle('open'); + } + + if(itemId==='enableReverse'){ + this.reverse(list); + var state = document.getElementById('enableReverse').checked; + $.get(OC.generateUrl("/apps/files/api/v1/setreversequickaccess"), {reverse: state}, function(data, status){}); + document.getElementById('menu-favorites').classList.toggle('open'); + } + //ev.preventDefault(); + }, + + /** + * Sort initially as setup of sidebar for QuickAccess + */ + initialSort: function() { + + var domRevState=document.getElementById('enableReverse').checked; + var domSortAlphabetState=document.getElementById('sortByAlphabet').checked; + var domSortDateState=document.getElementById('sortByDate').checked; + + var qaKey= 'quickaccess-list'; + var list = document.getElementById(qaKey).getElementsByTagName('li'); + + if(domSortAlphabetState){ + this.sortingStrategy='alphabet'; + } + if(domSortDateState){ + this.sortingStrategy='date'; + } + + this.QuickSort(list, 0, list.length - 1); + + if(domRevState){ + this.reverse(list); + } + + /*This creates flashes the UI, which is bad userexperience. It is the cleaner way to do it, that is why i haven't deleted it yet. + var scope=this; + $.get(OC.generateUrl("/apps/files/api/v1/getsortingstrategy"), function(data, status){ + scope.sortingStrategy=data; + scope.QuickSort(list, 0, list.length - 1); + + }); + + $.get(OC.generateUrl("/apps/files/api/v1/getreversequickaccess"), function(data, status){ + if(data){ + scope.reverse(list); + } + }); + */ + }, + + /** + * Sorting-Algorithm for QuickAccess + */ + QuickSort: function(list, start, end) { + var lastmatch; + if(list.length > 1){ + lastmatch = this.quicksort_helper(list, start, end); + if(start < lastmatch - 1){ + this.QuickSort(list, start, lastmatch - 1); + } + if(lastmatch < end){ + this.QuickSort(list, lastmatch, end); + } + } + }, + + /** + * Sorting-Algorithm-Helper for QuickAccess + */ + quicksort_helper: function(list, start, end) { + var pivot = Math.floor((end + start) / 2); + var pivotelem = this.getCompareValue(list,pivot); + var i = start; + var j = end; + + while(i <= j){ + while(this.getCompareValue(list,i) < pivotelem){ + i++; + } + while(this.getCompareValue(list,j) > pivotelem){ + j--; + } + if(i <= j){ + this.swap(list, i, j); + i++; + j--; + } + } + return i; + }, + + /** + * Sorting-Algorithm-Helper for QuickAccess + * This method allows easy access to the element which is sorted by. + */ + getCompareValue: function(nodes, int){ + if(this.sortingStrategy==='alphabet'){ + ; return nodes[int].getElementsByTagName('a')[0].innerHTML.toLowerCase() + }else if(this.sortingStrategy==='date'){ + return nodes[int].getAttribute('folderPos').toLowerCase(); + } + return nodes[int].getElementsByTagName('a')[0].innerHTML.toLowerCase(); + }, + + /** + * Sorting-Algorithm-Helper for QuickAccess + * This method allows easy swapping of elements. + */ + swap: function(list, j, i){ + list[i].before(list[j]); + list[j].before(list[i]); + }, + + /** + * Reverse QuickAccess-List + */ + reverse: function(list){ + var len=list.length-1; + for(var i = 0; i < len/2; i++) { + this.swap(list, i, len-i); + } } + }; OCA.Files.Navigation = Navigation; })(); + + + + + diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index b1af121ed6..53a8e1b55e 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -45,6 +45,7 @@ use OCP\IPreview; use OCP\Share\IManager; use OC\Files\Node\Node; use OCP\IUserSession; +use Sabre\VObject\Property\Boolean; /** * Class ApiController @@ -270,27 +271,64 @@ class ApiController extends Controller { * * @NoAdminRequired * - * @param int $value + * @param bool $show + * * @return Response */ - public function showQuickAccess() { - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', 1); + 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 + * quickaccess-sorting-strategy * * @NoAdminRequired * - * @param int $value + * @param string $strategy * @return Response */ - public function hideQuickAccess() { - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', 0); + public function setSortingStrategy($strategy) { + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_sorting_strategy', (String) $strategy); return new Response(); + } + + /** + * Get reverse-state for quickaccess-list + * + * @NoAdminRequired + * + * @return String + */ + public function getSortingStrategy() { + return $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_sorting_strategy', 'date'); + } + + /** + * Toggle for reverse quickaccess-list + * + * @NoAdminRequired + * + * @param bool $reverse + * @return Response + */ + public function setReverseQuickaccess($reverse) { + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_reverse_list', (int) $reverse); + return new Response(); + } + + /** + * Get reverse-state for quickaccess-list + * + * @NoAdminRequired + * + * @return bool + */ + public function getReverseQuickaccess() { + if($this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_reverse_list', false)){ + return true; } - - + return false; + } } diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 54602839eb..11a42fb529 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -159,58 +159,73 @@ class ViewController extends Controller { // FIXME: Make non static $storageInfo = $this->getStorageInfo(); + $user = $this->userSession->getUser()->getUID(); + + $sorting=$this->config->getUserValue($user,$this->appName,'quickaccess_sorting_strategy','date'); + $reverseListSetting=$this->config->getUserValue($user,$this->appName,'quickaccess_reverse_list','false'); + if($this->config->getUserValue($user,$this->appName,'show_Quick_Access',true)){ + $expanded='true'; + }else{ + $expanded='false'; + } \OCA\Files\App::getNavigationManager()->add( [ 'id' => 'favorites', 'appname' => 'files', 'script' => 'simplelist.php', + 'enableQuickaccess' => $expanded, + 'quickaccessSortingStrategy' => $sorting, + 'quickaccessSortingReverse' => $reverseListSetting, 'order' => 5, 'name' => $this->l10n->t('Favorites') ] ); - - - $user = $this->userSession->getUser()->getUID(); - $tagger=\OC::$server->getTagManager(); - $helper= new \OCA\Files\Activity\Helper($tagger); $favElements = $helper->getFavoriteFilePaths($this->userSession->getUser()->getUID()); - $favItems = $favElements['items']; - $key='show_Quick_Access'; + $FavoritesFolderCount=sizeof($favElements['folders']); + if($FavoritesFolderCount>0){ - if($this->config->getUserValue($user,$this->appName,$key,true) && sizeof($favElements['folders'])>0){ - /*$nav->assign('showQuickAccess', 1); - \OCA\Files\App::getNavigationManager()->add( - [ - 'id' => 'Spacer', - 'classes' => 'app-navigation-caption', - 'order' => 6, - 'name' => $this->l10n->t('Quick-Access') - ] - );*/ + $NavBarPositionPosition=6; + $currentCount=0; + foreach($favElements['folders'] as $elem){ - $i=0; - foreach($favElements['folders'] as $elem){ + $id=substr( $elem, strrpos($elem,'/')+1, strlen($elem)); + $link=\OC::$WEBROOT.'/index.php/apps/files/?dir='.$elem; - \OCA\Files\App::getNavigationManager()->add( - [ - 'id' => substr( $elem, strrpos($elem,'/')+1, strlen($elem)), - 'href' => \OC::$WEBROOT.'/index.php/apps/files/?dir='.$elem, - 'order' => 7+$i, - 'classes' => 'app-navigation-subelement', - 'name' => substr( $elem, strrpos($elem,'/')+1, strlen($elem)), - 'icon' => 'files' - ] - ); - $i++; + $SortingValue=++$currentCount; + if($currentCount!=$FavoritesFolderCount){ + \OCA\Files\App::getNavigationManager()->add( + [ + 'id' => $id, + 'href' => $link, + 'order' => $NavBarPositionPosition, + 'folderPosition' => $SortingValue, + 'name' => $id, + 'icon' => 'files', + 'quickaccesselement' => 'true' + ] + ); + }else{ + \OCA\Files\App::getNavigationManager()->add( + [ + 'id' => $id, + 'href' => $link, + 'order' => $NavBarPositionPosition, + 'folderPosition' => $SortingValue, + 'name' => $id, + 'icon' => 'files', + 'quickaccesselement' => 'last' + ] + ); + } + $NavBarPositionPosition++; + } } - } - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); @@ -218,10 +233,6 @@ class ViewController extends Controller { return $item1['order'] - $item2['order']; }); - - - - $nav->assign('navigationItems', $navItems); $nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used'])); diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php index 749f36a44e..c2f15fde80 100644 --- a/apps/files/templates/appnavigation.php +++ b/apps/files/templates/appnavigation.php @@ -5,12 +5,55 @@ - +
  • - - t('Use this address to access your Files via WebDAV', array(link_to_docs('user-webdav'))));?> diff --git a/core/css/apps.scss b/core/css/apps.scss index 2e3ab7b1a2..ab4e338a69 100644 --- a/core/css/apps.scss +++ b/core/css/apps.scss @@ -602,23 +602,6 @@ kbd { user-select: none; pointer-events:none; } - - .app-navigation-subelement { - line-height: 24px; - white-space: nowrap; - text-overflow: ellipsis; - float: left; - padding-left: 14px; - & a { - //Overrides normal size for smaller subelements - line-height: 24px; - min-height: 24px; - //Removes the double border on the a element - &:visited { box-shadow:none;} - &:hover { box-shadow:none;} - &:active {box-shadow:none; } - } - } } /* APP-CONTENT ---------------------------------------------------------------*/ From ce05cb371b044d08b45b49303f76d23a7fe84875 Mon Sep 17 00:00:00 2001 From: fnuesse Date: Sun, 17 Jun 2018 22:21:11 +0200 Subject: [PATCH 03/19] Fixed complete app-breakdown if no favorites are set Signed-off-by: fnuesse Hid three-dot menu if no favorites are selected Signed-off-by: fnuesse --- apps/files/lib/Controller/ViewController.php | 25 +++++++++++++++----- apps/files/templates/appnavigation.php | 6 +++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 11a42fb529..936f09154d 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -161,6 +161,7 @@ class ViewController extends Controller { $user = $this->userSession->getUser()->getUID(); + //Load QuickAccess-Defaults $sorting=$this->config->getUserValue($user,$this->appName,'quickaccess_sorting_strategy','date'); $reverseListSetting=$this->config->getUserValue($user,$this->appName,'quickaccess_reverse_list','false'); if($this->config->getUserValue($user,$this->appName,'show_Quick_Access',true)){ @@ -169,6 +170,20 @@ class ViewController extends Controller { $expanded='false'; } + + //Get Favorite-Folder + $tagger=\OC::$server->getTagManager(); + + $helper= new \OCA\Files\Activity\Helper($tagger); + + try { + $favElements = $helper->getFavoriteFilePaths($this->userSession->getUser()->getUID()); + } catch (\RuntimeException $e) { + $favElements['folders'] = null; + } + + $FavoritesFolderCount=sizeof($favElements['folders']); + \OCA\Files\App::getNavigationManager()->add( [ 'id' => 'favorites', @@ -178,16 +193,14 @@ class ViewController extends Controller { 'quickaccessSortingStrategy' => $sorting, 'quickaccessSortingReverse' => $reverseListSetting, 'order' => 5, - 'name' => $this->l10n->t('Favorites') + 'name' => $this->l10n->t('Favorites'), + //If there are zero elements, add ul end tag directly. + 'favoritescount' => $FavoritesFolderCount ] ); - $tagger=\OC::$server->getTagManager(); - $helper= new \OCA\Files\Activity\Helper($tagger); - $favElements = $helper->getFavoriteFilePaths($this->userSession->getUser()->getUID()); - - $FavoritesFolderCount=sizeof($favElements['folders']); + //Add Favorite-folder as menuentries, if there are any if($FavoritesFolderCount>0){ $NavBarPositionPosition=6; diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php index c2f15fde80..1488bee40d 100644 --- a/apps/files/templates/appnavigation.php +++ b/apps/files/templates/appnavigation.php @@ -14,7 +14,7 @@ class="nav-icon- svg"> -
    +
    style="display: none">
    @@ -47,8 +47,10 @@
  • -
      style="display: none"> +
        style="display: none"> +
      +
    From 9cd4b53a51c6b1ed4835df5976f7310b6fb3f75f Mon Sep 17 00:00:00 2001 From: fnuesse Date: Mon, 18 Jun 2018 11:13:52 +0200 Subject: [PATCH 04/19] Added responsive folderadding Signed-off-by: fnuesse Added collapsible to quickaccesslist Signed-off-by: fnuesse Refactored Code Signed-off-by: fnuesse --- apps/files/js/navigation.js | 16 ++++- apps/files/js/tagsplugin.js | 65 ++++++++++++++++++++ apps/files/lib/Controller/ViewController.php | 1 + apps/files/templates/appnavigation.php | 20 +++--- 4 files changed, 91 insertions(+), 11 deletions(-) diff --git a/apps/files/js/navigation.js b/apps/files/js/navigation.js index cf4de7d61e..04c9143581 100644 --- a/apps/files/js/navigation.js +++ b/apps/files/js/navigation.js @@ -143,6 +143,16 @@ _onClickMenuButton: function(ev) { var $target = $(ev.target); var itemId = $target.closest('button').attr('id'); + var qaSelector= '#quickaccess-list'; + + if(itemId==='button-collapseQuickAccess'){ + $.get(OC.generateUrl("/apps/files/api/v1/showquickaccess"), {show: document.getElementById('enableQuickAccess').checked}, function(data, status){ + }); + $("#quickaccess-list" ).toggle('open'); + var dotmenu = document.getElementById("quickaccess-list"); + dotmenu.style.display=''; + } + if(itemId==='button-favorites'){ document.getElementById('menu-favorites').classList.toggle('open'); } @@ -160,10 +170,10 @@ var itemId = $(ev.target).closest('input').attr('id'); var list = document.getElementById(qaKey).getElementsByTagName('li'); - if(itemId==='enableQuickAccess'){ + if(itemId==='enableQuickAccess' ){ $.get(OC.generateUrl("/apps/files/api/v1/showquickaccess"), {show: document.getElementById('enableQuickAccess').checked}, function(data, status){ }); - $(qaSelector ).toggle(); + $(qaSelector).toggle('open'); document.getElementById('menu-favorites').classList.toggle('open'); } @@ -290,7 +300,7 @@ */ getCompareValue: function(nodes, int){ if(this.sortingStrategy==='alphabet'){ - ; return nodes[int].getElementsByTagName('a')[0].innerHTML.toLowerCase() + return nodes[int].getElementsByTagName('a')[0].innerHTML.toLowerCase(); }else if(this.sortingStrategy==='date'){ return nodes[int].getAttribute('folderPos').toLowerCase(); } diff --git a/apps/files/js/tagsplugin.js b/apps/files/js/tagsplugin.js index b174aa7d76..8cdc26ab3b 100644 --- a/apps/files/js/tagsplugin.js +++ b/apps/files/js/tagsplugin.js @@ -62,6 +62,68 @@ $favoriteMarkEl.toggleClass('permanent', state); } + /** + * Remove Item from Quickaccesslist + * + * @param {String} $appfolder folder to be removed + */ + function removeFavoriteFromList(appfolder) { + + var qaKey= 'quickaccess-list'; + var listUL = document.getElementById(qaKey); + var list = listUL.getElementsByTagName('li'); + var appname=appfolder.substring(appfolder.lastIndexOf("/")+1, appfolder.length); + + for(var i = 0; i <= list.length-1; i++) { + if(appname === list[i].getElementsByTagName('a')[0].innerHTML){ + list[i].remove(); + } + } + + if(listUL.childElementCount==0){ + var dotmenu = document.getElementById("quickaccessbutton"); + dotmenu.style.display='none'; + } + } + + /** + * Add Item to Quickaccesslist + * + * @param {String} $appfolder folder to be added + */ + function addFavoriteToList(appfolder) { + var qaKey= 'quickaccess-list'; + var listUL = document.getElementById(qaKey); + var list = listUL.getElementsByTagName('li'); + + var appname=appfolder.substring(appfolder.lastIndexOf("/")+1, appfolder.length); + + var a = document.createElement('A'); + a.setAttribute("href","/cloud/index.php/apps/files/?dir="+appfolder); + a.setAttribute("class","nav-icon-files svg"); + a.innerHTML=appname; + + var len=list.length+1; + var li = document.createElement('li'); + li.setAttribute("data-id", "/cloud/index.php/apps/files/?dir="+appfolder); + li.setAttribute("class", "nav-"+appname); + li.setAttribute("folderpos", len.toString()); + li.appendChild(a); + + + if(listUL.childElementCount<=0){ + listUL.appendChild(li); + var dotmenu = document.getElementById("quickaccessbutton"); + dotmenu.style.display=''; + }else{ + list[list.length-1].after(li); + } + + //list[list.length-1].after(li); + //document.getElementById('menu-favorites').classList.toggle('open'); + //this.QuickSort(list, 0, list.length - 1); + } + OCA.Files = OCA.Files || {}; /** @@ -121,6 +183,7 @@ var fileInfo = context.fileList.files[$file.index()]; var dir = context.dir || context.fileList.getCurrentDirectory(); var tags = $file.attr('data-tags'); + if (_.isUndefined(tags)) { tags = ''; } @@ -130,8 +193,10 @@ if (isFavorite) { // remove tag from list tags = _.without(tags, OC.TAG_FAVORITE); + removeFavoriteFromList(dir + '/' + fileName); } else { tags.push(OC.TAG_FAVORITE); + addFavoriteToList(dir + '/' + fileName); } // pre-toggle the star diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 936f09154d..c218063f97 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -189,6 +189,7 @@ class ViewController extends Controller { 'id' => 'favorites', 'appname' => 'files', 'script' => 'simplelist.php', + 'classes' => 'collapsible', 'enableQuickaccess' => $expanded, 'quickaccessSortingStrategy' => $sorting, 'quickaccessSortingReverse' => $reverseListSetting, diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php index 1488bee40d..5f1baafaf8 100644 --- a/apps/files/templates/appnavigation.php +++ b/apps/files/templates/appnavigation.php @@ -7,18 +7,22 @@ ?> From edd2ab219416f2a0dd9c5afd15fac9bb973370d7 Mon Sep 17 00:00:00 2001 From: fnuesse Date: Wed, 20 Jun 2018 22:33:21 +0200 Subject: [PATCH 07/19] Added copyright notice Signed-off-by: fnuesse --- apps/files/lib/Controller/ViewController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 787216e36a..8afec0be90 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -8,6 +8,7 @@ * @author Roeland Jago Douma * @author Thomas Müller * @author Vincent Petry + * @author Felix Nüsse Petry * * @license AGPL-3.0 * From df9bae41bbae73220df134e8fc92d084ed03fa64 Mon Sep 17 00:00:00 2001 From: fnuesse Date: Wed, 20 Jun 2018 22:40:10 +0200 Subject: [PATCH 08/19] Removed old code Signed-off-by: fnuesse Removed duplicate collapse-button and changed api-endpoints Signed-off-by: fnuesse Removed app-navigation-caption from apps.scss Signed-off-by: fnuesse Changed api-endpoints Signed-off-by: fnuesse Fixed Codestyle (.js) Signed-off-by: fnuesse Hid away extended Settings Signed-off-by: fnuesse Fixed reverse state Signed-off-by: fnuesse Fixed Missing reverse after changing sort-strategy Signed-off-by: fnuesse Fixed Copyright-Header Signed-off-by: fnuesse Removed UI-Flickering Signed-off-by: fnuesse hid dotmenu on toggle while favorites are empty Signed-off-by: fnuesse Added Draggable to listelements (WIP) Signed-off-by: fnuesse Rebuild appnavigation.php with recursive function to allow easy implementation of sublists Signed-off-by: fnuesse Fixed draggable Sublist-Elements Signed-off-by: fnuesse Fixed draggable Sublist-Elements Signed-off-by: fnuesse Added date-modified sorting option to quickaccess Signed-off-by: fnuesse Added custom order sorting option to quickaccess Signed-off-by: fnuesse Added custom order sorting option to quickaccess Signed-off-by: fnuesse Added fallback for custom ordering Signed-off-by: fnuesse --- apps/files/appinfo/routes.php | 41 ++- apps/files/js/navigation.js | 303 +++++++++++-------- apps/files/js/tagsplugin.js | 129 ++++---- apps/files/lib/Controller/ApiController.php | 105 ++++++- apps/files/lib/Controller/ViewController.php | 97 +++--- apps/files/templates/appnavigation.php | 165 +++++----- core/css/apps.scss | 18 -- 7 files changed, 491 insertions(+), 367 deletions(-) diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index ed2373149f..ec8c3e03b7 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -78,34 +78,59 @@ $application->registerRoutes( ], [ 'name' => 'API#showQuickAccess', - 'url' => '/api/v1/showquickaccess', + 'url' => '/api/v1/quickaccess/set/showList', 'verb' => 'GET', ], [ - 'name' => 'API#hideQuickAccess', - 'url' => '/api/v1/hidequickaccess', + 'name' => 'API#getShowQuickAccess', + 'url' => '/api/v1/quickaccess/get/showList', + 'verb' => 'GET', + ], + [ + 'name' => 'API#getShowQuickaccessSettings', + 'url' => '/api/v1/quickaccess/showsettings', + 'verb' => 'GET', + ], + [ + 'name' => 'API#setShowQuickaccessSettings', + 'url' => '/api/v1/quickaccess/set/showsettings', 'verb' => 'GET', ], [ 'name' => 'API#setSortingStrategy', - 'url' => '/api/v1/setsortingstrategy', + 'url' => '/api/v1/quickaccess/set/SortingStrategy', 'verb' => 'GET', ], [ 'name' => 'API#setReverseQuickaccess', - 'url' => '/api/v1/setreversequickaccess', + 'url' => '/api/v1/quickaccess/set/ReverseList', 'verb' => 'GET', ], [ 'name' => 'API#getSortingStrategy', - 'url' => '/api/v1/getsortingstrategy', + 'url' => '/api/v1/quickaccess/get/SortingStrategy', 'verb' => 'GET', ], [ 'name' => 'API#getReverseQuickaccess', - 'url' => '/api/v1/getreversequickaccess', + 'url' => '/api/v1/quickaccess/get/ReverseList', 'verb' => 'GET', - ] + ], + [ + 'name' => 'API#getFavoritesFolder', + 'url' => '/api/v1/quickaccess/get/FavoriteFolders/', + 'verb' => 'GET' + ], + [ + 'name' => 'API#setSortingOrder', + 'url' => '/api/v1/quickaccess/set/CustomSortingOrder', + 'verb' => 'GET', + ], + [ + 'name' => 'API#getSortingOrder', + 'url' => '/api/v1/quickaccess/get/CustomSortingOrder', + 'verb' => 'GET', + ], ] ] ); diff --git a/apps/files/js/navigation.js b/apps/files/js/navigation.js index db39cac987..b83cd82128 100644 --- a/apps/files/js/navigation.js +++ b/apps/files/js/navigation.js @@ -1,10 +1,9 @@ /* - * Copyright (c) 2014 + * @Copyright 2014 Vincent Petry * * @author Vincent Petry - * @copyright 2014 Vincent Petry + * @author Felix Nüsse * - * Edited by: Felix Nüsse 2018 * * This file is licensed under the Affero General Public License version 3 * or later. @@ -13,7 +12,7 @@ * */ -(function() { +(function () { /** * @class OCA.Files.Navigation @@ -21,7 +20,7 @@ * * @param $el element containing the navigation */ - var Navigation = function($el) { + var Navigation = function ($el) { this.initialize($el); }; @@ -42,29 +41,44 @@ /** * Strategy by which the quickaccesslist is sorted + * + * Possible Strategies: + * customorder + * datemodified + * date + * alphabet + * */ - $sortingStrategy: 'alphabet', + $sortingStrategy: 'customorder', + + /** + * Key for the quick-acces-list + */ + $quickAccessListKey: 'sublist-favorites', /** * Initializes the navigation from the given container * * @private * @param $el element containing the navigation */ - initialize: function($el) { + initialize: function ($el) { this.$el = $el; this._activeItem = null; this.$currentContent = null; this._setupEvents(); - this.initialSort(); + this.setInitialQuickaccessSettings(); + + }, /** * Setup UI events */ - _setupEvents: function() { + _setupEvents: function () { this.$el.on('click', 'li a', _.bind(this._onClickItem, this)) this.$el.on('click', 'li button', _.bind(this._onClickMenuButton, this)); - this.$el.on('click', 'li input', _.bind(this._onClickMenuItem, this)); + this._setOnDrag(); + }, /** @@ -72,16 +86,16 @@ * * @return app container */ - getActiveContainer: function() { + getActiveContainer: function () { return this.$currentContent; }, /** * Returns the currently active item - * + * * @return item ID */ - getActiveItem: function() { + getActiveItem: function () { return this._activeItem; }, @@ -92,12 +106,15 @@ * @param string itemId id of the navigation item to select * @param array options "silent" to not trigger event */ - setActiveItem: function(itemId, options) { + setActiveItem: function (itemId, options) { var oldItemId = this._activeItem; if (itemId === this._activeItem) { if (!options || !options.silent) { this.$el.trigger( - new $.Event('itemChanged', {itemId: itemId, previousItemId: oldItemId}) + new $.Event('itemChanged', { + itemId: itemId, + previousItemId: oldItemId + }) ); } return; @@ -114,7 +131,10 @@ if (!options || !options.silent) { this.$currentContent.trigger(jQuery.Event('show')); this.$el.trigger( - new $.Event('itemChanged', {itemId: itemId, previousItemId: oldItemId}) + new $.Event('itemChanged', { + itemId: itemId, + previousItemId: oldItemId + }) ); } }, @@ -122,14 +142,14 @@ /** * Returns whether a given item exists */ - itemExists: function(itemId) { + itemExists: function (itemId) { return this.$el.find('li[data-id=' + itemId + ']').length; }, /** * Event handler for when clicking on an item. */ - _onClickItem: function(ev) { + _onClickItem: function (ev) { var $target = $(ev.target); var itemId = $target.closest('li').attr('data-id'); if (!_.isUndefined(itemId)) { @@ -137,136 +157,148 @@ } ev.preventDefault(); }, + /** - * Event handler for when clicking on an three-dot-menu. + * Event handler for when dragging an item */ - _onClickMenuButton: function(ev) { - var $target = $(ev.target); - var itemId = $target.closest('button').attr('id'); - var qaSelector= '#quickaccess-list'; - - if(itemId==='button-collapseQuickAccess'){ - - document.getElementById('enableQuickAccess').checked=!document.getElementById('enableQuickAccess').checked; - $.get(OC.generateUrl("/apps/files/api/v1/showquickaccess"), {show: document.getElementById('enableQuickAccess').checked}, function(data, status){ - }); - - $("#favorites-toggle" ).toggleClass('open'); - - } - - if(itemId==='button-favorites'){ - document.getElementById('menu-favorites').classList.toggle('open'); - } - ev.preventDefault(); + _setOnDrag: function () { + var scope=this; + $(function () { + if (document.getElementById(scope.$quickAccessListKey.toString()).hasAttribute("draggable")) { + $("#sublist-favorites").sortable({ + update: function (event, ui) { + var list = document.getElementById(scope.$quickAccessListKey.toString()).getElementsByTagName('li'); + var string=[]; + for (var j = 0; j < list.length; j++) { + var Object = {id:j, name:scope.getCompareValue(list,j,'alphabet') }; + string.push(Object); + } + var resultorder=JSON.stringify(string); + console.log(resultorder); + $.get(OC.generateUrl("/apps/files/api/v1/quickaccess/set/CustomSortingOrder"),{ + order: resultorder}, function (data, status) {}); + } + }); + }else{ + if(scope.$sortingStrategy === 'customorder'){ + scope.$sortingStrategy = 'datemodified'; + } + } + }); }, /** - * Event handler for when clicking on a menuitem. + * Event handler for clicking a button */ - _onClickMenuItem: function(ev) { + _onClickMenuButton: function (ev) { + var $target = $(ev.target); + var itemId = $target.closest('button').attr('id'); - var qaSelector= '#quickaccess-list'; - var qaKey= 'quickaccess-list'; + var collapsibleToggles = []; + var dotmenuToggles = []; - var itemId = $(ev.target).closest('input').attr('id'); - var list = document.getElementById(qaKey).getElementsByTagName('li'); + // 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"]); - if(itemId==='enableQuickAccess' ){ - $.get(OC.generateUrl("/apps/files/api/v1/showquickaccess"), {show: document.getElementById('enableQuickAccess').checked}, function(data, status){ - }); - $("#favorites-toggle" ).toggleClass('open'); - document.getElementById('menu-favorites').classList.toggle('open'); - } + // 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"]); - if(itemId==='sortByAlphabet'){ - //Prevents deselecting Group-Item - if(!document.getElementById('sortByAlphabet').checked){ - ev.preventDefault(); - return; + + 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) { + }); } - this.sortingStrategy='alphabet'; - document.getElementById('sortByDate').checked=false; - $.get(OC.generateUrl("/apps/files/api/v1/setsortingstrategy"), {strategy: this.sortingStrategy}, function(data, status){}); - this.QuickSort(list, 0, list.length - 1); - document.getElementById('menu-favorites').classList.toggle('open'); - } + }); - if(itemId==='sortByDate'){ - //Prevents deselecting Group-Item - if(!document.getElementById('sortByDate').checked){ - ev.preventDefault(); - return; + dotmenuToggles.forEach(function foundToggle (item) { + if (item[0] === ("#" + itemId)) { + document.getElementById(item[1]).classList.toggle('open'); } - this.sortingStrategy='date'; - document.getElementById('sortByAlphabet').checked=false; - $.get(OC.generateUrl("/apps/files/api/v1/setsortingstrategy"), {strategy: this.sortingStrategy}, function(data, status){}); - this.QuickSort(list, 0, list.length - 1); - document.getElementById('menu-favorites').classList.toggle('open'); - } + }); - if(itemId==='enableReverse'){ - this.reverse(list); - var state = document.getElementById('enableReverse').checked; - $.get(OC.generateUrl("/apps/files/api/v1/setreversequickaccess"), {reverse: state}, function(data, status){}); - document.getElementById('menu-favorites').classList.toggle('open'); - } - //ev.preventDefault(); + ev.preventDefault(); }, /** * Sort initially as setup of sidebar for QuickAccess */ - initialSort: function() { + setInitialQuickaccessSettings: function () { - var domRevState=document.getElementById('enableReverse').checked; - var domSortAlphabetState=document.getElementById('sortByAlphabet').checked; - var domSortDateState=document.getElementById('sortByDate').checked; + var quickAccesKey = this.$quickAccessListKey; + var list = document.getElementById(quickAccesKey).getElementsByTagName('li'); - var qaKey= 'quickaccess-list'; - var list = document.getElementById(qaKey).getElementsByTagName('li'); + var sort = true; + var reverse = false; + if (this.$sortingStrategy === 'datemodified') { + sort = false; + reverse = false; - if(domSortAlphabetState){ - this.sortingStrategy='alphabet'; - } - if(domSortDateState){ - this.sortingStrategy='date'; + var scope = this; + $.get(OC.generateUrl("/apps/files/api/v1/quickaccess/get/FavoriteFolders/"), function (data, status) { + for (var i = 0; i < data.favoriteFolders.length; i++) { + for (var j = 0; j < list.length; j++) { + if (scope.getCompareValue(list, j, 'alphabet').toLowerCase() === data.favoriteFolders[i].name.toLowerCase()) { + list[j].setAttribute("mtime", data.favoriteFolders[i].mtime); + } + } + } + scope.QuickSort(list, 0, list.length - 1); + scope.reverse(list); + }); + + + } else if (this.$sortingStrategy === 'alphabet') { + sort = true; + } else if (this.$sortingStrategy === 'date') { + sort = true; + } else if (this.$sortingStrategy === 'customorder') { + var scope = this; + $.get(OC.generateUrl("/apps/files/api/v1/quickaccess/get/CustomSortingOrder"), function (data, status) { + console.log("load order:"); + var ordering=JSON.parse(data) + console.log(ordering); + for (var i = 0; i < ordering.length; i++) { + for (var j = 0; j < list.length; j++) { + if (scope.getCompareValue(list, j, 'alphabet').toLowerCase() === ordering[i].name.toLowerCase()) { + list[j].setAttribute("folderPosition", ordering[i].id); + } + } + } + scope.QuickSort(list, 0, list.length - 1); + }); + + sort = false; } - this.QuickSort(list, 0, list.length - 1); - - if(domRevState){ + if (sort) { + this.QuickSort(list, 0, list.length - 1); + } + if (reverse) { this.reverse(list); } - /*This creates flashes the UI, which is bad userexperience. It is the cleaner way to do it, that is why i haven't deleted it yet. - var scope=this; - $.get(OC.generateUrl("/apps/files/api/v1/getsortingstrategy"), function(data, status){ - scope.sortingStrategy=data; - scope.QuickSort(list, 0, list.length - 1); - - }); - - $.get(OC.generateUrl("/apps/files/api/v1/getreversequickaccess"), function(data, status){ - if(data){ - scope.reverse(list); - } - }); - */ }, /** * Sorting-Algorithm for QuickAccess */ - QuickSort: function(list, start, end) { - var lastmatch; - if(list.length > 1){ - lastmatch = this.quicksort_helper(list, start, end); - if(start < lastmatch - 1){ - this.QuickSort(list, start, lastmatch - 1); + QuickSort: function (list, start, end) { + var lastMatch; + if (list.length > 1) { + lastMatch = this.quicksort_helper(list, start, end); + if (start < lastMatch - 1) { + this.QuickSort(list, start, lastMatch - 1); } - if(lastmatch < end){ - this.QuickSort(list, lastmatch, end); + if (lastMatch < end) { + this.QuickSort(list, lastMatch, end); } } }, @@ -274,20 +306,20 @@ /** * Sorting-Algorithm-Helper for QuickAccess */ - quicksort_helper: function(list, start, end) { + quicksort_helper: function (list, start, end) { var pivot = Math.floor((end + start) / 2); - var pivotelem = this.getCompareValue(list,pivot); - var i = start; - var j = end; + var pivotElement = this.getCompareValue(list, pivot); + var i = start; + var j = end; - while(i <= j){ - while(this.getCompareValue(list,i) < pivotelem){ + while (i <= j) { + while (this.getCompareValue(list, i) < pivotElement) { i++; } - while(this.getCompareValue(list,j) > pivotelem){ + while (this.getCompareValue(list, j) > pivotElement) { j--; } - if(i <= j){ + if (i <= j) { this.swap(list, i, j); i++; j--; @@ -300,11 +332,20 @@ * Sorting-Algorithm-Helper for QuickAccess * This method allows easy access to the element which is sorted by. */ - getCompareValue: function(nodes, int){ - if(this.sortingStrategy==='alphabet'){ + getCompareValue: function (nodes, int, strategy) { + + if ((typeof strategy === 'undefined')) { + strategy = this.$sortingStrategy; + } + + if (strategy === 'alphabet') { return nodes[int].getElementsByTagName('a')[0].innerHTML.toLowerCase(); - }else if(this.sortingStrategy==='date'){ + } else if (strategy === 'date') { return nodes[int].getAttribute('folderPos').toLowerCase(); + } else if (strategy === 'datemodified') { + return nodes[int].getAttribute('mtime'); + }else if (strategy === 'customorder') { + return nodes[int].getAttribute('folderPosition'); } return nodes[int].getElementsByTagName('a')[0].innerHTML.toLowerCase(); }, @@ -313,7 +354,7 @@ * Sorting-Algorithm-Helper for QuickAccess * This method allows easy swapping of elements. */ - swap: function(list, j, i){ + swap: function (list, j, i) { list[i].before(list[j]); list[j].before(list[i]); }, @@ -321,10 +362,10 @@ /** * Reverse QuickAccess-List */ - reverse: function(list){ - var len=list.length-1; - for(var i = 0; i < len/2; i++) { - this.swap(list, i, len-i); + reverse: function (list) { + var len = list.length - 1; + for (var i = 0; i < len / 2; i++) { + this.swap(list, i, len - i); } } diff --git a/apps/files/js/tagsplugin.js b/apps/files/js/tagsplugin.js index ce35f8bcdf..7729a540d3 100644 --- a/apps/files/js/tagsplugin.js +++ b/apps/files/js/tagsplugin.js @@ -10,11 +10,11 @@ /* global Handlebars */ -(function(OCA) { +(function (OCA) { _.extend(OC.Files.Client, { - PROPERTY_TAGS: '{' + OC.Files.Client.NS_OWNCLOUD + '}tags', - PROPERTY_FAVORITE: '{' + OC.Files.Client.NS_OWNCLOUD + '}favorite' + PROPERTY_TAGS: '{' + OC.Files.Client.NS_OWNCLOUD + '}tags', + PROPERTY_FAVORITE: '{' + OC.Files.Client.NS_OWNCLOUD + '}favorite' }); var TEMPLATE_FAVORITE_MARK = @@ -30,7 +30,7 @@ * @param {boolean} state true if starred, false otherwise * @return {string} icon class for star image */ - function getStarIconClass(state) { + function getStarIconClass (state) { return state ? 'icon-starred' : 'icon-star'; } @@ -40,7 +40,7 @@ * @param {boolean} state true if starred, false otherwise * @return {Object} jQuery object */ - function renderStar(state) { + function renderStar (state) { if (!this._template) { this._template = Handlebars.compile(TEMPLATE_FAVORITE_MARK); } @@ -57,7 +57,7 @@ * @param {Object} $favoriteMarkEl favorite mark element * @param {boolean} state true if starred, false otherwise */ - function toggleStar($favoriteMarkEl, state) { + function toggleStar ($favoriteMarkEl, state) { $favoriteMarkEl.removeClass('icon-star icon-starred').addClass(getStarIconClass(state)); $favoriteMarkEl.toggleClass('permanent', state); } @@ -65,73 +65,64 @@ /** * Remove Item from Quickaccesslist * - * @param {String} $appfolder folder to be removed + * @param {String} appfolder folder to be removed */ - function removeFavoriteFromList(appfolder) { + function removeFavoriteFromList (appfolder) { - var qaKey= 'quickaccess-list'; - var listUL = document.getElementById(qaKey); - var list = listUL.getElementsByTagName('li'); - var appname=appfolder.substring(appfolder.lastIndexOf("/")+1, appfolder.length); + var quickAccessList = 'sublist-favorites'; + var collapsibleButtonId = 'button-collapse-favorites'; + var listULElements = document.getElementById(quickAccessList); + var listLIElements = listULElements.getElementsByTagName('li'); + var appName = appfolder.substring(appfolder.lastIndexOf("/") + 1, appfolder.length); - for(var i = 0; i <= list.length-1; i++) { - if(appname === list[i].getElementsByTagName('a')[0].innerHTML){ - list[i].remove(); + for (var i = 0; i <= listLIElements.length - 1; i++) { + if (appName === listLIElements[i].getElementsByTagName('a')[0].innerHTML) { + listLIElements[i].remove(); } } - if(listUL.childElementCount==0){ - var dotmenu = document.getElementById("quickaccessbutton"); - dotmenu.style.display='none'; - - var collapsibleButton = document.getElementById("button-collapseQuickAccess"); - collapsibleButton.style.display='none'; - - $("#favorites-toggle" ).removeClass('collapsible'); + if (listULElements.childElementCount === 0) { + var collapsibleButton = document.getElementById(collapsibleButtonId); + collapsibleButton.style.display = 'none'; + $("#favorites-toggle").removeClass('collapsible'); } } /** * Add Item to Quickaccesslist * - * @param {String} $appfolder folder to be added + * @param {String} appfolder folder to be added */ - function addFavoriteToList(appfolder) { - var qaKey= 'quickaccess-list'; - var listUL = document.getElementById(qaKey); - var list = listUL.getElementsByTagName('li'); + function addFavoriteToList (appfolder) { + var quickAccessList = 'sublist-favorites'; + var collapsibleButtonId = 'button-collapse-favorites'; + var listULElements = document.getElementById(quickAccessList); + var listLIElements = listULElements.getElementsByTagName('li'); - var appname=appfolder.substring(appfolder.lastIndexOf("/")+1, appfolder.length); + var appName = appfolder.substring(appfolder.lastIndexOf("/") + 1, appfolder.length); - var a = document.createElement('A'); - a.setAttribute("href","/cloud/index.php/apps/files/?dir="+appfolder); - a.setAttribute("class","nav-icon-files svg"); - a.innerHTML=appname; + var innerTagA = document.createElement('A'); + innerTagA.setAttribute("href", "/cloud/index.php/apps/files/?dir=" + appfolder); + innerTagA.setAttribute("class", "nav-icon-files svg"); + innerTagA.innerHTML = appName; - var len=list.length+1; - var li = document.createElement('li'); - li.setAttribute("data-id", "/cloud/index.php/apps/files/?dir="+appfolder); - li.setAttribute("class", "nav-"+appname); - li.setAttribute("folderpos", len.toString()); - li.appendChild(a); + var length = listLIElements.length + 1; + var innerTagLI = document.createElement('li'); + innerTagLI.setAttribute("data-id", "/cloud/index.php/apps/files/?dir=" + appfolder); + innerTagLI.setAttribute("class", "nav-" + appName); + innerTagLI.setAttribute("folderpos", length.toString()); + innerTagLI.appendChild(innerTagA); - if(listUL.childElementCount<=0){ - listUL.appendChild(li); - var dotmenu = document.getElementById("quickaccessbutton"); - dotmenu.style.display=''; + if (listULElements.childElementCount <= 0) { + listULElements.appendChild(innerTagLI); + var collapsibleButton = document.getElementById(collapsibleButtonId); + collapsibleButton.style.display = ''; - var collapsibleButton = document.getElementById("button-collapseQuickAccess"); - collapsibleButton.style.display=''; - - $("#favorites-toggle" ).addClass('collapsible'); - }else{ - list[list.length-1].after(li); + $("#favorites-toggle").addClass('collapsible'); + } else { + listLIElements[listLIElements.length - 1].after(innerTagLI); } - - //list[list.length-1].after(li); - //document.getElementById('menu-favorites').classList.toggle('open'); - //this.QuickSort(list, 0, list.length - 1); } OCA.Files = OCA.Files || {}; @@ -155,12 +146,12 @@ 'shares.link' ], - _extendFileActions: function(fileActions) { + _extendFileActions: function (fileActions) { var self = this; fileActions.registerAction({ name: 'Favorite', - displayName: function(context) { + displayName: function (context) { var $file = context.$file; var isFavorite = $file.data('favorite') === true; @@ -177,7 +168,7 @@ mime: 'all', order: -100, permissions: OC.PERMISSION_NONE, - iconClass: function(fileName, context) { + iconClass: function (fileName, context) { var $file = context.$file; var isFavorite = $file.data('favorite') === true; @@ -187,7 +178,7 @@ return 'icon-starred'; }, - actionHandler: function(fileName, context) { + actionHandler: function (fileName, context) { var $favoriteMarkEl = context.$file.find('.favorite-mark'); var $file = context.$file; var fileInfo = context.fileList.files[$file.index()]; @@ -219,7 +210,7 @@ tags, $favoriteMarkEl, isFavorite - ).then(function(result) { + ).then(function (result) { context.fileInfoModel.trigger('busy', context.fileInfoModel, false); // response from server should contain updated tags var newTags = result.tags; @@ -235,10 +226,10 @@ }); }, - _extendFileList: function(fileList) { + _extendFileList: function (fileList) { // extend row prototype var oldCreateRow = fileList._createRow; - fileList._createRow = function(fileData) { + fileList._createRow = function (fileData) { var $tr = oldCreateRow.apply(this, arguments); var isFavorite = false; if (fileData.tags) { @@ -253,7 +244,7 @@ return $tr; }; var oldElementToFile = fileList.elementToFile; - fileList.elementToFile = function($el) { + fileList.elementToFile = function ($el) { var fileInfo = oldElementToFile.apply(this, arguments); var tags = $el.attr('data-tags'); if (_.isUndefined(tags)) { @@ -266,22 +257,22 @@ }; var oldGetWebdavProperties = fileList._getWebdavProperties; - fileList._getWebdavProperties = function() { + fileList._getWebdavProperties = function () { var props = oldGetWebdavProperties.apply(this, arguments); props.push(OC.Files.Client.PROPERTY_TAGS); props.push(OC.Files.Client.PROPERTY_FAVORITE); return props; }; - fileList.filesClient.addFileInfoParser(function(response) { + fileList.filesClient.addFileInfoParser(function (response) { var data = {}; var props = response.propStat[0].properties; var tags = props[OC.Files.Client.PROPERTY_TAGS]; var favorite = props[OC.Files.Client.PROPERTY_FAVORITE]; if (tags && tags.length) { - tags = _.chain(tags).filter(function(xmlvalue) { + tags = _.chain(tags).filter(function (xmlvalue) { return (xmlvalue.namespaceURI === OC.Files.Client.NS_OWNCLOUD && xmlvalue.nodeName.split(':')[1] === 'tag'); - }).map(function(xmlvalue) { + }).map(function (xmlvalue) { return xmlvalue.textContent || xmlvalue.text; }).value(); } @@ -296,7 +287,7 @@ }); }, - attach: function(fileList) { + attach: function (fileList) { if (this.allowedLists.indexOf(fileList.id) < 0) { return; } @@ -312,7 +303,7 @@ * @param {Object} $favoriteMarkEl favorite mark element * @param {boolean} isFavorite Was the item favorited before */ - applyFileTags: function(fileName, tagNames, $favoriteMarkEl, isFavorite) { + applyFileTags: function (fileName, tagNames, $favoriteMarkEl, isFavorite) { var encodedPath = OC.encodePath(fileName); while (encodedPath[0] === '/') { encodedPath = encodedPath.substr(1); @@ -325,10 +316,10 @@ }), dataType: 'json', type: 'POST' - }).fail(function(response) { + }).fail(function (response) { var message = ''; // show message if it is available - if(response.responseJSON && response.responseJSON.message) { + if (response.responseJSON && response.responseJSON.message) { message = ': ' + response.responseJSON.message; } OC.Notification.show(t('files', 'An error occurred while trying to update the tags' + message), {type: 'error'}); diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index 53a8e1b55e..9269f336f3 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -11,7 +11,7 @@ * @author Roeland Jago Douma * @author Tobias Kaminsky * @author Vincent Petry - * + * @author Felix Nüsse * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify @@ -55,7 +55,7 @@ use Sabre\VObject\Property\Boolean; class ApiController extends Controller { /** @var TagService */ private $tagService; - /** @var IManager **/ + /** @var IManager * */ private $shareManager; /** @var IPreview */ private $previewManager; @@ -108,7 +108,7 @@ class ApiController extends Controller { * @return DataResponse|FileDisplayResponse */ public function getThumbnail($x, $y, $file) { - if($x < 1 || $y < 1) { + if ($x < 1 || $y < 1) { return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); } @@ -199,6 +199,29 @@ class ApiController extends Controller { return new DataResponse(['files' => $files]); } + /** + * Returns a list of favorites modifed folder. + * + * @NoAdminRequired + * + * @return DataResponse + */ + public function getFavoritesFolder() { + $nodes = $this->userFolder->searchByTag('_$!!$_', $this->userSession->getUser()->getUID()); + + $favorites = []; + $i = 0; + foreach ($nodes as &$node) { + + $favorites[$i]['id'] = $node->getId(); + $favorites[$i]['name'] = $node->getName(); + $favorites[$i]['mtime'] = $node->getMTime(); + $i++; + } + + return new DataResponse(['favoriteFolders' => $favorites]); + } + /** * Return a list of share types for outgoing shares * @@ -262,7 +285,7 @@ class ApiController extends Controller { * @param bool $show */ public function showHiddenFiles($show) { - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int) $show); + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show); return new Response(); } @@ -276,9 +299,21 @@ class ApiController extends Controller { * @return Response */ public function showQuickAccess($show) { - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', (int) $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', 1); + } /** * quickaccess-sorting-strategy @@ -289,7 +324,7 @@ class ApiController extends Controller { * @return Response */ public function setSortingStrategy($strategy) { - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_sorting_strategy', (String) $strategy); + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_sorting_strategy', (String)$strategy); return new Response(); } @@ -313,7 +348,7 @@ class ApiController extends Controller { * @return Response */ public function setReverseQuickaccess($reverse) { - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_reverse_list', (int) $reverse); + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_reverse_list', (int)$reverse); return new Response(); } @@ -325,10 +360,62 @@ class ApiController extends Controller { * @return bool */ public function getReverseQuickaccess() { - if($this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_reverse_list', false)){ + if ($this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_reverse_list', false)) { return true; } return false; } + /** + * Set state for show sorting menu + * + * @NoAdminRequired + * + * @param bool $show + * @return Response + */ + public function setShowQuickaccessSettings($show) { + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_show_settings', (int)$show); + return new Response(); + } + + /** + * Get state for show sorting menu + * + * @NoAdminRequired + * + * @return bool + */ + public function getShowQuickaccessSettings() { + if ($this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_show_settings', false)) { + return true; + } + return false; + } + + /** + * Set sorting-order for custom sorting + * + * @NoAdminRequired + * + * @param String $order + * @return Response + */ + public function setSortingOrder($order) { + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_custom_sorting_order', (String)$order); + return new Response(); + } + + /** + * Get sorting-order for custom sorting + * + * @NoAdminRequired + * + * @param String + * @return String + */ + public function getSortingOrder() { + return $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_custom_sorting_order', ""); + } + } diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 8afec0be90..165cf86a1c 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -8,7 +8,7 @@ * @author Roeland Jago Douma * @author Thomas Müller * @author Vincent Petry - * @author Felix Nüsse Petry + * @author Felix Nüsse * * @license AGPL-3.0 * @@ -162,16 +162,6 @@ class ViewController extends Controller { $user = $this->userSession->getUser()->getUID(); - //Load QuickAccess-Defaults - $sorting = $this->config->getUserValue($user, $this->appName, 'quickaccess_sorting_strategy', 'date'); - $reverseListSetting = $this->config->getUserValue($user, $this->appName, 'quickaccess_reverse_list', 'false'); - if ($this->config->getUserValue($user, $this->appName, 'show_Quick_Access', true)) { - $quickAccessExpandedState = 'true'; - } else { - $quickAccessExpandedState = 'false'; - } - - //Get Favorite-Folder $tagger = \OC::$server->getTagManager(); $helper = new \OCA\Files\Activity\Helper($tagger); @@ -182,71 +172,56 @@ class ViewController extends Controller { $favElements['folders'] = null; } - $favoritesFolderCount = sizeof($favElements['folders']); - $collapseClasses = ''; - if ($favoritesFolderCount > 0) { + if (sizeof($favElements['folders']) > 0) { $collapseClasses = 'collapsible'; } + $favoritesSublistArray = Array(); + + $navBarPositionPosition = 6; + $currentCount = 0; + foreach ($favElements['folders'] as $elem) { + + $id = substr($elem, strrpos($elem, '/') + 1, strlen($elem)); + $link = $this->urlGenerator->linkToRouteAbsolute('files.view.index', ['dir' => $elem]); + $sortingValue = ++$currentCount; + + $element = [ + 'id' => $id, + 'href' => $link, + 'order' => $navBarPositionPosition, + 'folderPosition' => $sortingValue, + 'name' => $id, + 'icon' => 'files', + 'quickaccesselement' => 'true' + ]; + + array_push($favoritesSublistArray, $element); + $navBarPositionPosition++; + } + + + $defaultExpandedState='true'; + if(!$this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', 1)){ + $defaultExpandedState='false'; + } + \OCA\Files\App::getNavigationManager()->add( [ 'id' => 'favorites', 'appname' => 'files', 'script' => 'simplelist.php', 'classes' => $collapseClasses, - 'enableQuickaccess' => $quickAccessExpandedState, - 'quickaccessSortingStrategy' => $sorting, - 'quickaccessSortingReverse' => $reverseListSetting, 'order' => 5, 'name' => $this->l10n->t('Favorites'), - //If there are zero elements, add ul end tag directly. - 'favoritescount' => $favoritesFolderCount + 'sublist' => $favoritesSublistArray, + 'draggableSublist' => 'false', + 'defaultExpandedState' => $defaultExpandedState, + 'enableMenuButton' => 0, ] ); - - //Add Favorite-folder as menuentries, if there are any - if ($favoritesFolderCount > 0) { - - $navBarPositionPosition = 6; - $currentCount = 0; - foreach ($favElements['folders'] as $elem) { - - $id = substr($elem, strrpos($elem, '/') + 1, strlen($elem)); - $link = $this->urlGenerator->linkToRouteAbsolute('files.view.index', ['dir' => $elem]); - - $sortingValue = ++$currentCount; - if ($currentCount != $favoritesFolderCount) { - \OCA\Files\App::getNavigationManager()->add( - [ - 'id' => $id, - 'href' => $link, - 'order' => $navBarPositionPosition, - 'folderPosition' => $sortingValue, - 'name' => $id, - 'icon' => 'files', - 'quickaccesselement' => 'true' - ] - ); - } else { - \OCA\Files\App::getNavigationManager()->add( - [ - 'id' => $id, - 'href' => $link, - 'order' => $navBarPositionPosition, - 'folderPosition' => $sortingValue, - 'name' => $id, - 'icon' => 'files', - 'quickaccesselement' => 'last' - ] - ); - } - $navBarPositionPosition++; - } - } - - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); usort($navItems, function ($item1, $item2) { return $item1['order'] - $item2['order']; diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php index 7bf92995de..56a84edf3b 100644 --- a/apps/files/templates/appnavigation.php +++ b/apps/files/templates/appnavigation.php @@ -1,71 +1,18 @@
      - - + " - class="nav- open" - folderPos="" - id="favorites-toggle"> + $pinned = 0; + foreach ($_['navigationItems'] as $item) { + $pinned = NavigationListElements($item, $pinned, $l); + } + ?> - - - - - -
      style="display: none"> -
        -
      • - -
      • -
      -
      -
      -
        -
      • - - checked/> - - -
      • -
      • - - checked/> - - -
      • -
      • - - checked/> - - -
      • -
      • - - checked/> - - -
      • -
      -
      -
        -
      - - - -
    - - - - - -
  • t('%s used', [$_['usage']])); } ?>

    - 80): ?> class="warn" > + 80): ?> class="warn" >
  • -
    - +
    - - - t('Use this address to access your Files via WebDAV', array(link_to_docs('user-webdav'))));?> + + + t('Use this address to access your Files via WebDAV', array(link_to_docs('user-webdav')))); ?>
    + + + +
  • id="button-collapse-parent-" + data-id=" " + class="nav- open" + folderPos="" > + + + + + + +
      draggable="true"> + +
    + +
  • + + + +
    style="display: none"> +
      +
    • + +
    • +
    +
    +
    +
      + +
    +
    + Date: Wed, 27 Jun 2018 00:26:52 +0200 Subject: [PATCH 09/19] Set Quickaccess-ordering to custom order Signed-off-by: fnuesse --- apps/files/lib/Controller/ViewController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 165cf86a1c..7a07df678b 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -216,7 +216,7 @@ class ViewController extends Controller { 'order' => 5, 'name' => $this->l10n->t('Favorites'), 'sublist' => $favoritesSublistArray, - 'draggableSublist' => 'false', + 'draggableSublist' => 'true', 'defaultExpandedState' => $defaultExpandedState, 'enableMenuButton' => 0, ] From 55ebdc9344dc8edb665491bf89595f406cfc4d62 Mon Sep 17 00:00:00 2001 From: fnuesse Date: Wed, 27 Jun 2018 00:35:28 +0200 Subject: [PATCH 10/19] Fix collapsible-Button when list was emptied (or got first element) Signed-off-by: fnuesse Fixed Bad url-generation in javascript for new quickaccessitems Signed-off-by: fnuesse Fixed vertical scrolling in sortable-list which leads to "hidden" navbar Signed-off-by: fnuesse Removed unnessessary console logs Signed-off-by: fnuesse Fixed Bounds in custom sorting Signed-off-by: fnuesse Reformatted code Signed-off-by: fnuesse Fixed horizontalscroll on sortable-list Fixed "stuck element" where you could not switch back to the original ordering in the sortable-list Signed-off-by: fnuesse --- apps/files/js/navigation.js | 25 +++++++++++++++----- apps/files/js/tagsplugin.js | 10 ++++---- apps/files/lib/Controller/ViewController.php | 6 ++--- apps/files/templates/appnavigation.php | 14 +++++------ 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/apps/files/js/navigation.js b/apps/files/js/navigation.js index b83cd82128..799e265bdf 100644 --- a/apps/files/js/navigation.js +++ b/apps/files/js/navigation.js @@ -163,9 +163,25 @@ */ _setOnDrag: function () { var scope=this; + var element = $("#sublist-favorites"); $(function () { if (document.getElementById(scope.$quickAccessListKey.toString()).hasAttribute("draggable")) { - $("#sublist-favorites").sortable({ + element.sortable({ + axis: "y", + containment: "parent", + scroll: false, + zIndex: 0, + opacity: 0.5, + delay: 150, + tolerance: "pointer", + start:function(event, ui){ + //Fix for offset + ui.helper[0].style.left ='0px'; + }, + stop: function( event, ui ) { + //Clean up offset + ui.item.removeAttr("style"); + }, update: function (event, ui) { var list = document.getElementById(scope.$quickAccessListKey.toString()).getElementsByTagName('li'); var string=[]; @@ -174,7 +190,6 @@ string.push(Object); } var resultorder=JSON.stringify(string); - console.log(resultorder); $.get(OC.generateUrl("/apps/files/api/v1/quickaccess/set/CustomSortingOrder"),{ order: resultorder}, function (data, status) {}); } @@ -262,9 +277,7 @@ } else if (this.$sortingStrategy === 'customorder') { var scope = this; $.get(OC.generateUrl("/apps/files/api/v1/quickaccess/get/CustomSortingOrder"), function (data, status) { - console.log("load order:"); - var ordering=JSON.parse(data) - console.log(ordering); + var ordering=JSON.parse(data); for (var i = 0; i < ordering.length; i++) { for (var j = 0; j < list.length; j++) { if (scope.getCompareValue(list, j, 'alphabet').toLowerCase() === ordering[i].name.toLowerCase()) { @@ -341,7 +354,7 @@ if (strategy === 'alphabet') { return nodes[int].getElementsByTagName('a')[0].innerHTML.toLowerCase(); } else if (strategy === 'date') { - return nodes[int].getAttribute('folderPos').toLowerCase(); + return nodes[int].getAttribute('folderPosition').toLowerCase(); } else if (strategy === 'datemodified') { return nodes[int].getAttribute('mtime'); }else if (strategy === 'customorder') { diff --git a/apps/files/js/tagsplugin.js b/apps/files/js/tagsplugin.js index 7729a540d3..853874f4e8 100644 --- a/apps/files/js/tagsplugin.js +++ b/apps/files/js/tagsplugin.js @@ -82,9 +82,9 @@ } if (listULElements.childElementCount === 0) { - var collapsibleButton = document.getElementById(collapsibleButtonId); + var collapsibleButton = document.getElementById("button-collapse-favorites"); collapsibleButton.style.display = 'none'; - $("#favorites-toggle").removeClass('collapsible'); + $("#button-collapse-parent-favorites").removeClass('collapsible'); } } @@ -102,13 +102,13 @@ var appName = appfolder.substring(appfolder.lastIndexOf("/") + 1, appfolder.length); var innerTagA = document.createElement('A'); - innerTagA.setAttribute("href", "/cloud/index.php/apps/files/?dir=" + appfolder); + innerTagA.setAttribute("href", OC.generateUrl('/apps/files/?dir=') + appfolder); innerTagA.setAttribute("class", "nav-icon-files svg"); innerTagA.innerHTML = appName; var length = listLIElements.length + 1; var innerTagLI = document.createElement('li'); - innerTagLI.setAttribute("data-id", "/cloud/index.php/apps/files/?dir=" + appfolder); + innerTagLI.setAttribute("data-id", OC.generateUrl('/apps/files/?dir=') + appfolder); innerTagLI.setAttribute("class", "nav-" + appName); innerTagLI.setAttribute("folderpos", length.toString()); innerTagLI.appendChild(innerTagA); @@ -119,7 +119,7 @@ var collapsibleButton = document.getElementById(collapsibleButtonId); collapsibleButton.style.display = ''; - $("#favorites-toggle").addClass('collapsible'); + $("#button-collapse-parent-favorites").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 7a07df678b..82f9ea000a 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -202,9 +202,9 @@ class ViewController extends Controller { } - $defaultExpandedState='true'; - if(!$this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', 1)){ - $defaultExpandedState='false'; + $defaultExpandedState = 'true'; + if (!$this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_Quick_Access', 1)) { + $defaultExpandedState = 'false'; } \OCA\Files\App::getNavigationManager()->add( diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php index 56a84edf3b..1302225c91 100644 --- a/apps/files/templates/appnavigation.php +++ b/apps/files/templates/appnavigation.php @@ -5,7 +5,7 @@ $pinned = 0; foreach ($_['navigationItems'] as $item) { - $pinned = NavigationListElements($item, $pinned, $l); + $pinned = NavigationListElements($item, $l, $pinned); } ?> @@ -58,18 +58,18 @@ * Prints the HTML for a single Entry. * * @param $item The item to be added - * @param $pinned IntegerValue to count the pinned entries at the bottom * @param $l Translator + * @param $pinned IntegerValue to count the pinned entries at the bottom * * @return int Returns the pinned value */ -function NavigationListElements($item, $pinned, $l) { +function NavigationListElements($item, $l, $pinned) { strpos($item['classes'], 'pinned') !== false ? $pinned++ : ''; ?>
  • id="button-collapse-parent-" data-id=" " class="nav- open" - folderPos="" > + folderposition="" > @@ -80,11 +80,11 @@ function NavigationListElements($item, $pinned, $l) { if (isset($item['sublist'])) { ?> -