This reverts commit 206969e49d
.
This commit is contained in:
parent
abae6ecadc
commit
7b165c6c2f
|
@ -1 +1,5 @@
|
|||
<DButton class="bulk-select" @action={{this.toggleBulkSelect}} @icon="list" />
|
||||
<DButton
|
||||
class="bulk-select"
|
||||
@action={{action "toggleBulkSelect"}}
|
||||
@icon="list"
|
||||
/>
|
|
@ -1,15 +1,17 @@
|
|||
import Component from "@glimmer/component";
|
||||
import Component from "@ember/component";
|
||||
import { action } from "@ember/object";
|
||||
import { getOwner } from "discourse-common/lib/get-owner";
|
||||
|
||||
export default class BulkSelectToggle extends Component {
|
||||
export default Component.extend({
|
||||
parentController: null,
|
||||
|
||||
@action
|
||||
toggleBulkSelect() {
|
||||
const controller = getOwner(this).lookup(
|
||||
`controller:${this.args.parentController}`
|
||||
`controller:${this.parentController}`
|
||||
);
|
||||
const helper = controller.bulkSelectHelper;
|
||||
helper.clear();
|
||||
helper.bulkSelectEnabled = !helper.bulkSelectEnabled;
|
||||
}
|
||||
}
|
||||
const selection = controller.selected;
|
||||
controller.toggleProperty("bulkSelectEnabled");
|
||||
selection.clear();
|
||||
},
|
||||
});
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
<div class="navigation-controls">
|
||||
{{#if (and this.notCategoriesRoute this.site.mobileView this.canBulk)}}
|
||||
<BulkSelectToggle @parentController="discovery/topics" />
|
||||
<BulkSelectToggle @parentController="discovery/topics" @tagName="" />
|
||||
{{/if}}
|
||||
|
||||
{{#if this.showCategoryAdmin}}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { inject as controller } from "@ember/controller";
|
||||
import { inject as service } from "@ember/service";
|
||||
import { alias, empty, equal, gt, or, readOnly } from "@ember/object/computed";
|
||||
import BulkSelectHelper from "discourse/lib/bulk-select-helper";
|
||||
import { alias, empty, equal, gt, readOnly } from "@ember/object/computed";
|
||||
import BulkTopicSelection from "discourse/mixins/bulk-topic-selection";
|
||||
import DismissTopics from "discourse/mixins/dismiss-topics";
|
||||
import DiscoveryController from "discourse/controllers/discovery";
|
||||
import I18n from "I18n";
|
||||
|
@ -12,18 +12,17 @@ import { endWith } from "discourse/lib/computed";
|
|||
import { routeAction } from "discourse/helpers/route-action";
|
||||
import { userPath } from "discourse/lib/url";
|
||||
import { action } from "@ember/object";
|
||||
import { filterTypeForMode } from "discourse/lib/filter-mode";
|
||||
|
||||
export default class TopicsController extends DiscoveryController.extend(
|
||||
BulkTopicSelection,
|
||||
DismissTopics
|
||||
) {
|
||||
@service router;
|
||||
@service composer;
|
||||
@controller discovery;
|
||||
|
||||
bulkSelectHelper = new BulkSelectHelper(this);
|
||||
|
||||
period = null;
|
||||
selected = null;
|
||||
expandGloballyPinned = false;
|
||||
expandAllPinned = false;
|
||||
|
||||
|
@ -41,25 +40,14 @@ export default class TopicsController extends DiscoveryController.extend(
|
|||
@equal("period", "weekly") weekly;
|
||||
@equal("period", "daily") daily;
|
||||
|
||||
@or("currentUser.canManageTopic", "showDismissRead", "showResetNew")
|
||||
canBulkSelect;
|
||||
|
||||
get bulkSelectEnabled() {
|
||||
return this.bulkSelectHelper.bulkSelectEnabled;
|
||||
}
|
||||
|
||||
get selected() {
|
||||
return this.bulkSelectHelper.selected;
|
||||
@discourseComputed("model.filter", "model.topics.length")
|
||||
showDismissRead(filter, topicsLength) {
|
||||
return this._isFilterPage(filter, "unread") && topicsLength > 0;
|
||||
}
|
||||
|
||||
@discourseComputed("model.filter", "model.topics.length")
|
||||
showDismissRead(filterMode, topicsLength) {
|
||||
return filterTypeForMode(filterMode) === "unread" && topicsLength > 0;
|
||||
}
|
||||
|
||||
@discourseComputed("model.filter", "model.topics.length")
|
||||
showResetNew(filterMode, topicsLength) {
|
||||
return filterTypeForMode(filterMode) === "new" && topicsLength > 0;
|
||||
showResetNew(filter, topicsLength) {
|
||||
return this._isFilterPage(filter, "new") && topicsLength > 0;
|
||||
}
|
||||
|
||||
callResetNew(dismissPosts = false, dismissTopics = false, untrack = false) {
|
||||
|
@ -224,24 +212,4 @@ export default class TopicsController extends DiscoveryController.extend(
|
|||
!this.get("bulkSelectEnabled")
|
||||
);
|
||||
}
|
||||
|
||||
@action
|
||||
toggleBulkSelect() {
|
||||
this.bulkSelectHelper.toggleBulkSelect();
|
||||
}
|
||||
|
||||
@action
|
||||
dismissRead(operationType, options) {
|
||||
this.bulkSelectHelper.dismissRead(operationType, options);
|
||||
}
|
||||
|
||||
@action
|
||||
updateAutoAddTopicsToBulkSelect(value) {
|
||||
this.bulkSelectHelper.autoAddTopicsToBulkSelect = value;
|
||||
}
|
||||
|
||||
@action
|
||||
addTopicsToBulkSelect(topics) {
|
||||
this.bulkSelectHelper.addTopics(topics);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { inject as service } from "@ember/service";
|
||||
import { or, readOnly } from "@ember/object/computed";
|
||||
import { readOnly } from "@ember/object/computed";
|
||||
import DiscoverySortableController from "discourse/controllers/discovery-sortable";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import BulkSelectHelper from "discourse/lib/bulk-select-helper";
|
||||
import BulkTopicSelection from "discourse/mixins/bulk-topic-selection";
|
||||
import DismissTopics from "discourse/mixins/dismiss-topics";
|
||||
import I18n from "I18n";
|
||||
import NavItem from "discourse/models/nav-item";
|
||||
|
@ -14,6 +14,7 @@ import { dependentKeyCompat } from "@ember/object/compat";
|
|||
import { tracked } from "@glimmer/tracking";
|
||||
|
||||
export default class TagShowController extends DiscoverySortableController.extend(
|
||||
BulkTopicSelection,
|
||||
DismissTopics
|
||||
) {
|
||||
@service dialog;
|
||||
|
@ -25,8 +26,6 @@ export default class TagShowController extends DiscoverySortableController.exten
|
|||
@tracked filterType;
|
||||
@tracked noSubcategories;
|
||||
|
||||
bulkSelectHelper = new BulkSelectHelper(this);
|
||||
|
||||
tag = null;
|
||||
additionalTags = null;
|
||||
list = null;
|
||||
|
@ -40,17 +39,6 @@ export default class TagShowController extends DiscoverySortableController.exten
|
|||
|
||||
@endWith("list.filter", "top") top;
|
||||
|
||||
@or("currentUser.canManageTopic", "showDismissRead", "showResetNew")
|
||||
canBulkSelect;
|
||||
|
||||
get bulkSelectEnabled() {
|
||||
return this.bulkSelectHelper.bulkSelectEnabled;
|
||||
}
|
||||
|
||||
get selected() {
|
||||
return this.bulkSelectHelper.selected;
|
||||
}
|
||||
|
||||
@dependentKeyCompat
|
||||
get filterMode() {
|
||||
return calculateFilterMode({
|
||||
|
@ -108,14 +96,14 @@ export default class TagShowController extends DiscoverySortableController.exten
|
|||
}
|
||||
}
|
||||
|
||||
@discourseComputed("filterType", "list.topics.length")
|
||||
showDismissRead(filterType, topicsLength) {
|
||||
return filterType === "unread" && topicsLength > 0;
|
||||
@discourseComputed("list.filter", "list.topics.length")
|
||||
showDismissRead(filter, topicsLength) {
|
||||
return this._isFilterPage(filter, "unread") && topicsLength > 0;
|
||||
}
|
||||
|
||||
@discourseComputed("filterType")
|
||||
new(filterType) {
|
||||
return filterType === "new";
|
||||
@discourseComputed("list.filter")
|
||||
new(filter) {
|
||||
return this._isFilterPage(filter, "new");
|
||||
}
|
||||
|
||||
@discourseComputed("new")
|
||||
|
@ -270,24 +258,4 @@ export default class TagShowController extends DiscoverySortableController.exten
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
@action
|
||||
toggleBulkSelect() {
|
||||
this.bulkSelectHelper.toggleBulkSelect();
|
||||
}
|
||||
|
||||
@action
|
||||
dismissRead(operationType, options) {
|
||||
this.bulkSelectHelper.dismissRead(operationType, options);
|
||||
}
|
||||
|
||||
@action
|
||||
updateAutoAddTopicsToBulkSelect(value) {
|
||||
this.bulkSelectHelper.autoAddTopicsToBulkSelect = value;
|
||||
}
|
||||
|
||||
@action
|
||||
addTopicsToBulkSelect(topics) {
|
||||
this.bulkSelectHelper.addTopics(topics);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import Controller from "@ember/controller";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import { or, reads } from "@ember/object/computed";
|
||||
import BulkSelectHelper from "discourse/lib/bulk-select-helper";
|
||||
import { reads } from "@ember/object/computed";
|
||||
import BulkTopicSelection from "discourse/mixins/bulk-topic-selection";
|
||||
import { action } from "@ember/object";
|
||||
import Topic from "discourse/models/topic";
|
||||
|
||||
|
@ -11,27 +11,16 @@ import {
|
|||
} from "discourse/routes/build-private-messages-route";
|
||||
|
||||
// Lists of topics on a user's page.
|
||||
export default class UserTopicsListController extends Controller {
|
||||
export default class UserTopicsListController extends Controller.extend(
|
||||
BulkTopicSelection
|
||||
) {
|
||||
hideCategory = false;
|
||||
showPosters = false;
|
||||
channel = null;
|
||||
tagsForUser = null;
|
||||
|
||||
bulkSelectHelper = new BulkSelectHelper(this);
|
||||
|
||||
@reads("pmTopicTrackingState.newIncoming.length") incomingCount;
|
||||
|
||||
@or("currentUser.canManageTopic", "showDismissRead", "showResetNew")
|
||||
canBulkSelect;
|
||||
|
||||
get bulkSelectEnabled() {
|
||||
return this.bulkSelectHelper.bulkSelectEnabled;
|
||||
}
|
||||
|
||||
get selected() {
|
||||
return this.bulkSelectHelper.selected;
|
||||
}
|
||||
|
||||
@discourseComputed("model.topics.length", "incomingCount")
|
||||
noContent(topicsLength, incomingCount) {
|
||||
return topicsLength === 0 && incomingCount === 0;
|
||||
|
@ -94,24 +83,4 @@ export default class UserTopicsListController extends Controller {
|
|||
refresh() {
|
||||
this.send("triggerRefresh");
|
||||
}
|
||||
|
||||
@action
|
||||
toggleBulkSelect() {
|
||||
this.bulkSelectHelper.toggleBulkSelect();
|
||||
}
|
||||
|
||||
@action
|
||||
dismissRead(operationType, options) {
|
||||
this.bulkSelectHelper.dismissRead(operationType, options);
|
||||
}
|
||||
|
||||
@action
|
||||
updateAutoAddTopicsToBulkSelect(value) {
|
||||
this.bulkSelectHelper.autoAddTopicsToBulkSelect = value;
|
||||
}
|
||||
|
||||
@action
|
||||
addTopicsToBulkSelect(topics) {
|
||||
this.bulkSelectHelper.addTopics(topics);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
import { NotificationLevels } from "discourse/lib/notification-levels";
|
||||
import Topic from "discourse/models/topic";
|
||||
import { inject as service } from "@ember/service";
|
||||
import { getOwner, setOwner } from "@ember/application";
|
||||
import { tracked } from "@glimmer/tracking";
|
||||
import { TrackedArray } from "@ember-compat/tracked-built-ins";
|
||||
|
||||
export default class BulkSelectHelper {
|
||||
@service router;
|
||||
@service modal;
|
||||
@service pmTopicTrackingState;
|
||||
@service topicTrackingState;
|
||||
|
||||
@tracked bulkSelectEnabled = false;
|
||||
@tracked autoAddTopicsToBulkSelect = false;
|
||||
|
||||
selected = new TrackedArray();
|
||||
|
||||
constructor(context) {
|
||||
setOwner(this, getOwner(context));
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.selected.length = 0;
|
||||
}
|
||||
|
||||
addTopics(topics) {
|
||||
this.selected.concat(topics);
|
||||
}
|
||||
|
||||
toggleBulkSelect() {
|
||||
this.bulkSelectEnabled = !this.bulkSelectEnabled;
|
||||
this.clear();
|
||||
}
|
||||
|
||||
dismissRead(operationType, options) {
|
||||
const operation =
|
||||
operationType === "posts"
|
||||
? { type: "dismiss_posts" }
|
||||
: {
|
||||
type: "change_notification_level",
|
||||
notification_level_id: NotificationLevels.REGULAR,
|
||||
};
|
||||
|
||||
const isTracked =
|
||||
(this.router.currentRoute.queryParams["f"] ||
|
||||
this.router.currentRoute.queryParams["filter"]) === "tracked";
|
||||
|
||||
const promise = this.selected.length
|
||||
? Topic.bulkOperation(this.selected, operation, isTracked)
|
||||
: Topic.bulkOperationByFilter("unread", operation, options, isTracked);
|
||||
|
||||
promise.then((result) => {
|
||||
if (result?.topic_ids) {
|
||||
if (options.private_message_inbox) {
|
||||
this.pmTopicTrackingState.removeTopics(result.topic_ids);
|
||||
} else {
|
||||
this.topicTrackingState.removeTopics(result.topic_ids);
|
||||
}
|
||||
}
|
||||
|
||||
this.modal.close();
|
||||
this.router.refresh();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -11,5 +11,5 @@ export function calculateFilterMode({ category, filterType, noSubcategories }) {
|
|||
}
|
||||
|
||||
export function filterTypeForMode(mode) {
|
||||
return mode?.split("/").pop();
|
||||
return mode.split("/").pop();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
import Mixin from "@ember/object/mixin";
|
||||
import { or } from "@ember/object/computed";
|
||||
import { on } from "discourse-common/utils/decorators";
|
||||
import { NotificationLevels } from "discourse/lib/notification-levels";
|
||||
import Topic from "discourse/models/topic";
|
||||
import { inject as service } from "@ember/service";
|
||||
|
||||
export default Mixin.create({
|
||||
router: service(),
|
||||
|
||||
bulkSelectEnabled: false,
|
||||
autoAddTopicsToBulkSelect: false,
|
||||
selected: null,
|
||||
lastChecked: null,
|
||||
|
||||
canBulkSelect: or(
|
||||
"currentUser.canManageTopic",
|
||||
"showDismissRead",
|
||||
"showResetNew"
|
||||
),
|
||||
|
||||
@on("init")
|
||||
resetSelected() {
|
||||
this.set("selected", []);
|
||||
},
|
||||
|
||||
_isFilterPage(filter, filterType) {
|
||||
if (!filter) {
|
||||
return false;
|
||||
}
|
||||
return new RegExp(filterType + "$", "gi").test(filter);
|
||||
},
|
||||
|
||||
actions: {
|
||||
toggleBulkSelect() {
|
||||
this.toggleProperty("bulkSelectEnabled");
|
||||
this.selected.clear();
|
||||
},
|
||||
|
||||
dismissRead(operationType, options) {
|
||||
const operation =
|
||||
operationType === "posts"
|
||||
? { type: "dismiss_posts" }
|
||||
: {
|
||||
type: "change_notification_level",
|
||||
notification_level_id: NotificationLevels.REGULAR,
|
||||
};
|
||||
|
||||
const tracked =
|
||||
(this.router.currentRoute.queryParams["f"] ||
|
||||
this.router.currentRoute.queryParams["filter"]) === "tracked";
|
||||
|
||||
const promise = this.selected.length
|
||||
? Topic.bulkOperation(this.selected, operation, tracked)
|
||||
: Topic.bulkOperationByFilter("unread", operation, options, tracked);
|
||||
|
||||
promise.then((result) => {
|
||||
if (result && result.topic_ids) {
|
||||
if (options.private_message_inbox) {
|
||||
this.pmTopicTrackingState.removeTopics(result.topic_ids);
|
||||
} else {
|
||||
this.topicTrackingState.removeTopics(result.topic_ids);
|
||||
}
|
||||
}
|
||||
|
||||
this.send("closeModal");
|
||||
this.send(
|
||||
"refresh",
|
||||
tracked ? { skipResettingParams: ["filter", "f"] } : {}
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
updateAutoAddTopicsToBulkSelect(newVal) {
|
||||
this.set("autoAddTopicsToBulkSelect", newVal);
|
||||
},
|
||||
|
||||
addTopicsToBulkSelect(topics) {
|
||||
this.selected.pushObjects(topics);
|
||||
},
|
||||
},
|
||||
});
|
|
@ -162,6 +162,7 @@ class AbstractCategoryRoute extends DiscourseRoute {
|
|||
period:
|
||||
topics.get("for_period") ||
|
||||
(model.modelParams && model.modelParams.period),
|
||||
selected: [],
|
||||
noSubcategories: this.routeConfig && !!this.routeConfig.no_subcategories,
|
||||
expandAllPinned: true,
|
||||
};
|
||||
|
@ -177,7 +178,6 @@ class AbstractCategoryRoute extends DiscourseRoute {
|
|||
}
|
||||
|
||||
this.controllerFor("discovery/topics").setProperties(topicOpts);
|
||||
this.controllerFor("discovery/topics").bulkSelectHelper.clear();
|
||||
this.searchService.searchContext = category.get("searchContext");
|
||||
this.set("topics", null);
|
||||
}
|
||||
|
|
|
@ -60,12 +60,12 @@ export default (inboxType, path, filter) => {
|
|||
hideCategory: true,
|
||||
showPosters: true,
|
||||
tagsForUser: this.modelFor("user").get("username_lower"),
|
||||
selected: [],
|
||||
showToggleBulkSelect: true,
|
||||
filter,
|
||||
group: null,
|
||||
inbox: inboxType,
|
||||
});
|
||||
userTopicsListController.bulkSelectHelper.clear();
|
||||
|
||||
userTopicsListController.subscribe();
|
||||
|
||||
|
|
|
@ -139,12 +139,12 @@ class AbstractTopicRoute extends DiscourseRoute {
|
|||
model,
|
||||
category: null,
|
||||
period: model.get("for_period") || model.get("params.period"),
|
||||
selected: [],
|
||||
expandAllPinned: false,
|
||||
expandGloballyPinned: true,
|
||||
};
|
||||
|
||||
this.controllerFor("discovery/topics").setProperties(topicOpts);
|
||||
this.controllerFor("discovery/topics").bulkSelectHelper.clear();
|
||||
|
||||
this.controllerFor("navigation/default").set(
|
||||
"canCreateTopic",
|
||||
|
|
|
@ -30,7 +30,7 @@ export default DiscourseRoute.extend({
|
|||
|
||||
this.controllerFor("user-topics-list").setProperties({
|
||||
showToggleBulkSelect: false,
|
||||
selected: [],
|
||||
});
|
||||
this.controllerFor("user-topics-list").bulkSelectHelper.clear();
|
||||
},
|
||||
});
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<div class="navigation-controls">
|
||||
{{#if this.site.mobileView}}
|
||||
{{#if this.currentUser.admin}}
|
||||
<BulkSelectToggle @parentController="user-topics-list" />
|
||||
<BulkSelectToggle @parentController="user-topics-list" @tagName="" />
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
|
|
Loading…
Reference in New Issue