From 52d88771d9d3bd31d3da3a2d52ddf2f57048c033 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Fri, 4 Nov 2022 21:07:44 +0100 Subject: [PATCH] add apps sorter is user side (fix #160) --- lib/Controller/JsController.php | 8 +++- lib/Controller/NavController.php | 2 +- lib/Controller/PersonalSettingController.php | 2 +- lib/Service/AppRepository.php | 11 ++++- lib/Settings/Personal.php | 2 + templates/settings/personal-form.php | 48 +++++++++++++++++--- 6 files changed, 63 insertions(+), 10 deletions(-) diff --git a/lib/Controller/JsController.php b/lib/Controller/JsController.php index 32cd630..c0831a9 100644 --- a/lib/Controller/JsController.php +++ b/lib/Controller/JsController.php @@ -100,10 +100,12 @@ class JsController extends Controller $useAvatar = $this->config->getAppValueBool('use-avatar', '0'); $isForced = $this->config->getAppValueBool('force', '0'); $addLogoLink = $this->config->getAppValueBool('add-logo-link', '1'); + $appsOrder = $this->config->getAppValueArray('apps-order', '[]'); $avatar = null; $settings = null; if ($this->user) { + $userAppsOrder = $this->config->getUserValueArray($this->user, 'apps-order', '[]'); $userTopMenuApps = $this->config->getUserValueArray($this->user, 'top-menu-apps', '[]'); $userTopSideMenuApps = $this->config->getUserValueArray($this->user, 'top-side-menu-apps', '[]'); @@ -115,6 +117,10 @@ class JsController extends Controller $topSideMenuApps = $userTopSideMenuApps; } + if (!empty($userAppsOrder) && !$isForced) { + $appsOrder = $userAppsOrder; + } + $userTargetBlankMode = $this->config->getUserValueInt($this->user, 'target-blank-mode', '1'); $userTargetBlankApps = $this->config->getUserValueArray($this->user, 'target-blank-apps', '[]'); @@ -162,7 +168,7 @@ class JsController extends Controller 'side-with-categories' => $this->config->getAppValueBool('side-with-categories', '0'), 'big-menu' => $this->config->getAppValueBool('big-menu', '0'), 'big-menu-hidden-apps' => $this->config->getAppValueArray('big-menu-hidden-apps', '[]'), - 'apps-order' => $this->config->getAppValueArray('apps-order', '[]'), + 'apps-order' => $appsOrder, 'avatar' => $avatar, 'top-menu-apps' => $topMenuApps, 'top-side-menu-apps' => $topSideMenuApps, diff --git a/lib/Controller/NavController.php b/lib/Controller/NavController.php index ac766a5..6ea8e46 100644 --- a/lib/Controller/NavController.php +++ b/lib/Controller/NavController.php @@ -93,7 +93,7 @@ class NavController extends Controller ]); } - $apps = $this->appRepository->getOrderedApps(); + $apps = $this->appRepository->getOrderedApps($user); $categoriesLabels = $this->categoryRepository->getOrderedCategories(); $hiddenApps = $this->config->getAppValueArray('big-menu-hidden-apps', '[]'); $isForced = $this->config->getAppValueBool('force', '0'); diff --git a/lib/Controller/PersonalSettingController.php b/lib/Controller/PersonalSettingController.php index bdc9fca..6f126c7 100644 --- a/lib/Controller/PersonalSettingController.php +++ b/lib/Controller/PersonalSettingController.php @@ -97,7 +97,7 @@ class PersonalSettingController extends Controller } } - if (in_array($name, ['top-menu-apps', 'top-side-menu-apps'])) { + if (in_array($name, ['top-menu-apps', 'top-side-menu-apps', 'apps-order'])) { $doSave = true; $data = json_decode($value, true); diff --git a/lib/Service/AppRepository.php b/lib/Service/AppRepository.php index 2ae59d5..ce96107 100644 --- a/lib/Service/AppRepository.php +++ b/lib/Service/AppRepository.php @@ -2,6 +2,7 @@ namespace OCA\SideMenu\Service; +use OC\User\User; use OCP\L10N\IFactory; /** @@ -110,11 +111,19 @@ class AppRepository ); } - public function getOrderedApps() + public function getOrderedApps(?User $user = null) { $apps = $this->getVisibleApps(); $orders = $this->config->getAppValueArray('apps-order', '[]'); + if (null !== $user && !$this->config->getAppValueBool('force', '0')) { + $userOrders = $this->config->getUserValueArray($user, 'apps-order', '[]'); + + if (!empty($userOrders)) { + $orders = $userOrders; + } + } + usort($apps, function ($a, $b) use ($orders) { $ak = array_keys($orders, $a['id'])[0] ?? null; $bk = array_keys($orders, $b['id'])[0] ?? null; diff --git a/lib/Settings/Personal.php b/lib/Settings/Personal.php index 9ac24c7..e61f9e5 100644 --- a/lib/Settings/Personal.php +++ b/lib/Settings/Personal.php @@ -81,7 +81,9 @@ class Personal implements ISettings 'top-side-menu-apps' => $this->config->getUserValueArray($user, 'top-side-menu-apps', '[]'), 'target-blank-mode' => $this->config->getUserValue($user, 'target-blank-mode', '1'), 'target-blank-apps' => $this->config->getUserValueArray($user, 'target-blank-apps', '[]'), + 'apps-order' => $this->config->getUserValueArray($user, 'apps-order', '[]'), 'apps' => $this->appRepository->getVisibleApps(), + 'ordered-apps' => $this->appRepository->getOrderedApps($user), ]; return new TemplateResponse(Application::APP_ID, 'settings/personal-form', $parameters, ''); diff --git a/templates/settings/personal-form.php b/templates/settings/personal-form.php index 7794f23..e49f8a7 100644 --- a/templates/settings/personal-form.php +++ b/templates/settings/personal-form.php @@ -27,6 +27,7 @@ $choicesYesNo = [ $labelShowHideApps = 'Show and hide the list of applications'; +$labelReset = 'Reset to default'; ?>
@@ -41,10 +42,6 @@ $labelShowHideApps = 'Show and hide the list of applications';
-

- t('Menu')); ?> -

-

t('Use the shortcut Ctrl+o to open and to hide the side menu. Use tab to navigate.'); ?>

@@ -123,7 +120,7 @@ $labelShowHideApps = 'Show and hide the list of applications';
- t('Apps only visible in the top menu')); ?> + t('Applications kept in the top menu')); ?>

t('If there is no selection then the global configuration is applied.')); ?> @@ -163,9 +160,10 @@ $labelShowHideApps = 'Show and hide the list of applications';

- t('Apps visible in the top and side menus')); ?> + t('Applications kept in the top menu but also shown in side menu')); ?>

+ t('These applications must be selected in the previous option.')); ?>
t('If there is no selection then the global configuration is applied.')); ?>

@@ -200,6 +198,44 @@ $labelShowHideApps = 'Show and hide the list of applications';
+
+

+ t('Applications')); ?> +

+ +
+
+
+ t('Customize sorting')); ?> +
+
+ + 🖱️ t($labelShowHideApps)); ?> + + +
+ + + + ' name="apps-order" class="side-menu-setting" id="side-menu-apps-order" data-personal> +
+
+
+