Upgraded navigation submenu management and api + created sharing submenu

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-07-13 09:33:57 +02:00
parent 1f9e50086c
commit 6f45607f57
No known key found for this signature in database
GPG key ID: 60C25B8C072916CF
9 changed files with 135 additions and 137 deletions

View file

@ -39,24 +39,29 @@ $templateManager->registerTemplate('application/vnd.oasis.opendocument.presentat
$templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'core/templates/filetemplates/template.odt');
$templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');
\OCA\Files\App::getNavigationManager()->add(function () use ($l) {
return [
'id' => 'files',
'appname' => 'files',
'script' => 'list.php',
'order' => 0,
'name' => $l->t('All files'),
];
});
\OCA\Files\App::getNavigationManager()->add([
'id' => 'files',
'appname' => 'files',
'script' => 'list.php',
'order' => 0,
'name' => $l->t('All files'),
]);
\OCA\Files\App::getNavigationManager()->add(function () use ($l) {
return [
'id' => 'recent',
'appname' => 'files',
'script' => 'recentlist.php',
'order' => 2,
'name' => $l->t('Recent'),
];
});
\OCA\Files\App::getNavigationManager()->add([
'id' => 'recent',
'appname' => 'files',
'script' => 'recentlist.php',
'order' => 2,
'name' => $l->t('Recent'),
]);
\OCA\Files\App::getNavigationManager()->add([
'id' => 'favorites',
'appname' => 'files',
'script' => 'simplelist.php',
'order' => 5,
'name' => $l->t('Favorites'),
'expandedState' => 'show_Quick_Access'
]);
\OCP\Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig');

View file

@ -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',

View file

@ -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 {

View file

@ -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)) {

View file

@ -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;
}
/**

View file

@ -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' => []]);

View file

@ -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>

View file

@ -50,56 +50,54 @@ $eventDispatcher->addListener(
$config = \OC::$server->getConfig();
$shareManager = \OC::$server->getShareManager();
$userSession = \OC::$server->getUserSession();
$l = \OC::$server->getL10N('files_sharing');
if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') {
\OCA\Files\App::getNavigationManager()->add(function () {
$l = \OC::$server->getL10N('files_sharing');
return [
'id' => 'sharingin',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 15,
'name' => $l->t('Shared with you'),
];
});
$sharingSublistArray = [];
array_push($sharingSublistArray, [
'id' => 'sharingin',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 15,
'name' => $l->t('Shared with you'),
]);
if (\OCP\Util::isSharingDisabledForUser() === false) {
\OCA\Files\App::getNavigationManager()->add(function () {
$l = \OC::$server->getL10N('files_sharing');
return [
'id' => 'sharingout',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 16,
'name' => $l->t('Shared with others'),
];
});
array_push($sharingSublistArray, [
'id' => 'sharingout',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 16,
'name' => $l->t('Shared with others'),
]);
// Check if sharing by link is enabled
if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') {
\OCA\Files\App::getNavigationManager()->add(function () {
$l = \OC::$server->getL10N('files_sharing');
return [
'id' => 'sharinglinks',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 17,
'name' => $l->t('Shared by link'),
];
});
array_push($sharingSublistArray, [
'id' => 'sharinglinks',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 17,
'name' => $l->t('Shared by link'),
]);
}
}
\OCA\Files\App::getNavigationManager()->add(function () {
$l = \OC::$server->getL10N('files_sharing');
return [
'id' => 'shareoverview',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 18,
'name' => $l->t('Share overview'),
];
});
// show_Quick_Access stored as string
$defaultExpandedState = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_sharing_menu', '0') === '1';
\OCA\Files\App::getNavigationManager()->add([
'id' => 'shareoverview',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 18,
'name' => $l->t('Share overview'),
'classes' => 'collapsible',
'sublist' => $sharingSublistArray,
'expandedState' => 'show_sharing_menu'
]);
\OCA\Files\App::getNavigationManager()->add(function () {

View file

@ -100,7 +100,7 @@ class NavigationManager implements INavigationManager {
if(!isset($entry['type'])) {
$entry['type'] = 'link';
}
$this->entries[] = $entry;
$this->entries[$entry['id']] = $entry;
}
/**
@ -133,7 +133,7 @@ class NavigationManager implements INavigationManager {
* @return array
*/
private function proceedNavigation(array $list): array {
usort($list, function($a, $b) {
uasort($list, function($a, $b) {
if (isset($a['order']) && isset($b['order'])) {
return ($a['order'] < $b['order']) ? -1 : 1;
} else if (isset($a['order']) || isset($b['order'])) {