mirror of
https://github.com/discourse/discourse.git
synced 2025-02-26 01:07:59 +08:00

`discourse-common` was created in the past to share logic between the 'wizard' app and the main 'discourse' app. Since then, the wizard has been consolidated into the main app, so the separation of `discourse-common` is no longer useful. This commit moves `discourse-common/(lib|utils)/*` into `discourse/lib/*`, adds shims for the imports, and updates existing uses in core.
79 lines
1.8 KiB
JavaScript
79 lines
1.8 KiB
JavaScript
import { dependentKeyCompat } from "@ember/object/compat";
|
|
import { isPresent } from "@ember/utils";
|
|
import { deepEqual } from "discourse/lib/object";
|
|
import { i18n } from "discourse-i18n";
|
|
|
|
export default class SettingObjectHelper {
|
|
constructor(settingObj) {
|
|
this.settingObj = settingObj;
|
|
}
|
|
|
|
@dependentKeyCompat
|
|
get overridden() {
|
|
let val = this.settingObj.get("value");
|
|
let defaultVal = this.settingObj.get("default");
|
|
|
|
if (val === null) {
|
|
val = "";
|
|
}
|
|
if (defaultVal === null) {
|
|
defaultVal = "";
|
|
}
|
|
|
|
return !deepEqual(val, defaultVal);
|
|
}
|
|
|
|
@dependentKeyCompat
|
|
get computedValueProperty() {
|
|
if (isPresent(this.settingObj.get("valueProperty"))) {
|
|
return this.settingObj.get("valueProperty");
|
|
}
|
|
|
|
if (isPresent(this.validValues.get("firstObject.value"))) {
|
|
return "value";
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@dependentKeyCompat
|
|
get computedNameProperty() {
|
|
if (isPresent(this.settingObj.get("nameProperty"))) {
|
|
return this.settingObj.get("nameProperty");
|
|
}
|
|
|
|
if (isPresent(this.validValues.get("firstObject.name"))) {
|
|
return "name";
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@dependentKeyCompat
|
|
get validValues() {
|
|
const originalValidValues = this.settingObj.get("valid_values");
|
|
const values = [];
|
|
const translateNames = this.settingObj.translate_names;
|
|
|
|
(originalValidValues || []).forEach((v) => {
|
|
if (v.name && v.name.length > 0 && translateNames) {
|
|
values.addObject({ name: i18n(v.name), value: v.value });
|
|
} else {
|
|
values.addObject(v);
|
|
}
|
|
});
|
|
return values;
|
|
}
|
|
|
|
@dependentKeyCompat
|
|
get allowsNone() {
|
|
if (this.settingObj.get("valid_values")?.includes("")) {
|
|
return "admin.settings.none";
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
@dependentKeyCompat
|
|
get anyValue() {
|
|
return this.settingObj.get("allow_any");
|
|
}
|
|
}
|