2023-08-25 20:21:38 +08:00
|
|
|
import Component from "@glimmer/component";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { tracked } from "@glimmer/tracking";
|
2023-08-25 20:21:38 +08:00
|
|
|
import { action } from "@ember/object";
|
2024-03-07 01:05:11 +08:00
|
|
|
import { service } from "@ember/service";
|
2023-08-25 20:21:38 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2024-11-20 04:45:18 +08:00
|
|
|
import { i18n } from "discourse-i18n";
|
2023-08-25 20:21:38 +08:00
|
|
|
|
|
|
|
export default class Reseed extends Component {
|
|
|
|
@service dialog;
|
|
|
|
|
|
|
|
@tracked loading = true;
|
|
|
|
@tracked reseeding = false;
|
|
|
|
@tracked categories = null;
|
|
|
|
@tracked topics = null;
|
2023-12-18 22:34:19 +08:00
|
|
|
@tracked flash;
|
2023-08-25 20:21:38 +08:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
this.loadReseed();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
async loadReseed() {
|
|
|
|
try {
|
|
|
|
const result = await ajax("/admin/customize/reseed");
|
|
|
|
this.categories = result.categories;
|
|
|
|
this.topics = result.topics;
|
|
|
|
} finally {
|
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_extractSelectedIds(items) {
|
|
|
|
return items.filter((item) => item.selected).map((item) => item.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
async reseed() {
|
|
|
|
try {
|
|
|
|
this.reseeding = true;
|
|
|
|
await ajax("/admin/customize/reseed", {
|
|
|
|
data: {
|
|
|
|
category_ids: this._extractSelectedIds(this.categories),
|
|
|
|
topic_ids: this._extractSelectedIds(this.topics),
|
|
|
|
},
|
|
|
|
type: "POST",
|
|
|
|
});
|
2023-09-27 23:11:44 +08:00
|
|
|
|
|
|
|
this.flash = null;
|
|
|
|
this.args.closeModal();
|
2023-08-25 20:21:38 +08:00
|
|
|
} catch {
|
2024-11-20 04:45:18 +08:00
|
|
|
this.flash = i18n("generic_error");
|
2023-08-25 20:21:38 +08:00
|
|
|
} finally {
|
|
|
|
this.reseeding = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|