FEATURE: Implement bulk operations for PMs (#12286)

This commit is contained in:
Bianca Nenciu 2021-03-10 14:49:38 +02:00 committed by GitHub
parent 9bd436c20b
commit c0421e4586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 50 deletions

View File

@ -0,0 +1,7 @@
import DButton from "discourse/components/d-button";
export default DButton.extend({
click() {
$("input.bulk-select:not(checked)").click();
},
});

View File

@ -31,14 +31,27 @@ function addBulkButton(action, key, opts) {
addBulkButton("showChangeCategory", "change_category", {
icon: "pencil-alt",
class: "btn-default",
buttonVisible: (topics) => !topics.some((t) => t.isPrivateMessage),
});
addBulkButton("closeTopics", "close_topics", {
icon: "lock",
class: "btn-default",
buttonVisible: (topics) => !topics.some((t) => t.isPrivateMessage),
});
addBulkButton("archiveTopics", "archive_topics", {
icon: "folder",
class: "btn-default",
buttonVisible: (topics) => !topics.some((t) => t.isPrivateMessage),
});
addBulkButton("archiveMessages", "archive_topics", {
icon: "folder",
class: "btn-default",
buttonVisible: (topics) => topics.some((t) => t.isPrivateMessage),
});
addBulkButton("moveMessagesToInbox", "move_messages_to_inbox", {
icon: "folder",
class: "btn-default",
buttonVisible: (topics) => topics.some((t) => t.isPrivateMessage),
});
addBulkButton("showNotificationLevel", "notification_level", {
icon: "d-regular",
@ -51,12 +64,14 @@ addBulkButton("resetRead", "reset_read", {
addBulkButton("unlistTopics", "unlist_topics", {
icon: "far-eye-slash",
class: "btn-default",
buttonVisible: (topics) => topics.some((t) => t.visible),
buttonVisible: (topics) =>
topics.some((t) => t.visible) && !topics.some((t) => t.isPrivateMessage),
});
addBulkButton("relistTopics", "relist_topics", {
icon: "far-eye",
class: "btn-default",
buttonVisible: (topics) => topics.some((t) => !t.visible),
buttonVisible: (topics) =>
topics.some((t) => !t.visible) && !topics.some((t) => t.isPrivateMessage),
});
addBulkButton("showTagTopics", "change_tags", {
icon: "tag",
@ -230,6 +245,18 @@ export default Controller.extend(ModalFunctionality, {
);
},
archiveMessages() {
this.forEachPerformed({ type: "archive_messages" }, (t) =>
t.set("archived", true)
);
},
moveMessagesToInbox() {
this.forEachPerformed({ type: "move_messages_to_inbox" }, (t) =>
t.set("archived", false)
);
},
unlistTopics() {
this.forEachPerformed({ type: "unlist" }, (t) => t.set("visible", false));
},

View File

@ -1,4 +1,5 @@
import Controller, { inject as controller } from "@ember/controller";
import { action } from "@ember/object";
import { alias, and, equal } from "@ember/object/computed";
import I18n from "I18n";
import Topic from "discourse/models/topic";
@ -26,16 +27,6 @@ export default Controller.extend({
return bulkSelectEnabled && selected && selected.length > 0;
},
@discourseComputed("hasSelection", "pmView", "archive")
canMoveToInbox(hasSelection, pmView, archive) {
return hasSelection && (pmView === "archive" || archive);
},
@discourseComputed("hasSelection", "pmView", "archive")
canArchive(hasSelection, pmView, archive) {
return hasSelection && pmView !== "archive" && !archive;
},
bulkOperation(operation) {
const selected = this.selected;
let params = { type: operation };
@ -57,21 +48,13 @@ export default Controller.extend({
);
},
actions: {
changeGroupNotificationLevel(notificationLevel) {
this.group.setNotification(notificationLevel, this.get("user.model.id"));
},
archive() {
this.bulkOperation("archive_messages");
},
toInbox() {
this.bulkOperation("move_messages_to_inbox");
},
toggleBulkSelect() {
this.toggleProperty("bulkSelectEnabled");
},
selectAll() {
$("input.bulk-select:not(checked)").click();
},
@action
changeGroupNotificationLevel(notificationLevel) {
this.group.setNotification(notificationLevel, this.get("user.model.id"));
},
@action
toggleBulkSelect() {
this.toggleProperty("bulkSelectEnabled");
},
});

View File

@ -59,11 +59,8 @@
<div class="list-actions">
{{#unless site.mobileView}}
{{#if showToggleBulkSelect}}
{{d-button
class="btn-default bulk-select"
action=(action "toggleBulkSelect")
title="user.messages.bulk_select"
icon="list"}}
{{d-button icon="list" class="btn-default bulk-select" title="topics.bulk.toggle" action=(action "toggleBulkSelect")}}
{{bulk-select-button selected=selected}}
{{/if}}
{{/unless}}
@ -77,24 +74,9 @@
{{/if}}
{{/if}}
{{#if canArchive}}
{{d-button
class="btn-default btn-archive"
action=(action "archive")
label="user.messages.move_to_archive"}}
{{/if}}
{{#if canMoveToInbox}}
{{d-button
class="btn-default btn-to-inbox"
action=(action "toInbox")
label="user.messages.move_to_inbox"}}
{{/if}}
{{#if bulkSelectEnabled}}
{{d-button
{{bulk-select-all
class="btn-default btn-select-all"
action=(action "selectAll")
label="user.messages.select_all"}}
{{/if}}

View File

@ -177,7 +177,7 @@
z-index: z("dropdown");
@supports (position: sticky) {
@media screen and (min-width: 1250px) {
body:not(.search-page) & {
body:not(.search-page):not(.user-messages-page) & {
position: absolute;
right: -60px;
top: 0;

View File

@ -2321,6 +2321,7 @@ en:
change_category: "Set Category"
close_topics: "Close Topics"
archive_topics: "Archive Topics"
move_messages_to_inbox: "Move to Inbox"
notification_level: "Notifications"
change_notification_level: "Change Notification Level"
choose_new_category: "Choose the new category for the topics:"