aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-07-13 09:33:57 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-07-13 09:33:57 +0200
commit6f45607f57c55550808824ffdeebbf10353a2554 (patch)
tree632299fe9ad96d6ef54001121a9bfaa61de1bc20 /apps/files
parent1f9e50086cc404d6dd46c5ae664f951faaf74c98 (diff)
downloadnextcloud-server-6f45607f57c55550808824ffdeebbf10353a2554.tar.gz
nextcloud-server-6f45607f57c55550808824ffdeebbf10353a2554.zip
Upgraded navigation submenu management and api + created sharing submenu
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/appinfo/app.php43
-rw-r--r--apps/files/appinfo/routes.php11
-rw-r--r--apps/files/css/files.scss3
-rw-r--r--apps/files/js/navigation.js26
-rw-r--r--apps/files/lib/Controller/ApiController.php33
-rw-r--r--apps/files/lib/Controller/ViewController.php55
-rw-r--r--apps/files/templates/appnavigation.php21
7 files changed, 96 insertions, 96 deletions
diff --git a/apps/files/appinfo/app.php b/apps/files/appinfo/app.php
index fbe33fb54fe..a7ce4e18306 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(function () use ($l) {
- return [
- 'id' => 'recent',
- 'appname' => 'files',
- 'script' => 'recentlist.php',
- 'order' => 2,
- 'name' => $l->t('Recent'),
- ];
-});
+\OCA\Files\App::getNavigationManager()->add([
+ 'id' => 'files',
+ 'appname' => 'files',
+ 'script' => 'list.php',
+ 'order' => 0,
+ 'name' => $l->t('All files'),
+]);
+
+\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 a9d8ba0a1b9..44663d185d1 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 24ecbf399e3..79dc2a26ebd 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 d4fa06cb45e..8ce976a6f53 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 aae1bec2e78..fd63d545151 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 f240e04c721..063d16c62d7 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 0b9ac665901..04bcc577001 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++ : '';
?>
- <li <?php if (isset($item['sublist'])){ ?>id="button-collapse-parent-<?php p($item['id']); ?>"<?php } ?>
- data-id="<?php p($item['id']) ?>" data-dir="<?php p($item['dir']) ?>" data-view="<?php p($item['view']) ?>"
- class="nav-<?php p($item['id']) ?> <?php p($item['classes']) ?> <?php p($pinned === 1 ? 'first-pinned' : '') ?> <?php if ($item['defaultExpandedState']) { ?> open<?php } ?>"
+ <li
+ data-id="<?php p($item['id']) ?>"
+ <?php if (isset($item['dir'])) { ?> data-dir="<?php p($item['dir']); ?>" <?php } ?>
+ <?php if (isset($item['view'])) { ?> data-view="<?php p($item['view']); ?>" <?php } ?>
+ <?php if (isset($item['expandedState'])) { ?> data-expandedstate="<?php p($item['expandedState']); ?>" <?php } ?>
+ class="nav-<?php p($item['id']) ?>
+ <?php if (isset($item['classes'])) { p($item['classes']); } ?>
+ <?php p($pinned === 1 ? 'first-pinned' : '') ?>
+ <?php if (isset($item['defaultExpandedState']) && $item['defaultExpandedState']) { ?> open<?php } ?>"
<?php if (isset($item['folderPosition'])) { ?> folderposition="<?php p($item['folderPosition']); ?>" <?php } ?>>
<a href="<?php p(isset($item['href']) ? $item['href'] : '#') ?>"
- class="nav-icon-<?php p($item['icon'] !== '' ? $item['icon'] : $item['id']) ?> svg"><?php p($item['name']); ?></a>
+ class="nav-icon-<?php p(isset($item['icon']) && $item['icon'] !== '' ? $item['icon'] : $item['id']) ?> svg"><?php p($item['name']); ?></a>
<?php
NavigationElementMenu($item);
if (isset($item['sublist'])) {
?>
- <button id="button-collapse-<?php p($item['id']); ?>"
- class="collapse app-navigation-noclose" <?php if (sizeof($item['sublist']) == 0) { ?> style="display: none" <?php } ?>></button>
+ <button class="collapse app-navigation-noclose" <?php if (sizeof($item['sublist']) == 0) { ?> style="display: none" <?php } ?>></button>
<ul id="sublist-<?php p($item['id']); ?>">
<?php
foreach ($item['sublist'] as $item) {
@@ -104,10 +109,10 @@ function NavigationListElements($item, $l, $pinned) {
* @return void
*/
function NavigationElementMenu($item) {
- if ($item['menubuttons'] === 'true') {
+ if (isset($item['menubuttons']) && $item['menubuttons'] === 'true') {
?>
<div id="dotmenu-<?php p($item['id']); ?>"
- class="app-navigation-entry-utils" <?php if ($item['enableMenuButton'] === 0) { ?> style="display: none"<?php } ?>>
+ class="app-navigation-entry-utils" <?php if (isset($item['enableMenuButton']) && $item['enableMenuButton'] === 0) { ?> style="display: none"<?php } ?>>
<ul>
<li class="app-navigation-entry-utils-menu-button svg">
<button id="dotmenu-button-<?php p($item['id']) ?>"></button>