Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Theme-owned color palettes (#32795)

Osama Sayegh7fce72408923
diff --git a/app/assets/javascripts/admin/addon/adapters/theme.js b/app/assets/javascripts/admin/addon/adapters/theme.js
index 79751760eed..4f0d7e3651c 100644
--- a/app/assets/javascripts/admin/addon/adapters/theme.js
+++ b/app/assets/javascripts/admin/addon/adapters/theme.js
@@ -7,13 +7,6 @@ export default class Theme extends RestAdapter {
return "/admin/";
}
- pathFor(store, type, findArgs) {
- if (findArgs?.useConfigAreaEndpoint) {
- return "/admin/config/customize/themes";
- }
- return super.pathFor(...arguments);
- }
-
afterFindAll(results) {
let map = {};
diff --git a/app/assets/javascripts/admin/addon/components/admin-config-areas/color-palette.gjs b/app/assets/javascripts/admin/addon/components/admin-config-areas/color-palette.gjs
index 2b815efc337..bacc07b4d05 100644
--- a/app/assets/javascripts/admin/addon/components/admin-config-areas/color-palette.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-config-areas/color-palette.gjs
@@ -55,15 +55,13 @@ export default class AdminConfigAreasColorPalette extends Component {
}
@action
- onLightColorChange(name, value) {
- const color = this.data.colors.find((c) => c.name === name);
+ onLightColorChange(color, value) {
color.hex = value;
this.hasChangedColors = true;
}
@action
- onDarkColorChange(name, value) {
- const color = this.data.colors.find((c) => c.name === name);
+ onDarkColorChange(color, value) {
color.dark_hex = value;
this.hasChangedColors = true;
}
diff --git a/app/assets/javascripts/admin/addon/components/admin-site-settings-changes-banner.gjs b/app/assets/javascripts/admin/addon/components/admin-site-settings-changes-banner.gjs
index 0e9c06f90ce..a19fd4adff7 100644
--- a/app/assets/javascripts/admin/addon/components/admin-site-settings-changes-banner.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-site-settings-changes-banner.gjs
@@ -1,28 +1,16 @@
import Component from "@glimmer/component";
-import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
-import didInsert from "@ember/render-modifiers/modifiers/did-insert";
-import willDestroy from "@ember/render-modifiers/modifiers/will-destroy";
import { service } from "@ember/service";
-import DButton from "discourse/components/d-button";
-import htmlSafe from "discourse/helpers/html-safe";
+import { gt } from "truth-helpers";
import { i18n } from "discourse-i18n";
+import ChangesBanner from "admin/components/changes-banner";
export default class AdminSiteSettingsChangesBanner extends Component {
@service siteSettingChangeTracker;
- @tracked isSaving = false;
- _resizer = null;
-
@action
async save() {
- this.isSaving = true;
-
- try {
- await this.siteSettingChangeTracker.save();
- } finally {
- this.isSaving = false;
- }
+ await this.siteSettingChangeTracker.save();
}
@action
@@ -30,37 +18,10 @@ export default class AdminSiteSettingsChangesBanner extends Component {
this.siteSettingChangeTracker.discard();
}
- @action
- setupResizeObserver(element) {
- const container = document.getElementById("main-container");
- this._resizer = () => this.positionBanner(container, element);
-
- this._resizer();
-
- this._resizeObserver = window.addEventListener("resize", this._resizer);
- }
-
- @action
- teardownResizeObserver() {
- window.removeEventListener("resize", this._resizer);
- }
-
- positionBanner(container, element) {
- if (container) {
- const { width } = container.getBoundingClientRect();
-
- element.style.width = `${width}px`;
- }
- }
-
get dirtyCount() {
return this.siteSettingChangeTracker.count;
}
- get showBanner() {
- return this.dirtyCount > 0;
- }
-
get bannerLabel() {
return i18n("admin.site_settings.dirty_banner", {
count: this.dirtyCount,
@@ -80,30 +41,14 @@ export default class AdminSiteSettingsChangesBanner extends Component {
}
<template>
- {{#if this.showBanner}}
- <div
- class="admin-site-settings__changes-banner"
- {{didInsert this.setupResizeObserver}}
- {{willDestroy this.teardownResizeObserver}}
- >
- <span>{{htmlSafe this.bannerLabel}}</span>
- <div class="controls">
- <DButton
- @action={{this.discard}}
- @disabled={{this.isSaving}}
- class="btn-secondary btn-small"
- >
- {{this.discardLabel}}
- </DButton>
- <DButton
- @action={{this.save}}
- @isLoading={{this.isSaving}}
- class="btn-primary btn-small"
- >
- {{this.saveLabel}}
- </DButton>
- </div>
- </div>
+ {{#if (gt this.dirtyCount 0)}}
+ <ChangesBanner
+ @bannerLabel={{this.bannerLabel}}
+ @saveLabel={{this.saveLabel}}
+ @discardLabel={{this.discardLabel}}
+ @save={{this.save}}
+ @discard={{this.discard}}
+ />
{{/if}}
</template>
}
diff --git a/app/assets/javascripts/admin/addon/components/changes-banner.gjs b/app/assets/javascripts/admin/addon/components/changes-banner.gjs
new file mode 100644
index 00000000000..d6a48c2a647
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/components/changes-banner.gjs
@@ -0,0 +1,60 @@
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { action } from "@ember/object";
+import { modifier } from "ember-modifier";
+import DButton from "discourse/components/d-button";
+import htmlSafe from "discourse/helpers/html-safe";
+
+export default class ChangesBanner extends Component {
+ @tracked isSaving = false;
+
+ resizerModifier = modifier((element) => {
+ const container = document.getElementById("main-container");
+ const resizer = () => this.positionBanner(container, element);
+ resizer();
+
+ window.addEventListener("resize", resizer);
+ return () => window.removeEventListener("resize", resizer);
+ });
+
+ @action
+ async save() {
+ this.isSaving = true;
+
+ try {
+ await this.args.save();
+ } finally {
+ this.isSaving = false;
+ }
+ }
+
+ positionBanner(container, element) {
+ if (container) {
+ const { width } = container.getBoundingClientRect();
+
+ element.style.width = `${width}px`;
+ }
+ }
+
+ <template>
+ <div class="admin-changes-banner" {{this.resizerModifier}}>
+ <span class="admin-changes-banner__main-label">{{htmlSafe
+ @bannerLabel
+ }}</span>
+ <div class="controls">
+ <DButton
+ class="btn-secondary btn-small"
+ @action={{@discard}}
+ @disabled={{this.isSaving}}
+ @translatedLabel={{@discardLabel}}
+ />
+ <DButton
+ class="btn-primary btn-small"
+ @action={{this.save}}
+ @isLoading={{this.isSaving}}
+ @translatedLabel={{@saveLabel}}
+ />
+ </div>
+ </div>
+ </template>
+}
diff --git a/app/assets/javascripts/admin/addon/components/color-palette-editor.gjs b/app/assets/javascripts/admin/addon/components/color-palette-editor.gjs
index 3d8bebef83c..311b3843907 100644
--- a/app/assets/javascripts/admin/addon/components/color-palette-editor.gjs
+++ b/app/assets/javascripts/admin/addon/components/color-palette-editor.gjs
@@ -3,6 +3,7 @@ import { tracked } from "@glimmer/tracking";
import { fn } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
+import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
import concatClass from "discourse/helpers/concat-class";
@@ -14,34 +15,9 @@ export const DARK = "dark";
function isColorOverriden(color, darkModeActive) {
if (darkModeActive) {
- return color.defaultDarkValue && color.defaultDarkValue !== color.darkValue;
+ return color.default_dark_hex && color.default_dark_hex !== color.dark_hex;
} else {
- return (
- color.defaultLightValue && color.defaultLightValue !== color.lightValue
- );
- }
-}
-
-class Color {
- @tracked lightValue;
- @tracked darkValue;
-
- constructor({
- name,
- lightValue,
- darkValue,
- description,
- translatedName,
- defaultLightValue,
- defaultDarkValue,
- }) {
- this.name = name;
- this.lightValue = lightValue;
- this.darkValue = darkValue;
- this.displayName = translatedName;
- this.description = description;
- this.defaultLightValue = defaultLightValue;
- this.defaultDarkValue = defaultDarkValue;
+ return color.default_hex && color.default_hex !== color.hex;
}
}
@@ -63,13 +39,15 @@ const NavTab = <template>
const Picker = class extends Component {
@service toasts;
+ @tracked invalid = false;
+
@action
onInput(event) {
const color = event.target.value.replace("#", "");
if (this.args.showDark) {
- this.args.color.darkValue = color;
+ this.args.onDarkChange(color);
} else {
- this.args.color.lightValue = color;
+ this.args.onLightChange(color);
}
}
@@ -78,31 +56,73 @@ const Picker = class extends Component {
const color = event.target.value.replace("#", "");
if (this.args.showDark) {
this.args.onDarkChange(color);
- this.args.color.darkValue = color;
} else {
this.args.onLightChange(color);
- this.args.color.lightValue = color;
}
}
@action
onTextChange(event) {
- const color = event.target.value;
+ let color = event.target.value;
+
+ if (!this.isValidHex(color)) {
+ event.preventDefault();
+ this.invalid = true;
+ this.toasts.error({
+ data: {
+ message: i18n(
+ "admin.config_areas.color_palettes.invalid_color_length"
+ ),
+ },
+ });
+ return;
+ }
+ this.invalid = false;
+
+ color = this.ensureSixDigitsHex(color);
if (this.args.showDark) {
this.args.onDarkChange(color);
- this.args.color.darkValue = color;
} else {
this.args.onLightChange(color);
- this.args.color.lightValue = color;
}
}
@action
onTextKeypress(event) {
- const color = event.target.value + event.key;
+ const currentValue = event.target.value;
+
+ if (event.keyCode === 13) {
+ event.preventDefault();
+
+ if (currentValue.length !== 6 && currentValue.length !== 3) {
+ this.invalid = true;
+ this.toasts.error({
+ data: {
+ message: i18n(
+ "admin.config_areas.color_palettes.invalid_color_length"
+ ),
+ },
+ });
+ return;
+ }
+ this.invalid = false;
+
+ const nextPosition = this.args.position + 1;
+ if (nextPosition < this.args.totalColors) {
+ this.args.editorElement
+ .querySelector(
+ `.color-palette-editor__text-input[data-position="${nextPosition}"]`
+ )
+ .focus();
+ }
+ return;
+ }
+
+ const color = currentValue + event.key;
if (color && !color.match(/^[0-9A-Fa-f]+$/)) {
event.preventDefault();
+ this.invalid = true;
this.toasts.error({
data: {
message: i18n(
@@ -110,25 +130,47 @@ const Picker = class extends Component {
),
},
});
+ } else {
+ this.invalid = false;
+ }
+ }
+
+ @action
+ onTextPaste(event) {
+ const content = (event.clipboardData || window.clipboardData).getData(
+ "text"
+ );
+
+ if (!this.isValidHex(content)) {
+ event.preventDefault();
+ this.toasts.error({
+ data: {
+ message: i18n(
+ "admin.config_areas.color_palettes.invalid_color_length"
+ ),
+ },
+ });
+ return;
}
}
get displayedColor() {
let color;
if (this.args.showDark) {
- color = this.args.color.darkValue ?? this.args.color.lightValue;
+ color = this.args.color.dark_hex;
} else {
- color = this.args.color.lightValue ?? this.args.color.darkValue;
+ color = this.args.color.hex;
}
+
return this.ensureSixDigitsHex(color);
}
get activeValue() {
let color;
if (this.args.showDark) {
- color = this.args.color.darkValue ?? this.args.color.lightValue;
+ color = this.args.color.dark_hex;
} else {
- color = this.args.color.lightValue ?? this.args.color.darkValue;
+ color = this.args.color.hex;
}
if (color) {
@@ -146,28 +188,46 @@ const Picker = class extends Component {
return hex;
}
+ isValidHex(hex) {
+ return !!hex?.match(/^([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/);
+ }
+
<template>
- <input
- class="color-palette-editor__input"
- type="color"
- value={{this.activeValue}}
- {{on "input" this.onInput}}
- {{on "change" this.onChange}}
- />
- {{icon "hashtag"}}
- <input
- class="color-palette-editor__text-input"
- type="text"
- maxlength="6"
- value={{this.displayedColor}}
- {{on "keypress" this.onTextKeypress}}
- {{on "change" this.onTextChange}}
- />
+ <div
+ class={{concatClass
+ "color-palette-editor__picker"
+ "form-kit__control-input"
+ (if this.invalid "--invalid")
+ }}
+ >
+ <input
+ class="color-palette-editor__input"
+ data-position={{@position}}
+ type="color"
+ value={{this.activeValue}}
+ {{on "input" this.onInput}}
+ {{on "change" this.onChange}}
+ />
+ <div class="color-palette-editor__input-wrapper">
+ {{icon "hashtag" class="color-palette-editor__icon"}}
+ <input
+ class="color-palette-editor__text-input"
+ data-position={{@position}}
+ type="text"
+ maxlength="6"
+ value={{this.displayedColor}}
+ {{on "keypress" this.onTextKeypress}}
+ {{on "change" this.onTextChange}}
+ {{on "paste" this.onTextPaste}}
+ />
+ </div>
+ </div>
</template>
};
export default class ColorPaletteEditor extends Component {
@tracked selectedMode;
+ editorElement;
get currentMode() {
return this.selectedMode ?? this.args.initialMode ?? LIGHT;
@@ -181,20 +241,6 @@ export default class ColorPaletteEditor extends Component {
return this.currentMode === DARK;
}
- get colors() {
- return this.args.colors.map((color) => {
- return new Color({
- name: color.name,
- lightValue: color.hex,
- darkValue: color.dark_hex,
- description: color.description,
- translatedName: color.translatedName,
- defaultLightValue: color.default_hex,
- defaultDarkValue: color.default_dark_hex,
- });
- });
- }
-
@action
changeMode(newMode, event) {
if (
@@ -212,16 +258,19 @@ export default class ColorPaletteEditor extends Component {
@action
revert(color) {
if (this.darkModeActive) {
- this.args.onDarkColorChange(color.name, color.defaultDarkValue);
- color.darkValue = color.defaultDarkValue;
+ this.args.onDarkColorChange(color, color.default_dark_hex);
} else {
- this.args.onLightColorChange(color.name, color.defaultLightValue);
- color.lightValue = color.defaultLightValue;
+ this.args.onLightColorChange(color, color.default_hex);
}
}
+ @action
+ editorInserted(element) {
+ this.editorElement = element;
+ }
+
<template>
- <div class="color-palette-editor">
+ <div class="color-palette-editor" {{didInsert this.editorInserted}}>
<div class="nav-pills color-palette-editor__nav-pills">
<NavTab
@active={{this.lightModeActive}}
@@ -239,45 +288,50 @@ export default class ColorPaletteEditor extends Component {
/>
</div>
<div class="color-palette-editor__colors-list">
- {{#each this.colors as |color|}}
+ {{#each @colors as |color index|}}
<div
data-color-name={{color.name}}
class="color-palette-editor__colors-item"
>
<div class="color-palette-editor__color-info">
- <div class="color-palette-editor__color-description">
+ <div
+ class="color-palette-editor__color-description form-kit__container-title"
+ >
{{#if color.description}}
{{color.description}}
{{else}}
- {{color.displayName}}
+ {{color.translatedName}}
{{/if}}
</div>
{{#if color.description}}
<div class="color-palette-editor__color-name">
- {{color.displayName}}
+ {{color.translatedName}}
</div>
{{/if}}
</div>
<div class="color-palette-editor__color-controls">
- <div class="color-palette-editor__picker">
- <Picker
- @color={{color}}
- @showDark={{this.darkModeActive}}
- @onLightChange={{fn @onLightColorChange color.name}}
- @onDarkChange={{fn @onDarkColorChange color.name}}
- />
- </div>
- <DButton
- class={{concatClass
- "btn-flat"
- "color-palette-editor__revert"
- (unless
- (isColorOverriden color this.darkModeActive) "--hidden"
- )
- }}
- @icon="arrow-rotate-left"
- @action={{fn this.revert color}}
+ <Picker
+ @color={{color}}
+ @position={{index}}
+ @totalColors={{@colors.length}}
+ @editorElement={{this.editorElement}}
+ @showDark={{this.darkModeActive}}
+ @onLightChange={{fn @onLightColorChange color}}
+ @onDarkChange={{fn @onDarkColorChange color}}
/>
+ {{#unless @hideRevertButton}}
+ <DButton
+ class={{concatClass
+ "btn-flat"
+ "color-palette-editor__revert"
+ (unless
+ (isColorOverriden color this.darkModeActive) "--hidden"
+ )
+ }}
+ @icon="arrow-rotate-left"
+ @action={{fn this.revert color}}
+ />
+ {{/unless}}
</div>
</div>
{{/each}}
diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-show-colors.js b/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-show-colors.js
new file mode 100644
index 00000000000..53f4235b4e5
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-show-colors.js
@@ -0,0 +1,37 @@
+import { tracked } from "@glimmer/tracking";
+import Controller from "@ember/controller";
+import { TrackedSet } from "@ember-compat/tracked-built-ins";
+
+class ChangeTracker {
+ @tracked dirtyLightColors = new TrackedSet();
+ @tracked dirtyDarkColors = new TrackedSet();
+
+ addDirtyLightColor(name) {
+ this.dirtyLightColors.add(name);
+ }
+
+ addDirtyDarkColor(name) {
+ this.dirtyDarkColors.add(name);
+ }
+
+ removeDirtyLightColor(name) {
+ this.dirtyLightColors.delete(name);
+ }
+
+ removeDirtyDarkColor(name) {
+ this.dirtyDarkColors.delete(name);
+ }
+
+ clear() {
+ this.dirtyLightColors.clear();
+ this.dirtyDarkColors.clear();
+ }
+
+ get dirtyColorsCount() {
+ return this.dirtyLightColors.size + this.dirtyDarkColors.size;
+ }
+}
+
+export default class AdminCustomizeThemesShowColorsController extends Controller {
+ colorPaletteChangeTracker = new ChangeTracker();
+}
diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-show-index.js b/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-show-index.js
new file mode 100644
index 00000000000..eedeb1835f2
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-show-index.js
@@ -0,0 +1,440 @@
+import Controller from "@ember/controller";
+import { action } from "@ember/object";
+import {
+ empty,
+ filterBy,
+ mapBy,
+ notEmpty,
+ readOnly,
+} from "@ember/object/computed";
+import { service } from "@ember/service";
+import { ajax } from "discourse/lib/ajax";
+import { popupAjaxError } from "discourse/lib/ajax-error";
+import { url } from "discourse/lib/computed";
+import discourseComputed from "discourse/lib/decorators";
+import { makeArray } from "discourse/lib/helpers";
+import { i18n } from "discourse-i18n";
+import ThemeSettingsEditor from "admin/components/theme-settings-editor";
+import SiteSetting from "admin/models/site-setting";
+import { COMPONENTS, THEMES } from "admin/models/theme";
+import ThemeSettings from "admin/models/theme-settings";
+import ThemeUploadAddModal from "../components/theme-upload-add";
+
+const THEME_UPLOAD_VAR = 2;
+
+export default class AdminCustomizeThemesShowIndexController extends Controller {
+ @service dialog;
+ @service router;
+ @service siteSettings;
+ @service modal;
+
+ editRouteName = "adminCustomizeThemes.edit";
+
+ @url("model.id", "/admin/customize/themes/%@/export") downloadUrl;
+ @url("model.id", "/admin/themes/%@/preview") previewUrl;
+ @url("model.id", "model.locale", "/admin/themes/%@/translations/%@")
+ getTranslationsUrl;
+ @empty("selectedChildThemeId") addButtonDisabled;
+ @mapBy("model.parentThemes", "name") parentThemesNames;
+ @filterBy("allThemes", "component", false) availableParentThemes;
+ @filterBy("availableParentThemes", "isActive") availableActiveParentThemes;
+ @mapBy("availableParentThemes", "name") availableThemesNames;
+ @mapBy("availableActiveParentThemes", "name") availableActiveThemesNames;
+ @filterBy("availableChildThemes", "hasParents") availableActiveChildThemes;
+ @mapBy("availableChildThemes", "name") availableComponentsNames;
+ @mapBy("availableActiveChildThemes", "name") availableActiveComponentsNames;
+ @mapBy("model.childThemes", "name") childThemesNames;
+ @filterBy("model.theme_fields", "target", "extra_js") extraFiles;
+ @notEmpty("settings") hasSettings;
+ @notEmpty("translations") hasTranslations;
+ @readOnly("model.settings") settings;
+
+ @discourseComputed("model.component", "model.remote_theme")
+ showCheckboxes() {
+ return !this.model.component || this.model.remote_theme;
+ }
+
+ @discourseComputed("model.editedFields")
+ editedFieldsFormatted() {
+ const descriptions = [];
+ ["common", "desktop", "mobile"].forEach((target) => {
+ const fields = this.editedFieldsForTarget(target);
+ if (fields.length < 1) {
+ return;
+ }
+ let resultString = i18n("admin.customize.theme." + target);
+ const formattedFields = fields
+ .map((f) => i18n("admin.customize.theme." + f.name + ".text"))
+ .join(" , ");
+ resultString += `: ${formattedFields}`;
+ descriptions.push(resultString);
+ });
+ return descriptions;
+ }
+
+ @discourseComputed("colorSchemeId", "model.color_scheme_id")
+ colorSchemeChanged(colorSchemeId, existingId) {
+ colorSchemeId = colorSchemeId === null ? null : parseInt(colorSchemeId, 10);
+ return colorSchemeId !== existingId;
+ }
+
+ @discourseComputed("availableChildThemes", "model.childThemes.[]", "model")
+ selectableChildThemes(available, childThemes) {
+ if (available) {
+ const themes = !childThemes
+ ? available
+ : available.filter((theme) => !childThemes.includes(theme));
+ return themes.length === 0 ? null : themes;
+ }
+ }
+
+ @discourseComputed("model.parentThemes.[]")
+ relativesSelectorSettingsForComponent() {
+ return SiteSetting.create({
+ list_type: "compact",
+ type: "list",
+ preview: null,
+ allow_any: false,
+ setting: "parent_theme_ids",
+ label: i18n("admin.customize.theme.component_on_themes"),
+ choices: this.availableThemesNames,
+ default: this.parentThemesNames.join("|"),
+ value: this.parentThemesNames.join("|"),
+ defaultValues: this.availableActiveThemesNames.join("|"),
+ allThemes: this.allThemes,
+ setDefaultValuesLabel: i18n("admin.customize.theme.add_all_themes"),
+ });
+ }
+
+ @discourseComputed("model.childThemesNames.[]")
+ relativesSelectorSettingsForTheme() {
+ return SiteSetting.create({
+ list_type: "compact",
+ type: "list",
+ preview: null,
+ allow_any: false,
+ setting: "child_theme_ids",
+ label: i18n("admin.customize.theme.included_components"),
+ choices: this.availableComponentsNames,
+ default: this.childThemesNames.join("|"),
+ value: this.childThemesNames.join("|"),
+ defaultValues: this.availableActiveComponentsNames.join("|"),
+ allThemes: this.allThemes,
+ setDefaultValuesLabel: i18n("admin.customize.theme.add_all"),
+ });
+ }
+
+ @discourseComputed("allThemes", "model.component", "model")
+ availableChildThemes(allThemes) {
+ if (!this.get("model.component")) {
+ const themeId = this.get("model.id");
+ return allThemes.filter(
+ (theme) => theme.get("id") !== themeId && theme.get("component")
+ );
+ }
+ }
+
+ @discourseComputed("model.component")
+ convertKey(component) {
+ const type = component ? "component" : "theme";
+ return `admin.customize.theme.convert_${type}`;
+ }
+
+ @discourseComputed("model.component")
+ convertIcon(component) {
+ return component ? "cube" : "";
+ }
+
+ @discourseComputed("model.component")
+ convertTooltip(component) {
+ const type = component ? "component" : "theme";
+ return `admin.customize.theme.convert_${type}_tooltip`;
+ }
+
+ @discourseComputed("model.translations")
+ translations(translations) {
+ return translations.map((setting) =>
+ ThemeSettings.create({ ...setting, textarea: true })
+ );
+ }
+
+ @discourseComputed(
+ "model.remote_theme.local_version",
+ "model.remote_theme.remote_version",
+ "model.remote_theme.commits_behind"
+ )
+ hasOverwrittenHistory(localVersion, remoteVersion, commitsBehind) {
+ return localVersion !== remoteVersion && commitsBehind === -1;
+ }
+
+ @discourseComputed("model.remoteError", "updatingRemote")
+ showRemoteError(errorMessage, updating) {
+ return errorMessage && !updating;
+ }
+
+ editedFieldsForTarget(target) {
+ return this.get("model.editedFields").filter(
+ (field) => field.target === target
+ );
+ }
+
+ commitSwitchType() {
+ const model = this.model;
+ const newValue = !model.get("component");
+ model.set("component", newValue);
+
+ if (newValue) {
+ this.set("parentController.currentTab", COMPONENTS);
+ } else {
+ this.set("parentController.currentTab", THEMES);
+ }
+
+ model
+ .saveChanges("component")
+ .then(() => {
+ this.set("colorSchemeId", null);
+
+ model.setProperties({
+ default: false,
+ color_scheme_id: null,
+ user_selectable: false,
+ child_themes: [],
+ childThemes: [],
+ });
+
+ this.get("parentController.model.content").forEach((theme) => {
+ const children = makeArray(theme.get("childThemes"));
+ const rawChildren = makeArray(theme.get("child_themes"));
+ const index = children ? children.indexOf(model) : -1;
+ if (index > -1) {
+ children.splice(index, 1);
+ rawChildren.splice(index, 1);
+ theme.setProperties({
+ childThemes: children,
+ child_themes: rawChildren,
+ });
+ }
+ });
+ })
+ .catch(popupAjaxError);
+ }
+
+ transitionToEditRoute() {
+ this.router.transitionTo(
+ this.editRouteName,
+ this.get("model.id"),
+ "common",
+ "scss"
+ );
+ }
+
+ @discourseComputed("model.user.id", "model.default")
+ showConvert(userId, defaultTheme) {
+ return userId > 0 && !defaultTheme;
+ }
+
+ @action
+ refreshModel() {
+ this.send("routeRefreshModel");
+ }
+
+ @action
+ updateToLatest() {
+ this.set("updatingRemote", true);
+ this.model
+ .updateToLatest()
+ .catch(popupAjaxError)
+ .finally(() => {
+ this.set("updatingRemote", false);
+ });
+ }
+
+ @action
+ checkForThemeUpdates() {
+ this.set("updatingRemote", true);
+ this.model
+ .checkForUpdates()
+ .catch(popupAjaxError)
+ .finally(() => {
+ this.set("updatingRemote", false);
+ });
+ }
+
+ @action
+ addUploadModal() {
+ this.modal.show(ThemeUploadAddModal, {
+ model: {
+ themeFields: this.model.theme_fields,
+ addUpload: this.addUpload,
+ },
+ });
+ }
+
+ @action
+ addUpload(info) {
+ let model = this.model;
+ model.setField("common", info.name, "", info.upload_id, THEME_UPLOAD_VAR);
+ model.saveChanges("theme_fields").catch((e) => popupAjaxError(e));
+ }
+
+ get availableLocales() {
+ return JSON.parse(this.siteSettings.available_locales);
+ }
+
+ get locale() {
+ return (
+ this.get("model.locale") ||
+ this.userLocale ||
+ this.siteSettings.default_locale
+ );
+ }
+
+ @action
+ updateLocale(value) {
+ this.set("model.loadingTranslations", true);
+ this.set("model.locale", value);
+ ajax(this.getTranslationsUrl).then(({ translations }) => {
+ this.set("model.translations", translations);
+ this.set("model.loadingTranslations", false);
+ });
+ }
+
+ @action
+ cancelChangeScheme() {
+ this.set("colorSchemeId", this.get("model.color_scheme_id"));
+ }
+
+ @action
+ changeScheme() {
+ let schemeId = this.colorSchemeId;
+ this.set(
+ "model.color_scheme_id",
+ schemeId === null ? null : parseInt(schemeId, 10)
+ );
+ this.model.saveChanges("color_scheme_id");
+ }
+
+ @action
+ editTheme() {
+ if (this.get("model.remote_theme.is_git")) {
+ this.dialog.confirm({
+ message: i18n("admin.customize.theme.edit_confirm"),
+ didConfirm: () => this.transitionToEditRoute(),
+ });
+ } else {
+ this.transitionToEditRoute();
+ }
+ }
+
+ @action
+ applyDefault() {
+ const model = this.model;
+ model.saveChanges("default").then(() => {
+ if (model.get("default")) {
+ this.allThemes.forEach((theme) => {
+ if (theme !== model && theme.get("default")) {
+ theme.set("default", false);
+ }
+ });
+ }
+ });
+ }
+
+ @action
+ applyUserSelectable() {
+ this.model.saveChanges("user_selectable");
+ }
+
+ @action
+ applyAutoUpdateable() {
+ this.model.saveChanges("auto_update");
+ }
+
+ @action
+ addChildTheme() {
+ let themeId = parseInt(this.selectedChildThemeId, 10);
+ let theme = this.allThemes.findBy("id", themeId);
+ this.model.addChildTheme(theme).then(() => this.store.findAll("theme"));
+ }
+
+ @action
+ removeUpload(upload) {
+ return this.dialog.deleteConfirm({
+ title: i18n("admin.customize.theme.delete_upload_confirm"),
+ didConfirm: () => this.model.removeField(upload),
+ });
+ }
+
+ @action
+ removeChildTheme(theme) {
+ this.model.removeChildTheme(theme).then(() => this.store.findAll("theme"));
+ }
+
+ @action
+ destroyTheme() {
+ return this.dialog.deleteConfirm({
+ title: i18n("admin.customize.delete_confirm", {
+ theme_name: this.get("model.name"),
+ }),
+ didConfirm: () => {
+ const model = this.model;
+ model.setProperties({ recentlyInstalled: false });
+ model.destroyRecord().then(() => {
+ this.allThemes.removeObject(model);
+ this.router.transitionTo("adminConfig.customize.themes");
+ });
+ },
+ });
+ }
+
+ @action
+ showThemeSettingsEditor() {
+ this.dialog.alert({
+ title: "Edit Settings",
+ bodyComponent: ThemeSettingsEditor,
+ bodyComponentModel: { model: this.model, controller: this },
+ class: "theme-settings-editor-dialog",
+ });
+ }
+
+ @action
+ switchType() {
+ const relatives = this.get("model.component")
+ ? this.get("model.parentThemes")
+ : this.get("model.childThemes");
+
+ let message = i18n(`${this.convertKey}_alert_generic`);
+
+ if (relatives && relatives.length > 0) {
+ message = i18n(`${this.convertKey}_alert`, {
+ relatives: relatives.map((relative) => relative.get("name")).join(", "),
+ });
+ }
+
+ return this.dialog.yesNoConfirm({
+ message,
+ didConfirm: () => this.commitSwitchType(),
+ });
+ }
+
+ @action
+ enableComponent() {
+ this.model.set("enabled", true);
+ this.model
+ .saveChanges("enabled")
+ .catch(() => this.model.set("enabled", false));
+ }
+
+ @action
+ disableComponent() {
+ this.model.set("enabled", false);
+ this.model
+ .saveChanges("enabled")
+ .catch(() => this.model.set("enabled", true));
+ }
+
+ @action
+ editColorScheme() {
+ this.router.transitionTo("adminCustomize.colors.show", this.colorSchemeId);
+ }
+}
diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-show.js b/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-show.js
index 7151b08c62d..cb7d2d065e9 100644
--- a/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-show.js
+++ b/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-show.js
@@ -1,172 +1,25 @@
import Controller from "@ember/controller";
import { action } from "@ember/object";
-import {
- empty,
- filterBy,
- mapBy,
- match,
- notEmpty,
- readOnly,
-} from "@ember/object/computed";
+import { match } from "@ember/object/computed";
import { service } from "@ember/service";
-import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
-import { url } from "discourse/lib/computed";
import discourseComputed from "discourse/lib/decorators";
-import { makeArray } from "discourse/lib/helpers";
import { i18n } from "discourse-i18n";
-import ThemeSettingsEditor from "admin/components/theme-settings-editor";
-import SiteSetting from "admin/models/site-setting";
-import { COMPONENTS, THEMES } from "admin/models/theme";
-import ThemeSettings from "admin/models/theme-settings";
-import ThemeUploadAddModal from "../components/theme-upload-add";
-
-const THEME_UPLOAD_VAR = 2;
export default class AdminCustomizeThemesShowController extends Controller {
@service dialog;
@service router;
- @service siteSettings;
- @service modal;
-
- editRouteName = "adminCustomizeThemes.edit";
- @url("model.id", "/admin/customize/themes/%@/export") downloadUrl;
- @url("model.id", "/admin/themes/%@/preview") previewUrl;
- @url("model.id", "model.locale", "/admin/themes/%@/translations/%@")
- getTranslationsUrl;
- @empty("selectedChildThemeId") addButtonDisabled;
- @mapBy("model.parentThemes", "name") parentThemesNames;
- @filterBy("allThemes", "component", false) availableParentThemes;
- @filterBy("availableParentThemes", "isActive") availableActiveParentThemes;
- @mapBy("availableParentThemes", "name") availableThemesNames;
- @mapBy("availableActiveParentThemes", "name") availableActiveThemesNames;
- @filterBy("availableChildThemes", "hasParents") availableActiveChildThemes;
- @mapBy("availableChildThemes", "name") availableComponentsNames;
- @mapBy("availableActiveChildThemes", "name") availableActiveComponentsNames;
- @mapBy("model.childThemes", "name") childThemesNames;
- @filterBy("model.theme_fields", "target", "extra_js") extraFiles;
- @notEmpty("settings") hasSettings;
- @notEmpty("translations") hasTranslations;
@match("model.remote_theme.remote_url", /^http(s)?:\/\//) sourceIsHttp;
- @readOnly("model.settings") settings;
-
- @discourseComputed("model.component", "model.remote_theme")
- showCheckboxes() {
- return !this.model.component || this.model.remote_theme;
- }
-
- @discourseComputed("model.editedFields")
- editedFieldsFormatted() {
- const descriptions = [];
- ["common", "desktop", "mobile"].forEach((target) => {
- const fields = this.editedFieldsForTarget(target);
- if (fields.length < 1) {
- return;
- }
- let resultString = i18n("admin.customize.theme." + target);
- const formattedFields = fields
- .map((f) => i18n("admin.customize.theme." + f.name + ".text"))
- .join(" , ");
- resultString += `: ${formattedFields}`;
- descriptions.push(resultString);
- });
- return descriptions;
- }
-
- @discourseComputed("colorSchemeId", "model.color_scheme_id")
- colorSchemeChanged(colorSchemeId, existingId) {
- colorSchemeId = colorSchemeId === null ? null : parseInt(colorSchemeId, 10);
- return colorSchemeId !== existingId;
- }
-
- @discourseComputed("availableChildThemes", "model.childThemes.[]", "model")
- selectableChildThemes(available, childThemes) {
- if (available) {
- const themes = !childThemes
- ? available
- : available.filter((theme) => !childThemes.includes(theme));
- return themes.length === 0 ? null : themes;
- }
- }
-
- @discourseComputed("model.parentThemes.[]")
- relativesSelectorSettingsForComponent() {
- return SiteSetting.create({
- list_type: "compact",
- type: "list",
- preview: null,
- allow_any: false,
- setting: "parent_theme_ids",
- label: i18n("admin.customize.theme.component_on_themes"),
- choices: this.availableThemesNames,
- default: this.parentThemesNames.join("|"),
- value: this.parentThemesNames.join("|"),
- defaultValues: this.availableActiveThemesNames.join("|"),
- allThemes: this.allThemes,
- setDefaultValuesLabel: i18n("admin.customize.theme.add_all_themes"),
- });
- }
-
- @discourseComputed("model.childThemesNames.[]")
- relativesSelectorSettingsForTheme() {
- return SiteSetting.create({
- list_type: "compact",
- type: "list",
- preview: null,
- allow_any: false,
- setting: "child_theme_ids",
- label: i18n("admin.customize.theme.included_components"),
- choices: this.availableComponentsNames,
- default: this.childThemesNames.join("|"),
- value: this.childThemesNames.join("|"),
- defaultValues: this.availableActiveComponentsNames.join("|"),
- allThemes: this.allThemes,
- setDefaultValuesLabel: i18n("admin.customize.theme.add_all"),
- });
- }
-
- @discourseComputed("allThemes", "model.component", "model")
- availableChildThemes(allThemes) {
- if (!this.get("model.component")) {
- const themeId = this.get("model.id");
- return allThemes.filter(
- (theme) => theme.get("id") !== themeId && theme.get("component")
- );
- }
- }
-
- @discourseComputed("model.component")
- convertKey(component) {
- const type = component ? "component" : "theme";
- return `admin.customize.theme.convert_${type}`;
- }
-
- @discourseComputed("model.component")
- convertIcon(component) {
- return component ? "cube" : "";
- }
-
- @discourseComputed("model.component")
- convertTooltip(component) {
- const type = component ? "component" : "theme";
- return `admin.customize.theme.convert_${type}_tooltip`;
- }
-
- @discourseComputed("model.translations")
- translations(translations) {
- return translations.map((setting) =>
- ThemeSettings.create({ ...setting, textarea: true })
- );
- }
@discourseComputed(
- "model.remote_theme.local_version",
- "model.remote_theme.remote_version",
- "model.remote_theme.commits_behind"
+ "model.remote_theme.remote_url",
+ "model.remote_theme.branch"
)
- hasOverwrittenHistory(localVersion, remoteVersion, commitsBehind) {
- return localVersion !== remoteVersion && commitsBehind === -1;
+ remoteThemeLink(remoteThemeUrl, remoteThemeBranch) {
+ return remoteThemeBranch
+ ? `${remoteThemeUrl.replace(/\.git$/, "")}/tree/${remoteThemeBranch}`
+ : remoteThemeUrl;
}
@discourseComputed("model.remoteError", "updatingRemote")
@@ -183,158 +36,6 @@ export default class AdminCustomizeThemesShowController extends Controller {
return remoteUrl && !localVersion && !commitsBehind;
}
- editedFieldsForTarget(target) {
- return this.get("model.editedFields").filter(
- (field) => field.target === target
- );
- }
-
- commitSwitchType() {
- const model = this.model;
- const newValue = !model.get("component");
- model.set("component", newValue);
-
- if (newValue) {
- this.set("parentController.currentTab", COMPONENTS);
- } else {
- this.set("parentController.currentTab", THEMES);
- }
-
- model
- .saveChanges("component")
- .then(() => {
- this.set("colorSchemeId", null);
-
- model.setProperties({
- default: false,
- color_scheme_id: null,
- user_selectable: false,
- child_themes: [],
- childThemes: [],
- });
-
- this.get("parentController.model.content").forEach((theme) => {
- const children = makeArray(theme.get("childThemes"));
- const rawChildren = makeArray(theme.get("child_themes"));
- const index = children ? children.indexOf(model) : -1;
- if (index > -1) {
- children.splice(index, 1);
- rawChildren.splice(index, 1);
- theme.setProperties({
- childThemes: children,
- child_themes: rawChildren,
- });
- }
- });
- })
- .catch(popupAjaxError);
- }
-
- transitionToEditRoute() {
- this.router.transitionTo(
- this.editRouteName,
- this.get("model.id"),
- "common",
- "scss"
- );
- }
-
- @discourseComputed(
- "model.remote_theme.remote_url",
- "model.remote_theme.branch"
- )
- remoteThemeLink(remoteThemeUrl, remoteThemeBranch) {
- return remoteThemeBranch
- ? `${remoteThemeUrl.replace(/\.git$/, "")}/tree/${remoteThemeBranch}`
- : remoteThemeUrl;
- }
-
- @discourseComputed("model.user.id", "model.default")
- showConvert(userId, defaultTheme) {
- return userId > 0 && !defaultTheme;
- }
-
- @action
- refreshModel() {
- this.send("routeRefreshModel");
- }
-
- @action
- updateToLatest() {
- this.set("updatingRemote", true);
- this.model
- .updateToLatest()
- .catch(popupAjaxError)
- .finally(() => {
- this.set("updatingRemote", false);
- });
- }
-
- @action
- checkForThemeUpdates() {
- this.set("updatingRemote", true);
- this.model
- .checkForUpdates()
- .catch(popupAjaxError)
- .finally(() => {
- this.set("updatingRemote", false);
- });
- }
-
- @action
- addUploadModal() {
- this.modal.show(ThemeUploadAddModal, {
- model: {
- themeFields: this.model.theme_fields,
- addUpload: this.addUpload,
- },
- });
- }
-
- @action
- addUpload(info) {
- let model = this.model;
- model.setField("common", info.name, "", info.upload_id, THEME_UPLOAD_VAR);
- model.saveChanges("theme_fields").catch((e) => popupAjaxError(e));
- }
-
- get availableLocales() {
- return JSON.parse(this.siteSettings.available_locales);
- }
-
- get locale() {
- return (
- this.get("model.locale") ||
- this.userLocale ||
- this.siteSettings.default_locale
- );
- }
-
- @action
- updateLocale(value) {
- this.set("model.loadingTranslations", true);
- this.set("model.locale", value);
- ajax(this.getTranslationsUrl).then(({ translations }) => {
- this.set("model.translations", translations);
- this.set("model.loadingTranslations", false);
- });
- }
-
- @action
- cancelChangeScheme() {
- this.set("colorSchemeId", this.get("model.color_scheme_id"));
- }
-
- @action
- changeScheme() {
- let schemeId = this.colorSchemeId;
- this.set(
- "model.color_scheme_id",
- schemeId === null ? null : parseInt(schemeId, 10)
- );
- this.model.saveChanges("color_scheme_id");
- }
-
@action
startEditingName() {
this.set("oldName", this.get("model.name"));
@@ -354,65 +55,20 @@ export default class AdminCustomizeThemesShowController extends Controller {
}
@action
- editTheme() {
- if (this.get("model.remote_theme.is_git")) {
- this.dialog.confirm({
- message: i18n("admin.customize.theme.edit_confirm"),
- didConfirm: () => this.transitionToEditRoute(),
+ updateToLatest() {
+ this.set("updatingRemote", true);
+ this.model
+ .updateToLatest()
+ .catch(popupAjaxError)
+ .finally(() => {
+ this.set("updatingRemote", false);
});
- } else {
- this.transitionToEditRoute();
- }
- }
-
- @action
- applyDefault() {
- const model = this.model;
- model.saveChanges("default").then(() => {
- if (model.get("default")) {
- this.allThemes.forEach((theme) => {
- if (theme !== model && theme.get("default")) {
- theme.set("default", false);
- }
- });
- }
- });
- }
-
- @action
- applyUserSelectable() {
- this.model.saveChanges("user_selectable");
- }
-
- @action
- applyAutoUpdateable() {
- this.model.saveChanges("auto_update");
- }
-
- @action
- addChildTheme() {
- let themeId = parseInt(this.selectedChildThemeId, 10);
- let theme = this.allThemes.findBy("id", themeId);
- this.model.addChildTheme(theme).then(() => this.store.findAll("theme"));
- }
-
- @action
- removeUpload(upload) {
- return this.dialog.deleteConfirm({
- title: i18n("admin.customize.theme.delete_upload_confirm"),
- didConfirm: () => this.model.removeField(upload),
- });
- }
-
- @action
- removeChildTheme(theme) {
- this.model.removeChildTheme(theme).then(() => this.store.findAll("theme"));
}
@action
destroyTheme() {
- return this.dialog.deleteConfirm({
- title: i18n("admin.customize.delete_confirm", {
+ return this.dialog.yesNoConfirm({
+ message: i18n("admin.customize.delete_confirm", {
theme_name: this.get("model.name"),
}),
didConfirm: () => {
@@ -426,36 +82,6 @@ export default class AdminCustomizeThemesShowController extends Controller {
});
}
- @action
- showThemeSettingsEditor() {
- this.dialog.alert({
- title: "Edit Settings",
- bodyComponent: ThemeSettingsEditor,
- bodyComponentModel: { model: this.model, controller: this },
- class: "theme-settings-editor-dialog",
- });
- }
-
- @action
- switchType() {
- const relatives = this.get("model.component")
- ? this.get("model.parentThemes")
- : this.get("model.childThemes");
-
- let message = i18n(`${this.convertKey}_alert_generic`);
-
- if (relatives && relatives.length > 0) {
- message = i18n(`${this.convertKey}_alert`, {
- relatives: relatives.map((relative) => relative.get("name")).join(", "),
- });
- }
-
- return this.dialog.yesNoConfirm({
- message,
- didConfirm: () => this.commitSwitchType(),
- });
- }
-
@action
enableComponent() {
this.model.set("enabled", true);
@@ -463,17 +89,4 @@ export default class AdminCustomizeThemesShowController extends Controller {
.saveChanges("enabled")
.catch(() => this.model.set("enabled", false));
}
-
- @action
- disableComponent() {
- this.model.set("enabled", false);
- this.model
- .saveChanges("enabled")
- .catch(() => this.model.set("enabled", true));
- }
-
- @action
- editColorScheme() {
- this.router.transitionTo("adminCustomize.colors.show", this.colorSchemeId);
- }
}
diff --git a/app/assets/javascripts/admin/addon/models/color-scheme-color.js b/app/assets/javascripts/admin/addon/models/color-scheme-color.js
index e5b7b89c569..7a69ab8ec30 100644
--- a/app/assets/javascripts/admin/addon/models/color-scheme-color.js
+++ b/app/assets/javascripts/admin/addon/models/color-scheme-color.js
@@ -9,9 +9,23 @@ export default class ColorSchemeColor extends EmberObject {
@tracked hex;
@tracked dark_hex;
+ @tracked originalHex;
+ @tracked originalDarkHex;
+
// Whether the current value is different than Discourse's default color scheme.
@propertyNotEqual("hex", "default_hex") overridden;
+ init(object) {
+ super.init(...arguments);
+ this.originalHex = object.hex;
+ this.originalDarkHex = object.dark_hex;
+ }
+
+ discardColorChange() {
+ this.hex = this.originalHex;
+ this.dark_hex = this.originalDarkHex;
+ }
+
@on("init")
startTrackingChanges() {
this.set("originals", {
diff --git a/app/assets/javascripts/admin/addon/models/color-scheme.js b/app/assets/javascripts/admin/addon/models/color-scheme.js
index 396fa41d195..16e89f8a076 100644
--- a/app/assets/javascripts/admin/addon/models/color-scheme.js
+++ b/app/assets/javascripts/admin/addon/models/color-scheme.js
@@ -30,15 +30,7 @@ export default class ColorScheme extends EmberObject {
theme_name: colorScheme.theme_name,
base_scheme_id: colorScheme.base_scheme_id,
user_selectable: colorScheme.user_selectable,
- colors: colorScheme.colors.map((c) => {
- return ColorSchemeColor.create({
- name: c.name,
- hex: c.hex,
- dark_hex: c.dark_hex,
- default_hex: c.default_hex,
- is_advanced: c.is_advanced,
- });
- }),
+ colors: colorScheme.colors,
})
);
});
@@ -56,15 +48,7 @@ export default class ColorScheme extends EmberObject {
theme_name: json.theme_name,
base_scheme_id: json.base_scheme_id,
user_selectable: json.user_selectable,
- colors: json.colors.map((c) => {
- return ColorSchemeColor.create({
- name: c.name,
- hex: c.hex,
- dark_hex: c.dark_hex,
- default_hex: c.default_hex,
- is_advanced: c.is_advanced,
- });
- }),
+ colors: json.colors,
});
}
@@ -76,6 +60,10 @@ export default class ColorScheme extends EmberObject {
init() {
super.init(...arguments);
+ const colors = A(this.colors ?? []);
+ this.colors = colors.map((c) => {
+ return ColorSchemeColor.create(c);
+ });
this.startTrackingChanges();
}
diff --git a/app/assets/javascripts/admin/addon/models/theme.js b/app/assets/javascripts/admin/addon/models/theme.js
index 75c6c252457..c93374cc33a 100644
--- a/app/assets/javascripts/admin/addon/models/theme.js
+++ b/app/assets/javascripts/admin/addon/models/theme.js
@@ -1,10 +1,13 @@
+import { tracked } from "@glimmer/tracking";
import { get } from "@ember/object";
import { gt, or } from "@ember/object/computed";
import { isBlank, isEmpty } from "@ember/utils";
+import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import discourseComputed from "discourse/lib/decorators";
import RestModel from "discourse/models/rest";
import { i18n } from "discourse-i18n";
+import ColorScheme from "admin/models/color-scheme";
import ThemeSettings from "admin/models/theme-settings";
const THEME_UPLOAD_VAR = 2;
@@ -24,9 +27,17 @@ class Theme extends RestModel {
);
}
+ const palette =
+ json.owned_color_palette || json.color_scheme || json.base_palette;
+ if (palette) {
+ json.colorPalette = ColorScheme.create(palette);
+ }
+
return json;
}
+ @tracked colorPalette;
+
@or("default", "user_selectable") isActive;
@gt("remote_theme.commits_behind", 0) isPendingUpdates;
@gt("editedFields.length", 0) hasEditedFields;
@@ -174,6 +185,34 @@ class Theme extends RestModel {
return field ? field.error : "";
}
+ async changeColors() {
+ const colors = [];
+
+ for (const color of this.colorPalette.colors) {
+ const colorPayload = {
+ name: color.name,
+ hex: color.hex,
+ dark_hex: color.dark_hex,
+ };
+
+ colors.push(colorPayload);
+ }
+
+ const paletteData = await ajax(`/admin/themes/${this.id}/change-colors`, {
+ type: "PUT",
+ data: JSON.stringify({ colors }),
+ contentType: "application/json",
+ });
+ this.owned_color_palette = paletteData;
+ this.colorPalette = ColorScheme.create(paletteData);
+ }
+
+ discardColorChanges() {
+ for (const color of this.colorPalette.colors) {
+ color.discardColorChange();
+ }
+ }
+
getField(target, name) {
if (target === "common" && name === "js") {
target = "extra_js";
diff --git a/app/assets/javascripts/admin/addon/routes/admin-config-customize-themes.js b/app/assets/javascripts/admin/addon/routes/admin-config-customize-themes.js
index 5b72a69f008..659c01b1fa3 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-config-customize-themes.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-config-customize-themes.js
@@ -1,5 +1,7 @@
+import { ajax } from "discourse/lib/ajax";
import DiscourseRoute from "discourse/routes/discourse";
import { i18n } from "discourse-i18n";
+import Theme from "admin/models/theme";
export default class AdminConfigThemesAndComponentsThemesRoute extends DiscourseRoute {
queryParams = {
@@ -7,19 +9,27 @@ export default class AdminConfigThemesAndComponentsThemesRoute extends Discourse
repoName: { replace: true },
};
- titleToken() {
- return i18n("admin.config_areas.themes_and_components.themes.title");
- }
-
async model(params) {
+ const data = await ajax("/admin/config/customize/themes");
return {
- themes: (
- await this.store.findAll("theme", {
- useConfigAreaEndpoint: true,
- })
- ).content,
+ themes: data.themes.map((theme) =>
+ // TODO(osama) MEGA HACK. remove the __type and __state properties when
+ // we have rebuilt the theme "show" page and stopped requiring all
+ // themes/components be loaded for the page.
+ // If we use the store to load the themes here, the logic in afterFindAll
+ // interfers with the themes objects already loaded for the theme "show"
+ // page and breaks it.
+ // If we don't use the store (and remove the __type and __state props
+ // here), then the save method on the theme model breaks because it
+ // expects the theme to be a store object.
+ Theme.create({ ...theme, __type: "theme", __state: "created" })
+ ),
repoUrl: params.repoUrl,
repoName: params.repoName,
};
}
+
+ titleToken() {
+ return i18n("admin.config_areas.themes_and_components.themes.title");
+ }
}
diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show-colors.js b/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show-colors.js
new file mode 100644
index 00000000000..2873edb2105
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show-colors.js
@@ -0,0 +1,31 @@
+import { action } from "@ember/object";
+import { service } from "@ember/service";
+import DiscourseRoute from "discourse/routes/discourse";
+import { i18n } from "discourse-i18n";
+
+export default class AdminCustomizeThemesShowColorsRoute extends DiscourseRoute {
+ @service dialog;
+
+ @action
+ willTransition(transition) {
+ if (
+ this.controller.colorPaletteChangeTracker.dirtyColorsCount > 0 &&
+ transition.intent.name !== "adminCustomizeThemes.show.index"
+ ) {
+ transition.abort();
+ this.dialog.yesNoConfirm({
+ message: i18n(
+ "admin.customize.theme.unsaved_colors_leave_route_confirmation"
+ ),
+ didConfirm: () => {
+ this.controller.colorPaletteChangeTracker.clear();
+ transition.retry();
+ },
+ });
+ }
+ }
+
+ titleToken() {
+ return i18n("admin.customize.theme.colors_title");
+ }
+}
diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show-index.js b/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show-index.js
new file mode 100644
index 00000000000..b1f95eff419
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show-index.js
@@ -0,0 +1,51 @@
+import { action } from "@ember/object";
+import { service } from "@ember/service";
+import { scrollTop } from "discourse/lib/scroll-top";
+import DiscourseRoute from "discourse/routes/discourse";
+import { i18n } from "discourse-i18n";
+
+export default class AdminCustomizeThemesShowIndexRoute extends DiscourseRoute {
+ @service dialog;
+
+ async model() {
+ return this.modelFor("adminCustomizeThemesShow");
+ }
+
+ setupController(controller, model) {
+ super.setupController(...arguments);
+
+ const parentController = this.controllerFor("adminCustomizeThemes");
+
+ controller.setProperties({
+ model,
+ parentController,
+ allThemes: parentController.get("model"),
+ colorSchemeId: model.get("color_scheme_id"),
+ colorSchemes: parentController.get("model.extras.color_schemes"),
+ editingName: false,
+ userLocale: parentController.get("model.extras.locale"),
+ });
+ }
+
+ @action
+ didTransition() {
+ scrollTop();
+ }
+
+ @action
+ willTransition(transition) {
+ const model = this.controller.model;
+ if (model.warnUnassignedComponent) {
+ transition.abort();
+
+ this.dialog.yesNoConfirm({
+ message: i18n("admin.customize.theme.unsaved_parent_themes"),
+ didConfirm: () => {
+ model.set("recentlyInstalled", false);
+ transition.retry();
+ },
+ didCancel: () => model.set("recentlyInstalled", false),
+ });
+ }
+ }
+}
diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show.js b/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show.js
index 6514fab974e..e65f01c419e 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show.js
@@ -1,12 +1,7 @@
-import { action } from "@ember/object";
-import Route from "@ember/routing/route";
import { service } from "@ember/service";
-import { scrollTop } from "discourse/lib/scroll-top";
-import { i18n } from "discourse-i18n";
-import { COMPONENTS, THEMES } from "admin/models/theme";
+import DiscourseRoute from "discourse/routes/discourse";
-export default class AdminCustomizeThemesShowRoute extends Route {
- @service dialog;
+export default class AdminCustomizeThemesShowRoute extends DiscourseRoute {
@service router;
serialize(model) {
@@ -23,62 +18,15 @@ export default class AdminCustomizeThemesShowRoute extends Route {
}
}
- setupController(controller, model) {
+ setupController(controller) {
super.setupController(...arguments);
const parentController = this.controllerFor("adminCustomizeThemes");
-
- parentController.setProperties({
- editingTheme: false,
- currentTab: model.get("component") ? COMPONENTS : THEMES,
- });
-
- controller.setProperties({
- model,
- parentController,
- allThemes: parentController.get("model"),
- colorSchemeId: model.get("color_scheme_id"),
- colorSchemes: parentController.get("model.extras.color_schemes"),
- editingName: false,
- editingThemeSetting: false,
- userLocale: parentController.get("model.extras.locale"),
- });
-
- this.handleHighlight(model);
- }
-
- deactivate() {
- this.handleHighlight();
- }
-
- handleHighlight(theme) {
- this.get("controller.allThemes")
- .filter((t) => t.get("selected"))
- .forEach((t) => t.set("selected", false));
- if (theme) {
- theme.set("selected", true);
- }
- }
-
- @action
- didTransition() {
- scrollTop();
+ controller.set("allThemes", parentController.get("model"));
}
- @action
- willTransition(transition) {
+ titleToken() {
const model = this.controller.model;
- if (model.warnUnassignedComponent) {
- transition.abort();
-
- this.dialog.yesNoConfirm({
- message: i18n("admin.customize.theme.unsaved_parent_themes"),
- didConfirm: () => {
- model.set("recentlyInstalled", false);
- transition.retry();
- },
- didCancel: () => model.set("recentlyInstalled", false),
- });
- }
+ return model.name;
}
}
diff --git a/app/assets/javascripts/admin/addon/routes/admin-route-map.js b/app/assets/javascripts/admin/addon/routes/admin-route-map.js
index 7021b1b5165..8d2c7c6ed2c 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-route-map.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-route-map.js
@@ -70,6 +70,7 @@ export default function () {
function () {
this.route("show", { path: "/:theme_id" }, function () {
this.route("schema", { path: "schema/:setting_name" });
+ this.route("colors");
});
this.route("edit", { path: "/:theme_id/:target/:field_name/edit" });
}
diff --git a/app/assets/javascripts/admin/addon/templates/customize-themes-show-colors.gjs b/app/assets/javascripts/admin/addon/templates/customize-themes-show-colors.gjs
new file mode 100644
index 00000000000..ecd365cc718
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/templates/customize-themes-show-colors.gjs
@@ -0,0 +1,75 @@
+import Component from "@glimmer/component";
+import { action } from "@ember/object";
+import RouteTemplate from "ember-route-template";
+import { gt } from "truth-helpers";
+import { i18n } from "discourse-i18n";
+import ChangesBanner from "admin/components/changes-banner";
+import ColorPaletteEditor from "admin/components/color-palette-editor";
+
+export default RouteTemplate(
+ class extends Component {
+ get pendingChangesBannerLabel() {
+ return i18n("admin.customize.theme.unsaved_colors", {
+ count: this.args.controller.colorPaletteChangeTracker.dirtyColorsCount,
+ });
+ }
+
+ @action
+ onLightColorChange(color, value) {
+ color.hex = value;
+ if (color.hex !== color.originalHex) {
+ this.args.controller.colorPaletteChangeTracker.addDirtyLightColor(
+ color.name
+ );
+ } else {
+ this.args.controller.colorPaletteChangeTracker.removeDirtyLightColor(
+ color.name
+ );
+ }
+ }
+
+ @action
+ onDarkColorChange(color, value) {
+ color.dark_hex = value;
+ if (color.dark_hex !== color.originalDarkHex) {
+ this.args.controller.colorPaletteChangeTracker.addDirtyDarkColor(
+ color.name
+ );
+ } else {
+ this.args.controller.colorPaletteChangeTracker.removeDirtyDarkColor(
+ color.name
+ );
+ }
+ }
+
+ @action
+ async save() {
+ await this.args.model.changeColors();
+ this.args.controller.colorPaletteChangeTracker.clear();
+ }
+
+ @action
+ discard() {
+ this.args.model.discardColorChanges();
+ this.args.controller.colorPaletteChangeTracker.clear();
+ }
+
+ <template>
+ <ColorPaletteEditor
+ @colors={{@model.colorPalette.colors}}
+ @onLightColorChange={{this.onLightColorChange}}
+ @onDarkColorChange={{this.onDarkColorChange}}
+ @hideRevertButton={{true}}
+ />
+ {{#if (gt @controller.colorPaletteChangeTracker.dirtyColorsCount 0)}}
+ <ChangesBanner
+ @bannerLabel={{this.pendingChangesBannerLabel}}
+ @saveLabel={{i18n "admin.customize.theme.save_colors"}}
+ @discardLabel={{i18n "admin.customize.theme.discard_colors"}}
+ @save={{this.save}}
+ @discard={{this.discard}}
+ />
+ {{/if}}
+ </template>
+ }
+);
diff --git a/app/assets/javascripts/admin/addon/templates/customize-themes-show-index.gjs b/app/assets/javascripts/admin/addon/templates/customize-themes-show-index.gjs
new file mode 100644
index 00000000000..eb8081c30f7
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/templates/customize-themes-show-index.gjs
@@ -0,0 +1,390 @@
+import { fn, hash } from "@ember/helper";
+import RouteTemplate from "ember-route-template";
+import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";
+import DButton from "discourse/components/d-button";
+import PluginOutlet from "discourse/components/plugin-outlet";
+import UserLink from "discourse/components/user-link";
+import icon from "discourse/helpers/d-icon";
+import formatDate from "discourse/helpers/format-date";
+import formatUsername from "discourse/helpers/format-username";
+import lazyHash from "discourse/helpers/lazy-hash";
+import { i18n } from "discourse-i18n";
+import InlineEditCheckbox from "admin/components/inline-edit-checkbox";
+import ThemeSettingEditor from "admin/components/theme-setting-editor";
+import ThemeSettingRelativesSelector from "admin/components/theme-setting-relatives-selector";
+import ThemeTranslation from "admin/components/theme-translation";
+import ColorPalettes from "select-kit/components/color-palettes";
+import ComboBox from "select-kit/components/combo-box";
+
+export default RouteTemplate(
+ <template>
+ <div class="metadata control-unit">
+ {{#if @controller.model.remote_theme}}
+ <div class="control-unit">
+ {{#if @controller.model.remote_theme.is_git}}
+ {{#if @controller.model.remote_theme.commits_behind}}
+ <DButton
+ @action={{@controller.updateToLatest}}
+ @icon="download"
+ @label="admin.customize.theme.update_to_latest"
+ class="btn-primary"
+ />
+ {{else}}
+ <DButton
+ @action={{@controller.checkForThemeUpdates}}
+ @icon="arrows-rotate"
+ @label="admin.customize.theme.check_for_updates"
+ class="btn-default"
+ />
+ {{/if}}
+
+ <span class="status-message">
+ {{#if @controller.updatingRemote}}
+ {{i18n "admin.customize.theme.updating"}}
+ {{else}}
+ {{#if @controller.model.remote_theme.commits_behind}}
+ {{#if @controller.hasOverwrittenHistory}}
+ {{i18n "admin.customize.theme.has_overwritten_history"}}
+ {{else}}
+ {{i18n
+ "admin.customize.theme.commits_behind"
+ [email protected]_theme.commits_behind
+ }}
+ {{/if}}
+ {{#if @controller.model.remote_theme.github_diff_link}}
+ <a href={{@controller.model.remote_theme.github_diff_link}}>
+ {{i18n "admin.customize.theme.compare_commits"}}
+ </a>
+ {{/if}}
+ {{else}}
+ {{#unless @controller.showRemoteError}}
+ {{i18n "admin.customize.theme.up_to_date"}}
+ {{formatDate
+ @controller.model.remote_theme.updated_at
+ leaveAgo="true"
+ }}
+ {{/unless}}
+ {{/if}}
+ {{/if}}
+ </span>
+ {{else}}
+ <span class="status-message">
+ {{icon "circle-info"}}
+ {{i18n "admin.customize.theme.imported_from_archive"}}
+ </span>
+ {{/if}}
+ </div>
+ {{else}}
+ <span class="heading">{{i18n "admin.customize.theme.creator"}}</span>
+ <span>
+ <UserLink @user={{@controller.model.user}}>
+ {{formatUsername @controller.model.user.username}}
+ </UserLink>
+ </span>
+ {{/if}}
+ </div>
+
+ {{#if @controller.showCheckboxes}}
+ <div class="control-unit">
+ {{#unless @controller.model.component}}
+ <InlineEditCheckbox
+ @action={{@controller.applyDefault}}
+ @labelKey="admin.customize.theme.is_default"
+ @checked={{@controller.model.default}}
+ @modelId={{@controller.model.id}}
+ />
+ <InlineEditCheckbox
+ @action={{@controller.applyUserSelectable}}
+ @labelKey="admin.customize.theme.user_selectable"
+ @checked={{@controller.model.user_selectable}}
+ @modelId={{@controller.model.id}}
+ />
+ {{/unless}}
+ {{#if @controller.model.remote_theme}}
+ <InlineEditCheckbox
+ @action={{@controller.applyAutoUpdateable}}
+ @labelKey="admin.customize.theme.auto_update"
+ @checked={{@controller.model.auto_update}}
+ @modelId={{@controller.model.id}}
+ />
+ {{/if}}
+ </div>
+ {{/if}}
+
+ {{#unless @controller.model.component}}
+ {{#unless @controller.siteSettings.use_overhauled_theme_color_palette}}
+ <section
+ class="form-horizontal theme settings control-unit theme-settings__color-scheme"
+ >
+ <div class="row setting">
+ <div class="setting-label">
+ {{i18n "admin.customize.theme.color_scheme"}}
+ </div>
+
+ <div class="setting-value">
+ <div class="color-palette-input-group">
+ <ColorPalettes
+ @content={{@controller.colorSchemes}}
+ @value={{@controller.colorSchemeId}}
+ @icon="paintbrush"
+ @options={{hash filterable=true}}
+ />
+ {{#if @controller.colorSchemeId}}
+ <DButton
+ @icon="pencil"
+ @action={{@controller.editColorScheme}}
+ @title="admin.customize.theme.edit_color_scheme"
+ />
+ {{/if}}
+ </div>
+
+ <div class="desc">{{i18n
+ "admin.customize.theme.color_scheme_select"
+ }}</div>
+ </div>
+
+ <div class="setting-controls">
+ {{#if @controller.colorSchemeChanged}}
+ <DButton
+ @action={{@controller.changeScheme}}
+ @icon="check"
+ class="ok submit-edit"
+ />
+ <DButton
+ @action={{@controller.cancelChangeScheme}}
+ @icon="xmark"
+ class="cancel cancel-edit"
+ />
+ {{/if}}
+ </div>
+ </div>
+ </section>
+ {{/unless}}
+ {{/unless}}
+
+ {{#if @controller.model.component}}
+ <section class="form-horizontal theme settings control-unit">
+ <div class="row setting">
+ <ThemeSettingRelativesSelector
+ @setting={{@controller.relativesSelectorSettingsForComponent}}
+ @model={{@controller.model}}
+ class="theme-setting"
+ />
+ </div>
+ </section>
+ {{else}}
+ <section class="form-horizontal theme settings control-unit">
+ <div class="row setting">
+ <ThemeSettingRelativesSelector
+ @setting={{@controller.relativesSelectorSettingsForTheme}}
+ @model={{@controller.model}}
+ class="theme-setting"
+ />
+ </div>
+ </section>
+ {{/if}}
+
+ {{#unless @controller.model.remote_theme.is_git}}
+ <div class="control-unit">
+ <div class="mini-title">{{i18n "admin.customize.theme.css_html"}}</div>
+ {{#if @controller.model.hasEditedFields}}
+ <div class="description">{{i18n
+ "admin.customize.theme.custom_sections"
+ }}</div>
+ <ul>
+ {{#each @controller.editedFieldsFormatted as |field|}}
+ <li>{{field}}</li>
+ {{/each}}
+ </ul>
+ {{else}}
+ <div class="description">
+ {{i18n "admin.customize.theme.edit_css_html_help"}}
+ </div>
+ {{/if}}
+
+ <DButton
+ @action={{@controller.editTheme}}
+ @label="admin.customize.theme.edit_css_html"
+ class="btn-default edit"
+ />
+ </div>
+
+ <div class="control-unit">
+ <div class="mini-title">{{i18n "admin.customize.theme.uploads"}}</div>
+ {{#if @controller.model.uploads}}
+ <ul class="removable-list">
+ {{#each @controller.model.uploads as |upload|}}
+ <li>
+ {{! template-lint-disable no-unnecessary-curly-strings }}
+ {{! workaround for https://github.com/typed-ember/glint/issues/840 }}
+ <span class="col">{{"$"}}{{upload.name}}:
+ <a
+ href={{upload.url}}
+ rel="noopener noreferrer"
+ target="_blank"
+ >{{upload.filename}}</a></span>
+ <span class="col">
+ <DButton
+ @action={{fn @controller.removeUpload upload}}
+ @icon="xmark"
+ class="second btn-default btn-default cancel-edit"
+ />
+ </span>
+ </li>
+ {{/each}}
+ </ul>
+ {{else}}
+ <div class="description">{{i18n
+ "admin.customize.theme.no_uploads"
+ }}</div>
+ {{/if}}
+ <DButton
+ @action={{@controller.addUploadModal}}
+ @icon="plus"
+ @label="admin.customize.theme.add"
+ class="btn-default"
+ />
+ </div>
+ {{/unless}}
+
+ {{#if @controller.extraFiles.length}}
+ <div class="control-unit">
+ <div class="mini-title">{{i18n
+ "admin.customize.theme.extra_files"
+ }}</div>
+ {{! template-lint-disable no-nested-interactive }}
+ <details>
+ <summary>
+ {{#if @controller.model.remote_theme}}
+ {{i18n "admin.customize.theme.extra_files_remote"}}
+ {{else}}
+ {{i18n "admin.customize.theme.extra_files_upload"}}
+ {{/if}}
+ </summary>
+ <ul>
+ {{#each @controller.extraFiles as |extraFile|}}
+ <li>{{extraFile.name}}</li>
+ {{/each}}
+ </ul>
+ </details>
+ </div>
+ {{/if}}
+
+ {{#if @controller.hasSettings}}
+ <div class="control-unit">
+ <div class="mini-title">{{i18n
+ "admin.customize.theme.theme_settings"
+ }}</div>
+ <p><i>{{i18n
+ "admin.customize.theme.overriden_settings_explanation"
+ }}</i></p>
+ <section class="form-horizontal theme settings control-unit">
+ {{#each @controller.settings as |setting|}}
+ <ThemeSettingEditor
+ @setting={{setting}}
+ @model={{@controller.model}}
+ class="theme-setting control-unit"
+ />
+ {{/each}}
+ </section>
+ </div>
+ {{/if}}
+
+ {{#if @controller.hasTranslations}}
+ <div class="control-unit">
+ <div class="translation-selector-container">
+ <span class="mini-title">
+ {{i18n "admin.customize.theme.theme_translations"}}
+ </span>
+ <ComboBox
+ @valueProperty="value"
+ @content={{@controller.availableLocales}}
+ @value={{@controller.locale}}
+ @onChange={{@controller.updateLocale}}
+ @options={{hash filterable=true}}
+ class="translation-selector"
+ />
+ </div>
+ <ConditionalLoadingSpinner
+ @condition={{@controller.model.loadingTranslations}}
+ >
+ <section
+ class="form-horizontal theme settings translations control-unit"
+ >
+
+ {{#each @controller.translations as |translation|}}
+ <ThemeTranslation
+ @translation={{translation}}
+ @model={{@controller.model}}
+ class="theme-translation"
+ />
+ {{/each}}
+ </section>
+ </ConditionalLoadingSpinner>
+ </div>
+ {{/if}}
+
+ <PluginOutlet
+ @name="admin-customize-theme-before-controls"
+ @outletArgs={{lazyHash [email protected]}}
+ />
+ <div class="theme-controls">
+ <a
+ href={{@controller.previewUrl}}
+ title={{i18n "admin.customize.explain_preview"}}
+ rel="noopener noreferrer"
+ target="_blank"
+ class="btn btn-default"
+ >{{icon "desktop"}}{{i18n "admin.customize.theme.preview"}}</a>
+ <a
+ class="btn btn-default export"
+ rel="noopener noreferrer"
+ target="_blank"
+ href={{@controller.downloadUrl}}
+ >{{icon "download"}} {{i18n "admin.export_json.button_text"}}</a>
+
+ {{#if @controller.showConvert}}
+ <DButton
+ @action={{@controller.switchType}}
+ @label="admin.customize.theme.convert"
+ @icon={{@controller.convertIcon}}
+ @title={{@controller.convertTooltip}}
+ class="btn-default btn-normal"
+ />
+ {{/if}}
+
+ {{#if @controller.model.component}}
+ {{#if @controller.model.enabled}}
+ <DButton
+ @action={{@controller.disableComponent}}
+ @icon="ban"
+ @label="admin.customize.theme.disable"
+ class="btn-default"
+ />
+ {{else}}
+ <DButton
+ @action={{@controller.enableComponent}}
+ @icon="check"
+ @label="admin.customize.theme.enable"
+ class="btn-default"
+ />
+ {{/if}}
+ {{/if}}
+ {{#if @controller.hasSettings}}
+ <DButton
+ @action={{@controller.showThemeSettingsEditor}}
+ @label="admin.customize.theme.settings_editor"
+ @icon="pencil"
+ @title="admin.customize.theme.settings_editor"
+ class="btn-default btn-normal"
+ />
+ {{/if}}
+ <DButton
+ @action={{@controller.destroyTheme}}
+ @label="admin.customize.delete"
+ @icon="trash-can"
+ class="btn-danger"
+ />
+ </div>
+ </template>
+);
diff --git a/app/assets/javascripts/admin/addon/templates/customize-themes-show.gjs b/app/assets/javascripts/admin/addon/templates/customize-themes-show.gjs
index 0ec1131ab33..97b3988025c 100644
--- a/app/assets/javascripts/admin/addon/templates/customize-themes-show.gjs
+++ b/app/assets/javascripts/admin/addon/templates/customize-themes-show.gjs
@@ -1,30 +1,21 @@
-import { fn, hash } from "@ember/helper";
import { LinkTo } from "@ember/routing";
import RouteTemplate from "ember-route-template";
-import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";
import DButton from "discourse/components/d-button";
+import DPageHeader from "discourse/components/d-page-header";
+import NavItem from "discourse/components/nav-item";
import PluginOutlet from "discourse/components/plugin-outlet";
import TextField from "discourse/components/text-field";
import UserLink from "discourse/components/user-link";
import avatar from "discourse/helpers/avatar";
import icon from "discourse/helpers/d-icon";
import formatDate from "discourse/helpers/format-date";
-import formatUsername from "discourse/helpers/format-username";
import htmlSafe from "discourse/helpers/html-safe";
import lazyHash from "discourse/helpers/lazy-hash";
import { i18n } from "discourse-i18n";
-import InlineEditCheckbox from "admin/components/inline-edit-checkbox";
-import ThemeSettingEditor from "admin/components/theme-setting-editor";
-import ThemeSettingRelativesSelector from "admin/components/theme-setting-relatives-selector";
-import ThemeTranslation from "admin/components/theme-translation";
-import ColorPalettes from "select-kit/components/color-palettes";
-import ComboBox from "select-kit/components/combo-box";
export default RouteTemplate(
<template>
- {{#if @controller.editingThemeSetting}}
- {{outlet}}
- {{else}}
+ <div class="show-current-style">
<div class="back-to-themes-and-components">
<LinkTo
@route={{if
@@ -43,582 +34,231 @@ export default RouteTemplate(
}}
</LinkTo>
</div>
- <div class="show-current-style">
- <span>
- <PluginOutlet
- @name="admin-customize-themes-show-top"
- @connectorTagName="div"
- @outletArgs={{lazyHash [email protected]}}
- />
- </span>
-
- <div class="title">
- {{#if @controller.editingName}}
- <TextField @value={{@controller.model.name}} @autofocus="true" />
- <DButton
- @action={{@controller.finishedEditingName}}
- @icon="check"
- class="btn-primary btn-small submit-edit"
- />
- <DButton
- @action={{@controller.cancelEditingName}}
- @icon="xmark"
- class="btn-small cancel-edit"
- />
- {{else}}
- <span>{{@controller.model.name}}</span>
- <DButton
- @action={{@controller.startEditingName}}
- @icon="pencil"
- class="btn-small"
- />
- {{/if}}
- </div>
+ <span>
<PluginOutlet
- @name="admin-customize-theme-before-errors"
+ @name="admin-customize-themes-show-top"
+ @connectorTagName="div"
@outletArgs={{lazyHash [email protected]}}
/>
-
- {{#each @controller.model.errors as |error|}}
- <div class="alert alert-error">{{error}}</div>
- {{/each}}
-
- {{#if @controller.finishInstall}}
- <div class="control-unit">
- {{#if @controller.sourceIsHttp}}
- <a class="remote-url" href={{@controller.remoteThemeLink}}>{{i18n
- "admin.customize.theme.source_url"
- }}{{icon "link"}}</a>
- {{else}}
- <div class="remote-url">
- <code>{{@controller.model.remote_theme.remote_url}}</code>
- {{#if @controller.model.remote_theme.branch}}
- (<code>{{@controller.model.remote_theme.branch}}</code>)
- {{/if}}
- </div>
- {{/if}}
-
- {{#if @controller.showRemoteError}}
- <div class="error-message">
- {{icon "triangle-exclamation"}}
- {{i18n "admin.customize.theme.repo_unreachable"}}
- </div>
- <div class="raw-error">
- <code>{{@controller.model.remoteError}}</code>
- </div>
- {{/if}}
-
- <DButton
- @action={{@controller.updateToLatest}}
- @icon="download"
- @label="admin.customize.theme.finish_install"
- class="btn-primary finish-install"
- />
- <DButton
- @action={{@controller.destroyTheme}}
- @label="admin.customize.delete"
- @icon="trash-can"
- class="btn-danger"
- />
-
- <span class="status-message">
- {{i18n "admin.customize.theme.last_attempt"}}
- {{formatDate
- @controller.model.remote_theme.updated_at
- leaveAgo="true"
- }}
- </span>
- </div>
+ </span>
+
+ <div class="title">
+ {{#if @controller.editingName}}
+ <TextField @value={{@controller.model.name}} @autofocus="true" />
+ <DButton
+ @action={{@controller.finishedEditingName}}
+ @icon="check"
+ class="btn-primary btn-small submit-edit"
+ />
+ <DButton
+ @action={{@controller.cancelEditingName}}
+ @icon="xmark"
+ class="btn-small cancel-edit"
+ />
{{else}}
- {{#unless @controller.model.supported}}
- <div class="alert alert-error">
- {{i18n "admin.customize.theme.required_version.error"}}
- {{#if @controller.model.remote_theme.minimum_discourse_version}}
- {{i18n
- "admin.customize.theme.required_version.minimum"
- [email protected]_theme.minimum_discourse_version
- }}
- {{/if}}
- {{#if @controller.model.remote_theme.maximum_discourse_version}}
- {{i18n
- "admin.customize.theme.required_version.maximum"
- [email protected]_theme.maximum_discourse_version
- }}
- {{/if}}
- </div>
- {{/unless}}
+ <span>{{@controller.model.name}}</span>
+ <DButton
+ @action={{@controller.startEditingName}}
+ @icon="pencil"
+ class="btn-small"
+ />
+ {{/if}}
+ </div>
- {{#unless @controller.model.enabled}}
- <div class="alert alert-error">
- {{#if @controller.model.disabled_by}}
- {{i18n "admin.customize.theme.disabled_by"}}
- <UserLink @user={{@controller.model.disabled_by}}>
- {{avatar @controller.model.disabled_by imageSize="tiny"}}
- {{@controller.model.disabled_by.username}}
- </UserLink>
- {{formatDate @controller.model.disabled_at leaveAgo="true"}}
- {{else}}
- {{i18n "admin.customize.theme.disabled"}}
+ <PluginOutlet
+ @name="admin-customize-theme-before-errors"
+ @outletArgs={{lazyHash [email protected]}}
+ />
+
+ {{#each @controller.model.errors as |error|}}
+ <div class="alert alert-error">{{error}}</div>
+ {{/each}}
+
+ {{#if @controller.finishInstall}}
+ <div class="control-unit">
+ {{#if @controller.sourceIsHttp}}
+ <a class="remote-url" href={{@controller.remoteThemeLink}}>{{i18n
+ "admin.customize.theme.source_url"
+ }}{{icon "link"}}</a>
+ {{else}}
+ <div class="remote-url">
+ <code>{{@controller.model.remote_theme.remote_url}}</code>
+ {{#if @controller.model.remote_theme.branch}}
+ (<code>{{@controller.model.remote_theme.branch}}</code>)
{{/if}}
- <DButton
- @action={{@controller.enableComponent}}
- @icon="check"
- @label="admin.customize.theme.enable"
- class="btn-default"
- />
</div>
- {{/unless}}
-
- <div class="metadata control-unit">
- {{#if @controller.model.remote_theme}}
- {{#if @controller.model.remote_theme.remote_url}}
- {{#if @controller.sourceIsHttp}}
- <a
- class="remote-url"
- href={{@controller.remoteThemeLink}}
- >{{i18n "admin.customize.theme.source_url"}}{{icon
- "link"
- }}</a>
- {{else}}
- <div class="remote-url">
- <code>{{@controller.model.remote_theme.remote_url}}</code>
- {{#if @controller.model.remote_theme.branch}}
- (<code>{{@controller.model.remote_theme.branch}}</code>)
- {{/if}}
- </div>
- {{/if}}
- {{/if}}
-
- {{#if @controller.model.remote_theme.about_url}}
- <a
- class="url about-url"
- href={{@controller.model.remote_theme.about_url}}
- >{{i18n "admin.customize.theme.about_theme"}}{{icon "link"}}</a>
- {{/if}}
-
- {{#if @controller.model.remote_theme.license_url}}
- <a
- class="url license-url"
- href={{@controller.model.remote_theme.license_url}}
- >{{i18n "admin.customize.theme.license"}}{{icon "link"}}</a>
- {{/if}}
-
- {{#if @controller.model.description}}
- <span
- class="theme-description"
- >{{@controller.model.description}}</span>
- {{/if}}
-
- {{#if @controller.model.remote_theme.authors}}<span
- class="authors"
- ><span class="heading">{{i18n
- "admin.customize.theme.authors"
- }}</span>
- {{@controller.model.remote_theme.authors}}</span>{{/if}}
-
- {{#if @controller.model.remote_theme.theme_version}}<span
- class="version"
- ><span class="heading">{{i18n
- "admin.customize.theme.version"
- }}</span>
- {{@controller.model.remote_theme.theme_version}}</span>{{/if}}
-
- <div class="control-unit">
- {{#if @controller.model.remote_theme.is_git}}
- <div class="alert alert-info">
- {{htmlSafe
- (i18n
- "admin.customize.theme.remote_theme_edits"
- )
- }}
- </div>
+ {{/if}}
- {{#if @controller.showRemoteError}}
- <div class="error-message">
- {{icon "triangle-exclamation"}}
- {{i18n "admin.customize.theme.repo_unreachable"}}
- </div>
- <div class="raw-error">
- <code>{{@controller.model.remoteError}}</code>
- </div>
- {{/if}}
+ {{#if @controller.showRemoteError}}
+ <div class="error-message">
+ {{icon "triangle-exclamation"}}
+ {{i18n "admin.customize.theme.repo_unreachable"}}
+ </div>
+ <div class="raw-error">
+ <code>{{@controller.model.remoteError}}</code>
+ </div>
+ {{/if}}
- {{#if @controller.model.remote_theme.commits_behind}}
- <DButton
- @action={{@controller.updateToLatest}}
- @icon="download"
- @label="admin.customize.theme.update_to_latest"
- class="btn-primary"
- />
- {{else}}
- <DButton
- @action={{@controller.checkForThemeUpdates}}
- @icon="arrows-rotate"
- @label="admin.customize.theme.check_for_updates"
- class="btn-default"
- />
- {{/if}}
+ <DButton
+ @action={{@controller.updateToLatest}}
+ @icon="download"
+ @label="admin.customize.theme.finish_install"
+ class="btn-primary finish-install"
+ />
+ <DButton
+ @action={{@controller.destroyTheme}}
+ @label="admin.customize.delete"
+ @icon="trash-can"
+ class="btn-danger"
+ />
- <span class="status-message">
- {{#if @controller.updatingRemote}}
- {{i18n "admin.customize.theme.updating"}}
- {{else}}
- {{#if @controller.model.remote_theme.commits_behind}}
- {{#if @controller.hasOverwrittenHistory}}
- {{i18n
- "admin.customize.theme.has_overwritten_history"
- }}
- {{else}}
- {{i18n
- "admin.customize.theme.commits_behind"
- [email protected]_theme.commits_behind
- }}
- {{/if}}
- {{#if @controller.model.remote_theme.github_diff_link}}
- <a
- href={{@controller.model.remote_theme.github_diff_link}}
- >
- {{i18n "admin.customize.theme.compare_commits"}}
- </a>
- {{/if}}
- {{else}}
- {{#unless @controller.showRemoteError}}
- {{i18n "admin.customize.theme.up_to_date"}}
- {{formatDate
- @controller.model.remote_theme.updated_at
- leaveAgo="true"
- }}
- {{/unless}}
- {{/if}}
- {{/if}}
- </span>
- {{else}}
- <span class="status-message">
- {{icon "circle-info"}}
- {{i18n "admin.customize.theme.imported_from_archive"}}
- </span>
- {{/if}}
- </div>
+ <span class="status-message">
+ {{i18n "admin.customize.theme.last_attempt"}}
+ {{formatDate
+ @controller.model.remote_theme.updated_at
+ leaveAgo="true"
+ }}
+ </span>
+ </div>
+ {{else}}
+ {{#unless @controller.model.supported}}
+ <div class="alert alert-error">
+ {{i18n "admin.customize.theme.required_version.error"}}
+ {{#if @controller.model.remote_theme.minimum_discourse_version}}
+ {{i18n
+ "admin.customize.theme.required_version.minimum"
+ [email protected]_theme.minimum_discourse_version
+ }}
+ {{/if}}
+ {{#if @controller.model.remote_theme.maximum_discourse_version}}
+ {{i18n
+ "admin.customize.theme.required_version.maximum"
+ [email protected]_theme.maximum_discourse_version
+ }}
+ {{/if}}
+ </div>
+ {{/unless}}
+
+ {{#unless @controller.model.enabled}}
+ <div class="alert alert-error">
+ {{#if @controller.model.disabled_by}}
+ {{i18n "admin.customize.theme.disabled_by"}}
+ <UserLink @user={{@controller.model.disabled_by}}>
+ {{avatar @controller.model.disabled_by imageSize="tiny"}}
+ {{@controller.model.disabled_by.username}}
+ </UserLink>
+ {{formatDate @controller.model.disabled_at leaveAgo="true"}}
{{else}}
- <span class="heading">{{i18n
- "admin.customize.theme.creator"
- }}</span>
- <span>
- <UserLink @user={{@controller.model.user}}>
- {{formatUsername @controller.model.user.username}}
- </UserLink>
- </span>
+ {{i18n "admin.customize.theme.disabled"}}
{{/if}}
+ <DButton
+ @action={{@controller.enableComponent}}
+ @icon="check"
+ @label="admin.customize.theme.enable"
+ class="btn-default"
+ />
</div>
+ {{/unless}}
- {{#if @controller.showCheckboxes}}
- <div class="control-unit">
- {{#unless @controller.model.component}}
- <InlineEditCheckbox
- @action={{@controller.applyDefault}}
- @labelKey="admin.customize.theme.is_default"
- @checked={{@controller.model.default}}
- @modelId={{@controller.model.id}}
- />
- <InlineEditCheckbox
- @action={{@controller.applyUserSelectable}}
- @labelKey="admin.customize.theme.user_selectable"
- @checked={{@controller.model.user_selectable}}
- @modelId={{@controller.model.id}}
- />
- {{/unless}}
- {{#if @controller.model.remote_theme}}
- <InlineEditCheckbox
- @action={{@controller.applyAutoUpdateable}}
- @labelKey="admin.customize.theme.auto_update"
- @checked={{@controller.model.auto_update}}
- @modelId={{@controller.model.id}}
- />
- {{/if}}
- </div>
- {{/if}}
-
- {{#unless @controller.model.component}}
- <section
- class="form-horizontal theme settings control-unit theme-settings__color-scheme"
- >
- <div class="row setting">
- <div class="setting-label">
- {{i18n "admin.customize.theme.color_scheme"}}
- </div>
-
- <div class="setting-value">
- <div class="color-palette-input-group">
- <ColorPalettes
- @content={{@controller.colorSchemes}}
- @value={{@controller.colorSchemeId}}
- @icon="paintbrush"
- @options={{hash filterable=true}}
- />
- {{#if @controller.colorSchemeId}}
- <DButton
- @icon="pencil"
- @action={{@controller.editColorScheme}}
- @title="admin.customize.theme.edit_color_scheme"
- />
- {{/if}}
- </div>
-
- <div class="desc">{{i18n
- "admin.customize.theme.color_scheme_select"
- }}</div>
- </div>
-
- <div class="setting-controls">
- {{#if @controller.colorSchemeChanged}}
- <DButton
- @action={{@controller.changeScheme}}
- @icon="check"
- class="ok submit-edit"
- />
- <DButton
- @action={{@controller.cancelChangeScheme}}
- @icon="xmark"
- class="cancel cancel-edit"
- />
- {{/if}}
- </div>
- </div>
- </section>
- {{/unless}}
-
- {{#if @controller.model.component}}
- <section class="form-horizontal theme settings control-unit">
- <div class="row setting">
- <ThemeSettingRelativesSelector
- @setting={{@controller.relativesSelectorSettingsForComponent}}
- @model={{@controller.model}}
- class="theme-setting"
- />
- </div>
- </section>
- {{else}}
- <section class="form-horizontal theme settings control-unit">
- <div class="row setting">
- <ThemeSettingRelativesSelector
- @setting={{@controller.relativesSelectorSettingsForTheme}}
- @model={{@controller.model}}
- class="theme-setting"
- />
- </div>
- </section>
- {{/if}}
-
- {{#unless @controller.model.remote_theme.is_git}}
- <div class="control-unit">
- <div class="mini-title">{{i18n
- "admin.customize.theme.css_html"
- }}</div>
- {{#if @controller.model.hasEditedFields}}
- <div class="description">{{i18n
- "admin.customize.theme.custom_sections"
- }}</div>
- <ul>
- {{#each @controller.editedFieldsFormatted as |field|}}
- <li>{{field}}</li>
- {{/each}}
- </ul>
+ <div class="metadata control-unit remote-theme-metadata">
+ {{#if @controller.model.remote_theme}}
+ {{#if @controller.model.remote_theme.remote_url}}
+ {{#if @controller.sourceIsHttp}}
+ <a
+ class="remote-url"
+ href={{@controller.remoteThemeLink}}
+ >{{i18n "admin.customize.theme.source_url"}}{{icon "link"}}</a>
{{else}}
- <div class="description">
- {{i18n "admin.customize.theme.edit_css_html_help"}}
+ <div class="remote-url">
+ <code>{{@controller.model.remote_theme.remote_url}}</code>
+ {{#if @controller.model.remote_theme.branch}}
+ (<code>{{@controller.model.remote_theme.branch}}</code>)
+ {{/if}}
</div>
{{/if}}
+ {{/if}}
- <DButton
- @action={{@controller.editTheme}}
- @label="admin.customize.theme.edit_css_html"
- class="btn-default edit"
- />
- </div>
-
- <div class="control-unit">
- <div class="mini-title">{{i18n
- "admin.customize.theme.uploads"
- }}</div>
- {{#if @controller.model.uploads}}
- <ul class="removable-list">
- {{#each @controller.model.uploads as |upload|}}
- <li>
- {{! template-lint-disable no-unnecessary-curly-strings }}
- {{! workaround for https://github.com/typed-ember/glint/issues/840 }}
- <span class="col">{{"$"}}{{upload.name}}:
- <a
- href={{upload.url}}
- rel="noopener noreferrer"
- target="_blank"
- >{{upload.filename}}</a></span>
- <span class="col">
- <DButton
- @action={{fn @controller.removeUpload upload}}
- @icon="xmark"
- class="second btn-default btn-default cancel-edit"
- />
- </span>
- </li>
- {{/each}}
- </ul>
- {{else}}
- <div class="description">{{i18n
- "admin.customize.theme.no_uploads"
- }}</div>
- {{/if}}
- <DButton
- @action={{@controller.addUploadModal}}
- @icon="plus"
- @label="admin.customize.theme.add"
- class="btn-default"
- />
- </div>
- {{/unless}}
+ {{#if @controller.model.remote_theme.about_url}}
+ <a
+ class="url about-url"
+ href={{@controller.model.remote_theme.about_url}}
+ >{{i18n "admin.customize.theme.about_theme"}}{{icon "link"}}</a>
+ {{/if}}
- {{#if @controller.extraFiles.length}}
- <div class="control-unit">
- <div class="mini-title">{{i18n
- "admin.customize.theme.extra_files"
- }}</div>
- {{! template-lint-disable no-nested-interactive }}
- <details>
- <summary>
- {{#if @controller.model.remote_theme}}
- {{i18n "admin.customize.theme.extra_files_remote"}}
- {{else}}
- {{i18n "admin.customize.theme.extra_files_upload"}}
- {{/if}}
- </summary>
- <ul>
- {{#each @controller.extraFiles as |extraFile|}}
- <li>{{extraFile.name}}</li>
- {{/each}}
- </ul>
- </details>
- </div>
- {{/if}}
+ {{#if @controller.model.remote_theme.license_url}}
+ <a
+ class="url license-url"
+ href={{@controller.model.remote_theme.license_url}}
+ >{{i18n "admin.customize.theme.license"}}{{icon "link"}}</a>
+ {{/if}}
- {{#if @controller.hasSettings}}
- <div class="control-unit">
- <div class="mini-title">{{i18n
- "admin.customize.theme.theme_settings"
- }}</div>
- <p><i>{{i18n
- "admin.customize.theme.overriden_settings_explanation"
- }}</i></p>
- <section class="form-horizontal theme settings control-unit">
- {{#each @controller.settings as |setting|}}
- <ThemeSettingEditor
- @setting={{setting}}
- @model={{@controller.model}}
- class="theme-setting control-unit"
- />
- {{/each}}
- </section>
- </div>
- {{/if}}
+ {{#if @controller.model.description}}
+ <span
+ class="theme-description"
+ >{{@controller.model.description}}</span>
+ {{/if}}
- {{#if @controller.hasTranslations}}
- <div class="control-unit">
- <div class="translation-selector-container">
- <span class="mini-title">
- {{i18n "admin.customize.theme.theme_translations"}}
- </span>
- <ComboBox
- @valueProperty="value"
- @content={{@controller.availableLocales}}
- @value={{@controller.locale}}
- @onChange={{@controller.updateLocale}}
- @options={{hash filterable=true}}
- class="translation-selector"
- />
+ {{#if @controller.model.remote_theme.authors}}<span
+ class="authors"
+ ><span class="heading">{{i18n
+ "admin.customize.theme.authors"
+ }}</span>
+ {{@controller.model.remote_theme.authors}}</span>{{/if}}
+
+ {{#if @controller.model.remote_theme.theme_version}}<span
+ class="version"
+ ><span class="heading">{{i18n
+ "admin.customize.theme.version"
+ }}</span>
+ {{@controller.model.remote_theme.theme_version}}</span>{{/if}}
+
+ {{#if @controller.model.remote_theme.is_git}}
+ <div class="alert alert-info remote-theme-edits">
+ {{htmlSafe
+ (i18n
+ "admin.customize.theme.remote_theme_edits"
+ )
+ }}
</div>
- <ConditionalLoadingSpinner
- @condition={{@controller.model.loadingTranslations}}
- >
- <section
- class="form-horizontal theme settings translations control-unit"
- >
-
- {{#each @controller.translations as |translation|}}
- <ThemeTranslation
- @translation={{translation}}
- @model={{@controller.model}}
- class="theme-translation"
- />
- {{/each}}
- </section>
- </ConditionalLoadingSpinner>
- </div>
- {{/if}}
-
- <PluginOutlet
- @name="admin-customize-theme-before-controls"
- @outletArgs={{lazyHash [email protected]}}
- />
- <div class="theme-controls">
- <a
- href={{@controller.previewUrl}}
- title={{i18n "admin.customize.explain_preview"}}
- rel="noopener noreferrer"
- target="_blank"
- class="btn btn-default"
- >{{icon "desktop"}}{{i18n "admin.customize.theme.preview"}}</a>
- <a
- class="btn btn-default export"
- rel="noopener noreferrer"
- target="_blank"
- href={{@controller.downloadUrl}}
- >{{icon "download"}} {{i18n "admin.export_json.button_text"}}</a>
- {{#if @controller.showConvert}}
- <DButton
- @action={{@controller.switchType}}
- @label="admin.customize.theme.convert"
- @icon={{@controller.convertIcon}}
- @title={{@controller.convertTooltip}}
- class="btn-default btn-normal"
- />
+ {{#if @controller.showRemoteError}}
+ <div class="error-message">
+ {{icon "triangle-exclamation"}}
+ {{i18n "admin.customize.theme.repo_unreachable"}}
+ </div>
+ <div class="raw-error">
+ <code>{{@controller.model.remoteError}}</code>
+ </div>
+ {{/if}}
{{/if}}
+ {{/if}}
+ </div>
- {{#if @controller.model.component}}
- {{#if @controller.model.enabled}}
- <DButton
- @action={{@controller.disableComponent}}
- @icon="ban"
- @label="admin.customize.theme.disable"
- class="btn-default"
+ {{#if @controller.siteSettings.use_overhauled_theme_color_palette}}
+ {{#unless @controller.model.component}}
+ <DPageHeader>
+ <:tabs>
+ <NavItem
+ class="admin-customize-theme-tabs__settings"
+ @route="adminCustomizeThemes.show.index"
+ @routeParam={{@controller.model.id}}
+ @label="admin.customize.theme.settings"
/>
- {{else}}
- <DButton
- @action={{@controller.enableComponent}}
- @icon="check"
- @label="admin.customize.theme.enable"
- class="btn-default"
+ <NavItem
+ class="admin-customize-theme-tabs__colors"
+ @route="adminCustomizeThemes.show.colors"
+ @routeParam={{@controller.model.id}}
+ @label="admin.customize.theme.colors"
/>
- {{/if}}
- {{/if}}
- {{#if @controller.hasSettings}}
- <DButton
- @action={{@controller.showThemeSettingsEditor}}
- @label="admin.customize.theme.settings_editor"
- @icon="pencil"
- @title="admin.customize.theme.settings_editor"
- class="btn-default btn-normal"
- />
- {{/if}}
- <DButton
- @action={{@controller.destroyTheme}}
- @label="admin.customize.delete"
- @icon="trash-can"
- class="btn-danger"
- />
- </div>
+ </:tabs>
+ </DPageHeader>
+ {{/unless}}
{{/if}}
- </div>
- {{/if}}
+
+ {{outlet}}
+ {{/if}}
+ </div>
</template>
);
diff --git a/app/assets/javascripts/discourse/app/components/d-page-header.gjs b/app/assets/javascripts/discourse/app/components/d-page-header.gjs
index 97af113430e..92349a7e6c3 100644
--- a/app/assets/javascripts/discourse/app/components/d-page-header.gjs
+++ b/app/assets/javascripts/discourse/app/components/d-page-header.gjs
@@ -62,65 +62,69 @@ export default class DPageHeader extends Component {
<template>
{{#if this.shouldDisplay}}
<div class="d-page-header">
- <div class="d-page-header__breadcrumbs">
- <DBreadcrumbsContainer />
- {{yield to="breadcrumbs"}}
- </div>
+ {{#if (has-block "breadcrumbs")}}
+ <div class="d-page-header__breadcrumbs">
+ <DBreadcrumbsContainer />
+ {{yield to="breadcrumbs"}}
+ </div>
+ {{/if}}
- <div class="d-page-header__title-row">
- {{#if @titleLabel}}
- <h1 class="d-page-header__title">{{@titleLabel}}</h1>
- {{/if}}
+ {{#if (or @titleLabel (has-block "actions") @headerActionComponent)}}
+ <div class="d-page-header__title-row">
+ {{#if @titleLabel}}
+ <h1 class="d-page-header__title">{{@titleLabel}}</h1>
+ {{/if}}
- {{#if (or (has-block "actions") @headerActionComponent)}}
- <div class="d-page-header__actions">
- {{#if this.site.mobileView}}
- <DMenu
- @identifier="d-page-header-mobile-actions"
- @title={{i18n "more_options"}}
- @icon="ellipsis-vertical"
- class="btn-small"
- >
- <:content>
- <DropdownMenu class="d-page-header__mobile-actions">
- {{#let
- (hash
- Primary=DefaultActionListItem
- Default=DefaultActionListItem
- Danger=DangerActionListItem
- Wrapped=WrappedActionListItem
- )
- as |actions|
- }}
- {{#if (has-block "actions")}}
- {{yield actions to="actions"}}
- {{else}}
- <@headerActionComponent @actions={{actions}} />
- {{/if}}
- {{/let}}
- </DropdownMenu>
- </:content>
- </DMenu>
- {{else}}
- {{#let
- (hash
- Primary=PrimaryButton
- Default=DefaultButton
- Danger=DangerButton
- Wrapped=WrappedButton
- )
- as |actions|
- }}
- {{#if (has-block "actions")}}
- {{yield actions to="actions"}}
- {{else}}
- <@headerActionComponent @actions={{actions}} />
- {{/if}}
- {{/let}}
- {{/if}}
- </div>
- {{/if}}
- </div>
+ {{#if (or (has-block "actions") @headerActionComponent)}}
+ <div class="d-page-header__actions">
+ {{#if this.site.mobileView}}
+ <DMenu
+ @identifier="d-page-header-mobile-actions"
+ @title={{i18n "more_options"}}
+ @icon="ellipsis-vertical"
+ class="btn-small"
+ >
+ <:content>
+ <DropdownMenu class="d-page-header__mobile-actions">
+ {{#let
+ (hash
+ Primary=DefaultActionListItem
+ Default=DefaultActionListItem
+ Danger=DangerActionListItem
+ Wrapped=WrappedActionListItem
+ )
+ as |actions|
+ }}
+ {{#if (has-block "actions")}}
+ {{yield actions to="actions"}}
+ {{else}}
+ <@headerActionComponent @actions={{actions}} />
+ {{/if}}
+ {{/let}}
+ </DropdownMenu>
+ </:content>
+ </DMenu>
+ {{else}}
+ {{#let
+ (hash
+ Primary=PrimaryButton
+ Default=DefaultButton
+ Danger=DangerButton
+ Wrapped=WrappedButton
+ )
+ as |actions|
+ }}
+ {{#if (has-block "actions")}}
+ {{yield actions to="actions"}}
+ {{else}}
+ <@headerActionComponent @actions={{actions}} />
+ {{/if}}
+ {{/let}}
+ {{/if}}
+ </div>
+ {{/if}}
+ </div>
+ {{/if}}
{{#if @descriptionLabel}}
<p class="d-page-header__description">
diff --git a/app/assets/javascripts/discourse/tests/integration/components/color-palette-editor-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/color-palette-editor-test.gjs
index 5c7aa49242e..ff7de87d96e 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/color-palette-editor-test.gjs
+++ b/app/assets/javascripts/discourse/tests/integration/components/color-palette-editor-test.gjs
@@ -209,11 +209,13 @@ module("Integration | Component | ColorPaletteEditor", function (hooks) {
const lightChanges = [];
const darkChanges = [];
- const onLightColorChange = (name, value) => {
- lightChanges.push([name, value]);
+ const onLightColorChange = (color, value) => {
+ lightChanges.push([color.name, value]);
+ color.hex = value;
};
- const onDarkColorChange = (name, value) => {
- darkChanges.push([name, value]);
+ const onDarkColorChange = (color, value) => {
+ darkChanges.push([color.name, value]);
+ color.dark_hex = value;
};
await render(
@@ -238,15 +240,15 @@ module("Integration | Component | ColorPaletteEditor", function (hooks) {
"abcdef",
"text input value for the primary color updates for `input` events"
);
- assert.strictEqual(
- lightChanges.length,
- 0,
- "light color change callbacks aren't triggered for `input` events"
+ assert.deepEqual(
+ lightChanges,
+ [["primary", "abcdef"]],
+ "light color change callbacks are triggered for `input` events"
);
assert.strictEqual(
darkChanges.length,
0,
- "dark color change callbacks aren't triggered for `input` events"
+ "dark color change callbacks aren't triggered for `input` events when the light color changes"
);
await this.subject.color("primary").sendColorChangeEvent("#fedcba");
@@ -263,8 +265,11 @@ module("Integration | Component | ColorPaletteEditor", function (hooks) {
);
assert.deepEqual(
lightChanges,
- [["primary", "fedcba"]],
- "light color change callbacks are triggered for `change` eventswhen the light color changes"
+ [
+ ["primary", "abcdef"],
+ ["primary", "fedcba"],
+ ],
+ "light color change callbacks are triggered for `change` events when the light color changes"
);
assert.strictEqual(
@@ -306,12 +311,12 @@ module("Integration | Component | ColorPaletteEditor", function (hooks) {
assert.strictEqual(
lightChanges.length,
0,
- "light color change callbacks aren't triggered for `input` events"
+ "light color change callbacks aren't triggered for `input` events when the dark color changes"
);
- assert.strictEqual(
- darkChanges.length,
- 0,
- "dark color change callbacks aren't triggered for `input` events"
+ assert.deepEqual(
+ darkChanges,
+ [["header_background", "776655"]],
+ "dark color change callbacks are triggered for `input` events"
);
await this.subject
@@ -330,8 +335,11 @@ module("Integration | Component | ColorPaletteEditor", function (hooks) {
);
assert.deepEqual(
darkChanges,
- [["header_background", "99aaff"]],
- "dark color change callbacks are triggered for `change` eventswhen the dark color changes"
+ [
+ ["header_background", "776655"],
+ ["header_background", "99aaff"],
+ ],
+ "dark color change callbacks are triggered for `change` events when the dark color changes"
);
assert.strictEqual(
@@ -401,11 +409,13 @@ module("Integration | Component | ColorPaletteEditor", function (hooks) {
const lightChanges = [];
const darkChanges = [];
- const onLightColorChange = (name, value) => {
- lightChanges.push([name, value]);
+ const onLightColorChange = (color, value) => {
+ lightChanges.push([color.name, value]);
+ color.hex = value;
};
- const onDarkColorChange = (name, value) => {
- darkChanges.push([name, value]);
+ const onDarkColorChange = (color, value) => {
+ darkChanges.push([color.name, value]);
+ color.dark_hex = value;
};
await render(
@@ -497,4 +507,249 @@ module("Integration | Component | ColorPaletteEditor", function (hooks) {
"the text input value shows the 6 digits format"
);
});
+
+ test("validates hex color input", async function (assert) {
+ const colors = [
+ {
+ name: "primary",
+ hex: "aaaaaa",
+ dark_hex: "1e3c8a",
+ },
+ ].map((data) => ColorSchemeColor.create(data));
+
+ const lightChanges = [];
+
+ const onLightColorChange = (color, value) => {
+ lightChanges.push([color.name, value]);
+ color.hex = value;
+ };
+
+ await render(
+ <template>
+ <ColorPaletteEditor
+ @colors={{colors}}
+ @onLightColorChange={{onLightColorChange}}
+ />
+ </template>
+ );
+
+ await this.subject.color("primary").sendTextChangeEvent("333333");
+ assert.strictEqual(
+ this.subject.color("primary").colorInput().value,
+ "#333333",
+ "valid 6-digit hex color is accepted"
+ );
+ assert.deepEqual(
+ lightChanges,
+ [["primary", "333333"]],
+ "light color change callback is called with the expanded value"
+ );
+ lightChanges.length = 0;
+
+ await this.subject.color("primary").sendTextChangeEvent("abc");
+ assert.strictEqual(
+ this.subject.color("primary").colorInput().value,
+ "#aabbcc",
+ "valid 3-digit hex color is accepted and expanded"
+ );
+ assert.deepEqual(
+ lightChanges,
+ [["primary", "aabbcc"]],
+ "light color change callback is called with the expanded value"
+ );
+ lightChanges.length = 0;
+
+ await this.subject.color("primary").sendTextChangeEvent("gggggg");
+ assert.strictEqual(
+ this.subject.color("primary").colorInput().value,
+ "#aabbcc",
+ "invalid hex color is rejected"
+ );
+ assert.strictEqual(
+ lightChanges.length,
+ 0,
+ "light color change callback is not called"
+ );
+ });
+
+ test("keypress events handle hex validation", async function (assert) {
+ const colors = [
+ {
+ name: "primary",
+ hex: "aaaaaa",
+ dark_hex: "1e3c8a",
+ },
+ ].map((data) => ColorSchemeColor.create(data));
+
+ await render(
+ <template><ColorPaletteEditor @colors={{colors}} /></template>
+ );
+
+ const textInput = this.subject.color("primary").textInput();
+ const event = new KeyboardEvent("keypress", {
+ key: "g",
+ bubbles: true,
+ cancelable: true,
+ });
+
+ textInput.dispatchEvent(event);
+ assert.true(
+ event.defaultPrevented,
+ "non-hex character keypress is prevented"
+ );
+
+ const validEvent = new KeyboardEvent("keypress", {
+ key: "a",
+ bubbles: true,
+ cancelable: true,
+ });
+ textInput.dispatchEvent(validEvent);
+ assert.false(
+ validEvent.defaultPrevented,
+ "hex character keypress is allowed"
+ );
+ });
+
+ test("Enter key navigates to next color field", async function (assert) {
+ const colors = [
+ {
+ name: "primary",
+ hex: "aaaaaa",
+ dark_hex: "1e3c8a",
+ },
+ {
+ name: "secondary",
+ hex: "bbbbbb",
+ dark_hex: "2d4c9a",
+ },
+ {
+ name: "tertiary",
+ hex: "cccccc",
+ dark_hex: "3e5daa",
+ },
+ ].map((data) => ColorSchemeColor.create(data));
+
+ await render(
+ <template><ColorPaletteEditor @colors={{colors}} /></template>
+ );
+
+ this.subject.color("primary").textInput().focus();
+ assert.strictEqual(
+ document.activeElement,
+ this.subject.color("primary").textInput(),
+ "primary color input is focused"
+ );
+
+ const enterEvent = new KeyboardEvent("keypress", {
+ keyCode: 13,
+ bubbles: true,
+ cancelable: true,
+ });
+ document.activeElement.dispatchEvent(enterEvent);
+
+ assert.strictEqual(
+ document.activeElement,
+ this.subject.color("secondary").textInput(),
+ "secondary color input is focused after Enter key"
+ );
+ });
+
+ test("paste event validates hex color input", async function (assert) {
+ const toastService = this.owner.lookup("service:toasts");
+
+ const colors = [
+ {
+ name: "primary",
+ hex: "aaaaaa",
+ dark_hex: "1e3c8a",
+ },
+ ].map((data) => ColorSchemeColor.create(data));
+
+ await render(
+ <template><ColorPaletteEditor @colors={{colors}} /></template>
+ );
+
+ const textInput = this.subject.color("primary").textInput();
+
+ const validPasteEvent = new ClipboardEvent("paste", {
+ clipboardData: new DataTransfer(),
+ bubbles: true,
+ cancelable: true,
+ });
+ validPasteEvent.clipboardData.setData("text", "123abc");
+ textInput.dispatchEvent(validPasteEvent);
+ assert.false(
+ validPasteEvent.defaultPrevented,
+ "valid hex color paste is not prevented"
+ );
+ assert.strictEqual(
+ toastService.activeToasts.length,
+ 0,
+ "no error toast is shown for valid hex color paste"
+ );
+
+ const invalidPasteEvent = new ClipboardEvent("paste", {
+ clipboardData: new DataTransfer(),
+ bubbles: true,
+ cancelable: true,
+ });
+ invalidPasteEvent.clipboardData.setData("text", "xyz123");
+ textInput.dispatchEvent(invalidPasteEvent);
+ assert.true(
+ invalidPasteEvent.defaultPrevented,
+ "invalid hex color paste is prevented"
+ );
+ assert.strictEqual(
+ toastService.activeToasts.length,
+ 1,
+ "a toast is shown for invalid hex color paste"
+ );
+ const toast = toastService.activeToasts[0];
+ assert.strictEqual(
+ toast.options.data.theme,
+ "error",
+ "toast is an error type"
+ );
+ });
+
+ test("shows error for invalid color length on Enter", async function (assert) {
+ const toastService = this.owner.lookup("service:toasts");
+
+ const colors = [
+ {
+ name: "primary",
+ hex: "aaaaaa",
+ dark_hex: "1e3c8a",
+ },
+ ].map((data) => ColorSchemeColor.create(data));
+
+ await render(
+ <template><ColorPaletteEditor @colors={{colors}} /></template>
+ );
+
+ const textInput = this.subject.color("primary").textInput();
+ textInput.value = "1234";
+
+ const enterEvent = new KeyboardEvent("keypress", {
+ keyCode: 13,
+ bubbles: true,
+ cancelable: true,
+ });
+ textInput.dispatchEvent(enterEvent);
+ assert.strictEqual(
+ toastService.activeToasts.length,
+ 1,
+ "a toast is shown for invalid color length"
+ );
+ const toast = toastService.activeToasts[0];
+ assert.strictEqual(
+ toast.options.data.theme,
+ "error",
+ "toast is an error type"
+ );
+ assert.true(
+ enterEvent.defaultPrevented,
+ "Enter key default action is prevented"
+ );
+ });
});
diff --git a/app/assets/javascripts/discourse/tests/unit/controllers/admin-customize-themes-show-index-test.js b/app/assets/javascripts/discourse/tests/unit/controllers/admin-customize-themes-show-index-test.js
new file mode 100644
index 00000000000..04b61e5b7ab
--- /dev/null
+++ b/app/assets/javascripts/discourse/tests/unit/controllers/admin-customize-themes-show-index-test.js
@@ -0,0 +1,44 @@
+import { setupTest } from "ember-qunit";
+import { module, test } from "qunit";
+import Theme from "admin/models/theme";
+
+module(
+ "Unit | Controller | admin-customize-themes-show-index",
+ function (hooks) {
+ setupTest(hooks);
+
+ test("displays settings editor button with settings", function (assert) {
+ const theme = Theme.create({
+ id: 2,
+ default: true,
+ name: "default",
+ settings: [{}],
+ });
+ const controller = this.owner.lookup(
+ "controller:admin-customize-themes-show-index"
+ );
+ controller.setProperties({ model: theme });
+ assert.true(
+ controller.hasSettings,
+ "sets the hasSettings property to true with settings"
+ );
+ });
+
+ test("hides settings editor button with no settings", function (assert) {
+ const theme = Theme.create({
+ id: 2,
+ default: true,
+ name: "default",
+ settings: [],
+ });
+ const controller = this.owner.lookup(
+ "controller:admin-customize-themes-show-index"
+ );
+ controller.setProperties({ model: theme });
+ assert.false(
+ controller.hasSettings,
+ "sets the hasSettings property to true with settings"
+ );
+ });
+ }
+);
diff --git a/app/assets/javascripts/discourse/tests/unit/controllers/admin-customize-themes-show-test.js b/app/assets/javascripts/discourse/tests/unit/controllers/admin-customize-themes-show-test.js
index ec35962fed5..446de4ad94c 100644
--- a/app/assets/javascripts/discourse/tests/unit/controllers/admin-customize-themes-show-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/controllers/admin-customize-themes-show-test.js
@@ -50,38 +50,4 @@ module("Unit | Controller | admin-customize-themes-show", function (hooks) {
"returns theme's repo URL to branch"
);
});
-
- test("displays settings editor button with settings", function (assert) {
- const theme = Theme.create({
- id: 2,
- default: true,
- name: "default",
- settings: [{}],
- });
- const controller = this.owner.lookup(
- "controller:admin-customize-themes-show"
- );
- controller.setProperties({ model: theme });
- assert.true(
- controller.hasSettings,
- "sets the hasSettings property to true with settings"
- );
- });
-
- test("hides settings editor button with no settings", function (assert) {
- const theme = Theme.create({
- id: 2,
- default: true,
- name: "default",
- settings: [],
- });
- const controller = this.owner.lookup(
- "controller:admin-customize-themes-show"
- );
- controller.setProperties({ model: theme });
- assert.false(
- controller.hasSettings,
- "sets the hasSettings property to true with settings"
- );
- });
});
diff --git a/app/assets/stylesheets/admin/color-palette-editor.scss b/app/assets/stylesheets/admin/color-palette-editor.scss
index c8a9dde9bc1..242a52a6234 100644
--- a/app/assets/stylesheets/admin/color-palette-editor.scss
+++ b/app/assets/stylesheets/admin/color-palette-editor.scss
@@ -30,8 +30,7 @@
}
&__color-name {
- color: var(--primary-medium);
- font-size: var(--font-down-1);
+ font-size: var(--font-down-1-rem);
}
&__color-controls {
@@ -40,31 +39,55 @@
&__picker {
display: flex;
- justify-content: center;
align-items: center;
- padding: 5px 10px;
- gap: 5px;
- border: 1px solid var(--primary-low);
+ gap: var(--space-2);
+
+ &:focus-within {
+ border-color: var(--tertiary);
+ outline: 2px solid var(--tertiary);
+ outline-offset: -2px;
+ }
- .d-icon-hashtag {
- color: var(--primary-high);
- font-size: var(--font-down-2);
+ &.--invalid {
+ border-color: var(--danger);
+ outline: 2px solid var(--danger);
+ outline-offset: -2px;
}
}
+ &__input-wrapper {
+ position: relative;
+ display: flex;
+ align-items: center;
+ }
+
+ &__icon {
+ position: absolute;
+ pointer-events: none;
+ color: var(--primary-medium);
+ font-size: var(--font-down-2);
+ }
+
&__revert.--hidden {
visibility: hidden;
}
input[type="color"] {
- width: 23px;
- height: 23px;
+ width: 20px;
+ height: 20px;
+ border-radius: 50%;
}
input[type="text"] {
font-family: monospace;
margin: 0;
- width: 5em;
+ width: 4.5rem;
+ padding-left: var(--space-4);
+ border: none;
+
+ &:focus {
+ outline: none;
+ }
}
&__color-code {
diff --git a/app/assets/stylesheets/admin/customize.scss b/app/assets/stylesheets/admin/customize.scss
index 64d70228100..270613d5e05 100644
--- a/app/assets/stylesheets/admin/customize.scss
+++ b/app/assets/stylesheets/admin/customize.scss
@@ -70,6 +70,20 @@
background-color: var(--primary-very-low);
padding: 5px;
}
+
+ .d-page-header {
+ margin-bottom: 1em;
+ }
+
+ // add bottom margin so the unsaved changes banner does not cover the last
+ // color on short screens
+ .color-palette-editor {
+ margin-bottom: 4em;
+ }
+
+ .alert.remote-theme-edits {
+ margin-top: var(--space-2);
+ }
}
.admin-customize.admin-permalinks {
@@ -223,6 +237,10 @@
margin-left: auto;
}
}
+
+ &.remote-theme-metadata {
+ margin-bottom: 0;
+ }
}
.control {
diff --git a/app/assets/stylesheets/admin/site-settings.scss b/app/assets/stylesheets/admin/site-settings.scss
index af246c37368..4b6ebc266cd 100644
--- a/app/assets/stylesheets/admin/site-settings.scss
+++ b/app/assets/stylesheets/admin/site-settings.scss
@@ -22,7 +22,7 @@
}
}
-.admin-site-settings__changes-banner {
+.admin-changes-banner {
box-sizing: border-box;
display: flex;
justify-content: space-between;
diff --git a/app/controllers/admin/color_schemes_controller.rb b/app/controllers/admin/color_schemes_controller.rb
index 759feab1d1f..040c937c45b 100644
--- a/app/controllers/admin/color_schemes_controller.rb
+++ b/app/controllers/admin/color_schemes_controller.rb
@@ -4,15 +4,9 @@ class Admin::ColorSchemesController < Admin::AdminController
before_action :fetch_color_scheme, only: %i[update destroy]
def index
- schemes = ColorScheme.order("id ASC")
-
- if params[:exclude_theme_owned]
- schemes =
- schemes
- .where(theme_id: nil)
- .left_joins(:theme_color_scheme)
- .where(theme_color_scheme: { id: nil })
- end
+ schemes = ColorScheme.without_theme_owned_palettes.order("id ASC")
+
+ schemes = schemes.where(theme_id: nil) if params[:exclude_theme_owned]
render_serialized(ColorScheme.base_color_schemes + schemes.to_a, ColorSchemeSerializer)
end
@@ -43,7 +37,7 @@ class Admin::ColorSchemesController < Admin::AdminController
private
def fetch_color_scheme
- @color_scheme = ColorScheme.find(params[:id])
+ @color_scheme = ColorScheme.without_theme_owned_palettes.find(params[:id])
end
def color_scheme_params
diff --git a/app/controllers/admin/config/color_palettes_controller.rb b/app/controllers/admin/config/color_palettes_controller.rb
index 7fbf7bc1d96..a95cc8d11fe 100644
--- a/app/controllers/admin/config/color_palettes_controller.rb
+++ b/app/controllers/admin/config/color_palettes_controller.rb
@@ -4,6 +4,10 @@ class Admin::Config::ColorPalettesController < Admin::AdminController
end
def show
- render_serialized(ColorScheme.find(params[:id]), ColorSchemeSerializer, root: false)
+ render_serialized(
+ ColorScheme.without_theme_owned_palettes.find(params[:id]),
+ ColorSchemeSerializer,
+ root: false,
+ )
end
end
diff --git a/app/controllers/admin/themes_controller.rb b/app/controllers/admin/themes_controller.rb
index 68ea28610a5..6d3c7cf13c7 100644
--- a/app/controllers/admin/themes_controller.rb
+++ b/app/controllers/admin/themes_controller.rb
@@ -172,7 +172,12 @@ class Admin::ThemesController < Admin::AdminController
@themes = Theme.strict_loading.include_relations.order(:name)
@color_schemes =
- ColorScheme.strict_loading.all.includes(:theme, color_scheme_colors: :color_scheme).to_a
+ ColorScheme
+ .strict_loading
+ .all
+ .without_theme_owned_palettes
+ .includes(:theme, color_scheme_colors: :color_scheme)
+ .to_a
payload = {
themes: serialize_data(@themes, ThemeSerializer),
@@ -369,6 +374,19 @@ class Admin::ThemesController < Admin::AdminController
render_serialized(theme_setting, ThemeObjectsSettingMetadataSerializer, root: false)
end
+ def change_colors
+ theme = Theme.find_by(id: params[:id], component: false)
+ raise Discourse::NotFound if !theme
+
+ palette = theme.find_or_create_owned_color_palette
+
+ colors = params.permit(colors: %i[name hex dark_hex])
+
+ ColorSchemeRevisor.revise_existing_colors_only(palette, colors)
+
+ render_serialized(palette, ColorSchemeSerializer, root: false)
+ end
+
private
def ban_in_allowlist_mode!
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index d2ba9e9cc46..a34cf0c2a95 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -576,7 +576,10 @@ module ApplicationHelper
return if theme_id.blank?
- @scheme_id = Theme.where(id: theme_id).pick(:color_scheme_id)
+ if SiteSetting.use_overhauled_theme_color_palette
+ @scheme_id = ThemeColorScheme.where(theme_id: theme_id).pick(:color_scheme_id)
+ end
+ @scheme_id ||= Theme.where(id: theme_id).pick(:color_scheme_id)
end
def dark_scheme_id
diff --git a/app/models/color_scheme.rb b/app/models/color_scheme.rb
index 921762957e4..3f4a384c61e 100644
--- a/app/models/color_scheme.rb
+++ b/app/models/color_scheme.rb
@@ -312,12 +312,11 @@ class ColorScheme < ActiveRecord::Base
after_destroy :dump_caches
belongs_to :theme
- has_one :theme_color_scheme
+ has_one :theme_color_scheme, dependent: :destroy
has_one :owning_theme, class_name: "Theme", through: :theme_color_scheme, source: :theme
- default_scope do
- where("color_schemes.id NOT IN (SELECT color_scheme_id FROM theme_color_schemes)")
- end
+ scope :without_theme_owned_palettes,
+ -> { where("color_schemes.id NOT IN (SELECT color_scheme_id FROM theme_color_schemes)") }
validates_associated :color_scheme_colors
diff --git a/app/models/color_scheme_setting.rb b/app/models/color_scheme_setting.rb
index 8dc5ce5cc68..aef87141c4c 100644
--- a/app/models/color_scheme_setting.rb
+++ b/app/models/color_scheme_setting.rb
@@ -2,12 +2,12 @@
class ColorSchemeSetting < EnumSiteSetting
def self.valid_value?(val)
- val == -1 || ColorScheme.find_by_id(val)
+ val == -1 || ColorScheme.without_theme_owned_palettes.find_by_id(val)
end
def self.values
values = [{ name: I18n.t("site_settings.dark_mode_none"), value: -1 }]
- ColorScheme.all.map { |c| values << { name: c.name, value: c.id } }
+ ColorScheme.all.without_theme_owned_palettes.map { |c| values << { name: c.name, value: c.id } }
values
end
end
diff --git a/app/models/theme.rb b/app/models/theme.rb
index af0072b3a2b..b0a02921cdd 100644
--- a/app/models/theme.rb
+++ b/app/models/theme.rb
@@ -20,6 +20,8 @@ class Theme < ActiveRecord::Base
belongs_to :user
belongs_to :color_scheme
+ alias_method :color_palette, :color_scheme
+
has_many :theme_fields, dependent: :destroy, validate: false
has_many :theme_settings, dependent: :destroy
has_many :theme_translation_overrides, dependent: :destroy
@@ -51,6 +53,8 @@ class Theme < ActiveRecord::Base
class_name: "ColorScheme",
through: :theme_color_scheme,
source: :color_scheme
+ alias_method :owned_color_palette, :owned_color_scheme
+ alias_method :owned_color_palette=, :owned_color_scheme=
has_many :locale_fields,
-> { filter_locale_fields(I18n.fallbacks[I18n.locale]) },
@@ -86,7 +90,6 @@ class Theme < ActiveRecord::Base
include_basic_relations.includes(
:theme_settings,
:settings_field,
- color_scheme: %i[color_scheme_colors],
theme_fields: %i[upload theme_settings_migration],
child_themes: %i[color_scheme locale_fields theme_translation_overrides],
)
@@ -99,7 +102,8 @@ class Theme < ActiveRecord::Base
:user,
:locale_fields,
:theme_translation_overrides,
- color_scheme: %i[theme],
+ color_scheme: %i[theme color_scheme_colors],
+ owned_color_scheme: %i[theme color_scheme_colors],
parent_themes: %i[color_scheme locale_fields theme_translation_overrides],
)
end
@@ -1024,6 +1028,40 @@ class Theme < ActiveRecord::Base
UserOption.where(theme_ids: [id]).count
end
+ def find_or_create_owned_color_palette
+ Theme.transaction do
+ next self.owned_color_palette if self.owned_color_palette
+
+ palette = self.color_palette || ColorScheme.base
+
+ copy = palette.dup
+ copy.theme_id = self.id
+ copy.base_scheme_id = nil
+ copy.user_selectable = false
+ copy.via_wizard = false
+ copy.save!
+
+ result =
+ ThemeColorScheme.insert_all(
+ [{ theme_id: self.id, color_scheme_id: copy.id }],
+ unique_by: :index_theme_color_schemes_on_theme_id,
+ )
+
+ if result.rows.size == 0
+ # race condition, a palette has already been associated with this theme
+ copy.destroy!
+ self.reload.owned_color_palette
+ else
+ ColorSchemeColor.insert_all(
+ palette.colors.map do |color|
+ { color_scheme_id: copy.id, name: color.name, hex: color.hex, dark_hex: color.dark_hex }
+ end,
+ )
+ copy.reload
+ end
+ end
+ end
+
private
attr_accessor :theme_setting_requests_refresh
diff --git a/app/serializers/color_scheme_color_serializer.rb b/app/serializers/color_scheme_color_serializer.rb
index edc9274bb87..637c44aa78b 100644
--- a/app/serializers/color_scheme_color_serializer.rb
+++ b/app/serializers/color_scheme_color_serializer.rb
@@ -4,7 +4,11 @@ class ColorSchemeColorSerializer < ApplicationSerializer
attributes :name, :hex, :default_hex, :is_advanced, :dark_hex, :default_dark_hex
def hex
- object.hex # otherwise something crazy is returned
+ object.hex
+ end
+
+ def dark_hex
+ object.dark_hex || object.hex
end
def default_hex
diff --git a/app/serializers/theme_serializer.rb b/app/serializers/theme_serializer.rb
index 45580feb751..ece978d7da4 100644
--- a/app/serializers/theme_serializer.rb
+++ b/app/serializers/theme_serializer.rb
@@ -16,6 +16,8 @@ class ThemeSerializer < BasicThemeSerializer
:screenshot_url
has_one :color_scheme, serializer: ColorSchemeSerializer, embed: :object
+ has_one :owned_color_palette, serializer: ColorSchemeSerializer, embed: :object
+ has_one :base_palette, serializer: ColorSchemeSerializer, embed: :object
has_one :user, serializer: UserNameSerializer, embed: :object
has_one :disabled_by, serializer: UserNameSerializer, embed: :object
@@ -55,6 +57,14 @@ class ThemeSerializer < BasicThemeSerializer
object.parent_themes
end
+ def base_palette
+ ColorScheme.base
+ end
+
+ def include_base_palette?
+ object.color_scheme_id.blank? && object.owned_color_palette.blank?
+ end
+
def settings
object.settings.map do |_name, setting|
ThemeSettingsSerializer.new(setting, scope:, root: false)
diff --git a/app/services/color_scheme_revisor.rb b/app/services/color_scheme_revisor.rb
index ebbe227fcfc..510f25468a3 100644
--- a/app/services/color_scheme_revisor.rb
+++ b/app/services/color_scheme_revisor.rb
@@ -10,7 +10,11 @@ class ColorSchemeRevisor
self.new(color_scheme, params).revise
end
- def revise
+ def self.revise_existing_colors_only(color_scheme, params)
+ self.new(color_scheme, params).revise(update_existing_colors_only: true)
+ end
+
+ def revise(update_existing_colors_only: false)
ColorScheme.transaction do
@color_scheme.name = @params[:name] if @params.has_key?(:name)
@color_scheme.user_selectable = @params[:user_selectable] if @params.has_key?(
@@ -23,7 +27,7 @@ class ColorSchemeRevisor
@params[:colors].each do |c|
if existing = @color_scheme.colors_by_name[c[:name]]
existing.update(c)
- else
+ elsif !update_existing_colors_only
@color_scheme.color_scheme_colors << ColorSchemeColor.new(
name: c[:name],
hex: c[:hex],
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index d10976e1857..3fcbee5d0ec 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -6408,7 +6408,8 @@ en:
unsaved_changes: "You have unsaved changes"
copy_of: "Copy of %{name}"
copy_created: 'A new copy of "%{name}" has been created'
- illegal_character_in_color: "Colors consist of hexadecimal characters only"
+ illegal_character_in_color: "Color must consist of hexadecimal characters only"
+ invalid_color_length: "Color must in the format #rrggbb or #rgb"
delete_confirm: "Are you sure you want to delete this color palette?"
plugins:
title: "Plugins"
@@ -6710,6 +6711,15 @@ en:
remote_theme_edits: "If you want to edit this theme, you must <a href='%{repoURL}' target='_blank'>submit a change on its repository</a>"
repo_unreachable: "Couldn't contact the Git repository of this theme. Error message:"
imported_from_archive: "This theme was imported from a .zip file"
+ settings: "Settings"
+ colors: "Colors"
+ unsaved_colors:
+ one: "You have %{count} unsaved color"
+ other: "You have %{count} unsaved colors"
+ unsaved_colors_leave_route_confirmation: "You haven't saved your color palette changes yet. Are you sure you want to leave?"
+ save_colors: "Save colors"
+ discard_colors: "Discard"
+ colors_title: "Colors"
scss:
text: "CSS"
title: "Custom CSS rules with support for SCSS syntax"
diff --git a/config/routes.rb b/config/routes.rb
index 7b0d18f816a..0a563b5d82c 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -250,6 +250,7 @@ Discourse::Application.routes.draw do
get "translations/:locale" => "themes#get_translations"
put "setting" => "themes#update_single_setting"
get "objects_setting_metadata/:setting_name" => "themes#objects_setting_metadata"
+ put "change-colors" => "themes#change_colors"
end
collection do
@@ -270,6 +271,7 @@ Discourse::Application.routes.draw do
get "components/:id" => "themes#index"
get "components/:id/:target/:field_name/edit" => "themes#index"
get "themes/:id/export" => "themes#export"
+ get "themes/:id/colors" => "themes#index"
get "themes/:id/schema/:setting_name" => "themes#schema"
get "components/:id/schema/:setting_name" => "themes#schema"
diff --git a/spec/models/theme_spec.rb b/spec/models/theme_spec.rb
index 8dd8fb7accf..3960572a5b4 100644
--- a/spec/models/theme_spec.rb
+++ b/spec/models/theme_spec.rb
@@ -1718,4 +1718,49 @@ HTML
expect(theme.screenshot_url).to eq(upload.url)
end
end
+
+ describe "#find_or_create_owned_color_palette" do
+ it "correctly associates a theme with its owned color palette" do
+ palette = theme.find_or_create_owned_color_palette
+
+ expect(palette.owning_theme).to eq(theme)
+ expect(theme.reload.owned_color_palette).to eq(palette)
+ end
+
+ it "ensures owned color palette is not user selectable" do
+ palette = theme.find_or_create_owned_color_palette
+
+ expect(palette.user_selectable).to eq(false)
+ end
+
+ it "copies colors from base or theme color scheme" do
+ theme_without_scheme = Fabricate(:theme, color_scheme: nil)
+ base_palette = theme_without_scheme.find_or_create_owned_color_palette
+
+ expect(base_palette.colors.length).to be > 0
+ expect(base_palette.colors.map(&:name).sort).to eq(ColorScheme.base.colors.map(&:name).sort)
+
+ custom_palette =
+ Fabricate(
+ :color_scheme,
+ colors: [ColorSchemeColor.new(name: "custom", hex: "11ccff", dark_hex: "ee9955")],
+ )
+ theme_with_scheme = Fabricate(:theme, color_scheme: custom_palette)
+ custom_palette = theme_with_scheme.find_or_create_owned_color_palette
+
+ expect(custom_palette.colors.length).to be > 0
+ expect(custom_palette.colors.map(&:name).sort).to eq(custom_palette.colors.map(&:name).sort)
+ end
+
+ it "returns the existing palette if a race condition occurs and a theme-owned palette is created while it's executing" do
+ expect(theme.owned_color_palette).to eq(nil)
+
+ palette = Fabricate(:color_scheme)
+ ThemeColorScheme.create!(theme_id: theme.id, color_scheme_id: palette.id)
+
+ expect(theme.owned_color_palette).to eq(nil)
+ expect(theme.find_or_create_owned_color_palette.id).to eq(palette.id)
+ expect(theme.owned_color_palette).to eq(palette)
+ end
+ end
end
diff --git a/spec/requests/admin/themes_controller_spec.rb b/spec/requests/admin/themes_controller_spec.rb
index 261e6ba8258..c64b9df73c1 100644
--- a/spec/requests/admin/themes_controller_spec.rb
+++ b/spec/requests/admin/themes_controller_spec.rb
@@ -1504,4 +1504,83 @@ RSpec.describe Admin::ThemesController do
expect(response.status).to eq(200)
end
end
+
+ describe "#change_colors" do
+ fab!(:theme)
+
+ before { sign_in(admin) }
+
+ context "with valid parameters" do
+ it "creates a theme-owned color palette if one doesn't exist" do
+ expect(theme.owned_color_palette).to be_nil
+
+ put "/admin/themes/#{theme.id}/change-colors.json",
+ params: {
+ colors: [{ name: "primary", hex: "ff0000", dark_hex: "0000ff" }],
+ }
+
+ expect(response.status).to eq(200)
+
+ theme.reload
+ expect(theme.owned_color_palette.id).to eq(response.parsed_body["id"])
+
+ color = theme.owned_color_palette.colors.find_by(name: "primary")
+ expect(color.hex).to eq("ff0000")
+ expect(color.dark_hex).to eq("0000ff")
+ end
+
+ it "updates an existing theme-owned color palette" do
+ palette = theme.find_or_create_owned_color_palette
+ primary_color = palette.colors.find_by(name: "primary")
+ secondary_color = palette.colors.find_by(name: "secondary")
+
+ original_secondary_hex = secondary_color.hex
+ original_secondary_dark_hex = secondary_color.dark_hex
+
+ put "/admin/themes/#{theme.id}/change-colors.json",
+ params: {
+ colors: [{ name: "primary", hex: "aabbcc", dark_hex: "ccddee" }],
+ }
+
+ expect(response.status).to eq(200)
+
+ primary_color.reload
+ secondary_color.reload
+
+ expect(primary_color.hex).to eq("aabbcc")
+ expect(primary_color.dark_hex).to eq("ccddee")
+
+ expect(secondary_color.hex).to eq(original_secondary_hex)
+ expect(secondary_color.dark_hex).to eq(original_secondary_dark_hex)
+ end
+
+ it "returns the updated palette in the response" do
+ put "/admin/themes/#{theme.id}/change-colors.json",
+ params: {
+ colors: [{ name: "primary", hex: "abcdef", dark_hex: "fedcba" }],
+ }
+
+ expect(response.status).to eq(200)
+ json = response.parsed_body
+
+ expect(json["colors"]).to be_present
+ primary_color = json["colors"].find { |c| c["name"] == "primary" }
+ expect(primary_color["hex"]).to eq("abcdef")
+ expect(primary_color["dark_hex"]).to eq("fedcba")
+ end
+ end
+
+ context "with invalid parameters" do
+ it "returns 404 for non-existent theme" do
+ max_id = (Theme.maximum(:id) || 0) + 1
+
+ put "/admin/themes/#{max_id}/change-colors.json",
+ params: {
+ colors: [{ name: "primary", hex: "ff0000", dark_hex: "0000ff" }],
+ }
+
+ expect(response.status).to eq(404)
+ end
+ end
+ end
end
diff --git a/spec/system/admin_customize_themes_spec.rb b/spec/system/admin_customize_themes_spec.rb
index 2a48ba21f93..9e2551dab73 100644
--- a/spec/system/admin_customize_themes_spec.rb
+++ b/spec/system/admin_customize_themes_spec.rb
@@ -5,7 +5,8 @@ describe "Admin Customize Themes", type: :system do
fab!(:theme) { Fabricate(:theme, name: "Cool theme 1") }
fab!(:admin) { Fabricate(:admin, locale: "en") }
- let(:admin_customize_themes_page) { PageObjects::Pages::AdminCustomizeThemes.new }
+ let(:theme_page) { PageObjects::Pages::AdminCustomizeThemes.new }
+ let(:dialog) { PageObjects::Components::Dialog.new }
before { sign_in(admin) }
@@ -148,9 +149,125 @@ describe "Admin Customize Themes", type: :system do
context "when visting a component's page" do
fab!(:component) { Fabricate(:theme, component: true, name: "Cool component 493") }
- xit "has a link to the components page" do
+ it "has a link to the components page" do
visit("/admin/customize/themes/#{component.id}")
- expect(admin_customize_themes_page).to have_back_button_to_components_page
+ expect(theme_page).to have_back_button_to_components_page
+ end
+ end
+
+ describe "theme color palette editor" do
+ before { SiteSetting.use_overhauled_theme_color_palette = true }
+
+ it "allows editing colors of theme-owned palette" do
+ theme_page.visit(theme.id)
+ theme_page.colors_tab.click
+
+ expect(theme_page).to have_current_path("/admin/customize/themes/#{theme.id}/colors")
+
+ original_hex = theme_page.color_palette_editor.get_color_value("primary")
+ theme_page.color_palette_editor.change_color("primary", "#ff000e")
+
+ expect(theme_page.changes_banner).to be_visible
+ theme_page.changes_banner.click_save
+
+ page.refresh
+ expect(theme_page).to have_colors_tab_active
+
+ updated_color = theme_page.color_palette_editor.get_color_value("primary")
+ expect(updated_color).to eq("#ff000e")
+ end
+
+ it "allows discarding unsaved color changes" do
+ theme_page.visit(theme.id)
+ theme_page.colors_tab.click
+
+ original_hex = theme_page.color_palette_editor.get_color_value("primary")
+
+ theme_page.color_palette_editor.change_color("primary", "#10ff00")
+
+ theme_page.changes_banner.click_discard
+
+ expect(theme_page.changes_banner).to be_hidden
+
+ updated_color = theme_page.color_palette_editor.get_color_value("primary")
+ expect(updated_color).to eq(original_hex)
+ end
+
+ it "allows editing dark mode colors" do
+ theme_page.visit(theme.id)
+ theme_page.colors_tab.click
+
+ theme_page.color_palette_editor.switch_to_dark_tab
+
+ original_dark_hex = theme_page.color_palette_editor.get_color_value("primary")
+ theme_page.color_palette_editor.change_color("primary", "#000fff")
+
+ theme_page.changes_banner.click_save
+
+ page.refresh
+ theme_page.color_palette_editor.switch_to_dark_tab
+
+ updated_dark_color = theme_page.color_palette_editor.get_color_value("primary")
+ expect(updated_dark_color).to eq("#000fff")
+ end
+
+ it "shows count of unsaved colors" do
+ theme_page.visit(theme.id)
+ theme_page.colors_tab.click
+
+ theme_page.color_palette_editor.change_color("primary", "#eeff80")
+
+ expect(theme_page.changes_banner).to have_label(
+ I18n.t("admin_js.admin.customize.theme.unsaved_colors", count: 1),
+ )
+
+ theme_page.color_palette_editor.switch_to_dark_tab
+
+ theme_page.color_palette_editor.change_color("primary", "#ff80ee")
+
+ expect(theme_page.changes_banner).to have_label(
+ I18n.t("admin_js.admin.customize.theme.unsaved_colors", count: 2),
+ )
+
+ theme_page.color_palette_editor.change_color("secondary", "#ee30ab")
+ expect(theme_page.changes_banner).to have_label(
+ I18n.t("admin_js.admin.customize.theme.unsaved_colors", count: 3),
+ )
+ end
+
+ it "doesn't show colors tab or DPageHeader for components" do
+ component = Fabricate(:theme, component: true)
+ theme_page.visit(component.id)
+ expect(theme_page.header).to be_hidden
+
+ expect(theme_page).to have_no_color_scheme_selector
+ end
+
+ it "shows a confirmation dialog when leaving the page with unsaved changes" do
+ theme_page.visit(theme.id)
+ theme_page.colors_tab.click
+
+ theme_page.color_palette_editor.change_color("primary", "#eeff80")
+
+ expect(theme_page.changes_banner).to be_visible
+
+ find("#site-logo").click
+
+ expect(dialog).to be_open
+ expect(page).to have_content(
+ I18n.t("admin_js.admin.customize.theme.unsaved_colors_leave_route_confirmation"),
+ )
+
+ dialog.click_no
+
+ expect(dialog).to be_closed
+ expect(page).to have_current_path("/admin/customize/themes/#{theme.id}/colors")
+
+ find("#site-logo").click
+ expect(dialog).to be_open
+
+ dialog.click_yes
+ expect(page).to have_current_path("/")
end
end
end
diff --git a/spec/system/admin_site_setting_bulk_action_spec.rb b/spec/system/admin_site_setting_bulk_action_spec.rb
index 7f416a23e71..6acb501a74f 100644
--- a/spec/system/admin_site_setting_bulk_action_spec.rb
+++ b/spec/system/admin_site_setting_bulk_action_spec.rb
@@ -2,7 +2,7 @@
describe "Admin Site Setting Bulk Action", type: :system do
let(:settings_page) { PageObjects::Pages::AdminSiteSettings.new }
- let(:banner) { PageObjects::Components::AdminSiteSettingBulkBanner.new }
+ let(:banner) { PageObjects::Components::AdminChangesBanner.new }
let(:dialog) { PageObjects::Components::Dialog.new }
fab!(:admin)
diff --git a/spec/system/admin_site_setting_category_bulk_action_spec.rb b/spec/system/admin_site_setting_category_bulk_action_spec.rb
index a3a2b45781f..0c45f07437c 100644
--- a/spec/system/admin_site_setting_category_bulk_action_spec.rb
+++ b/spec/system/admin_site_setting_category_bulk_action_spec.rb
@@ -2,7 +2,7 @@
describe "Admin Site Setting Category Bulk Action", type: :system do
let(:settings_page) { PageObjects::Pages::AdminSiteSettings.new }
- let(:banner) { PageObjects::Components::AdminSiteSettingBulkBanner.new }
+ let(:banner) { PageObjects::Components::AdminChangesBanner.new }
let(:dialog) { PageObjects::Components::Dialog.new }
fab!(:admin)
diff --git a/spec/system/page_objects/components/admin_site_setting_bulk_banner.rb b/spec/system/page_objects/components/admin_changes_banner.rb
similarity index 58%
rename from spec/system/page_objects/components/admin_site_setting_bulk_banner.rb
rename to spec/system/page_objects/components/admin_changes_banner.rb
index 592a6c56f9f..9e726bcdefe 100644
--- a/spec/system/page_objects/components/admin_site_setting_bulk_banner.rb
+++ b/spec/system/page_objects/components/admin_changes_banner.rb
@@ -2,7 +2,7 @@
module PageObjects
module Components
- class AdminSiteSettingBulkBanner < Base
+ class AdminChangesBanner < Base
def visible?
has_css?(selector)
end
@@ -19,10 +19,18 @@ module PageObjects
element.find(".btn-primary").click
end
+ def click_discard
+ element.find(".btn-secondary").click
+ end
+
+ def has_label?(label)
+ element.has_css?(".admin-changes-banner__main-label", text: label)
+ end
+
private
def selector
- ".admin-site-settings__changes-banner"
+ ".admin-changes-banner"
end
end
end
diff --git a/spec/system/page_objects/components/color_palette_editor.rb b/spec/system/page_objects/components/color_palette_editor.rb
index be742fe806e..87a4948f5c8 100644
--- a/spec/system/page_objects/components/color_palette_editor.rb
+++ b/spec/system/page_objects/components/color_palette_editor.rb
@@ -31,6 +31,15 @@ module PageObjects
)
end
+ def get_color_value(name)
+ input_for_color(name).value
+ end
+
+ def change_color(name, hex)
+ hex = "##{hex}" if !hex.start_with?("#")
+ input_for_color(name).fill_in(with: hex)
+ end
+
def has_revert_button_for_color?(name)
component.has_css?(
".color-palette-editor__colors-item[data-color-name='#{name}'] .color-palette-editor__revert:not(.--hidden)",
diff --git a/spec/system/page_objects/components/d_page_header.rb b/spec/system/page_objects/components/d_page_header.rb
index 88d8cbf71cf..619c9018dce 100644
--- a/spec/system/page_objects/components/d_page_header.rb
+++ b/spec/system/page_objects/components/d_page_header.rb
@@ -7,8 +7,16 @@ module PageObjects
expect(page.all("#{tabs_container_selector} a").map(&:text)).to eq(names)
end
+ def has_tab?(tab_name)
+ has_css?(tab_selector(tab_name))
+ end
+
+ def has_no_tab?(tab_name)
+ has_no_css?(tab_selector(tab_name))
+ end
+
def has_active_tab?(tab_name)
- find("#{tab_selector(tab_name)} .active")
+ has_css?("#{tab_selector(tab_name)} .active")
end
def tab(tab_name)
diff --git a/spec/system/page_objects/pages/admin_base.rb b/spec/system/page_objects/pages/admin_base.rb
index adf85cc91dd..584c563ff91 100644
--- a/spec/system/page_objects/pages/admin_base.rb
+++ b/spec/system/page_objects/pages/admin_base.rb
@@ -9,10 +9,8 @@ module PageObjects
delegate(:has_tabs?, :has_active_tab?, to: :header)
- private
-
def header
- @header ||= Components::DPageHeader.new
+ Components::DPageHeader.new
end
end
end
diff --git a/spec/system/page_objects/pages/admin_customize_themes.rb b/spec/system/page_objects/pages/admin_customize_themes.rb
index 8a1678c6db6..ae963fa225c 100644
--- a/spec/system/page_objects/pages/admin_customize_themes.rb
+++ b/spec/system/page_objects/pages/admin_customize_themes.rb
@@ -2,7 +2,79 @@
module PageObjects
module Pages
- class AdminCustomizeThemes < PageObjects::Pages::Base
+ class AdminCustomizeThemes < PageObjects::Pages::AdminBase
+ def visit(id)
+ page.visit("/admin/customize/themes/#{id}")
+ end
+
+ def has_colors_tab?
+ header.has_tab?("colors")
+ end
+
+ def has_colors_tab_active?
+ header.has_active_tab?("colors")
+ end
+
+ def has_no_colors_tab?
+ header.has_no_tab?("colors")
+ end
+
+ def colors_tab
+ header.tab("colors")
+ end
+
+ def has_settings_tab?
+ header.has_tab?("settings")
+ end
+
+ def has_no_settings_tab?
+ header.has_no_tab?("settings")
+ end
+
+ def settings_tab
+ header.tab("settings")
+ end
+
+ def changes_banner
+ PageObjects::Components::AdminChangesBanner.new
+ end
+
+ def has_color_scheme_selector?
+ page.has_css?(".theme-settings__color-scheme")
+ end
+
+ def has_no_color_scheme_selector?
+ page.has_no_css?(".theme-settings__color-scheme")
+ end
+
+ def color_palette_editor
+ PageObjects::Components::ColorPaletteEditor.new(page.find(".color-palette-editor"))
+ end
+
+ def palette_editor_save_button
+ page.find(".admin-theme__save-palette-changes")
+ end
+
+ def has_palette_editor_save_button?
+ page.has_css?(".admin-theme__save-palette-changes")
+ end
+
+ def has_no_palette_editor_save_button?
+ page.has_no_css?(".admin-theme__save-palette-changes")
+ end
+
+ def palette_editor_discard_button
+ page.find(".admin-theme__discard-palette-changes")
+ end
+
+ def has_palette_editor_discard_button?
+ page.has_css?(".admin-theme__discard-palette-changes")
+ end
+
+ def has_no_palette_editor_discard_button?
+ page.has_no_css?(".admin-theme__discard-palette-changes")
+ end
+
def has_inactive_themes?
has_css?(".inactive-indicator")
end