2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2019-03-19 04:09:13 +08:00
|
|
|
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend(ModalFunctionality, {
|
2019-03-19 04:09:13 +08:00
|
|
|
loading: true,
|
|
|
|
reseeding: false,
|
|
|
|
categories: null,
|
|
|
|
topics: null,
|
|
|
|
|
|
|
|
onShow() {
|
|
|
|
ajax("/admin/customize/reseed")
|
|
|
|
.then(result => {
|
|
|
|
this.setProperties({
|
|
|
|
categories: result.categories,
|
|
|
|
topics: result.topics
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.finally(() => this.set("loading", false));
|
|
|
|
},
|
|
|
|
|
|
|
|
_extractSelectedIds(items) {
|
|
|
|
return items.filter(item => item.selected).map(item => item.id);
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
reseed() {
|
|
|
|
this.set("reseeding", true);
|
|
|
|
ajax("/admin/customize/reseed", {
|
|
|
|
data: {
|
|
|
|
category_ids: this._extractSelectedIds(this.categories),
|
|
|
|
topic_ids: this._extractSelectedIds(this.topics)
|
|
|
|
},
|
2020-03-27 04:00:10 +08:00
|
|
|
type: "POST"
|
2019-03-19 04:09:13 +08:00
|
|
|
})
|
|
|
|
.then(
|
|
|
|
() => this.send("closeModal"),
|
|
|
|
() => bootbox.alert(I18n.t("generic_error"))
|
|
|
|
)
|
|
|
|
.finally(() => this.set("reseeding", false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|