2024-08-20 20:27:29 +08:00
|
|
|
import Component from "@glimmer/component";
|
|
|
|
import { tracked } from "@glimmer/tracking";
|
2022-12-08 20:42:33 +08:00
|
|
|
import { action } from "@ember/object";
|
2024-08-20 20:27:29 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2022-12-08 20:42:33 +08:00
|
|
|
|
2023-02-23 23:32:53 +08:00
|
|
|
export default class AdminPenaltySimilarUsers extends Component {
|
2024-08-20 20:27:29 +08:00
|
|
|
@tracked isLoading;
|
|
|
|
@tracked similarUsers = [];
|
|
|
|
selectedUserIds = [];
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
|
|
|
|
this.loadSimilarUsers();
|
|
|
|
}
|
|
|
|
|
|
|
|
get penaltyField() {
|
|
|
|
const penaltyType = this.args.penaltyType;
|
2022-12-08 20:42:33 +08:00
|
|
|
if (penaltyType === "suspend") {
|
|
|
|
return "can_be_suspended";
|
|
|
|
} else if (penaltyType === "silence") {
|
|
|
|
return "can_be_silenced";
|
|
|
|
}
|
2023-02-23 23:32:53 +08:00
|
|
|
}
|
2022-12-08 20:42:33 +08:00
|
|
|
|
2024-08-20 20:27:29 +08:00
|
|
|
async loadSimilarUsers() {
|
|
|
|
this.isLoading = true;
|
|
|
|
try {
|
|
|
|
const data = await ajax(
|
|
|
|
`/admin/users/${this.args.user.id}/similar-users.json`
|
|
|
|
);
|
|
|
|
this.similarUsers = data.users;
|
|
|
|
} finally {
|
|
|
|
this.isLoading = false;
|
2022-12-08 20:42:33 +08:00
|
|
|
}
|
2024-08-20 20:27:29 +08:00
|
|
|
}
|
2022-12-08 20:42:33 +08:00
|
|
|
|
2024-08-20 20:27:29 +08:00
|
|
|
@action
|
|
|
|
selectUserId(userId, event) {
|
2022-12-08 20:42:33 +08:00
|
|
|
if (event.target.checked) {
|
2024-08-20 20:27:29 +08:00
|
|
|
this.selectedUserIds.push(userId);
|
2022-12-08 20:42:33 +08:00
|
|
|
} else {
|
2024-08-20 20:27:29 +08:00
|
|
|
this.selectedUserIds = this.selectedUserIds.filter((id) => id !== userId);
|
2022-12-08 20:42:33 +08:00
|
|
|
}
|
2024-08-20 20:27:29 +08:00
|
|
|
|
|
|
|
this.args.onUsersChanged(this.selectedUserIds);
|
2023-02-23 23:32:53 +08:00
|
|
|
}
|
|
|
|
}
|