From db831359d3ad10d35536bd5f0e72ba629b828471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Wed, 5 Oct 2022 12:14:03 +0200 Subject: [PATCH] Allow to pick custom colour MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/theming/css/default.css | 1 + apps/theming/css/settings-admin.css | 2 +- apps/theming/css/settings-admin.scss | 2 +- apps/theming/lib/ThemingDefaults.php | 33 +++++---- .../src/components/BackgroundSettings.vue | 18 ++++- .../tests/Service/ThemesServiceTest.php | 4 ++ apps/theming/tests/Settings/AdminTest.php | 4 +- apps/theming/tests/Settings/PersonalTest.php | 4 ++ .../theming/tests/Themes/DefaultThemeTest.php | 5 ++ .../theming/tests/Themes/DyslexiaFontTest.php | 5 ++ apps/theming/tests/ThemingDefaultsTest.php | 72 ++++++++++++++++++- tests/acceptance/features/app-theming.feature | 4 +- .../features/bootstrap/ThemingAppContext.php | 2 +- 13 files changed, 133 insertions(+), 23 deletions(-) diff --git a/apps/theming/css/default.css b/apps/theming/css/default.css index da4814d66ef..1f0a241307b 100644 --- a/apps/theming/css/default.css +++ b/apps/theming/css/default.css @@ -57,6 +57,7 @@ --background-invert-if-bright: invert(100%); --image-main-background: url('/core/img/app-background.jpg'); --color-primary: #00639a; + --color-primary-default: #0082c9; --color-primary-text: #ffffff; --color-primary-hover: #3282ae; --color-primary-light: #e5eff4; diff --git a/apps/theming/css/settings-admin.css b/apps/theming/css/settings-admin.css index 2b91404ec3b..00d4e2414fa 100644 --- a/apps/theming/css/settings-admin.css +++ b/apps/theming/css/settings-admin.css @@ -89,7 +89,7 @@ margin-top: 10px; margin-bottom: 20px; cursor: pointer; - background-color: var(--color-main-background-not-plain, var(--color-primary)); + background-color: var(--color-primary-default); background-image: var(--image-background, var(--image-background-plain, url("../../../core/img/app-background.jpg"), linear-gradient(40deg, #0082c9 0%, #30b6ff 100%))); } #theming #theming-preview #theming-preview-logo { diff --git a/apps/theming/css/settings-admin.scss b/apps/theming/css/settings-admin.scss index 706bd37f495..f43d3b8c417 100644 --- a/apps/theming/css/settings-admin.scss +++ b/apps/theming/css/settings-admin.scss @@ -100,7 +100,7 @@ margin-top: 10px; margin-bottom: 20px; cursor: pointer; - background-color: var(--color-main-background-not-plain, var(--color-primary)); + background-color: var(--color-primary-default); background-image: var(--image-background, var(--image-background-plain, url('../../../core/img/app-background.jpg'), linear-gradient(40deg, #0082c9 0%, #30b6ff 100%))); #theming-preview-logo { diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index cc23053a9c3..b1fb90e00e0 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -219,23 +219,28 @@ class ThemingDefaults extends \OC_Defaults { */ public function getColorPrimary() { $user = $this->userSession->getUser(); - $defaultColor = $this->getDefaultColorPrimary(); - $themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background'); - // if the user is defined and the selected background is not a colour - if ($user !== null - && !preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackground)) { + // admin-defined primary color + $defaultColor = $this->getDefaultColorPrimary(); + + // user-defined primary color + $themingBackground = ''; + if (!empty($user)) { $themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default'); - if ($themingBackground === 'default') { - return BackgroundService::DEFAULT_COLOR; - } else if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'])) { - return BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color']; + + // if the user-selected background is a background reference + if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackground)) { + if ($themingBackground === 'default') { + return BackgroundService::DEFAULT_COLOR; + } else if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'])) { + return BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color']; + } } - } - // If the user selected a specific colour - if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackground)) { - return $themingBackground; + // If the user selected a specific colour + if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackground)) { + return $themingBackground; + } } // If the default color is not valid, return the default background one @@ -253,7 +258,7 @@ class ThemingDefaults extends \OC_Defaults { * @return string */ public function getDefaultColorPrimary() { - $color = $this->config->getAppValue(Application::APP_ID, 'color', $this->color); + $color = $this->config->getAppValue(Application::APP_ID, 'color'); if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) { $color = '#0082c9'; } diff --git a/apps/theming/src/components/BackgroundSettings.vue b/apps/theming/src/components/BackgroundSettings.vue index aa65a333f0f..3767cebf815 100644 --- a/apps/theming/src/components/BackgroundSettings.vue +++ b/apps/theming/src/components/BackgroundSettings.vue @@ -32,6 +32,17 @@ @click="pickFile"> {{ t('theming', 'Pick from Files') }} + + +