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