add constante for the app id and the app name

This commit is contained in:
Simon Vieille
2020-09-21 11:28:55 +02:00
parent 78c95c58ff
commit 9a67c165bd
9 changed files with 89 additions and 77 deletions
+19 -18
View File
@@ -26,6 +26,7 @@ use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserSession;
use OCA\SideMenu\AppInfo\Application;
class CssController extends Controller
{
@@ -61,7 +62,7 @@ class CssController extends Controller
*/
public function stylesheet()
{
$response = new TemplateResponse('side_menu', 'css/stylesheet', $this->getConfig(), 'blank');
$response = new TemplateResponse(Application::APP_ID, 'css/stylesheet', $this->getConfig(), 'blank');
$response->addHeader('Content-Type', 'text/css');
return $response;
@@ -69,13 +70,13 @@ class CssController extends Controller
protected function getConfig(): array
{
$backgroundColor = $this->config->getAppValue('side_menu', 'background-color', '#333333');
$backgroundColorTo = $this->config->getAppValue('side_menu', 'background-color-to', $backgroundColor);
$backgroundColor = $this->config->getAppValue(Application::APP_ID, 'background-color', '#333333');
$backgroundColorTo = $this->config->getAppValue(Application::APP_ID, 'background-color-to', $backgroundColor);
$topMenuApps = (array) json_decode($this->config->getAppValue('side_menu', 'top-menu-apps', '[]'), true);
$topMenuApps = (array) json_decode($this->config->getAppValue(Application::APP_ID, 'top-menu-apps', '[]'), true);
if ($this->user) {
$userTopMenuApps = (array) json_decode($this->config->getUserValue($this->user->getUid(), 'side_menu', 'top-menu-apps', '[]'), true);
$userTopMenuApps = (array) json_decode($this->config->getUserValue($this->user->getUid(), Application::APP_ID, 'top-menu-apps', '[]'), true);
if (!empty($userTopMenuApps)) {
$topMenuApps = $userTopMenuApps;
@@ -86,20 +87,20 @@ class CssController extends Controller
'vars' => [
'background-color' => $backgroundColor,
'background-color-to' => $backgroundColorTo,
'current-app-background-color' => $this->config->getAppValue('side_menu', 'current-app-background-color', '#444444'),
'loader-color' => $this->config->getAppValue('side_menu', 'loader-color', '#0e75ac'),
'text-color' => $this->config->getAppValue('side_menu', 'text-color', '#FFFFFF'),
'opener' => $this->config->getAppValue('side_menu', 'opener', 'side-menu-opener'),
'icon-invert-filter' => abs((int) $this->config->getAppValue('side_menu', 'icon-invert-filter', '0')).'%',
'icon-opacity' => abs((int) $this->config->getAppValue('side_menu', 'icon-opacity', '100') / 100),
'current-app-background-color' => $this->config->getAppValue(Application::APP_ID, 'current-app-background-color', '#444444'),
'loader-color' => $this->config->getAppValue(Application::APP_ID, 'loader-color', '#0e75ac'),
'text-color' => $this->config->getAppValue(Application::APP_ID, 'text-color', '#FFFFFF'),
'opener' => $this->config->getAppValue(Application::APP_ID, 'opener', 'side-menu-opener'),
'icon-invert-filter' => abs((int) $this->config->getAppValue(Application::APP_ID, 'icon-invert-filter', '0')).'%',
'icon-opacity' => abs((int) $this->config->getAppValue(Application::APP_ID, 'icon-opacity', '100') / 100),
],
'display-logo' => (bool) $this->config->getAppValue('side_menu', 'display-logo', 1),
'opener-only' => (bool) $this->config->getAppValue('side_menu', 'opener-only', 0),
'external-sites-in-top-menu' => (bool) $this->config->getAppValue('side_menu', 'external-sites-in-top-menu', 0),
'size-icon' => $this->config->getAppValue('side_menu', 'size-icon', 'normal'),
'size-text' => $this->config->getAppValue('side_menu', 'size-text', 'normal'),
'always-displayed' => (bool) $this->config->getAppValue('side_menu', 'always-displayed', '0'),
'big-menu' => (bool) $this->config->getAppValue('side_menu', 'big-menu', '0'),
'display-logo' => (bool) $this->config->getAppValue(Application::APP_ID, 'display-logo', 1),
'opener-only' => (bool) $this->config->getAppValue(Application::APP_ID, 'opener-only', 0),
'external-sites-in-top-menu' => (bool) $this->config->getAppValue(Application::APP_ID, 'external-sites-in-top-menu', 0),
'size-icon' => $this->config->getAppValue(Application::APP_ID, 'size-icon', 'normal'),
'size-text' => $this->config->getAppValue(Application::APP_ID, 'size-text', 'normal'),
'always-displayed' => (bool) $this->config->getAppValue(Application::APP_ID, 'always-displayed', '0'),
'big-menu' => (bool) $this->config->getAppValue(Application::APP_ID, 'big-menu', '0'),
'top-menu-apps' => $topMenuApps,
];
}
+16 -15
View File
@@ -27,6 +27,7 @@ use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserSession;
use OCA\SideMenu\AppInfo\Application;
class JsController extends Controller
{
@@ -68,7 +69,7 @@ class JsController extends Controller
*/
public function script(): TemplateResponse
{
$response = new TemplateResponse('side_menu', 'js/script', $this->getConfig(), 'blank');
$response = new TemplateResponse(Application::APP_ID, 'js/script', $this->getConfig(), 'blank');
$response->addHeader('Content-Type', 'text/javascript');
return $response;
@@ -86,20 +87,20 @@ class JsController extends Controller
protected function getConfig(): array
{
$topMenuApps = (array) json_decode($this->config->getAppValue('side_menu', 'top-menu-apps', '[]'), true);
$targetBlankApps = (array) json_decode($this->config->getAppValue('side_menu', 'target-blank-apps', '[]'), true);
$useAvatar = (bool) $this->config->getAppValue('side_menu', 'use-avatar', '0');
$topMenuApps = (array) json_decode($this->config->getAppValue(Application::APP_ID, 'top-menu-apps', '[]'), true);
$targetBlankApps = (array) json_decode($this->config->getAppValue(Application::APP_ID, 'target-blank-apps', '[]'), true);
$useAvatar = (bool) $this->config->getAppValue(Application::APP_ID, 'use-avatar', '0');
$avatar = null;
if ($this->user) {
$userTopMenuApps = (array) json_decode($this->config->getUserValue($this->user->getUid(), 'side_menu', 'top-menu-apps', '[]'), true);
$userTopMenuApps = (array) json_decode($this->config->getUserValue($this->user->getUid(), Application::APP_ID, 'top-menu-apps', '[]'), true);
if (!empty($userTopMenuApps)) {
$topMenuApps = $userTopMenuApps;
}
$userTargetBlankMode = (int) $this->config->getUserValue($this->user->getUid(), 'side_menu', 'target-blank-mode', '1');
$userTargetBlankApps = (array) json_decode($this->config->getUserValue($this->user->getUid(), 'side_menu', 'target-blank-apps', '[]'), true);
$userTargetBlankMode = (int) $this->config->getUserValue($this->user->getUid(), Application::APP_ID, 'target-blank-mode', '1');
$userTargetBlankApps = (array) json_decode($this->config->getUserValue($this->user->getUid(), Application::APP_ID, 'target-blank-apps', '[]'), true);
if (2 === $userTargetBlankMode) {
$targetBlankApps = $userTargetBlankApps;
@@ -119,14 +120,14 @@ class JsController extends Controller
}
return [
'opener-position' => $this->config->getAppValue('side_menu', 'opener-position', 'before'),
'opener-hover' => (bool) $this->config->getAppValue('side_menu', 'opener-hover', '0'),
'external-sites-in-top-menu' => (bool) $this->config->getAppValue('side_menu', 'external-sites-in-top-menu', 0),
'force-light-icon' => (bool) $this->config->getAppValue('side_menu', 'force-light-icon', '0'),
'hide-when-no-apps' => (bool) $this->config->getAppValue('side_menu', 'hide-when-no-apps', '0'),
'loader-enabled' => (bool) $this->config->getAppValue('side_menu', 'loader-enabled', '1'),
'always-displayed' => (bool) $this->config->getAppValue('side_menu', 'always-displayed', '0'),
'big-menu' => (bool) $this->config->getAppValue('side_menu', 'big-menu', '0'),
'opener-position' => $this->config->getAppValue(Application::APP_ID, 'opener-position', 'before'),
'opener-hover' => (bool) $this->config->getAppValue(Application::APP_ID, 'opener-hover', '0'),
'external-sites-in-top-menu' => (bool) $this->config->getAppValue(Application::APP_ID, 'external-sites-in-top-menu', 0),
'force-light-icon' => (bool) $this->config->getAppValue(Application::APP_ID, 'force-light-icon', '0'),
'hide-when-no-apps' => (bool) $this->config->getAppValue(Application::APP_ID, 'hide-when-no-apps', '0'),
'loader-enabled' => (bool) $this->config->getAppValue(Application::APP_ID, 'loader-enabled', '1'),
'always-displayed' => (bool) $this->config->getAppValue(Application::APP_ID, 'always-displayed', '0'),
'big-menu' => (bool) $this->config->getAppValue(Application::APP_ID, 'big-menu', '0'),
'avatar' => $avatar,
'top-menu-apps' => $topMenuApps,
'target-blank-apps' => $targetBlankApps,
+4 -3
View File
@@ -29,6 +29,7 @@ use OCP\IL10N;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCA\SideMenu\AppInfo\Application;
class NavController extends Controller
{
@@ -98,7 +99,7 @@ class NavController extends Controller
$apps = $this->appRepository->getVisibleApps();
$currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
$categoriesLabels = $this->categoryFetcher->get();
$externalSitesInTopMenu = (bool) $this->config->getAppValue('side_menu', 'external-sites-in-top-menu', 0);
$externalSitesInTopMenu = (bool) $this->config->getAppValue(Application::APP_ID, 'external-sites-in-top-menu', 0);
$user = OC::$server[IUserSession::class]->getUser();
$appsCategories = [];
$categoriesAppsCount = [];
@@ -110,8 +111,8 @@ class NavController extends Controller
]);
}
$topMenuApps = (array) json_decode($this->config->getAppValue('side_menu', 'top-menu-apps', '[]'), true);
$userTopMenuApps = (array) json_decode($this->config->getUserValue($user->getUid(), 'side_menu', 'top-menu-apps', '[]'), true);
$topMenuApps = (array) json_decode($this->config->getAppValue(Application::APP_ID, 'top-menu-apps', '[]'), true);
$userTopMenuApps = (array) json_decode($this->config->getUserValue($user->getUid(), Application::APP_ID, 'top-menu-apps', '[]'), true);
if (!empty($userTopMenuApps)) {
$topMenuApps = $userTopMenuApps;
+2 -1
View File
@@ -23,6 +23,7 @@ use OCP\AppFramework\Http\Response;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserSession;
use OCA\SideMenu\AppInfo\Application;
class PersonalSettingController extends Controller
{
@@ -104,7 +105,7 @@ class PersonalSettingController extends Controller
}
if ($doSave) {
$this->config->setUserValue($user->getUid(), 'side_menu', $name, $value);
$this->config->setUserValue($user->getUid(), Application::APP_ID, $name, $value);
return [
'name' => $name,