mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
5c652dd7a1
<img width="728" alt="Screenshot 2023-08-24 at 1 35 53 PM" src="https://github.com/discourse/discourse/assets/50783505/5532eea4-1238-43dc-b2b7-a511e78d1f97">
56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
import Component from "@glimmer/component";
|
|
import { action } from "@ember/object";
|
|
import { inject as service } from "@ember/service";
|
|
import I18n from "I18n";
|
|
import { ajax } from "discourse/lib/ajax";
|
|
import { tracked } from "@glimmer/tracking";
|
|
|
|
export default class Reseed extends Component {
|
|
@service dialog;
|
|
|
|
@tracked loading = true;
|
|
@tracked reseeding = false;
|
|
@tracked categories = null;
|
|
@tracked topics = null;
|
|
|
|
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",
|
|
});
|
|
} catch {
|
|
this.flash = I18n.t("generic_error");
|
|
} finally {
|
|
this.reseeding = false;
|
|
this.flash = null;
|
|
this.args.closeModal();
|
|
}
|
|
}
|
|
}
|