DEV: Restructure file locations
- Colocate components / connectors - Move admin UI files to `admin/assets` so they are only served to admins
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import Ember from "ember";
|
||||
import MultiSelectComponent from "select-kit/components/multi-select";
|
||||
const { makeArray } = Ember;
|
||||
import { computed } from "@ember/object";
|
||||
|
||||
export default MultiSelectComponent.extend({
|
||||
classNames: ["house-ads-chooser"],
|
||||
filterable: true,
|
||||
filterPlaceholder: "admin.adplugin.house_ads.filter_placeholder",
|
||||
tokenSeparator: "|",
|
||||
allowCreate: false,
|
||||
allowAny: false,
|
||||
settingValue: "",
|
||||
valueAttribute: null,
|
||||
nameProperty: null,
|
||||
|
||||
value: computed("settingValue", function () {
|
||||
return this.settingValue
|
||||
.toString()
|
||||
.split(this.tokenSeparator)
|
||||
.filter(Boolean);
|
||||
}),
|
||||
|
||||
// TODO: kept for legacy, remove when Discourse is 2.5
|
||||
mutateValues(values) {
|
||||
this.set("settingValue", values.join(this.tokenSeparator));
|
||||
},
|
||||
computeValues() {
|
||||
return this.settingValue.split(this.tokenSeparator).filter(Boolean);
|
||||
},
|
||||
|
||||
content: computed("choices", function () {
|
||||
return makeArray(this.choices);
|
||||
}),
|
||||
|
||||
actions: {
|
||||
onChange(value) {
|
||||
const settingValue = makeArray(value).join(this.tokenSeparator);
|
||||
this.attrs.onChange && this.attrs.onChange(settingValue);
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
<label for={{name}}>{{title}}</label>
|
||||
{{house-ads-chooser
|
||||
settingValue=adValue
|
||||
choices=adNames
|
||||
onChange=(action (mut adValue))
|
||||
}}
|
||||
<div class="setting-controls">
|
||||
{{#if changed}}
|
||||
<DButton class="ok" @action={{action "save"}} @icon="check" />
|
||||
<DButton class="cancel" @action={{action "cancel"}} @icon="times" />
|
||||
{{/if}}
|
||||
</div>
|
||||
<p class="help">{{help}}</p>
|
||||
@@ -0,0 +1,7 @@
|
||||
import { mapBy } from "@ember/object/computed";
|
||||
import HouseAdsSetting from "discourse/plugins/discourse-adplugin/discourse/components/house-ads-setting";
|
||||
|
||||
export default HouseAdsSetting.extend({
|
||||
classNames: "house-ads-setting house-ads-list-setting",
|
||||
adNames: mapBy("allAds", "name"),
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
<label for={{name}}>{{title}}</label>
|
||||
<TextField @value={{adValue}} @classNames="house-ads-text-input" />
|
||||
<div class="setting-controls">
|
||||
{{#if changed}}
|
||||
<DButton class="ok" @action={{action "save"}} @icon="check" />
|
||||
<DButton class="cancel" @action={{action "cancel"}} @icon="times" />
|
||||
{{/if}}
|
||||
</div>
|
||||
<p class="help">{{help}}</p>
|
||||
@@ -0,0 +1,58 @@
|
||||
import Component from "@ember/component";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
import { i18n, propertyNotEqual } from "discourse/lib/computed";
|
||||
import I18n from "I18n";
|
||||
|
||||
export default Component.extend({
|
||||
classNames: "house-ads-setting",
|
||||
adValue: "",
|
||||
saving: false,
|
||||
savingStatus: "",
|
||||
title: i18n("name", "admin.adplugin.house_ads.%@.title"),
|
||||
help: i18n("name", "admin.adplugin.house_ads.%@.description"),
|
||||
changed: propertyNotEqual("adValue", "value"),
|
||||
|
||||
init() {
|
||||
this._super(...arguments);
|
||||
this.set("adValue", this.get("value"));
|
||||
},
|
||||
|
||||
actions: {
|
||||
save() {
|
||||
if (!this.get("saving")) {
|
||||
this.setProperties({
|
||||
saving: true,
|
||||
savingStatus: I18n.t("saving"),
|
||||
});
|
||||
|
||||
ajax(
|
||||
`/admin/plugins/pluginad/house_settings/${this.get("name")}.json`,
|
||||
{
|
||||
type: "PUT",
|
||||
data: { value: this.get("adValue") },
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
const adSettings = this.get("adSettings");
|
||||
adSettings.set(this.get("name"), this.get("adValue"));
|
||||
this.setProperties({
|
||||
value: this.get("adValue"),
|
||||
savingStatus: I18n.t("saved"),
|
||||
});
|
||||
})
|
||||
.catch(popupAjaxError)
|
||||
.finally(() => {
|
||||
this.setProperties({
|
||||
saving: false,
|
||||
savingStatus: "",
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
cancel() {
|
||||
this.set("adValue", this.get("value"));
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user