Skip to content

Commit 9014a25

Browse files
committed
Allow to pick custom colour
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent 537ec24 commit 9014a25

File tree

12 files changed

+133
-23
lines changed

12 files changed

+133
-23
lines changed

apps/theming/css/default.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
--background-invert-if-bright: invert(100%);
5656
--image-main-background: url('/core/img/app-background.jpg');
5757
--color-primary: #00639a;
58+
--color-primary-default: #0082c9;
5859
--color-primary-text: #ffffff;
5960
--color-primary-hover: #3282ae;
6061
--color-primary-light: #e5eff4;

apps/theming/css/settings-admin.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/theming/css/settings-admin.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
margin-top: 10px;
101101
margin-bottom: 20px;
102102
cursor: pointer;
103-
background-color: var(--color-main-background-not-plain, var(--color-primary));
103+
background-color: var(--color-primary-default);
104104
background-image: var(--image-background, var(--image-background-plain, url('../../../core/img/app-background.jpg'), linear-gradient(40deg, #0082c9 0%, #30b6ff 100%)));
105105

106106
#theming-preview-logo {

apps/theming/lib/ThemingDefaults.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -219,25 +219,30 @@ public function getShortFooter() {
219219
*/
220220
public function getColorPrimary() {
221221
$user = $this->userSession->getUser();
222-
$defaultColor = $this->getDefaultColorPrimary();
223-
$themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background');
224222

225-
// if the user is defined and the selected background is not a colour
226-
if ($user !== null
227-
&& !preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackground)) {
223+
// admin-defined primary color
224+
$defaultColor = $this->getDefaultColorPrimary();
225+
226+
// user-defined primary color
227+
$themingBackground = '';
228+
if (!empty($user)) {
228229
$themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default');
229-
if ($themingBackground === 'default') {
230-
$this->increaseCacheBuster();
231-
return BackgroundService::DEFAULT_COLOR;
232-
} else if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'])) {
233-
$this->increaseCacheBuster();
234-
return BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'];
230+
231+
// if the user-selected background is a background reference
232+
if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackground)) {
233+
if ($themingBackground === 'default') {
234+
$this->increaseCacheBuster();
235+
return BackgroundService::DEFAULT_COLOR;
236+
} else if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'])) {
237+
$this->increaseCacheBuster();
238+
return BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'];
239+
}
235240
}
236-
}
237241

238-
// If the user selected a specific colour
239-
if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackground)) {
240-
return $themingBackground;
242+
// If the user selected a specific colour
243+
if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackground)) {
244+
return $themingBackground;
245+
}
241246
}
242247

243248
// If the default color is not valid, return the default background one
@@ -255,7 +260,7 @@ public function getColorPrimary() {
255260
* @return string
256261
*/
257262
public function getDefaultColorPrimary() {
258-
$color = $this->config->getAppValue(Application::APP_ID, 'color', $this->color);
263+
$color = $this->config->getAppValue(Application::APP_ID, 'color');
259264
if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) {
260265
$color = '#0082c9';
261266
}

apps/theming/src/components/BackgroundSettings.vue

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@
3232
@click="pickFile">
3333
{{ t('theming', 'Pick from Files') }}
3434
</button>
35+
<NcColorPicker v-model="Theming.color" @input="pickColor">
36+
<button class="background color"
37+
:class="{ active: background === Theming.color}"
38+
tabindex="0"
39+
:data-color="Theming.color"
40+
:data-color-bright="invertTextColor(Theming.color)"
41+
:style="{ backgroundColor: Theming.color, color: invertTextColor(Theming.color) ? '#000000' : '#ffffff'}"
42+
@click="pickColor">
43+
{{ t('theming', 'Custom color') }}
44+
</button>
45+
</NcColorPicker>
3546

3647
<!-- Default background -->
3748
<button class="background default"
@@ -43,7 +54,7 @@
4354

4455
<!-- Default admin primary color -->
4556
<button class="background color"
46-
:class="{ active: background.startsWith('#') }"
57+
:class="{ active: background === Theming.defaultColor }"
4758
tabindex="0"
4859
:data-color="Theming.defaultColor"
4960
:data-color-bright="invertTextColor(Theming.defaultColor)"
@@ -68,6 +79,7 @@
6879
<script>
6980
import axios from '@nextcloud/axios'
7081
import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip'
82+
import NcColorPicker from '@nextcloud/vue/dist/Components/NcColorPicker'
7183
import { generateUrl } from '@nextcloud/router'
7284
import { loadState } from '@nextcloud/initial-state'
7385
import { getBackgroundUrl } from '../helpers/getBackgroundUrl.js'
@@ -81,6 +93,10 @@ export default {
8193
Tooltip,
8294
},
8395
96+
components: {
97+
NcColorPicker,
98+
},
99+
84100
props: {
85101
background: {
86102
type: String,

apps/theming/tests/Service/ThemesServiceTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ protected function setUp(): void {
6868
->method('getColorPrimary')
6969
->willReturn('#0082c9');
7070

71+
$this->themingDefaults->expects($this->any())
72+
->method('getDefaultColorPrimary')
73+
->willReturn('#0082c9');
74+
7175
$this->initThemes();
7276

7377
$this->themesService = new ThemesService(

apps/theming/tests/Settings/AdminTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function testGetFormNoErrors() {
9797
->willReturn('MySlogan');
9898
$this->themingDefaults
9999
->expects($this->once())
100-
->method('getColorPrimary')
100+
->method('getDefaultColorPrimary')
101101
->willReturn('#fff');
102102
$this->urlGenerator
103103
->expects($this->once())
@@ -156,7 +156,7 @@ public function testGetFormWithErrors() {
156156
->willReturn('MySlogan');
157157
$this->themingDefaults
158158
->expects($this->once())
159-
->method('getColorPrimary')
159+
->method('getDefaultColorPrimary')
160160
->willReturn('#fff');
161161
$this->urlGenerator
162162
->expects($this->once())

apps/theming/tests/Settings/PersonalTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ private function initThemes() {
138138
$themingDefaults->expects($this->any())
139139
->method('getColorPrimary')
140140
->willReturn('#0082c9');
141+
142+
$themingDefaults->expects($this->any())
143+
->method('getDefaultColorPrimary')
144+
->willReturn('#0082c9');
141145

142146
$this->themes = [
143147
'default' => new DefaultTheme(

apps/theming/tests/Themes/DefaultThemeTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ protected function setUp(): void {
7070
->method('getColorPrimary')
7171
->willReturn('#0082c9');
7272

73+
$this->themingDefaults
74+
->expects($this->any())
75+
->method('getDefaultColorPrimary')
76+
->willReturn('#0082c9');
77+
7378
$this->l10n
7479
->expects($this->any())
7580
->method('t')

apps/theming/tests/Themes/DyslexiaFontTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ protected function setUp(): void {
8484
->method('getColorPrimary')
8585
->willReturn('#0082c9');
8686

87+
$this->themingDefaults
88+
->expects($this->any())
89+
->method('getDefaultColorPrimary')
90+
->willReturn('#0082c9');
91+
8792
$this->l10n
8893
->expects($this->any())
8994
->method('t')

0 commit comments

Comments
 (0)