From 1cd32001d474bed977d56ff0fdbcfbc090191974 Mon Sep 17 00:00:00 2001 From: Lauri Ojansivu Date: Fri, 17 Jul 2026 23:12:55 +0300 Subject: [PATCH] Select Color: global override applies everywhere + visible grouped swatches (#5778). Two fixes from feedback that picking clearblue "did not change" and the dropdowns were hard to use: 1) The global theme override now wins EVERYWHERE, including board pages. Before, the autorun suppressed it whenever a board was open (onBoard gate), so changing the color while viewing a board did nothing. Now a set global override is applied regardless of board context, and #header / #header-quick-access (header.jade) and .board-wrapper (boardBody.jade) prefer the global override over the per-board color. Unset it to return to per-board colors. When no global is set, an open board still exposes its own custom colors. 2) The picker no longer uses category/theme dropdowns (colors were invisible). It now shows the actual color SWATCHES with their names, grouped by category, with the category name as a header above each group. The flat/clear color wheels still appear once such a color is selected; custom-capability is derived from the selected color. customTheme.css styles the group labels. Tests updated: themeColorPicker/globalThemeColor guards for grouped swatches and the global-wins-everywhere behaviour. --- client/components/boards/boardBody.jade | 2 +- client/components/main/customTheme.css | 11 ++++ client/components/main/globalThemeColor.js | 28 +++++----- client/components/main/header.jade | 4 +- client/components/main/themeColorPicker.jade | 33 ++++++------ client/components/main/themeColorPicker.js | 55 +++++++++----------- tests/globalThemeColor.test.cjs | 24 +++++---- tests/themeColorPicker.test.cjs | 17 +++--- 8 files changed, 97 insertions(+), 77 deletions(-) diff --git a/client/components/boards/boardBody.jade b/client/components/boards/boardBody.jade index df796d0d7b..356f1c9ff0 100644 --- a/client/components/boards/boardBody.jade +++ b/client/components/boards/boardBody.jade @@ -23,7 +23,7 @@ template(name="boardBody") if debugBoardState .debug-info(style="position: fixed; top: 0; inset-inline-start: 0; background: rgba(0,0,0,0.8); color: white; padding: 10px; z-index: 9999; font-size: 12px;") | {{_ 'board'}}: {{currentBoard.title}} | {{_ 'view'}}: {{boardView}} | {{_ 'has-swimlanes'}}: {{hasSwimlanes}} | {{_ 'swimlanes'}}: {{currentBoard.swimlanes.length}} - .board-wrapper(class=currentBoard.colorClass class="{{#if isMiniScreen}}mobile-view{{/if}}") + .board-wrapper(class="{{#if currentUser.globalThemeColorClass}}{{currentUser.globalThemeColorClass}}{{else}}{{currentBoard.colorClass}}{{/if}}" class="{{#if isMiniScreen}}mobile-view{{/if}}") .board-canvas.js-swimlanes.dragscroll( class="{{#if Sidebar.isOpen}}is-sibling-sidebar-open{{/if}}" class="{{#if MultiSelection.isActive}}is-multiselection-active{{/if}}" diff --git a/client/components/main/customTheme.css b/client/components/main/customTheme.css index da2582b594..e4e92cd67b 100644 --- a/client/components/main/customTheme.css +++ b/client/components/main/customTheme.css @@ -22,3 +22,14 @@ .has-custom-theme-slide #header-quick-access { background: linear-gradient(135deg, var(--theme-accent), var(--theme-accent-2)) !important; } + +/* Select Color picker: category groups with a visible name above each group of + * colour swatches (docs/Theme/Theme.md). */ +.theme-color-picker .theme-category-group { + margin-bottom: 8px; +} +.theme-color-picker .theme-category-label { + font-weight: bold; + margin: 6px 0 2px; + text-transform: capitalize; +} diff --git a/client/components/main/globalThemeColor.js b/client/components/main/globalThemeColor.js index c38b182e85..492641343a 100644 --- a/client/components/main/globalThemeColor.js +++ b/client/components/main/globalThemeColor.js @@ -53,20 +53,22 @@ Meteor.startup(() => { Tracker.autorun(() => { const user = Meteor.user(); - const boardId = Session.get('currentBoard'); - const onBoard = !!boardId; + const globalColor = user && user.profile && user.profile.globalThemeColor; - let colorClass = null; - let custom = []; - if (onBoard) { - const board = ReactiveCache.getBoard(boardId); - custom = (board && board.customThemeColors) || []; - } else { - const color = user && user.profile && user.profile.globalThemeColor; - colorClass = color ? `board-color-${color}` : null; - custom = (user && user.profile && user.profile.globalThemeCustomColors) || []; + if (globalColor) { + // #5778: a global override wins EVERYWHERE — including board pages. The header + // and .board-wrapper also prefer it (see header.jade / boardBody.jade), so the + // whole UI takes the chosen theme; unset it to return to per-board colors. + applyClass(`board-color-${globalColor}`); + applyCustom((user && user.profile && user.profile.globalThemeCustomColors) || []); + return; } - applyClass(colorClass); - applyCustom(custom); + + // No global override: on a board expose that board's own custom colors (its color + // class already lives on .board-wrapper/#header); off a board, apply nothing. + const boardId = Session.get('currentBoard'); + const board = boardId ? ReactiveCache.getBoard(boardId) : null; + applyClass(null); + applyCustom((board && board.customThemeColors) || []); }); }); diff --git a/client/components/main/header.jade b/client/components/main/header.jade index 1d505d2077..aa1e09b97a 100644 --- a/client/components/main/header.jade +++ b/client/components/main/header.jade @@ -5,7 +5,7 @@ template(name="header") Reddit "subreddit" bar. The first link goes to the boards page. if currentUser - #header-quick-access(class="{{#if currentBoard}}{{currentBoard.colorClass}}{{else}}{{currentUser.globalThemeColorClass}}{{/if}}" role="navigation" aria-label="{{_ 'all-boards'}}") + #header-quick-access(class="{{#if currentUser.globalThemeColorClass}}{{currentUser.globalThemeColorClass}}{{else}}{{currentBoard.colorClass}}{{/if}}" role="navigation" aria-label="{{_ 'all-boards'}}") // Home icon - always at left side of logo span.home-icon.allBoards a(href="{{pathFor 'home'}}") @@ -95,7 +95,7 @@ template(name="header") +headerUserBar - #header(class="{{#if currentBoard}}{{currentBoard.colorClass}}{{else}}{{currentUser.globalThemeColorClass}}{{/if}}") + #header(class="{{#if currentUser.globalThemeColorClass}}{{currentUser.globalThemeColorClass}}{{else}}{{currentBoard.colorClass}}{{/if}}") //- The main bar is a colorful bar that provide all the meta-data for the current page. This bar is contextual based. diff --git a/client/components/main/themeColorPicker.jade b/client/components/main/themeColorPicker.jade index 203046e200..f21bc46155 100644 --- a/client/components/main/themeColorPicker.jade +++ b/client/components/main/themeColorPicker.jade @@ -1,7 +1,8 @@ //- Shared "Select Color" picker (docs/Theme/Theme.md), used by both Board Settings - and Member Settings. Two-level dropdowns (category -> theme); the native color - wheel(s) appear only for flat (1) and clear (2) categories. `data.scope` is - 'board' or 'global'. + and Member Settings. Colors are shown as VISIBLE swatches grouped by category, with + the category name as a header above each group; the native color wheel(s) appear + for the flat (1) / clear (2) categories once such a color is selected. `data.scope` + is 'board' or 'global'. template(name="themeColorPicker") form.theme-color-picker.edit-label if isGlobal @@ -12,20 +13,22 @@ template(name="themeColorPicker") | {{_ 'theme-default'}} if isNoneSelected i.fa.fa-check - label(for="themeCategory") {{_ 'theme-category'}} - select.js-theme-category.wekan-form-control#themeCategory - each categories - option(value=key selected=selected) {{label}} - label(for="themeName") {{_ 'theme'}} - select.js-theme-color.wekan-form-control#themeName - each themes - option(value=color selected=selected) {{color}} + each themeGroups + .theme-category-group + .theme-category-label {{label}} + .board-backgrounds-list.clearfix + each colors + .board-background-select.js-select-theme(data-color="{{name}}") + span.background-box(class="board-color-{{name}}") + span {{name}} + if selected + i.fa.fa-check if showCustom .color-wheel-wrap label {{_ 'custom-color'}} each customWheels - input.js-theme-wheel(type="color" data-index=index value=value title="{{_ 'custom-color'}}") - .theme-preview - span.background-box(class=previewClass style=previewStyle) - span {{_ 'preview'}} + input.js-theme-wheel(type="color" data-index="{{index}}" value="{{value}}" title="{{_ 'custom-color'}}") + .theme-preview + span.background-box(class="{{previewClass}}" style="{{previewStyle}}") + span {{_ 'preview'}} button.primary.confirm.js-theme-save {{_ 'save'}} diff --git a/client/components/main/themeColorPicker.js b/client/components/main/themeColorPicker.js index b1dac9e9e7..6cd964dc0b 100644 --- a/client/components/main/themeColorPicker.js +++ b/client/components/main/themeColorPicker.js @@ -12,10 +12,10 @@ import { customColorCount, } from '/models/lib/themeCategories'; -// Shared "Select Color" picker (docs/Theme/Theme.md): two-level dropdowns -// (category -> theme) + native color wheel(s) for the flat/clear categories. -// data.scope is 'board' (writes board.color) or 'global' (writes the user's #5778 -// global override). +// Shared "Select Color" picker (docs/Theme/Theme.md): VISIBLE color swatches grouped +// by category (with the category name above each group) + native color wheel(s) for +// the flat/clear categories once such a color is selected. data.scope is 'board' +// (writes board.color) or 'global' (writes the user's #5778 global override). const DEFAULT_WHEEL = ['#2980b9', '#6dd5fa']; // stock flat accent / second slide stop @@ -34,9 +34,7 @@ function readCurrent(scope) { Template.themeColorPicker.onCreated(function () { const scope = this.data && this.data.scope === 'board' ? 'board' : 'global'; const cur = readCurrent(scope); - const forCategory = cur.color || 'belize'; this.scope = scope; - this.category = new ReactiveVar(categoryOf(forCategory) || 'flat'); this.color = new ReactiveVar(cur.color); // null for global = no override this.customColors = new ReactiveVar((cur.custom || []).slice()); }); @@ -49,25 +47,23 @@ Template.themeColorPicker.helpers({ const tpl = Template.instance(); return tpl.scope === 'global' && !tpl.color.get(); }, - categories() { - const cur = Template.instance().category.get(); + // Visible swatches grouped by category, each group labelled with its category name. + themeGroups() { + const cur = Template.instance().color.get(); return THEME_CATEGORY_ORDER.map(key => ({ key, label: TAPi18n.__(`theme-category-${key}`), - selected: key === cur, + colors: colorsInCategory(key).map(name => ({ name, selected: name === cur })), })); }, - themes() { - const tpl = Template.instance(); - const cur = tpl.color.get(); - return colorsInCategory(tpl.category.get()).map(color => ({ color, selected: color === cur })); - }, showCustom() { - return allowsCustomColor(Template.instance().category.get()); + const cur = Template.instance().color.get(); + return cur ? allowsCustomColor(categoryOf(cur)) : false; }, customWheels() { const tpl = Template.instance(); - const n = customColorCount(tpl.category.get()); + const cur = tpl.color.get(); + const n = cur ? customColorCount(categoryOf(cur)) : 0; const cc = tpl.customColors.get(); const wheels = []; for (let i = 0; i < n; i += 1) { @@ -83,10 +79,12 @@ Template.themeColorPicker.helpers({ // colors until the CSS-variable refactor; the preview swatch shows them directly). previewStyle() { const tpl = Template.instance(); - if (!allowsCustomColor(tpl.category.get())) return ''; + const cur = tpl.color.get(); + const cat = cur ? categoryOf(cur) : null; + if (!cat || !allowsCustomColor(cat)) return ''; const cc = tpl.customColors.get(); if (!cc.some(Boolean)) return ''; - if (customColorCount(tpl.category.get()) === 2 && cc[0] && cc[1]) { + if (customColorCount(cat) === 2 && cc[0] && cc[1]) { return `background: linear-gradient(135deg, ${cc[0]}, ${cc[1]}) !important;`; } if (cc[0]) return `background: ${cc[0]} !important;`; @@ -98,8 +96,9 @@ Template.themeColorPicker.helpers({ // which case read every wheel's current value (untouched ones contribute their shown // default) so the result is a complete set of the category's expected count. function gatherCustom(tpl) { - const cat = tpl.category.get(); - if (!allowsCustomColor(cat)) return []; + const color = tpl.color.get(); + const cat = color ? categoryOf(color) : null; + if (!cat || !allowsCustomColor(cat)) return []; if (!tpl.customColors.get().some(Boolean)) return []; const n = customColorCount(cat); const wheels = Array.from(tpl.findAll('.js-theme-wheel')) @@ -110,14 +109,12 @@ function gatherCustom(tpl) { } Template.themeColorPicker.events({ - 'change .js-theme-category'(event, tpl) { - const cat = event.currentTarget.value; - tpl.category.set(cat); - tpl.color.set(colorsInCategory(cat)[0]); // default to the first theme in the category - tpl.customColors.set([]); // custom colors do not carry across categories - }, - 'change .js-theme-color'(event, tpl) { - tpl.color.set(event.currentTarget.value); + // Pick a color by clicking its swatch. + 'click .js-select-theme'(event, tpl) { + const color = event.currentTarget.dataset.color; + if (!color) return; + tpl.color.set(color); + tpl.customColors.set([]); // reset custom colors when choosing a different swatch }, 'input .js-theme-wheel'(event, tpl) { const idx = parseInt(event.currentTarget.dataset.index, 10); @@ -129,7 +126,7 @@ Template.themeColorPicker.events({ }, async 'click .js-theme-save'(event, tpl) { event.preventDefault(); - const color = tpl.color.get() || colorsInCategory(tpl.category.get())[0]; + const color = tpl.color.get() || colorsInCategory(THEME_CATEGORY_ORDER[0])[0]; const custom = gatherCustom(tpl); if (tpl.scope === 'board') { const b = Utils.getCurrentBoard(); diff --git a/tests/globalThemeColor.test.cjs b/tests/globalThemeColor.test.cjs index 097031e58f..67baf5d3c9 100644 --- a/tests/globalThemeColor.test.cjs +++ b/tests/globalThemeColor.test.cjs @@ -77,22 +77,24 @@ test('member menu has Change Color, opening the shared theme picker (scope=globa assert.ok(/Popup\.open\('changeColor'\)/.test(js), 'opens the popup'); }); -test('body autorun applies the global class off-board and exposes custom colors', () => { +test('body autorun applies the global override EVERYWHERE (wins over board color)', () => { const j = read('client/components/main/globalThemeColor.js'); - assert.ok(/board-color-\$\{color\}/.test(j), 'builds the board-color class'); - assert.ok(/Session\.get\('currentBoard'\)/.test(j), 'checks whether on a board'); - // off-board: colorClass is computed only in the not-on-board branch. - assert.ok(/onBoard/.test(j) && /globalThemeColor/.test(j), 'gates on board context'); - // custom colors are applied as CSS variables consumed by customTheme.css. + assert.ok(/board-color-\$\{globalColor\}/.test(j), 'builds the board-color class from the global override'); + // A set global override returns early -> applied regardless of board context. + assert.ok(/if \(globalColor\)/.test(j), 'global override wins everywhere'); + // Falls back to the current board custom colors only when there is NO global. + assert.ok(/Session\.get\('currentBoard'\)/.test(j) && /customThemeColors/.test(j), 'board fallback when unset'); assert.ok(/--theme-accent/.test(j), 'sets the custom-color CSS variable'); }); -test('header falls back to the global theme class on non-board pages', () => { +test('header + board-wrapper prefer the global theme class when set', () => { const h = read('client/components/main/header.jade'); - // Both the quick-access bar and the main header use the board color when on a - // board, else the user global override. - const matches = h.match(/else\}\}\{\{currentUser\.globalThemeColorClass\}\}/g) || []; - assert.ok(matches.length >= 2, 'both #header and #header-quick-access fall back'); + // #header and #header-quick-access use the global override first, board color else. + const headerMatches = h.match(/if currentUser\.globalThemeColorClass\}\}\{\{currentUser\.globalThemeColorClass\}\}\{\{else\}\}\{\{currentBoard\.colorClass\}\}/g) || []; + assert.ok(headerMatches.length >= 2, 'both #header and #header-quick-access prefer the global override'); + const bb = read('client/components/boards/boardBody.jade'); + assert.ok(/if currentUser\.globalThemeColorClass\}\}\{\{currentUser\.globalThemeColorClass\}\}\{\{else\}\}\{\{currentBoard\.colorClass\}\}/.test(bb), + '.board-wrapper prefers the global override too (so board content is themed)'); }); test('i18n has the new strings', () => { diff --git a/tests/themeColorPicker.test.cjs b/tests/themeColorPicker.test.cjs index cc5f003686..0589c93f31 100644 --- a/tests/themeColorPicker.test.cjs +++ b/tests/themeColorPicker.test.cjs @@ -22,18 +22,23 @@ function test(name, fn) { console.log(' ok -', name); } -test('shared picker template has category + theme dropdowns and custom wheels', () => { +test('picker shows visible swatches grouped by category, with a group-name header', () => { const jade = read('client/components/main/themeColorPicker.jade'); - assert.ok(/js-theme-category/.test(jade), 'category dropdown'); - assert.ok(/js-theme-color/.test(jade), 'theme dropdown'); + assert.ok(/each themeGroups/.test(jade), 'iterates category groups'); + assert.ok(/theme-category-label \{\{label\}\}/.test(jade), 'category name shown above each group'); + assert.ok(/js-select-theme\(data-color="\{\{name\}\}"\)/.test(jade), 'clickable color swatches'); + assert.ok(/board-color-\{\{name\}\}/.test(jade), 'swatch shows the actual color'); + assert.ok(/span \{\{name\}\}/.test(jade), 'swatch shows the color name'); assert.ok(/if showCustom/.test(jade), 'wheels gated on custom-capable category'); assert.ok(/js-theme-wheel\(type="color"/.test(jade), 'native color wheel input'); }); -test('picker logic: repopulates themes by category, gates wheels, saves per scope', () => { +test('picker logic: swatch click selects, category derived from color, saves per scope', () => { const js = read('client/components/main/themeColorPicker.js'); - assert.ok(/colorsInCategory\(cat\)\[0\]/.test(js), 'category change picks first theme'); - assert.ok(/allowsCustomColor/.test(js) && /customColorCount/.test(js), 'uses category rules'); + assert.ok(/themeGroups\(\)/.test(js), 'builds category groups with labels'); + assert.ok(/'click \.js-select-theme'/.test(js) && /tpl\.color\.set\(color\)/.test(js), 'swatch click sets color'); + // custom-capability is derived from the SELECTED color's category (no dropdown state). + assert.ok(/allowsCustomColor\(categoryOf\(cur\)\)/.test(js), 'custom gate uses the selected color'); // board scope writes board.setColor; global scope calls the method. assert.ok(/b\.setColor\(color, custom\)/.test(js), 'board save'); assert.ok(/Meteor\.call\('setGlobalThemeColor', color, custom/.test(js), 'global save');