mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
DEV: Convert delete-user-posts-progress
modal to component-based API (#22916)
https://github.com/discourse/discourse/assets/50783505/414ffcc5-06e9-470f-b160-83b4c12bbb96
This commit is contained in:
@ -3,7 +3,6 @@ import { inject as service } from "@ember/service";
|
||||
import { and, notEmpty } from "@ember/object/computed";
|
||||
import DiscourseURL, { userPath } from "discourse/lib/url";
|
||||
import { fmt, propertyNotEqual, setting } from "discourse/lib/computed";
|
||||
import AdminUser from "admin/models/admin-user";
|
||||
import CanCheckEmails from "discourse/mixins/can-check-emails";
|
||||
import Controller from "@ember/controller";
|
||||
import I18n from "I18n";
|
||||
@ -11,12 +10,13 @@ import { ajax } from "discourse/lib/ajax";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import getURL from "discourse-common/lib/get-url";
|
||||
import { htmlSafe } from "@ember/template";
|
||||
import { extractError, popupAjaxError } from "discourse/lib/ajax-error";
|
||||
import showModal from "discourse/lib/show-modal";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
import AdminUser from "admin/models/admin-user";
|
||||
import MergeUsersConfirmationModal from "../components/modal/merge-users-confirmation";
|
||||
import MergeUsersPromptModal from "../components/modal/merge-users-prompt";
|
||||
import MergeUsersProgressModal from "../components/modal/merge-users-progress";
|
||||
import DeletePostsConfirmationModal from "../components/modal/delete-posts-confirmation";
|
||||
import DeleteUserPostsProgressModal from "../components/modal/delete-user-posts-progress";
|
||||
|
||||
export default class AdminUserIndexController extends Controller.extend(
|
||||
CanCheckEmails
|
||||
@ -628,42 +628,18 @@ export default class AdminUserIndexController extends Controller.extend(
|
||||
});
|
||||
}
|
||||
|
||||
@action
|
||||
updateUserPostCount(count) {
|
||||
this.model.set("post_count", count);
|
||||
}
|
||||
|
||||
@action
|
||||
deleteAllPosts() {
|
||||
let deletedPosts = 0;
|
||||
let deletedPercentage = 0;
|
||||
const user = this.model;
|
||||
|
||||
const performDelete = (progressModal) => {
|
||||
this.model
|
||||
.deleteAllPosts()
|
||||
.then(({ posts_deleted }) => {
|
||||
if (posts_deleted === 0) {
|
||||
user.set("post_count", 0);
|
||||
progressModal.send("closeModal");
|
||||
} else {
|
||||
deletedPosts += posts_deleted;
|
||||
deletedPercentage = Math.floor(
|
||||
(deletedPosts * 100) / user.get("post_count")
|
||||
);
|
||||
progressModal.setProperties({
|
||||
deletedPercentage,
|
||||
});
|
||||
performDelete(progressModal);
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
progressModal.send("closeModal");
|
||||
let error;
|
||||
AdminUser.find(user.get("id")).then((u) => user.setProperties(u));
|
||||
error = extractError(e, I18n.t("admin.user.delete_posts_failed"));
|
||||
this.dialog.alert(error);
|
||||
});
|
||||
};
|
||||
|
||||
const progressModal = showModal("admin-delete-user-posts-progress", {
|
||||
admin: true,
|
||||
this.modal.show(DeleteUserPostsProgressModal, {
|
||||
model: {
|
||||
user: this.model,
|
||||
updateUserPostCount: this.updateUserPostCount,
|
||||
},
|
||||
});
|
||||
performDelete(progressModal);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user