discourse/app/assets/javascripts/admin/addon/models/theme-settings.js
Kelv b07e7cc70f
DEV: refactor setting object mixin to helper class (#30529)
This PR moves the logic from the setting-object mixin to a helper class. I've opted to maintain the interface of the previous classes (ThemeSettings / SiteSetting) that used the mixed-in methods through aliases so that we limit the amount of changes here (these are referenced in the string form and across classes/templates).

Another option we may consider in future if we want to optimize for performance is straight duplication which would trade off this overhead of aliasing/chaining calls through the helper for some duplicate code - only 2 models require these methods at the time of this PR.
2025-01-06 12:02:46 +08:00

39 lines
1.2 KiB
JavaScript

import EmberObject from "@ember/object";
import { alias } from "@ember/object/computed";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import SettingObjectHelper from "admin/lib/setting-object-helper";
export default class ThemeSettings extends EmberObject {
settingObjectHelper = new SettingObjectHelper(this);
@alias("settingObjectHelper.overridden") overridden;
@alias("settingObjectHelper.computedValueProperty") computedValueProperty;
@alias("settingObjectHelper.computedNameProperty") computedNameProperty;
@alias("settingObjectHelper.validValues") validValues;
@alias("settingObjectHelper.allowsNone") allowsNone;
@alias("settingObjectHelper.anyValue") anyValue;
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,
},
});
}
loadMetadata(themeId) {
return ajax(
`/admin/themes/${themeId}/objects_setting_metadata/${this.setting}.json`
)
.then((result) => this.set("metadata", result))
.catch(popupAjaxError);
}
}