UX: Use topic list bulk select toggle for user messages list. (#13614)

This commit is contained in:
Alan Guo Xiang Tan 2021-07-05 10:43:58 +08:00 committed by GitHub
parent 100c3d6d62
commit 43058db3ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 21 additions and 58 deletions

View File

@ -1,67 +1,28 @@
import Controller, { inject as controller } from "@ember/controller"; import Controller, { inject as controller } from "@ember/controller";
import { action } from "@ember/object"; import { action } from "@ember/object";
import { alias, and, equal } from "@ember/object/computed"; 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 discourseComputed from "discourse-common/utils/decorators";
import { VIEW_NAME_WARNINGS } from "discourse/routes/user-private-messages-warnings"; import { VIEW_NAME_WARNINGS } from "discourse/routes/user-private-messages-warnings";
export default Controller.extend({ export default Controller.extend({
userTopicsList: controller("user-topics-list"),
user: controller(), user: controller(),
pmView: false, pmView: false,
viewingSelf: alias("user.viewingSelf"), viewingSelf: alias("user.viewingSelf"),
isGroup: equal("pmView", "groups"), isGroup: equal("pmView", "groups"),
currentPath: alias("router._router.currentPath"), currentPath: alias("router._router.currentPath"),
selected: alias("userTopicsList.selected"),
bulkSelectEnabled: alias("userTopicsList.bulkSelectEnabled"),
showToggleBulkSelect: true,
pmTaggingEnabled: alias("site.can_tag_pms"), pmTaggingEnabled: alias("site.can_tag_pms"),
tagId: null, tagId: null,
showNewPM: and("user.viewingSelf", "currentUser.can_send_private_messages"), 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") @discourseComputed("viewingSelf", "pmView", "currentUser.admin")
showWarningsWarning(viewingSelf, pmView, isAdmin) { showWarningsWarning(viewingSelf, pmView, isAdmin) {
return pmView === VIEW_NAME_WARNINGS && !viewingSelf && !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 @action
changeGroupNotificationLevel(notificationLevel) { changeGroupNotificationLevel(notificationLevel) {
this.group.setNotification(notificationLevel, this.get("user.model.id")); this.group.setNotification(notificationLevel, this.get("user.model.id"));
}, },
@action
toggleBulkSelect() {
this.selected.clear();
this.toggleProperty("bulkSelectEnabled");
},
}); });

View File

@ -1,8 +1,9 @@
import Controller, { inject as controller } from "@ember/controller"; import Controller, { inject as controller } from "@ember/controller";
import discourseComputed, { observes } from "discourse-common/utils/decorators"; import discourseComputed, { observes } from "discourse-common/utils/decorators";
import BulkTopicSelection from "discourse/mixins/bulk-topic-selection";
// Lists of topics on a user's page. // Lists of topics on a user's page.
export default Controller.extend({ export default Controller.extend(BulkTopicSelection, {
application: controller(), application: controller(),
hideCategory: false, hideCategory: false,

View File

@ -44,12 +44,12 @@ export default (viewName, path, channel) => {
canBulkSelect: true, canBulkSelect: true,
tagsForUser: this.modelFor("user").get("username_lower"), tagsForUser: this.modelFor("user").get("username_lower"),
selected: [], selected: [],
showToggleBulkSelect: true,
}); });
this.controllerFor("user-private-messages").setProperties({ this.controllerFor("user-private-messages").setProperties({
archive: false, archive: false,
pmView: viewName, pmView: viewName,
showToggleBulkSelect: true,
}); });
this.searchService.set("contextType", "private_messages"); this.searchService.set("contextType", "private_messages");

View File

@ -26,8 +26,13 @@ export default DiscourseRoute.extend({
: ["count:desc", "id"], : ["count:desc", "id"],
tagsForUser: this.modelFor("user").get("username_lower"), tagsForUser: this.modelFor("user").get("username_lower"),
}); });
this.controllerFor("user-private-messages").setProperties({
this.controllerFor("user-topics-list").setProperties({
showToggleBulkSelect: false, showToggleBulkSelect: false,
selected: [],
});
this.controllerFor("user-private-messages").setProperties({
pmView: "tags", pmView: "tags",
}); });
}, },

View File

@ -20,6 +20,8 @@
tagsForUser=tagsForUser tagsForUser=tagsForUser
onScroll=onScroll onScroll=onScroll
scrollOnLoad=scrollOnLoad scrollOnLoad=scrollOnLoad
toggleBulkSelect=toggleBulkSelect
updateAutoAddTopicsToBulkSelect=updateAutoAddTopicsToBulkSelect
}} }}
{{else}} {{else}}
{{#unless loadingMore}} {{#unless loadingMore}}

View File

@ -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")}} {{#load-more class="paginated-topics-list" selector=".paginated-topics-list .topic-list tr" action=(action "loadMore")}}
{{basic-topic-list topicList=model {{basic-topic-list topicList=model
hideCategory=hideCategory hideCategory=hideCategory
@ -9,7 +15,10 @@
showInserted=(action "showInserted") showInserted=(action "showInserted")
tagsForUser=tagsForUser tagsForUser=tagsForUser
onScroll=saveScrollPosition onScroll=saveScrollPosition
scrollOnLoad=true}} canBulkSelect=canBulkSelect
scrollOnLoad=true
toggleBulkSelect=(action "toggleBulkSelect")
updateAutoAddTopicsToBulkSelect=(action "updateAutoAddTopicsToBulkSelect")}}
{{conditional-loading-spinner condition=model.loadingMore}} {{conditional-loading-spinner condition=model.loadingMore}}
{{/load-more}} {{/load-more}}

View File

@ -57,13 +57,6 @@
<section class="user-content"> <section class="user-content">
<div class="list-actions"> <div class="list-actions">
{{#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 site.mobileView}}
{{#if showNewPM}} {{#if showNewPM}}
{{d-button {{d-button
@ -74,12 +67,6 @@
{{/if}} {{/if}}
{{/if}} {{/if}}
{{#if bulkSelectEnabled}}
{{bulk-select-all
class="btn-default btn-select-all"
label="user.messages.select_all"}}
{{/if}}
{{#if isGroup}} {{#if isGroup}}
{{group-notifications-button {{group-notifications-button
value=group.group_user.notification_level value=group.group_user.notification_level

View File

@ -1172,11 +1172,9 @@ en:
sent: "Sent" sent: "Sent"
archive: "Archive" archive: "Archive"
groups: "My Groups" groups: "My Groups"
bulk_select: "Select messages"
move_to_inbox: "Move to Inbox" move_to_inbox: "Move to Inbox"
move_to_archive: "Archive" move_to_archive: "Archive"
failed_to_move: "Failed to move selected messages (perhaps your network is down)" failed_to_move: "Failed to move selected messages (perhaps your network is down)"
select_all: "Select All"
tags: "Tags" tags: "Tags"
warnings: "Official Warnings" warnings: "Official Warnings"