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:
@@ -1,10 +0,0 @@
|
||||
export default {
|
||||
resource: "admin.adminPlugins",
|
||||
path: "/plugins",
|
||||
map() {
|
||||
this.route("houseAds", { path: "/pluginad/house_creatives" }, function () {
|
||||
this.route("index", { path: "/" });
|
||||
this.route("show", { path: "/:ad_id" });
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -1,42 +0,0 @@
|
||||
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);
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -1,7 +0,0 @@
|
||||
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"),
|
||||
});
|
||||
@@ -1,58 +0,0 @@
|
||||
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"));
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
{{ad-slot
|
||||
placement="post-bottom"
|
||||
category=@model.topic.category.slug
|
||||
postNumber=@model.post_number
|
||||
}}
|
||||
@@ -1,8 +0,0 @@
|
||||
import Controller, { inject as controller } from "@ember/controller";
|
||||
import { alias } from "@ember/object/computed";
|
||||
|
||||
export default Controller.extend({
|
||||
adminPluginsHouseAds: controller("adminPlugins.houseAds"),
|
||||
houseAds: alias("adminPluginsHouseAds.model"),
|
||||
adSettings: alias("adminPluginsHouseAds.houseAdsSettings"),
|
||||
});
|
||||
@@ -1,113 +0,0 @@
|
||||
import Controller, { inject as controller } from "@ember/controller";
|
||||
import { not, or } from "@ember/object/computed";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
import { propertyNotEqual } from "discourse/lib/computed";
|
||||
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
||||
import I18n from "I18n";
|
||||
|
||||
export default Controller.extend(bufferedProperty("model"), {
|
||||
adminPluginsHouseAds: controller("adminPlugins.houseAds"),
|
||||
|
||||
saving: false,
|
||||
savingStatus: "",
|
||||
|
||||
nameDirty: propertyNotEqual("buffered.name", "model.name"),
|
||||
htmlDirty: propertyNotEqual("buffered.html", "model.html"),
|
||||
visibleToAnonsDirty: propertyNotEqual(
|
||||
"buffered.visible_to_anons",
|
||||
"model.visible_to_anons"
|
||||
),
|
||||
visibleToLoggedInDirty: propertyNotEqual(
|
||||
"buffered.visible_to_logged_in_users",
|
||||
"model.visible_to_logged_in_users"
|
||||
),
|
||||
dirty: or(
|
||||
"nameDirty",
|
||||
"htmlDirty",
|
||||
"visibleToLoggedInDirty",
|
||||
"visibleToAnonsDirty"
|
||||
),
|
||||
disableSave: not("dirty"),
|
||||
|
||||
actions: {
|
||||
save() {
|
||||
if (!this.get("saving")) {
|
||||
this.setProperties({
|
||||
saving: true,
|
||||
savingStatus: I18n.t("saving"),
|
||||
});
|
||||
|
||||
const data = {},
|
||||
buffered = this.get("buffered"),
|
||||
newRecord = !buffered.get("id");
|
||||
|
||||
if (!newRecord) {
|
||||
data.id = buffered.get("id");
|
||||
}
|
||||
data.name = buffered.get("name");
|
||||
data.html = buffered.get("html");
|
||||
data.visible_to_logged_in_users = buffered.get(
|
||||
"visible_to_logged_in_users"
|
||||
);
|
||||
data.visible_to_anons = buffered.get("visible_to_anons");
|
||||
|
||||
ajax(
|
||||
newRecord
|
||||
? `/admin/plugins/pluginad/house_creatives`
|
||||
: `/admin/plugins/pluginad/house_creatives/${buffered.get("id")}`,
|
||||
{
|
||||
type: newRecord ? "POST" : "PUT",
|
||||
data,
|
||||
}
|
||||
)
|
||||
.then((ajaxData) => {
|
||||
this.commitBuffer();
|
||||
this.set("savingStatus", I18n.t("saved"));
|
||||
if (newRecord) {
|
||||
const model = this.get("model");
|
||||
model.set("id", ajaxData.house_ad.id);
|
||||
const houseAds = this.get("adminPluginsHouseAds.model");
|
||||
if (!houseAds.includes(model)) {
|
||||
houseAds.pushObject(model);
|
||||
}
|
||||
this.transitionToRoute(
|
||||
"adminPlugins.houseAds.show",
|
||||
model.get("id")
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch(popupAjaxError)
|
||||
.finally(() => {
|
||||
this.setProperties({
|
||||
saving: false,
|
||||
savingStatus: "",
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
cancel() {
|
||||
this.rollbackBuffer();
|
||||
},
|
||||
|
||||
destroy() {
|
||||
const houseAds = this.get("adminPluginsHouseAds.model");
|
||||
const model = this.get("model");
|
||||
|
||||
if (!model.get("id")) {
|
||||
this.transitionToRoute("adminPlugins.houseAds.index");
|
||||
return;
|
||||
}
|
||||
|
||||
ajax(`/admin/plugins/pluginad/house_creatives/${model.get("id")}`, {
|
||||
type: "DELETE",
|
||||
})
|
||||
.then(() => {
|
||||
houseAds.removeObject(model);
|
||||
this.transitionToRoute("adminPlugins.houseAds.index");
|
||||
})
|
||||
.catch(popupAjaxError);
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -1,5 +0,0 @@
|
||||
import Controller from "@ember/controller";
|
||||
|
||||
export default Controller.extend({
|
||||
loadingAds: true,
|
||||
});
|
||||
@@ -1,9 +0,0 @@
|
||||
import { action } from "@ember/object";
|
||||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
|
||||
export default DiscourseRoute.extend({
|
||||
@action
|
||||
moreSettings() {
|
||||
this.transitionTo("adminSiteSettingsCategory", "ad_plugin");
|
||||
},
|
||||
});
|
||||
@@ -1,21 +0,0 @@
|
||||
import EmberObject from "@ember/object";
|
||||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
import I18n from "I18n";
|
||||
|
||||
export default DiscourseRoute.extend({
|
||||
model(params) {
|
||||
if (params.ad_id === "new") {
|
||||
return EmberObject.create({
|
||||
name: I18n.t("admin.adplugin.house_ads.new_name"),
|
||||
html: "",
|
||||
visible_to_logged_in_users: true,
|
||||
visible_to_anons: true,
|
||||
});
|
||||
} else {
|
||||
return this.modelFor("adminPlugins.houseAds").findBy(
|
||||
"id",
|
||||
parseInt(params.ad_id, 10)
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -1,22 +0,0 @@
|
||||
import EmberObject from "@ember/object";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
|
||||
export default DiscourseRoute.extend({
|
||||
settings: null,
|
||||
|
||||
model() {
|
||||
return ajax("/admin/plugins/pluginad/house_creatives.json").then((data) => {
|
||||
this.set("settings", EmberObject.create(data.settings));
|
||||
return data.house_ads.map((ad) => EmberObject.create(ad));
|
||||
});
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
controller.setProperties({
|
||||
model,
|
||||
houseAdsSettings: this.get("settings"),
|
||||
loadingAds: false,
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -1,51 +0,0 @@
|
||||
<DSection @class="house-ads-settings content-body">
|
||||
<div>{{i18n "admin.adplugin.house_ads.description"}}</div>
|
||||
|
||||
{{#if houseAds.length}}
|
||||
<form class="form-horizontal">
|
||||
{{house-ads-list-setting
|
||||
name="topic_list_top"
|
||||
value=adSettings.topic_list_top
|
||||
allAds=houseAds
|
||||
adSettings=adSettings
|
||||
}}
|
||||
{{house-ads-list-setting
|
||||
name="topic_above_post_stream"
|
||||
value=adSettings.topic_above_post_stream
|
||||
allAds=houseAds
|
||||
adSettings=adSettings
|
||||
}}
|
||||
{{house-ads-list-setting
|
||||
name="topic_above_suggested"
|
||||
value=adSettings.topic_above_suggested
|
||||
allAds=houseAds
|
||||
adSettings=adSettings
|
||||
}}
|
||||
{{house-ads-list-setting
|
||||
name="post_bottom"
|
||||
value=adSettings.post_bottom
|
||||
allAds=houseAds
|
||||
adSettings=adSettings
|
||||
}}
|
||||
{{house-ads-list-setting
|
||||
name="topic_list_between"
|
||||
value=adSettings.topic_list_between
|
||||
allAds=houseAds
|
||||
adSettings=adSettings
|
||||
}}
|
||||
|
||||
<DButton
|
||||
@label="admin.adplugin.house_ads.more_settings"
|
||||
@icon="cog"
|
||||
class="btn-default"
|
||||
@action={{route-action "moreSettings"}}
|
||||
/>
|
||||
</form>
|
||||
{{else}}
|
||||
<p>
|
||||
{{#link-to "adminPlugins.houseAds.show" "new"}}
|
||||
{{i18n "admin.adplugin.house_ads.get_started"}}
|
||||
{{/link-to}}
|
||||
</p>
|
||||
{{/if}}
|
||||
</DSection>
|
||||
@@ -1,48 +0,0 @@
|
||||
<DSection @class="edit-house-ad content-body">
|
||||
<h1><TextField @class="house-ad-name" @value={{buffered.name}} /></h1>
|
||||
<div class="controls">
|
||||
<AceEditor @content={{buffered.html}} @mode="html" />
|
||||
</div>
|
||||
<div class="controls">
|
||||
<div class="visibility-settings">
|
||||
<div>
|
||||
<Input
|
||||
class="visible-to-logged-in-checkbox"
|
||||
@type="checkbox"
|
||||
@checked={{this.buffered.visible_to_logged_in_users}}
|
||||
/>
|
||||
<span>{{i18n "admin.adplugin.house_ads.show_to_logged_in_users"}}</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Input
|
||||
class="visible-to-anonymous-checkbox"
|
||||
@type="checkbox"
|
||||
@checked={{this.buffered.visible_to_anons}}
|
||||
/>
|
||||
<span>{{i18n "admin.adplugin.house_ads.show_to_anons"}}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DButton
|
||||
@action={{action "save"}}
|
||||
@disabled={{disableSave}}
|
||||
class="btn-primary save-button"
|
||||
@label="admin.adplugin.house_ads.save"
|
||||
/>
|
||||
|
||||
{{#if saving}}
|
||||
{{savingStatus}}
|
||||
{{else}}
|
||||
{{#if dirty}}
|
||||
<a href {{action "cancel"}}>{{i18n "cancel"}}</a>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
<DButton
|
||||
@action={{action "destroy"}}
|
||||
class="btn-danger delete-button"
|
||||
@label="admin.adplugin.house_ads.delete"
|
||||
/>
|
||||
</div>
|
||||
</DSection>
|
||||
@@ -1,27 +0,0 @@
|
||||
<div class="adplugin-mgmt">
|
||||
<h1>{{i18n "admin.adplugin.house_ads.title"}}</h1>
|
||||
{{#if model.length}}
|
||||
<div class="content-list">
|
||||
<div class="house-ads-actions">
|
||||
{{#link-to "adminPlugins.houseAds.show" "new" class="btn btn-primary"}}
|
||||
{{d-icon "plus"}}
|
||||
<span>{{i18n "admin.adplugin.house_ads.new"}}</span>
|
||||
{{/link-to}}
|
||||
{{#link-to "adminPlugins.houseAds.index" class="btn btn-default"}}
|
||||
{{d-icon "cog"}}
|
||||
<span>{{i18n "admin.adplugin.house_ads.settings"}}</span>
|
||||
{{/link-to}}
|
||||
</div>
|
||||
<ul class="house-ads-list">
|
||||
{{#each model as |ad|}}
|
||||
<li class="house-ads-list-item">
|
||||
{{#link-to "adminPlugins.houseAds.show" ad.id}}
|
||||
{{ad.name}}
|
||||
{{/link-to}}
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
</div>
|
||||
{{/if}}
|
||||
{{outlet}}
|
||||
</div>
|
||||
@@ -1,13 +0,0 @@
|
||||
<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>
|
||||
@@ -1,9 +0,0 @@
|
||||
<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>
|
||||
@@ -1,5 +0,0 @@
|
||||
{{ad-slot
|
||||
placement="post-bottom"
|
||||
category=model.topic.category.slug
|
||||
postNumber=model.post_number
|
||||
}}
|
||||
Reference in New Issue
Block a user