mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: add dismiss unread topics button when filtered by tag. (#10547)
This commit is contained in:
parent
c0cd69d280
commit
a8502ae1c4
@ -7,6 +7,7 @@ import NavItem from "discourse/models/nav-item";
|
|||||||
import FilterModeMixin from "discourse/mixins/filter-mode";
|
import FilterModeMixin from "discourse/mixins/filter-mode";
|
||||||
import { queryParams } from "discourse/controllers/discovery-sortable";
|
import { queryParams } from "discourse/controllers/discovery-sortable";
|
||||||
import bootbox from "bootbox";
|
import bootbox from "bootbox";
|
||||||
|
import showModal from "discourse/lib/show-modal";
|
||||||
|
|
||||||
export default Controller.extend(BulkTopicSelection, FilterModeMixin, {
|
export default Controller.extend(BulkTopicSelection, FilterModeMixin, {
|
||||||
application: controller(),
|
application: controller(),
|
||||||
@ -88,7 +89,7 @@ export default Controller.extend(BulkTopicSelection, FilterModeMixin, {
|
|||||||
|
|
||||||
@discourseComputed("navMode", "list.topics.length", "loading")
|
@discourseComputed("navMode", "list.topics.length", "loading")
|
||||||
footerMessage(navMode, listTopicsLength, loading) {
|
footerMessage(navMode, listTopicsLength, loading) {
|
||||||
if (loading || listTopicsLength !== 0) {
|
if (loading) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,13 +98,29 @@ export default Controller.extend(BulkTopicSelection, FilterModeMixin, {
|
|||||||
tag: this.get("tag.id")
|
tag: this.get("tag.id")
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return I18n.t(`tagging.topics.bottom.${navMode}`, {
|
return I18n.t(`topics.bottom.tag`, {
|
||||||
tag: this.get("tag.id")
|
tag: this.get("tag.id")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isFilterPage: function(filter, filterType) {
|
||||||
|
if (!filter) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return filter.match(new RegExp(filterType + "$", "gi")) ? true : false;
|
||||||
|
},
|
||||||
|
|
||||||
|
@discourseComputed("list.filter", "list.topics.length")
|
||||||
|
showDismissRead(filter, topicsLength) {
|
||||||
|
return this.isFilterPage(filter, "unread") && topicsLength > 0;
|
||||||
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
dismissReadPosts() {
|
||||||
|
showModal("dismiss-read", { title: "topics.bulk.dismiss_read" });
|
||||||
|
},
|
||||||
|
|
||||||
changeSort(order) {
|
changeSort(order) {
|
||||||
if (order === this.order) {
|
if (order === this.order) {
|
||||||
this.toggleProperty("ascending");
|
this.toggleProperty("ascending");
|
||||||
@ -122,7 +139,9 @@ export default Controller.extend(BulkTopicSelection, FilterModeMixin, {
|
|||||||
|
|
||||||
refresh() {
|
refresh() {
|
||||||
return this.store
|
return this.store
|
||||||
.findFiltered("topicList", { filter: "tags/" + this.get("tag.id") })
|
.findFiltered("topicList", {
|
||||||
|
filter: this.get("list.filter")
|
||||||
|
})
|
||||||
.then(list => {
|
.then(list => {
|
||||||
this.set("list", list);
|
this.set("list", list);
|
||||||
this.resetSelected();
|
this.resetSelected();
|
||||||
|
@ -21,7 +21,7 @@ export default Mixin.create({
|
|||||||
this.selected.clear();
|
this.selected.clear();
|
||||||
},
|
},
|
||||||
|
|
||||||
dismissRead(operationType, categoryOptions) {
|
dismissRead(operationType, options) {
|
||||||
let operation;
|
let operation;
|
||||||
if (operationType === "posts") {
|
if (operationType === "posts") {
|
||||||
operation = { type: "dismiss_posts" };
|
operation = { type: "dismiss_posts" };
|
||||||
@ -36,12 +36,7 @@ export default Mixin.create({
|
|||||||
if (this.selected.length > 0) {
|
if (this.selected.length > 0) {
|
||||||
promise = Topic.bulkOperation(this.selected, operation);
|
promise = Topic.bulkOperation(this.selected, operation);
|
||||||
} else {
|
} else {
|
||||||
promise = Topic.bulkOperationByFilter(
|
promise = Topic.bulkOperationByFilter("unread", operation, options);
|
||||||
"unread",
|
|
||||||
operation,
|
|
||||||
this.get("category.id"),
|
|
||||||
categoryOptions
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
promise.then(result => {
|
promise.then(result => {
|
||||||
|
@ -800,14 +800,21 @@ Topic.reopenClass({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
bulkOperationByFilter(filter, operation, categoryId, options) {
|
bulkOperationByFilter(filter, operation, options) {
|
||||||
let data = { filter, operation };
|
let data = { filter, operation };
|
||||||
|
|
||||||
if (options && options.includeSubcategories) {
|
if (options) {
|
||||||
data.include_subcategories = true;
|
if (options.categoryId) {
|
||||||
|
data.category_id = options.categoryId;
|
||||||
|
}
|
||||||
|
if (options.includeSubcategories) {
|
||||||
|
data.include_subcategories = true;
|
||||||
|
}
|
||||||
|
if (options.tagName) {
|
||||||
|
data.tag_name = options.tagName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (categoryId) data.category_id = categoryId;
|
|
||||||
return ajax("/topics/bulk", {
|
return ajax("/topics/bulk", {
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
data
|
data
|
||||||
|
@ -75,6 +75,7 @@ export default DiscourseRoute.extend(OpenComposer, {
|
|||||||
dismissRead(operationType) {
|
dismissRead(operationType) {
|
||||||
const controller = this.controllerFor("discovery/topics");
|
const controller = this.controllerFor("discovery/topics");
|
||||||
controller.send("dismissRead", operationType, {
|
controller.send("dismissRead", operationType, {
|
||||||
|
categoryId: controller.get("category.id"),
|
||||||
includeSubcategories: !controller.noSubcategories
|
includeSubcategories: !controller.noSubcategories
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,10 @@ import {
|
|||||||
filterQueryParams,
|
filterQueryParams,
|
||||||
findTopicList
|
findTopicList
|
||||||
} from "discourse/routes/build-topic-route";
|
} from "discourse/routes/build-topic-route";
|
||||||
import { queryParams } from "discourse/controllers/discovery-sortable";
|
import {
|
||||||
|
resetParams,
|
||||||
|
queryParams
|
||||||
|
} from "discourse/controllers/discovery-sortable";
|
||||||
import PermissionType from "discourse/models/permission-type";
|
import PermissionType from "discourse/models/permission-type";
|
||||||
import Category from "discourse/models/category";
|
import Category from "discourse/models/category";
|
||||||
import FilterModeMixin from "discourse/mixins/filter-mode";
|
import FilterModeMixin from "discourse/mixins/filter-mode";
|
||||||
@ -207,6 +210,30 @@ export default DiscourseRoute.extend(FilterModeMixin, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
dismissReadTopics(dismissTopics) {
|
||||||
|
const operationType = dismissTopics ? "topics" : "posts";
|
||||||
|
this.send("dismissRead", operationType);
|
||||||
|
},
|
||||||
|
|
||||||
|
dismissRead(operationType) {
|
||||||
|
const controller = this.controllerFor("tags-show");
|
||||||
|
let options = {
|
||||||
|
tagName: controller.get("tag.id")
|
||||||
|
};
|
||||||
|
const categoryId = controller.get("category.id");
|
||||||
|
|
||||||
|
if (categoryId) {
|
||||||
|
options = $.extend({}, options, {
|
||||||
|
categoryId: categoryId,
|
||||||
|
includeSubcategories: !controller.noSubcategories
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
controller.send("dismissRead", operationType, options);
|
||||||
|
},
|
||||||
|
|
||||||
|
resetParams,
|
||||||
|
|
||||||
didTransition() {
|
didTransition() {
|
||||||
this.controllerFor("tags.show")._showFooter();
|
this.controllerFor("tags.show")._showFooter();
|
||||||
return true;
|
return true;
|
||||||
|
@ -82,13 +82,21 @@
|
|||||||
changeSort=(action "changeSort")
|
changeSort=(action "changeSort")
|
||||||
}}
|
}}
|
||||||
{{/discovery-topics-list}}
|
{{/discovery-topics-list}}
|
||||||
{{else}}
|
|
||||||
<footer class="topic-list-bottom">
|
|
||||||
<h3>
|
|
||||||
{{footerMessage}}{{#link-to "discovery.categories"}} {{i18n "topic.browse_all_categories"}}{{/link-to}} {{i18n "or"}} {{#link-to "discovery.latest"}}{{i18n "topic.view_latest_topics"}}{{/link-to}}.
|
|
||||||
</h3>
|
|
||||||
</footer>
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
<footer class="topic-list-bottom">
|
||||||
|
{{#if showDismissRead}}
|
||||||
|
{{d-button
|
||||||
|
class="btn-default dismiss-read"
|
||||||
|
id="dismiss-topics"
|
||||||
|
action=(action "dismissReadPosts")
|
||||||
|
title="topics.bulk.dismiss_tooltip"
|
||||||
|
label="topics.bulk.dismiss_button"}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#footer-message education=footerEducation message=footerMessage}}
|
||||||
|
{{#link-to "tags"}} {{i18n "topic.browse_all_tags"}}{{/link-to}} {{i18n "or"}} {{#link-to "discovery.latest"}}{{i18n "topic.view_latest_topics"}}{{/link-to}}.
|
||||||
|
{{/footer-message}}
|
||||||
|
</footer>
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
||||||
{{conditional-loading-spinner condition=list.loadingMore}}
|
{{conditional-loading-spinner condition=list.loadingMore}}
|
||||||
|
@ -856,6 +856,11 @@ class TopicsController < ApplicationController
|
|||||||
topics = topics.where('category_id = ?', params[:category_id])
|
topics = topics.where('category_id = ?', params[:category_id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if params[:tag_name].present?
|
||||||
|
topics = topics.joins(:tags).where("tags.name": params[:tag_name])
|
||||||
|
end
|
||||||
|
|
||||||
topic_ids = topics.pluck(:id)
|
topic_ids = topics.pluck(:id)
|
||||||
else
|
else
|
||||||
raise ActionController::ParameterMissing.new(:topic_ids)
|
raise ActionController::ParameterMissing.new(:topic_ids)
|
||||||
|
@ -2166,6 +2166,7 @@ en:
|
|||||||
new: "There are no more new topics."
|
new: "There are no more new topics."
|
||||||
unread: "There are no more unread topics."
|
unread: "There are no more unread topics."
|
||||||
category: "There are no more %{category} topics."
|
category: "There are no more %{category} topics."
|
||||||
|
tag: "There are no more %{tag} topics."
|
||||||
top: "There are no more top topics."
|
top: "There are no more top topics."
|
||||||
bookmarks: "There are no more bookmarked topics."
|
bookmarks: "There are no more bookmarked topics."
|
||||||
|
|
||||||
@ -2256,6 +2257,7 @@ en:
|
|||||||
bumped_at_title_MF: "{FIRST_POST}: {CREATED_AT}\n{LAST_POST}: {BUMPED_AT}"
|
bumped_at_title_MF: "{FIRST_POST}: {CREATED_AT}\n{LAST_POST}: {BUMPED_AT}"
|
||||||
|
|
||||||
browse_all_categories: Browse all categories
|
browse_all_categories: Browse all categories
|
||||||
|
browse_all_tags: Browse all tags
|
||||||
|
|
||||||
view_latest_topics: view latest topics
|
view_latest_topics: view latest topics
|
||||||
suggest_create_topic: Why not create a topic?
|
suggest_create_topic: Why not create a topic?
|
||||||
@ -3388,14 +3390,6 @@ en:
|
|||||||
latest: "There are no latest topics."
|
latest: "There are no latest topics."
|
||||||
bookmarks: "You have no bookmarked topics yet."
|
bookmarks: "You have no bookmarked topics yet."
|
||||||
top: "There are no top topics."
|
top: "There are no top topics."
|
||||||
bottom:
|
|
||||||
latest: "There are no more latest topics."
|
|
||||||
posted: "There are no more posted topics."
|
|
||||||
read: "There are no more read topics."
|
|
||||||
new: "There are no more new topics."
|
|
||||||
unread: "There are no more unread topics."
|
|
||||||
top: "There are no more top topics."
|
|
||||||
bookmarks: "There are no more bookmarked topics."
|
|
||||||
|
|
||||||
invite:
|
invite:
|
||||||
custom_message: "Make your invite a little bit more personal by writing a <a href>custom message</a>."
|
custom_message: "Make your invite a little bit more personal by writing a <a href>custom message</a>."
|
||||||
|
@ -2505,6 +2505,26 @@ RSpec.describe TopicsController do
|
|||||||
expect(TopicUser.get(post1.topic, post1.user).last_read_post_number).to eq(2)
|
expect(TopicUser.get(post1.topic, post1.user).last_read_post_number).to eq(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "can mark tag topics unread" do
|
||||||
|
tag = Fabricate(:tag)
|
||||||
|
TopicTag.create!(
|
||||||
|
topic_id: topic.id,
|
||||||
|
tag_id: tag.id
|
||||||
|
)
|
||||||
|
|
||||||
|
post1 = create_post(user: user, topic_id: topic.id)
|
||||||
|
create_post(topic_id: topic.id)
|
||||||
|
|
||||||
|
put "/topics/bulk.json", params: {
|
||||||
|
tag_name: tag.name,
|
||||||
|
filter: 'unread',
|
||||||
|
operation: { type: 'dismiss_posts' }
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
expect(TopicUser.get(post1.topic, post1.user).last_read_post_number).to eq(2)
|
||||||
|
end
|
||||||
|
|
||||||
it "can find unread" do
|
it "can find unread" do
|
||||||
# mark all unread muted
|
# mark all unread muted
|
||||||
put "/topics/bulk.json", params: {
|
put "/topics/bulk.json", params: {
|
||||||
|
Loading…
Reference in New Issue
Block a user