From 43058db3cae5f9a06e62204253a8be0404948425 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Mon, 5 Jul 2021 10:43:58 +0800 Subject: [PATCH] UX: Use topic list bulk select toggle for user messages list. (#13614) --- .../app/controllers/user-private-messages.js | 39 ------------------- .../app/controllers/user-topics-list.js | 3 +- .../routes/build-private-messages-route.js | 2 +- .../app/routes/user-private-messages-tags.js | 7 +++- .../templates/components/basic-topic-list.hbs | 2 + .../app/templates/user-topics-list.hbs | 11 +++++- .../discourse/app/templates/user/messages.hbs | 13 ------- config/locales/client.en.yml | 2 - 8 files changed, 21 insertions(+), 58 deletions(-) diff --git a/app/assets/javascripts/discourse/app/controllers/user-private-messages.js b/app/assets/javascripts/discourse/app/controllers/user-private-messages.js index 3cc26e8361a..22f99d27bf7 100644 --- a/app/assets/javascripts/discourse/app/controllers/user-private-messages.js +++ b/app/assets/javascripts/discourse/app/controllers/user-private-messages.js @@ -1,67 +1,28 @@ 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"; -import bootbox from "bootbox"; import discourseComputed from "discourse-common/utils/decorators"; import { VIEW_NAME_WARNINGS } from "discourse/routes/user-private-messages-warnings"; export default Controller.extend({ - userTopicsList: controller("user-topics-list"), user: controller(), pmView: false, viewingSelf: alias("user.viewingSelf"), isGroup: equal("pmView", "groups"), currentPath: alias("router._router.currentPath"), - selected: alias("userTopicsList.selected"), - bulkSelectEnabled: alias("userTopicsList.bulkSelectEnabled"), - showToggleBulkSelect: true, pmTaggingEnabled: alias("site.can_tag_pms"), tagId: null, showNewPM: and("user.viewingSelf", "currentUser.can_send_private_messages"), - @discourseComputed("selected.[]", "bulkSelectEnabled") - hasSelection(selected, bulkSelectEnabled) { - return bulkSelectEnabled && selected && selected.length > 0; - }, - @discourseComputed("viewingSelf", "pmView", "currentUser.admin") showWarningsWarning(viewingSelf, pmView, isAdmin) { return pmView === VIEW_NAME_WARNINGS && !viewingSelf && !isAdmin; }, - bulkOperation(operation) { - const selected = this.selected; - let params = { type: operation }; - if (this.isGroup) { - params.group = this.groupFilter; - } - - Topic.bulkOperation(selected, params).then( - () => { - const model = this.get("userTopicsList.model"); - const topics = model.get("topics"); - topics.removeObjects(selected); - selected.clear(); - model.loadMore(); - }, - () => { - bootbox.alert(I18n.t("user.messages.failed_to_move")); - } - ); - }, - @action changeGroupNotificationLevel(notificationLevel) { this.group.setNotification(notificationLevel, this.get("user.model.id")); }, - - @action - toggleBulkSelect() { - this.selected.clear(); - this.toggleProperty("bulkSelectEnabled"); - }, }); diff --git a/app/assets/javascripts/discourse/app/controllers/user-topics-list.js b/app/assets/javascripts/discourse/app/controllers/user-topics-list.js index 1196916ebd3..61b3c118238 100644 --- a/app/assets/javascripts/discourse/app/controllers/user-topics-list.js +++ b/app/assets/javascripts/discourse/app/controllers/user-topics-list.js @@ -1,8 +1,9 @@ import Controller, { inject as controller } from "@ember/controller"; import discourseComputed, { observes } from "discourse-common/utils/decorators"; +import BulkTopicSelection from "discourse/mixins/bulk-topic-selection"; // Lists of topics on a user's page. -export default Controller.extend({ +export default Controller.extend(BulkTopicSelection, { application: controller(), hideCategory: false, diff --git a/app/assets/javascripts/discourse/app/routes/build-private-messages-route.js b/app/assets/javascripts/discourse/app/routes/build-private-messages-route.js index 102e3cf5859..caec153b5c2 100644 --- a/app/assets/javascripts/discourse/app/routes/build-private-messages-route.js +++ b/app/assets/javascripts/discourse/app/routes/build-private-messages-route.js @@ -44,12 +44,12 @@ export default (viewName, path, channel) => { canBulkSelect: true, tagsForUser: this.modelFor("user").get("username_lower"), selected: [], + showToggleBulkSelect: true, }); this.controllerFor("user-private-messages").setProperties({ archive: false, pmView: viewName, - showToggleBulkSelect: true, }); this.searchService.set("contextType", "private_messages"); diff --git a/app/assets/javascripts/discourse/app/routes/user-private-messages-tags.js b/app/assets/javascripts/discourse/app/routes/user-private-messages-tags.js index 3cbda900f14..24f3a942378 100644 --- a/app/assets/javascripts/discourse/app/routes/user-private-messages-tags.js +++ b/app/assets/javascripts/discourse/app/routes/user-private-messages-tags.js @@ -26,8 +26,13 @@ export default DiscourseRoute.extend({ : ["count:desc", "id"], tagsForUser: this.modelFor("user").get("username_lower"), }); - this.controllerFor("user-private-messages").setProperties({ + + this.controllerFor("user-topics-list").setProperties({ showToggleBulkSelect: false, + selected: [], + }); + + this.controllerFor("user-private-messages").setProperties({ pmView: "tags", }); }, diff --git a/app/assets/javascripts/discourse/app/templates/components/basic-topic-list.hbs b/app/assets/javascripts/discourse/app/templates/components/basic-topic-list.hbs index 98a64a01dfa..ed237acd6d9 100644 --- a/app/assets/javascripts/discourse/app/templates/components/basic-topic-list.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/basic-topic-list.hbs @@ -20,6 +20,8 @@ tagsForUser=tagsForUser onScroll=onScroll scrollOnLoad=scrollOnLoad + toggleBulkSelect=toggleBulkSelect + updateAutoAddTopicsToBulkSelect=updateAutoAddTopicsToBulkSelect }} {{else}} {{#unless loadingMore}} diff --git a/app/assets/javascripts/discourse/app/templates/user-topics-list.hbs b/app/assets/javascripts/discourse/app/templates/user-topics-list.hbs index adeab89c7f1..ba9067892d5 100644 --- a/app/assets/javascripts/discourse/app/templates/user-topics-list.hbs +++ b/app/assets/javascripts/discourse/app/templates/user-topics-list.hbs @@ -1,3 +1,9 @@ +{{#unless site.mobileView}} + {{#if showToggleBulkSelect}} + {{bulk-select-button selected=selected action=(route-action "refresh")}} + {{/if}} +{{/unless}} + {{#load-more class="paginated-topics-list" selector=".paginated-topics-list .topic-list tr" action=(action "loadMore")}} {{basic-topic-list topicList=model hideCategory=hideCategory @@ -9,7 +15,10 @@ showInserted=(action "showInserted") tagsForUser=tagsForUser onScroll=saveScrollPosition - scrollOnLoad=true}} + canBulkSelect=canBulkSelect + scrollOnLoad=true + toggleBulkSelect=(action "toggleBulkSelect") + updateAutoAddTopicsToBulkSelect=(action "updateAutoAddTopicsToBulkSelect")}} {{conditional-loading-spinner condition=model.loadingMore}} {{/load-more}} diff --git a/app/assets/javascripts/discourse/app/templates/user/messages.hbs b/app/assets/javascripts/discourse/app/templates/user/messages.hbs index 23eaded6dd0..5a845eafdc2 100644 --- a/app/assets/javascripts/discourse/app/templates/user/messages.hbs +++ b/app/assets/javascripts/discourse/app/templates/user/messages.hbs @@ -57,13 +57,6 @@
- {{#unless site.mobileView}} - {{#if showToggleBulkSelect}} - {{d-button icon="list" class="btn-default bulk-select" title="topics.bulk.toggle" action=(action "toggleBulkSelect")}} - {{bulk-select-button selected=selected action=(route-action "refresh")}} - {{/if}} - {{/unless}} - {{#if site.mobileView}} {{#if showNewPM}} {{d-button @@ -74,12 +67,6 @@ {{/if}} {{/if}} - {{#if bulkSelectEnabled}} - {{bulk-select-all - class="btn-default btn-select-all" - label="user.messages.select_all"}} - {{/if}} - {{#if isGroup}} {{group-notifications-button value=group.group_user.notification_level diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 5d9cfe77a21..9c28505b313 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1172,11 +1172,9 @@ en: sent: "Sent" archive: "Archive" groups: "My Groups" - bulk_select: "Select messages" move_to_inbox: "Move to Inbox" move_to_archive: "Archive" failed_to_move: "Failed to move selected messages (perhaps your network is down)" - select_all: "Select All" tags: "Tags" warnings: "Official Warnings"