forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV: Allow typed objects theme settings to be saved via settings edit…
…or (discourse#26100) Why this change? On the `/admin/customize/themes/<:id>` route, we allow admins to edit all settings via a settings editor. Prior to this change, trying to edit and save a typed objects theme settings will result in an error on the server.
- Loading branch information
Showing
11 changed files
with
171 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 4 additions & 11 deletions
15
app/assets/javascripts/admin/addon/components/theme-setting-editor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
import { ajax } from "discourse/lib/ajax"; | ||
import { url } from "discourse/lib/computed"; | ||
import SiteSettingComponent from "./site-setting"; | ||
|
||
export default class extends SiteSettingComponent { | ||
@url("model.id", "/admin/themes/%@/setting") updateUrl; | ||
|
||
_save() { | ||
return ajax(this.updateUrl, { | ||
type: "PUT", | ||
data: { | ||
name: this.setting.setting, | ||
value: this.get("buffered.value"), | ||
}, | ||
}); | ||
return this.setting.updateSetting( | ||
this.model.id, | ||
this.get("buffered.value") | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 16 additions & 1 deletion
17
app/assets/javascripts/admin/addon/models/theme-settings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
import EmberObject from "@ember/object"; | ||
import { ajax } from "discourse/lib/ajax"; | ||
import Setting from "admin/mixins/setting-object"; | ||
|
||
export default class ThemeSettings extends EmberObject.extend(Setting) {} | ||
export default class ThemeSettings extends EmberObject.extend(Setting) { | ||
updateSetting(themeId, newValue) { | ||
if (this.objects_schema) { | ||
newValue = JSON.stringify(newValue); | ||
} | ||
|
||
return ajax(`/admin/themes/${themeId}/setting`, { | ||
type: "PUT", | ||
data: { | ||
name: this.setting, | ||
value: newValue, | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
spec/system/page_objects/components/admin_theme_settings_editor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module PageObjects | ||
module Components | ||
class AdminThemeSettingsEditor < Base | ||
def fill_in(settings) | ||
editor.fill_input(settings) | ||
self | ||
end | ||
|
||
def save | ||
click_button(I18n.t("admin_js.admin.customize.theme.save")) | ||
self | ||
end | ||
|
||
private | ||
|
||
def editor | ||
@editor ||= within(".settings-editor") { AceEditor.new } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters