A platform for community discussion. Free, open, simple.
DEV: Open theme settings objects editor from admin customize theme page (#26006)
Alan Guo Xiang Tan94b09f33313b
diff --git a/app/assets/javascripts/admin/addon/components/site-setting.hbs b/app/assets/javascripts/admin/addon/components/site-setting.hbsindex be6c7705313..ee75c96ea12 100644--- a/app/assets/javascripts/admin/addon/components/site-setting.hbs+++ b/app/assets/javascripts/admin/addon/components/site-setting.hbs@@ -25,16 +25,25 @@</div><div class="setting-value">- {{component- this.componentName- setting=this.setting- value=this.buffered.value- validationMessage=this.validationMessage- preview=this.preview- isSecret=this.isSecret- allowAny=this.allowAny- changeValueCallback=this.changeValueCallback- }}+ {{#if this.settingEditButton}}+ <DButton+ @action={{this.settingEditButton.action}}+ @icon={{this.settingEditButton.icon}}+ @label={{this.settingEditButton.label}}+ class="setting-value-edit-button"+ />+ {{else}}+ {{component+ this.componentName+ setting=this.setting+ value=this.buffered.value+ validationMessage=this.validationMessage+ preview=this.preview+ isSecret=this.isSecret+ allowAny=this.allowAny+ changeValueCallback=this.changeValueCallback+ }}+ {{/if}}</div>{{#if this.dirty}}diff --git a/app/assets/javascripts/admin/addon/components/site-settings/string.hbs b/app/assets/javascripts/admin/addon/components/site-settings/string.hbsindex e4523829a8b..c8366232dce 100644--- a/app/assets/javascripts/admin/addon/components/site-settings/string.hbs+++ b/app/assets/javascripts/admin/addon/components/site-settings/string.hbs@@ -1,11 +1,5 @@{{#if this.setting.textarea}}<Textarea @value={{this.value}} class="input-setting-textarea" />-{{else if this.setting.json_schema}}- <DButton- @action={{fn (mut this.showJsonEditorModal) true}}- @icon="pencil-alt"- @label="admin.site_settings.json_schema.edit"- />{{else if this.isSecret}}<Input @type="password" @value={{this.value}} class="input-setting-string" />{{else}}@@ -13,14 +7,4 @@{{/if}}<SettingValidationMessage @message={{this.validationMessage}} />-<div class="desc">{{html-safe this.setting.description}}</div>--{{#if this.showJsonEditorModal}}- <Modal::JsonSchemaEditor- @updateValue={{fn (mut this.value)}}- @value={{this.value}}- @settingName={{this.setting.setting}}- @jsonSchema={{this.setting.json_schema}}- @closeModal={{fn (mut this.showJsonEditorModal) false}}- />-{{/if}}\ No newline at end of file+<div class="desc">{{html-safe this.setting.description}}</div>\ No newline at end of filediff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-schema.js b/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-schema.jsdeleted file mode 100644index 878a8b69360..00000000000--- a/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-schema.js+++ /dev/null@@ -1,98 +0,0 @@-import Controller from "@ember/controller";--export default class AdminCustomizeThemesSchemaController extends Controller {- data = [- {- name: "item 1",- width: 143,- is_valid: true,- enum_prop: 11,- children: [- {- name: "child 1-1",- grandchildren: [- {- name: "grandchild 1-1-1",- },- ],- },- {- name: "child 1-2",- grandchildren: [- {- name: "grandchild 1-2-1",- },- ],- },- ],- },- {- name: "item 2",- width: 803,- is_valid: false,- enum_prop: 22,- children: [- {- name: "child 2-1",- grandchildren: [- {- name: "grandchild 2-1-1",- },- ],- },- {- name: "child 2-2",- grandchildren: [- {- name: "grandchild 2-2-1",- },- ],- },- ],- },- ];-- schema = {- name: "item",- identifier: "name",- properties: {- name: {- type: "string",- },- width: {- type: "integer",- },- is_valid: {- type: "boolean",- },- enum_prop: {- type: "enum",- choices: [11, 22],- },- children: {- type: "objects",- schema: {- name: "child",- identifier: "name",- properties: {- name: {- type: "string",- },- grandchildren: {- type: "objects",- schema: {- name: "grandchild",- identifier: "name",- properties: {- name: {- type: "string",- },- },- },- },- },- },- },- },- };-}diff --git a/app/assets/javascripts/admin/addon/mixins/setting-component.js b/app/assets/javascripts/admin/addon/mixins/setting-component.jsindex e0a67e6fc58..56214250bcc 100644--- a/app/assets/javascripts/admin/addon/mixins/setting-component.js+++ b/app/assets/javascripts/admin/addon/mixins/setting-component.js@@ -5,6 +5,7 @@ import Mixin from "@ember/object/mixin";import { inject as service } from "@ember/service";import { htmlSafe } from "@ember/template";import { isNone } from "@ember/utils";+import JsonSchemaEditorModal from "discourse/components/modal/json-schema-editor";import { ajax } from "discourse/lib/ajax";import { fmt, propertyNotEqual } from "discourse/lib/computed";import { splitString } from "discourse/lib/utilities";@@ -78,6 +79,7 @@ const DEFAULT_USER_PREFERENCES = [export default Mixin.create({modal: service(),+ router: service(),site: service(),attributeBindings: ["setting.setting:data-setting"],classNameBindings: [":row", ":setting", "overridden", "typeClass"],@@ -168,6 +170,39 @@ export default Mixin.create({);},+ @discourseComputed("setting")+ settingEditButton(setting) {+ if (setting.json_schema) {+ return {+ action: () => {+ this.modal.show(JsonSchemaEditorModal, {+ model: {+ updateValue: (value) => {+ this.buffered.set("value", value);+ },+ value: this.buffered.get("value"),+ settingName: setting.setting,+ jsonSchema: setting.json_schema,+ },+ });+ },+ label: "admin.site_settings.json_schema.edit",+ icon: "pencil-alt",+ };+ } else if (setting.objects_schema) {+ return {+ action: () => {+ this.router.transitionTo(+ "adminCustomizeThemes.show.schema",+ setting.setting+ );+ },+ label: "admin.customize.theme.edit_objects_theme_setting",+ icon: "pencil-alt",+ };+ }+ },+@actionasync update() {const key = this.buffered.get("setting");diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-themes-schema.js b/app/assets/javascripts/admin/addon/routes/admin-customize-themes-schema.jsdeleted file mode 100644index 416dc2a0df2..00000000000--- a/app/assets/javascripts/admin/addon/routes/admin-customize-themes-schema.js+++ /dev/null@@ -1,8 +0,0 @@-import Route from "@ember/routing/route";--export default class AdminCustomizeThemesSchemaRoute extends Route {- setupController() {- super.setupController(...arguments);- this.controllerFor("adminCustomizeThemes").set("editingTheme", true);- }-}diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show-schema.js b/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show-schema.jsnew file mode 100644index 00000000000..83e82f87e7a--- /dev/null+++ b/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show-schema.js@@ -0,0 +1,32 @@+import Route from "@ember/routing/route";++export default class AdminCustomizeThemesShowSchemaRoute extends Route {+ model(params) {+ const theme = this.modelFor("adminCustomizeThemesShow");+ const setting = theme.settings.findBy("setting", params.setting_name);++ return {+ data: setting.value,+ schema: setting.objects_schema,+ };+ }++ setupController() {+ super.setupController(...arguments);+ this.controllerFor("adminCustomizeThemes").set("editingTheme", true);++ this.controllerFor("adminCustomizeThemes.show").set(+ "editingThemeSetting",+ true+ );+ }++ deactivate() {+ this.controllerFor("adminCustomizeThemes").set("editingTheme", false);++ this.controllerFor("adminCustomizeThemes.show").set(+ "editingThemeSetting",+ 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.jsindex d07b1ca68aa..ce3c5ea2ff3 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@@ -40,6 +40,7 @@ export default class AdminCustomizeThemesShowRoute extends Route {colorSchemeId: model.get("color_scheme_id"),colorSchemes: parentController.get("model.extras.color_schemes"),editingName: false,+ editingThemeSetting: false,});this.handleHighlight(model);diff --git a/app/assets/javascripts/admin/addon/routes/admin-route-map.js b/app/assets/javascripts/admin/addon/routes/admin-route-map.jsindex 2579e9bccda..7b871c260fb 100644--- a/app/assets/javascripts/admin/addon/routes/admin-route-map.js+++ b/app/assets/javascripts/admin/addon/routes/admin-route-map.js@@ -57,9 +57,10 @@ export default function () {"adminCustomizeThemes",{ path: "themes", resetNamespace: true },function () {- this.route("show", { path: "/:theme_id" });+ this.route("show", { path: "/:theme_id" }, function () {+ this.route("schema", { path: "schema/:setting_name" });+ });this.route("edit", { path: "/:theme_id/:target/:field_name/edit" });- this.route("schema", { path: "/:theme_id/schema/:setting_name" });});diff --git a/app/assets/javascripts/admin/addon/templates/customize-themes-schema.hbs b/app/assets/javascripts/admin/addon/templates/customize-themes-schema.hbsdeleted file mode 100644index 526551802a4..00000000000--- a/app/assets/javascripts/admin/addon/templates/customize-themes-schema.hbs+++ /dev/null@@ -1 +0,0 @@-<SchemaThemeSetting::Editor @schema={{this.schema}} @data={{this.data}} />\ No newline at end of filediff --git a/app/assets/javascripts/admin/addon/templates/customize-themes-show-schema.hbs b/app/assets/javascripts/admin/addon/templates/customize-themes-show-schema.hbsnew file mode 100644index 00000000000..509c1b71ff6--- /dev/null+++ b/app/assets/javascripts/admin/addon/templates/customize-themes-show-schema.hbs@@ -0,0 +1,4 @@+<SchemaThemeSetting::Editor+ @schema={{this.model.schema}}+ @data={{this.model.data}}+/>\ No newline at end of filediff --git a/app/assets/javascripts/admin/addon/templates/customize-themes-show.hbs b/app/assets/javascripts/admin/addon/templates/customize-themes-show.hbsindex 56b4a80e985..9be1c3760be 100644--- a/app/assets/javascripts/admin/addon/templates/customize-themes-show.hbs+++ b/app/assets/javascripts/admin/addon/templates/customize-themes-show.hbs@@ -1,531 +1,544 @@-<div class="show-current-style">- <span>- <PluginOutlet- @name="admin-customize-themes-show-top"- @connectorTagName="div"- @outletArgs={{hash theme=this.model}}- />- </span>- <div class="title">- {{#if this.editingName}}- <TextField @value={{this.model.name}} @autofocus="true" />- <DButton- @action={{this.finishedEditingName}}- @icon="check"- class="btn-primary btn-small submit-edit"- />- <DButton- @action={{this.cancelEditingName}}- @icon="times"- class="btn-small cancel-edit"+{{#if this.editingThemeSetting}}+ {{outlet}}+{{else}}+ <div class="show-current-style">+ <span>+ <PluginOutlet+ @name="admin-customize-themes-show-top"+ @connectorTagName="div"+ @outletArgs={{hash theme=this.model}}/>- {{else}}- <span>{{this.model.name}}</span>- <DButton- @action={{this.startEditingName}}- @icon="pencil-alt"- class="btn-small"- />- {{/if}}- </div>+ </span>- <PluginOutlet- @name="admin-customize-theme-before-errors"- @outletArgs={{hash theme=this.model}}- />- {{#each this.model.errors as |error|}}- <div class="alert alert-error">{{error}}</div>- {{/each}}-- {{#if this.finishInstall}}- <div class="control-unit">- {{#if this.sourceIsHttp}}- <a class="remote-url" href={{this.remoteThemeLink}}>{{i18n- "admin.customize.theme.source_url"- }}{{d-icon "link"}}</a>+ <div class="title">+ {{#if this.editingName}}+ <TextField @value={{this.model.name}} @autofocus="true" />+ <DButton+ @action={{this.finishedEditingName}}+ @icon="check"+ class="btn-primary btn-small submit-edit"+ />+ <DButton+ @action={{this.cancelEditingName}}+ @icon="times"+ class="btn-small cancel-edit"+ />{{else}}- <div class="remote-url">- <code>{{this.model.remote_theme.remote_url}}</code>- {{#if this.model.remote_theme.branch}}- (<code>{{this.model.remote_theme.branch}}</code>)- {{/if}}- </div>+ <span>{{this.model.name}}</span>+ <DButton+ @action={{this.startEditingName}}+ @icon="pencil-alt"+ class="btn-small"+ />{{/if}}+ </div>- {{#if this.showRemoteError}}- <div class="error-message">- {{d-icon "exclamation-triangle"}}- {{i18n "admin.customize.theme.repo_unreachable"}}- </div>- <div class="raw-error">- <code>{{this.model.remoteError}}</code>- </div>- {{/if}}+ <PluginOutlet+ @name="admin-customize-theme-before-errors"+ @outletArgs={{hash theme=this.model}}+ />- <DButton- @action={{this.updateToLatest}}- @icon="download"- @label="admin.customize.theme.finish_install"- class="btn-primary finish-install"- />- <DButton- @action={{this.destroyTheme}}- @label="admin.customize.delete"- @icon="trash-alt"- class="btn-danger"- />+ {{#each this.model.errors as |error|}}+ <div class="alert alert-error">{{error}}</div>+ {{/each}}- <span class="status-message">- {{i18n "admin.customize.theme.last_attempt"}}- {{format-date this.model.remote_theme.updated_at leaveAgo="true"}}- </span>- </div>- {{else}}- {{#unless this.model.supported}}- <div class="alert alert-error">- {{i18n "admin.customize.theme.required_version.error"}}- {{#if this.model.remote_theme.minimum_discourse_version}}- {{i18n- "admin.customize.theme.required_version.minimum"- version=this.model.remote_theme.minimum_discourse_version- }}- {{/if}}- {{#if this.model.remote_theme.maximum_discourse_version}}- {{i18n- "admin.customize.theme.required_version.maximum"- version=this.model.remote_theme.maximum_discourse_version- }}- {{/if}}- </div>- {{/unless}}-- {{#unless this.model.enabled}}- <div class="alert alert-error">- {{#if this.model.disabled_by}}- {{i18n "admin.customize.theme.disabled_by"}}- <UserLink @user={{this.model.disabled_by}}>- {{avatar this.model.disabled_by imageSize="tiny"}}- {{this.model.disabled_by.username}}- </UserLink>- {{format-date this.model.disabled_at leaveAgo="true"}}+ {{#if this.finishInstall}}+ <div class="control-unit">+ {{#if this.sourceIsHttp}}+ <a class="remote-url" href={{this.remoteThemeLink}}>{{i18n+ "admin.customize.theme.source_url"+ }}{{d-icon "link"}}</a>{{else}}- {{i18n "admin.customize.theme.disabled"}}+ <div class="remote-url">+ <code>{{this.model.remote_theme.remote_url}}</code>+ {{#if this.model.remote_theme.branch}}+ (<code>{{this.model.remote_theme.branch}}</code>)+ {{/if}}+ </div>+ {{/if}}++ {{#if this.showRemoteError}}+ <div class="error-message">+ {{d-icon "exclamation-triangle"}}+ {{i18n "admin.customize.theme.repo_unreachable"}}+ </div>+ <div class="raw-error">+ <code>{{this.model.remoteError}}</code>+ </div>{{/if}}+<DButton- @action={{this.enableComponent}}- @icon="check"- @label="admin.customize.theme.enable"- class="btn-default"+ @action={{this.updateToLatest}}+ @icon="download"+ @label="admin.customize.theme.finish_install"+ class="btn-primary finish-install"+ />+ <DButton+ @action={{this.destroyTheme}}+ @label="admin.customize.delete"+ @icon="trash-alt"+ class="btn-danger"/>++ <span class="status-message">+ {{i18n "admin.customize.theme.last_attempt"}}+ {{format-date this.model.remote_theme.updated_at leaveAgo="true"}}+ </span></div>- {{/unless}}-- <div class="metadata control-unit">- {{#if this.model.remote_theme}}- {{#if this.model.remote_theme.remote_url}}- {{#if this.sourceIsHttp}}- <a class="remote-url" href={{this.remoteThemeLink}}>{{i18n- "admin.customize.theme.source_url"- }}{{d-icon "link"}}</a>+ {{else}}+ {{#unless this.model.supported}}+ <div class="alert alert-error">+ {{i18n "admin.customize.theme.required_version.error"}}+ {{#if this.model.remote_theme.minimum_discourse_version}}+ {{i18n+ "admin.customize.theme.required_version.minimum"+ version=this.model.remote_theme.minimum_discourse_version+ }}+ {{/if}}+ {{#if this.model.remote_theme.maximum_discourse_version}}+ {{i18n+ "admin.customize.theme.required_version.maximum"+ version=this.model.remote_theme.maximum_discourse_version+ }}+ {{/if}}+ </div>+ {{/unless}}++ {{#unless this.model.enabled}}+ <div class="alert alert-error">+ {{#if this.model.disabled_by}}+ {{i18n "admin.customize.theme.disabled_by"}}+ <UserLink @user={{this.model.disabled_by}}>+ {{avatar this.model.disabled_by imageSize="tiny"}}+ {{this.model.disabled_by.username}}+ </UserLink>+ {{format-date this.model.disabled_at leaveAgo="true"}}{{else}}- <div class="remote-url">- <code>{{this.model.remote_theme.remote_url}}</code>- {{#if this.model.remote_theme.branch}}- (<code>{{this.model.remote_theme.branch}}</code>)- {{/if}}- </div>+ {{i18n "admin.customize.theme.disabled"}}{{/if}}- {{/if}}- {{#if this.model.remote_theme.about_url}}- <a- class="url about-url"- href={{this.model.remote_theme.about_url}}- >{{i18n "admin.customize.theme.about_theme"}}{{d-icon "link"}}</a>- {{/if}}- {{#if this.model.remote_theme.license_url}}- <a- class="url license-url"- href={{this.model.remote_theme.license_url}}- >{{i18n "admin.customize.theme.license"}}{{d-icon "link"}}</a>- {{/if}}+ <DButton+ @action={{this.enableComponent}}+ @icon="check"+ @label="admin.customize.theme.enable"+ class="btn-default"+ />+ </div>+ {{/unless}}- {{#if this.model.description}}- <span class="theme-description">{{this.model.description}}</span>- {{/if}}+ <div class="metadata control-unit">+ {{#if this.model.remote_theme}}+ {{#if this.model.remote_theme.remote_url}}+ {{#if this.sourceIsHttp}}+ <a class="remote-url" href={{this.remoteThemeLink}}>{{i18n+ "admin.customize.theme.source_url"+ }}{{d-icon "link"}}</a>+ {{else}}+ <div class="remote-url">+ <code>{{this.model.remote_theme.remote_url}}</code>+ {{#if this.model.remote_theme.branch}}+ (<code>{{this.model.remote_theme.branch}}</code>)+ {{/if}}+ </div>+ {{/if}}+ {{/if}}- {{#if this.model.remote_theme.authors}}<span class="authors"><span- class="heading"- >{{i18n "admin.customize.theme.authors"}}</span>- {{this.model.remote_theme.authors}}</span>{{/if}}- {{#if this.model.remote_theme.theme_version}}<span class="version"><span- class="heading"- >{{i18n "admin.customize.theme.version"}}</span>- {{this.model.remote_theme.theme_version}}</span>{{/if}}+ {{#if this.model.remote_theme.about_url}}+ <a+ class="url about-url"+ href={{this.model.remote_theme.about_url}}+ >{{i18n "admin.customize.theme.about_theme"}}{{d-icon "link"}}</a>+ {{/if}}- <div class="control-unit">- {{#if this.model.remote_theme.is_git}}- <div class="alert alert-info">- {{html-safe- (i18n- "admin.customize.theme.remote_theme_edits"- repoURL=this.remoteThemeLink- )- }}- </div>+ {{#if this.model.remote_theme.license_url}}+ <a+ class="url license-url"+ href={{this.model.remote_theme.license_url}}+ >{{i18n "admin.customize.theme.license"}}{{d-icon "link"}}</a>+ {{/if}}- {{#if this.showRemoteError}}- <div class="error-message">- {{d-icon "exclamation-triangle"}}- {{i18n "admin.customize.theme.repo_unreachable"}}- </div>- <div class="raw-error">- <code>{{this.model.remoteError}}</code>+ {{#if this.model.description}}+ <span class="theme-description">{{this.model.description}}</span>+ {{/if}}++ {{#if this.model.remote_theme.authors}}<span class="authors"><span+ class="heading"+ >{{i18n "admin.customize.theme.authors"}}</span>+ {{this.model.remote_theme.authors}}</span>{{/if}}++ {{#if this.model.remote_theme.theme_version}}<span+ class="version"+ ><span class="heading">{{i18n+ "admin.customize.theme.version"+ }}</span>+ {{this.model.remote_theme.theme_version}}</span>{{/if}}++ <div class="control-unit">+ {{#if this.model.remote_theme.is_git}}+ <div class="alert alert-info">+ {{html-safe+ (i18n+ "admin.customize.theme.remote_theme_edits"+ repoURL=this.remoteThemeLink+ )+ }}</div>- {{/if}}- {{#if this.model.remote_theme.commits_behind}}- <DButton- @action={{this.updateToLatest}}- @icon="download"- @label="admin.customize.theme.update_to_latest"- class="btn-primary"- />- {{else}}- <DButton- @action={{this.checkForThemeUpdates}}- @icon="sync"- @label="admin.customize.theme.check_for_updates"- class="btn-default"- />- {{/if}}+ {{#if this.showRemoteError}}+ <div class="error-message">+ {{d-icon "exclamation-triangle"}}+ {{i18n "admin.customize.theme.repo_unreachable"}}+ </div>+ <div class="raw-error">+ <code>{{this.model.remoteError}}</code>+ </div>+ {{/if}}- <span class="status-message">- {{#if this.updatingRemote}}- {{i18n "admin.customize.theme.updating"}}+ {{#if this.model.remote_theme.commits_behind}}+ <DButton+ @action={{this.updateToLatest}}+ @icon="download"+ @label="admin.customize.theme.update_to_latest"+ class="btn-primary"+ />{{else}}- {{#if this.model.remote_theme.commits_behind}}- {{#if this.hasOverwrittenHistory}}- {{i18n "admin.customize.theme.has_overwritten_history"}}+ <DButton+ @action={{this.checkForThemeUpdates}}+ @icon="sync"+ @label="admin.customize.theme.check_for_updates"+ class="btn-default"+ />+ {{/if}}++ <span class="status-message">+ {{#if this.updatingRemote}}+ {{i18n "admin.customize.theme.updating"}}+ {{else}}+ {{#if this.model.remote_theme.commits_behind}}+ {{#if this.hasOverwrittenHistory}}+ {{i18n "admin.customize.theme.has_overwritten_history"}}+ {{else}}+ {{i18n+ "admin.customize.theme.commits_behind"+ count=this.model.remote_theme.commits_behind+ }}+ {{/if}}+ {{#if this.model.remote_theme.github_diff_link}}+ <a href={{this.model.remote_theme.github_diff_link}}>+ {{i18n "admin.customize.theme.compare_commits"}}+ </a>+ {{/if}}{{else}}- {{i18n- "admin.customize.theme.commits_behind"- count=this.model.remote_theme.commits_behind- }}+ {{#unless this.showRemoteError}}+ {{i18n "admin.customize.theme.up_to_date"}}+ {{format-date+ this.model.remote_theme.updated_at+ leaveAgo="true"+ }}+ {{/unless}}{{/if}}- {{#if this.model.remote_theme.github_diff_link}}- <a href={{this.model.remote_theme.github_diff_link}}>- {{i18n "admin.customize.theme.compare_commits"}}- </a>- {{/if}}- {{else}}- {{#unless this.showRemoteError}}- {{i18n "admin.customize.theme.up_to_date"}}- {{format-date- this.model.remote_theme.updated_at- leaveAgo="true"- }}- {{/unless}}{{/if}}- {{/if}}- </span>- {{else}}- <span class="status-message">- {{d-icon "info-circle"}}- {{i18n "admin.customize.theme.imported_from_archive"}}- </span>+ </span>+ {{else}}+ <span class="status-message">+ {{d-icon "info-circle"}}+ {{i18n "admin.customize.theme.imported_from_archive"}}+ </span>+ {{/if}}+ </div>+ {{else}}+ <span class="heading">{{i18n "admin.customize.theme.creator"}}</span>+ <span>+ <UserLink @user={{this.model.user}}>+ {{format-username this.model.user.username}}+ </UserLink>+ </span>+ {{/if}}+ </div>++ {{#if this.showCheckboxes}}+ <div class="control-unit">+ {{#unless this.model.component}}+ <InlineEditCheckbox+ @action={{action "applyDefault"}}+ @labelKey="admin.customize.theme.is_default"+ @checked={{this.model.default}}+ @modelId={{this.model.id}}+ />+ <InlineEditCheckbox+ @action={{action "applyUserSelectable"}}+ @labelKey="admin.customize.theme.user_selectable"+ @checked={{this.model.user_selectable}}+ @modelId={{this.model.id}}+ />+ {{/unless}}+ {{#if this.model.remote_theme}}+ <InlineEditCheckbox+ @action={{action "applyAutoUpdateable"}}+ @labelKey="admin.customize.theme.auto_update"+ @checked={{this.model.auto_update}}+ @modelId={{this.model.id}}+ />{{/if}}</div>- {{else}}- <span class="heading">{{i18n "admin.customize.theme.creator"}}</span>- <span>- <UserLink @user={{this.model.user}}>- {{format-username this.model.user.username}}- </UserLink>- </span>{{/if}}- </div>- {{#if this.showCheckboxes}}- <div class="control-unit">- {{#unless this.model.component}}- <InlineEditCheckbox- @action={{action "applyDefault"}}- @labelKey="admin.customize.theme.is_default"- @checked={{this.model.default}}- @modelId={{this.model.id}}- />- <InlineEditCheckbox- @action={{action "applyUserSelectable"}}- @labelKey="admin.customize.theme.user_selectable"- @checked={{this.model.user_selectable}}- @modelId={{this.model.id}}- />- {{/unless}}- {{#if this.model.remote_theme}}- <InlineEditCheckbox- @action={{action "applyAutoUpdateable"}}- @labelKey="admin.customize.theme.auto_update"- @checked={{this.model.auto_update}}- @modelId={{this.model.id}}- />- {{/if}}- </div>- {{/if}}+ {{#unless this.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>- {{#unless this.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={{this.colorSchemes}}+ @value={{this.colorSchemeId}}+ @icon="paint-brush"+ @options={{hash filterable=true}}+ />+ {{#if this.colorSchemeId}}+ <DButton+ @icon="pen"+ @action={{this.editColorScheme}}+ @title="admin.customize.theme.edit_color_scheme"+ />+ {{/if}}+ </div>- <div class="setting-value">- <div class="color-palette-input-group">- <ColorPalettes- @content={{this.colorSchemes}}- @value={{this.colorSchemeId}}- @icon="paint-brush"- @options={{hash filterable=true}}- />- {{#if this.colorSchemeId}}+ <div class="desc">{{i18n+ "admin.customize.theme.color_scheme_select"+ }}</div>+ </div>++ <div class="setting-controls">+ {{#if this.colorSchemeChanged}}+ <DButton+ @action={{this.changeScheme}}+ @icon="check"+ class="ok submit-edit"+ /><DButton- @icon="pen"- @action={{this.editColorScheme}}- @title="admin.customize.theme.edit_color_scheme"+ @action={{this.cancelChangeScheme}}+ @icon="times"+ class="cancel cancel-edit"/>{{/if}}</div>-- <div class="desc">{{i18n- "admin.customize.theme.color_scheme_select"- }}</div></div>+ </section>+ {{/unless}}- <div class="setting-controls">- {{#if this.colorSchemeChanged}}- <DButton- @action={{this.changeScheme}}- @icon="check"- class="ok submit-edit"- />- <DButton- @action={{this.cancelChangeScheme}}- @icon="times"- class="cancel cancel-edit"- />- {{/if}}+ {{#if this.model.component}}+ <section class="form-horizontal theme settings control-unit">+ <div class="row setting">+ <ThemeSettingRelativesSelector+ @setting={{this.relativesSelectorSettingsForComponent}}+ @model={{this.model}}+ class="theme-setting"+ /></div>- </div>- </section>- {{/unless}}-- {{#if this.model.component}}- <section class="form-horizontal theme settings control-unit">- <div class="row setting">- <ThemeSettingRelativesSelector- @setting={{this.relativesSelectorSettingsForComponent}}- @model={{this.model}}- class="theme-setting"+ </section>+ {{else}}+ <section class="form-horizontal theme settings control-unit">+ <div class="row setting">+ <ThemeSettingRelativesSelector+ @setting={{this.relativesSelectorSettingsForTheme}}+ @model={{this.model}}+ class="theme-setting"+ />+ </div>+ </section>+ {{/if}}++ {{#unless this.model.remote_theme.is_git}}+ <div class="control-unit">+ <div class="mini-title">{{i18n+ "admin.customize.theme.css_html"+ }}</div>+ {{#if this.model.hasEditedFields}}+ <div class="description">{{i18n+ "admin.customize.theme.custom_sections"+ }}</div>+ <ul>+ {{#each this.editedFieldsFormatted as |field|}}+ <li>{{field}}</li>+ {{/each}}+ </ul>+ {{else}}+ <div class="description">+ {{i18n "admin.customize.theme.edit_css_html_help"}}+ </div>+ {{/if}}++ <DButton+ @action={{this.editTheme}}+ @label="admin.customize.theme.edit_css_html"+ class="btn-default edit"/></div>- </section>- {{else}}- <section class="form-horizontal theme settings control-unit">- <div class="row setting">- <ThemeSettingRelativesSelector- @setting={{this.relativesSelectorSettingsForTheme}}- @model={{this.model}}- class="theme-setting"++ <div class="control-unit">+ <div class="mini-title">{{i18n "admin.customize.theme.uploads"}}</div>+ {{#if this.model.uploads}}+ <ul class="removable-list">+ {{#each this.model.uploads as |upload|}}+ <li>+ <span class="col">${{upload.name}}:+ <a+ href={{upload.url}}+ rel="noopener noreferrer"+ target="_blank"+ >{{upload.filename}}</a></span>+ <span class="col">+ <DButton+ @action={{fn this.removeUpload upload}}+ @icon="times"+ 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={{this.addUploadModal}}+ @icon="plus"+ @label="admin.customize.theme.add"+ class="btn-default"/></div>- </section>- {{/if}}+ {{/unless}}- {{#unless this.model.remote_theme.is_git}}- <div class="control-unit">- <div class="mini-title">{{i18n "admin.customize.theme.css_html"}}</div>- {{#if this.model.hasEditedFields}}- <div class="description">{{i18n- "admin.customize.theme.custom_sections"+ {{#if this.extraFiles.length}}+ <div class="control-unit">+ <div class="mini-title">{{i18n+ "admin.customize.theme.extra_files"}}</div>- <ul>- {{#each this.editedFieldsFormatted as |field|}}- <li>{{field}}</li>- {{/each}}- </ul>- {{else}}- <div class="description">- {{i18n "admin.customize.theme.edit_css_html_help"}}- </div>- {{/if}}-- <DButton- @action={{this.editTheme}}- @label="admin.customize.theme.edit_css_html"- class="btn-default edit"- />- </div>+ <details>+ <summary>+ {{#if this.model.remote_theme}}+ {{i18n "admin.customize.theme.extra_files_remote"}}+ {{else}}+ {{i18n "admin.customize.theme.extra_files_upload"}}+ {{/if}}+ </summary>+ <ul>+ {{#each this.extraFiles as |extraFile|}}+ <li>{{extraFile.name}}</li>+ {{/each}}+ </ul>+ </details>+ </div>+ {{/if}}- <div class="control-unit">- <div class="mini-title">{{i18n "admin.customize.theme.uploads"}}</div>- {{#if this.model.uploads}}- <ul class="removable-list">- {{#each this.model.uploads as |upload|}}- <li>- <span class="col">${{upload.name}}:- <a- href={{upload.url}}- rel="noopener noreferrer"- target="_blank"- >{{upload.filename}}</a></span>- <span class="col">- <DButton- @action={{fn this.removeUpload upload}}- @icon="times"- class="second btn-default btn-default cancel-edit"- />- </span>- </li>- {{/each}}- </ul>- {{else}}- <div class="description">{{i18n- "admin.customize.theme.no_uploads"+ {{#if this.hasSettings}}+ <div class="control-unit">+ <div class="mini-title">{{i18n+ "admin.customize.theme.theme_settings"}}</div>- {{/if}}- <DButton- @action={{this.addUploadModal}}- @icon="plus"- @label="admin.customize.theme.add"- class="btn-default"- />- </div>- {{/unless}}-- {{#if this.extraFiles.length}}- <div class="control-unit">- <div class="mini-title">{{i18n- "admin.customize.theme.extra_files"- }}</div>- <details>- <summary>- {{#if this.model.remote_theme}}- {{i18n "admin.customize.theme.extra_files_remote"}}- {{else}}- {{i18n "admin.customize.theme.extra_files_upload"}}- {{/if}}- </summary>- <ul>- {{#each this.extraFiles as |extraFile|}}- <li>{{extraFile.name}}</li>+ <p><i>{{i18n+ "admin.customize.theme.overriden_settings_explanation"+ }}</i></p>+ <section class="form-horizontal theme settings control-unit">+ {{#each this.settings as |setting|}}+ <ThemeSettingEditor+ @setting={{setting}}+ @model={{this.model}}+ class="theme-setting control-unit"+ />{{/each}}- </ul>- </details>- </div>- {{/if}}-- {{#if this.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 this.settings as |setting|}}- <ThemeSettingEditor- @setting={{setting}}- @model={{this.model}}- class="theme-setting control-unit"- />- {{/each}}- </section>- </div>- {{/if}}-- {{#if this.hasTranslations}}- <div class="control-unit">- <div class="mini-title">{{i18n- "admin.customize.theme.theme_translations"- }}</div>- <section- class="form-horizontal theme settings translations control-unit"- >- {{#each this.translations as |translation|}}- <ThemeTranslation- @translation={{translation}}- @model={{this.model}}- class="theme-translation"- />- {{/each}}- </section>- </div>- {{/if}}+ </section>+ </div>+ {{/if}}- <PluginOutlet- @name="admin-customize-theme-before-controls"- @outletArgs={{hash theme=this.model}}- />- <div class="theme-controls">- <a- href={{this.previewUrl}}- title={{i18n "admin.customize.explain_preview"}}- rel="noopener noreferrer"- target="_blank"- class="btn btn-default"- >{{d-icon "desktop"}}{{i18n "admin.customize.theme.preview"}}</a>- <a- class="btn btn-default export"- rel="noopener noreferrer"- target="_blank"- href={{this.downloadUrl}}- >{{d-icon "download"}} {{i18n "admin.export_json.button_text"}}</a>-- {{#if this.showConvert}}- <DButton- @action={{this.switchType}}- @label="admin.customize.theme.convert"- @icon={{this.convertIcon}}- @title={{this.convertTooltip}}- class="btn-default btn-normal"- />+ {{#if this.hasTranslations}}+ <div class="control-unit">+ <div class="mini-title">{{i18n+ "admin.customize.theme.theme_translations"+ }}</div>+ <section+ class="form-horizontal theme settings translations control-unit"+ >+ {{#each this.translations as |translation|}}+ <ThemeTranslation+ @translation={{translation}}+ @model={{this.model}}+ class="theme-translation"+ />+ {{/each}}+ </section>+ </div>{{/if}}- {{#if this.model.component}}- {{#if this.model.enabled}}+ <PluginOutlet+ @name="admin-customize-theme-before-controls"+ @outletArgs={{hash theme=this.model}}+ />+ <div class="theme-controls">+ <a+ href={{this.previewUrl}}+ title={{i18n "admin.customize.explain_preview"}}+ rel="noopener noreferrer"+ target="_blank"+ class="btn btn-default"+ >{{d-icon "desktop"}}{{i18n "admin.customize.theme.preview"}}</a>+ <a+ class="btn btn-default export"+ rel="noopener noreferrer"+ target="_blank"+ href={{this.downloadUrl}}+ >{{d-icon "download"}} {{i18n "admin.export_json.button_text"}}</a>++ {{#if this.showConvert}}<DButton- @action={{this.disableComponent}}- @icon="ban"- @label="admin.customize.theme.disable"- class="btn-default"+ @action={{this.switchType}}+ @label="admin.customize.theme.convert"+ @icon={{this.convertIcon}}+ @title={{this.convertTooltip}}+ class="btn-default btn-normal"/>- {{else}}+ {{/if}}++ {{#if this.model.component}}+ {{#if this.model.enabled}}+ <DButton+ @action={{this.disableComponent}}+ @icon="ban"+ @label="admin.customize.theme.disable"+ class="btn-default"+ />+ {{else}}+ <DButton+ @action={{this.enableComponent}}+ @icon="check"+ @label="admin.customize.theme.enable"+ class="btn-default"+ />+ {{/if}}+ {{/if}}+ {{#if this.hasSettings}}<DButton- @action={{this.enableComponent}}- @icon="check"- @label="admin.customize.theme.enable"- class="btn-default"+ @action={{this.showThemeSettingsEditor}}+ @label="admin.customize.theme.settings_editor"+ @icon="pen"+ @title="admin.customize.theme.settings_editor"+ class="btn-default btn-normal"/>{{/if}}- {{/if}}- {{#if this.hasSettings}}<DButton- @action={{this.showThemeSettingsEditor}}- @label="admin.customize.theme.settings_editor"- @icon="pen"- @title="admin.customize.theme.settings_editor"- class="btn-default btn-normal"+ @action={{this.destroyTheme}}+ @label="admin.customize.delete"+ @icon="trash-alt"+ class="btn-danger"/>- {{/if}}- <DButton- @action={{this.destroyTheme}}- @label="admin.customize.delete"- @icon="trash-alt"- class="btn-danger"- />- </div>- {{/if}}-</div>\ No newline at end of file+ </div>+ {{/if}}+ </div>+{{/if}}\ No newline at end of filediff --git a/app/assets/javascripts/discourse/app/components/modal/json-schema-editor.hbs b/app/assets/javascripts/discourse/app/components/modal/json-schema-editor.hbsindex 2900864797b..f1ce01d1f14 100644--- a/app/assets/javascripts/discourse/app/components/modal/json-schema-editor.hbs+++ b/app/assets/javascripts/discourse/app/components/modal/json-schema-editor.hbs@@ -4,7 +4,7 @@@closeModal={{@closeModal}}@title={{i18n"admin.site_settings.json_schema.modal_title"- name=@settingName}}class="json-schema-editor-modal">diff --git a/app/assets/javascripts/discourse/app/components/modal/json-schema-editor.js b/app/assets/javascripts/discourse/app/components/modal/json-schema-editor.jsindex 65578a81b99..4db239e7478 100644--- a/app/assets/javascripts/discourse/app/components/modal/json-schema-editor.js+++ b/app/assets/javascripts/discourse/app/components/modal/json-schema-editor.js@@ -8,12 +8,12 @@ import { afterRender } from "discourse-common/utils/decorators";export default class JsonSchemaEditorModal extends Component {@tracked editor = null;- @tracked value = this.args.value;+ @tracked value = this.args.model.value;@tracked flash;@tracked flashType;get settingName() {- return this.args.settingName.replace(/\_/g, " ");+ return this.args.model.settingName.replace(/\_/g, " ");}@action@@ -34,7 +34,7 @@ export default class JsonSchemaEditorModal extends Component {if (!errors.length) {this.value = JSON.stringify(this.editor.getValue());- this.args.updateValue(this.value);+ this.args.model.updateValue(this.value);this.args.closeModal();} else {this.flash = errors.mapBy("message").join("\n");@@ -53,7 +53,7 @@ export default class JsonSchemaEditorModal extends Component {JSONEditor.defaults.options.iconlib = "discourseIcons";this.editor = new JSONEditor(editor, {- schema: this.args.jsonSchema,+ schema: this.args.model.jsonSchema,disable_array_delete_all_rows: true,disable_array_delete_last_row: true,disable_array_reorder: false,diff --git a/app/serializers/theme_settings_serializer.rb b/app/serializers/theme_settings_serializer.rbindex cbd01da5a87..7ab1d54df42 100644--- a/app/serializers/theme_settings_serializer.rb+++ b/app/serializers/theme_settings_serializer.rb@@ -9,7 +9,8 @@ class ThemeSettingsSerializer < ApplicationSerializer:valid_values,:list_type,:textarea,- :json_schema+ :json_schema,+ :objects_schemadef settingobject.name@@ -65,6 +66,14 @@ class ThemeSettingsSerializer < ApplicationSerializerobject.type == ThemeSetting.types[:string]end+ def objects_schema+ object.schema+ end++ def include_objects_schema?+ object.type == ThemeSetting.types[:objects]+ end+def json_schemaobject.json_schemaenddiff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex c1d34b96b69..d10bab68b49 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -5485,6 +5485,7 @@ en:has_overwritten_history: "Current theme version no longer exists because the Git history has been overwritten by a force push."add: "Add"theme_settings: "Theme Settings"+ edit_objects_theme_setting: "Objects Setting Editor"overriden_settings_explanation: "Overridden settings are marked with a dot and have a highlighted color. To reset these settings to the default value, press the reset button next to them."no_settings: "This theme has no settings."theme_translations: "Theme Translations"diff --git a/lib/theme_settings_manager/objects.rb b/lib/theme_settings_manager/objects.rbindex 3f51f6293bf..09da18bde79 100644--- a/lib/theme_settings_manager/objects.rb+++ b/lib/theme_settings_manager/objects.rb@@ -14,4 +14,8 @@ class ThemeSettingsManager::Objects < ThemeSettingsManagertheme.reloadrecord.json_valueend++ def schema+ @opts[:schema]+ endenddiff --git a/spec/serializers/theme_settings_serializer_spec.rb b/spec/serializers/theme_settings_serializer_spec.rbnew file mode 100644index 00000000000..69860527ed0--- /dev/null+++ b/spec/serializers/theme_settings_serializer_spec.rb@@ -0,0 +1,22 @@+# frozen_string_literal: true++RSpec.describe ThemeSettingsSerializer do+ fab!(:theme)++ describe "#objects_schema" do+ let(:objects_setting) do+ yaml = File.read("#{Rails.root}/spec/fixtures/theme_settings/objects_settings.yaml")+ theme.set_field(target: :settings, name: "yaml", value: yaml)+ theme.save!+ theme.settings[:objects_setting]+ end++ before { SiteSetting.experimental_objects_type_for_theme_settings = true }++ it "should include the attribute when theme setting is typed objects" do+ payload = ThemeSettingsSerializer.new(objects_setting).as_json++ expect(payload[:theme_settings][:objects_schema][:name]).to eq("sections")+ end+ end+enddiff --git a/spec/system/admin_customize_themes_spec.rb b/spec/system/admin_customize_themes_spec.rbindex 9fac1e4b9ee..4031e5d3ca5 100644--- a/spec/system/admin_customize_themes_spec.rb+++ b/spec/system/admin_customize_themes_spec.rb@@ -5,12 +5,13 @@ describe "Admin Customize Themes", type: :system dofab!(:theme)fab!(:admin)+ let(:admin_customize_themes_page) { PageObjects::Pages::AdminCustomizeThemes.new }+before { sign_in(admin) }describe "when visiting the page to customize themes" dofab!(:theme_2) { Fabricate(:theme) }fab!(:theme_3) { Fabricate(:theme) }- let(:admin_customize_themes_page) { PageObjects::Pages::AdminCustomizeThemes.new }let(:delete_themes_confirm_modal) { PageObjects::Modals::DeleteThemesConfirm.new }it "should allow admin to bulk delete inactive themes" do@@ -84,4 +85,32 @@ describe "Admin Customize Themes", type: :system doexpect(ace_content.text).to eq("console.log('test')")endend++ describe "when editing a theme setting of objects type" do+ let(:objects_setting) do+ theme.set_field(+ target: :settings,+ name: "yaml",+ value: File.read("#{Rails.root}/spec/fixtures/theme_settings/objects_settings.yaml"),+ )++ theme.save!+ theme.settings[:objects_setting]+ end++ before do+ SiteSetting.experimental_objects_type_for_theme_settings = true+ objects_setting+ end++ it "should allow admin to edit the theme setting of objecst type" do+ visit("/admin/customize/themes/#{theme.id}")++ admin_customize_themes_page.click_edit_objects_theme_setting_button("objects_setting")++ expect(page).to have_current_path(+ "/admin/customize/themes/#{theme.id}/schema/objects_setting",+ )+ end+ endenddiff --git a/spec/system/page_objects/pages/admin_customize_themes.rb b/spec/system/page_objects/pages/admin_customize_themes.rbindex 8c891688492..1ce116edc6a 100644--- a/spec/system/page_objects/pages/admin_customize_themes.rb+++ b/spec/system/page_objects/pages/admin_customize_themes.rb@@ -38,6 +38,10 @@ module PageObjectsdef click_delete_themes_buttonfind(".btn-delete").clickend++ def click_edit_objects_theme_setting_button(setting_name)+ find(".theme-setting[data-setting=\"#{setting_name}\"] .setting-value-edit-button").click+ endendendend