FEATURE: Add new site setting list type with name and values (#16045)
These changes include a bug fix because allow_any attribute of site settings was completely ignored before.
This commit is contained in:
parent
fd34ddef8a
commit
4fe99e39c3
|
@ -0,0 +1,33 @@
|
|||
import Component from "@ember/component";
|
||||
import { action, computed } from "@ember/object";
|
||||
|
||||
export default Component.extend({
|
||||
tokenSeparator: "|",
|
||||
|
||||
@computed("value")
|
||||
get settingValue() {
|
||||
return this.value.toString().split(this.tokenSeparator).filter(Boolean);
|
||||
},
|
||||
|
||||
@computed("setting.choices.[]", "settingValue")
|
||||
get settingChoices() {
|
||||
let choices = this.setting.choices;
|
||||
|
||||
if (this.settingValue) {
|
||||
const valuesSet = new Set(choices.map((choice) => choice.value));
|
||||
|
||||
choices = choices.concat(
|
||||
this.settingValue
|
||||
.filter((value) => !valuesSet.has(value))
|
||||
.map((value) => ({ name: value, value }))
|
||||
);
|
||||
}
|
||||
|
||||
return choices;
|
||||
},
|
||||
|
||||
@action
|
||||
onChangeListSetting(value) {
|
||||
this.set("value", value.join(this.tokenSeparator));
|
||||
},
|
||||
});
|
|
@ -32,6 +32,7 @@ const CUSTOM_TYPES = [
|
|||
"color",
|
||||
"simple_list",
|
||||
"emoji_list",
|
||||
"named_list",
|
||||
];
|
||||
|
||||
const AUTO_REFRESH_ON_SAVE = ["logo", "logo_small", "large_icon"];
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import I18n from "I18n";
|
||||
import Mixin from "@ember/object/mixin";
|
||||
import { computed } from "@ember/object";
|
||||
import { readOnly } from "@ember/object/computed";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import { isPresent } from "@ember/utils";
|
||||
|
||||
|
@ -66,4 +67,6 @@ export default Mixin.create({
|
|||
return "admin.settings.none";
|
||||
}
|
||||
},
|
||||
|
||||
anyValue: readOnly("allow_any"),
|
||||
});
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
{{list-setting
|
||||
value=settingValue
|
||||
settingName=setting.setting
|
||||
choices=settingChoices
|
||||
nameProperty="name"
|
||||
valueProperty="value"
|
||||
onChange=(action "onChangeListSetting")
|
||||
options=(hash
|
||||
allowAny=allowAny
|
||||
)
|
||||
}}
|
||||
|
||||
{{setting-validation-message message=validationMessage}}
|
||||
<div class="desc">{{html-safe setting.description}}</div>
|
|
@ -164,6 +164,10 @@ class SiteSettings::TypeSupervisor
|
|||
end
|
||||
end
|
||||
|
||||
if type == :list
|
||||
result[:allow_any] = @allow_any[name]
|
||||
end
|
||||
|
||||
result[:choices] = @choices[name] if @choices.has_key? name
|
||||
result[:list_type] = @list_type[name] if @list_type.has_key? name
|
||||
result[:textarea] = @textareas[name] if @textareas.has_key? name
|
||||
|
|
Loading…
Reference in New Issue