FEATURE: Allow searching topics in group assigned tab (#97)
This commit is contained in:
parent
f250dca93f
commit
069adc1af7
|
@ -3,9 +3,12 @@ import UserTopicsList from "discourse/controllers/user-topics-list";
|
||||||
export default UserTopicsList.extend({
|
export default UserTopicsList.extend({
|
||||||
user: Ember.inject.controller(),
|
user: Ember.inject.controller(),
|
||||||
taskActions: Ember.inject.service(),
|
taskActions: Ember.inject.service(),
|
||||||
queryParams: ["order", "ascending"],
|
|
||||||
order: null,
|
order: null,
|
||||||
ascending: false,
|
ascending: false,
|
||||||
|
searchTerm: null,
|
||||||
|
q: "",
|
||||||
|
|
||||||
|
queryParams: ["order", "ascending", "q"],
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
unassign(topic) {
|
unassign(topic) {
|
||||||
|
@ -25,6 +28,9 @@ export default UserTopicsList.extend({
|
||||||
this.setProperties({ order: sortBy, ascending: false });
|
this.setProperties({ order: sortBy, ascending: false });
|
||||||
this.model.refreshSort(sortBy, false);
|
this.model.refreshSort(sortBy, false);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
search() {
|
||||||
|
this.set("q", this.searchTerm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,7 +4,8 @@ import { findOrResetCachedTopicList } from "discourse/lib/cached-topic-list";
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
queryParams: {
|
queryParams: {
|
||||||
order: { refreshModel: true },
|
order: { refreshModel: true },
|
||||||
ascending: { refreshModel: true }
|
ascending: { refreshModel: true },
|
||||||
|
q: { refreshModel: true }
|
||||||
},
|
},
|
||||||
|
|
||||||
beforeModel(transition) {
|
beforeModel(transition) {
|
||||||
|
@ -32,7 +33,8 @@ export default DiscourseRoute.extend({
|
||||||
filter: filter,
|
filter: filter,
|
||||||
params: {
|
params: {
|
||||||
order: params.order,
|
order: params.order,
|
||||||
ascending: params.ascending
|
ascending: params.ascending,
|
||||||
|
q: params.q
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
<div class="form-horizontal bookmark-search-form">
|
||||||
|
{{input type="text"
|
||||||
|
value=searchTerm
|
||||||
|
enter=(action "search")
|
||||||
|
placeholder=(i18n "discourse_assign.topic_search_placeholder")
|
||||||
|
autocomplete="discourse"}}
|
||||||
|
{{d-button
|
||||||
|
class="btn-primary"
|
||||||
|
enter=(action "search")
|
||||||
|
type="button"
|
||||||
|
icon="search"}}
|
||||||
|
</div>
|
||||||
{{#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-assigned-topic-list topicList=model
|
{{basic-assigned-topic-list topicList=model
|
||||||
hideCategory=hideCategory
|
hideCategory=hideCategory
|
||||||
|
|
|
@ -11,6 +11,7 @@ en:
|
||||||
add_unassigned_filter: "Add 'unassigned' filter to category"
|
add_unassigned_filter: "Add 'unassigned' filter to category"
|
||||||
cant_act: "You cannot act on flags that have been assigned to other users"
|
cant_act: "You cannot act on flags that have been assigned to other users"
|
||||||
cant_act_unclaimed: "You must claim this topic before acting on flags."
|
cant_act_unclaimed: "You must claim this topic before acting on flags."
|
||||||
|
topic_search_placeholder: "Search topics by title or post content"
|
||||||
sidebar_name_filter_placeholder: "Name/Username"
|
sidebar_name_filter_placeholder: "Name/Username"
|
||||||
assigned: "Assigned"
|
assigned: "Assigned"
|
||||||
group_everyone: "Everyone"
|
group_everyone: "Everyone"
|
||||||
|
|
32
plugin.rb
32
plugin.rb
|
@ -221,11 +221,22 @@ after_initialize do
|
||||||
|
|
||||||
list = apply_ordering(list, options)
|
list = apply_ordering(list, options)
|
||||||
|
|
||||||
|
list = list.merge(secure)
|
||||||
|
|
||||||
|
if options[:q].present?
|
||||||
|
term = options[:q]
|
||||||
|
ts_query = Search.ts_query(term: term)
|
||||||
|
|
||||||
|
list = list
|
||||||
|
.joins("LEFT JOIN topic_search_data ON topic_search_data.topic_id=topics.id")
|
||||||
|
.where(
|
||||||
|
"#{ts_query} @@ topic_search_data.search_data"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
list = list.offset(per_page_setting * options[:page])
|
list = list.offset(per_page_setting * options[:page])
|
||||||
.limit(per_page_setting)
|
.limit(per_page_setting)
|
||||||
|
|
||||||
list = list.merge(secure)
|
|
||||||
|
|
||||||
create_list(:assigned, { unordered: true }, list)
|
create_list(:assigned, { unordered: true }, list)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -240,6 +251,7 @@ after_initialize do
|
||||||
list_opts[:page] = page
|
list_opts[:page] = page
|
||||||
list_opts[:ascending] = params[:ascending]
|
list_opts[:ascending] = params[:ascending]
|
||||||
list_opts[:order] = params[:order]
|
list_opts[:order] = params[:order]
|
||||||
|
list_opts[:q] = params[:q] if params[:q]
|
||||||
|
|
||||||
list = generate_list_for("messages_assigned", user, list_opts)
|
list = generate_list_for("messages_assigned", user, list_opts)
|
||||||
|
|
||||||
|
@ -262,11 +274,22 @@ after_initialize do
|
||||||
|
|
||||||
list = apply_ordering(list, options)
|
list = apply_ordering(list, options)
|
||||||
|
|
||||||
|
list = list.merge(secure)
|
||||||
|
|
||||||
|
if options[:q].present?
|
||||||
|
term = options[:q]
|
||||||
|
ts_query = Search.ts_query(term: term)
|
||||||
|
|
||||||
|
list = list
|
||||||
|
.joins("LEFT JOIN topic_search_data ON topic_search_data.topic_id=topics.id")
|
||||||
|
.where(
|
||||||
|
"#{ts_query} @@ topic_search_data.search_data"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
list = list.offset(per_page_setting * options[:page])
|
list = list.offset(per_page_setting * options[:page])
|
||||||
.limit(per_page_setting)
|
.limit(per_page_setting)
|
||||||
|
|
||||||
list = list.merge(secure)
|
|
||||||
|
|
||||||
create_list(:assigned, { unordered: true }, list)
|
create_list(:assigned, { unordered: true }, list)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -283,6 +306,7 @@ after_initialize do
|
||||||
list_opts[:page] = page
|
list_opts[:page] = page
|
||||||
list_opts[:ascending] = params[:ascending]
|
list_opts[:ascending] = params[:ascending]
|
||||||
list_opts[:order] = params[:order]
|
list_opts[:order] = params[:order]
|
||||||
|
list_opts[:q] = params[:q] if params[:q]
|
||||||
|
|
||||||
list = generate_list_for("group_topics_assigned", group, list_opts)
|
list = generate_list_for("group_topics_assigned", group, list_opts)
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,8 @@ describe ListController do
|
||||||
before do
|
before do
|
||||||
add_to_assign_allowed_group(user)
|
add_to_assign_allowed_group(user)
|
||||||
|
|
||||||
TopicAssigner.new(post1.topic, user).assign(user)
|
TopicAssigner.new(topic1, user).assign(user)
|
||||||
TopicAssigner.new(post2.topic, user).assign(user2)
|
TopicAssigner.new(topic2, user).assign(user2)
|
||||||
|
|
||||||
sign_in(user)
|
sign_in(user)
|
||||||
end
|
end
|
||||||
|
@ -137,9 +137,9 @@ describe ListController do
|
||||||
topic2.posts_count = 1
|
topic2.posts_count = 1
|
||||||
topic3.posts_count = 5
|
topic3.posts_count = 5
|
||||||
|
|
||||||
topic1.reload
|
topic1.save!
|
||||||
topic2.reload
|
topic2.save!
|
||||||
topic3.reload
|
topic3.save!
|
||||||
|
|
||||||
get "/topics/group-topics-assigned/#{get_assigned_allowed_group_name}.json?order=posts"
|
get "/topics/group-topics-assigned/#{get_assigned_allowed_group_name}.json?order=posts"
|
||||||
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic2.id, topic1.id, topic3.id])
|
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic2.id, topic1.id, topic3.id])
|
||||||
|
@ -194,6 +194,67 @@ describe ListController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'filtering of topics as per parameter' do
|
||||||
|
include_context 'A group that is allowed to assign'
|
||||||
|
|
||||||
|
fab!(:post1) { Fabricate(:post) }
|
||||||
|
fab!(:post2) { Fabricate(:post) }
|
||||||
|
fab!(:post3) { Fabricate(:post) }
|
||||||
|
fab!(:topic1) { post1.topic }
|
||||||
|
fab!(:topic2) { post2.topic }
|
||||||
|
fab!(:topic3) { post3.topic }
|
||||||
|
|
||||||
|
before do
|
||||||
|
SearchIndexer.enable
|
||||||
|
|
||||||
|
add_to_assign_allowed_group(user)
|
||||||
|
add_to_assign_allowed_group(user2)
|
||||||
|
|
||||||
|
TopicAssigner.new(post1.topic, user).assign(user)
|
||||||
|
TopicAssigner.new(post2.topic, user).assign(user2)
|
||||||
|
TopicAssigner.new(post3.topic, user).assign(user)
|
||||||
|
|
||||||
|
sign_in(user)
|
||||||
|
end
|
||||||
|
|
||||||
|
after { SearchIndexer.disable }
|
||||||
|
|
||||||
|
it 'returns topics as per filter for #group_topics_assigned' do
|
||||||
|
topic1.title = 'QUnit testing is love'
|
||||||
|
topic2.title = 'RSpec testing is too fun'
|
||||||
|
topic3.title = 'Testing is main part of programming'
|
||||||
|
|
||||||
|
topic1.save!
|
||||||
|
topic2.save!
|
||||||
|
topic3.save!
|
||||||
|
|
||||||
|
get "/topics/group-topics-assigned/#{get_assigned_allowed_group_name}.json", params: { q: 'Testing' }
|
||||||
|
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic1.id, topic2.id, topic3.id])
|
||||||
|
|
||||||
|
get "/topics/group-topics-assigned/#{get_assigned_allowed_group_name}.json", params: { q: 'RSpec' }
|
||||||
|
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic2.id])
|
||||||
|
|
||||||
|
get "/topics/group-topics-assigned/#{get_assigned_allowed_group_name}.json", params: { q: 'love' }
|
||||||
|
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic1.id])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns topics as per filter for #group_topics_assigned' do
|
||||||
|
topic1.title = 'QUnit testing is love'
|
||||||
|
topic2.title = 'RSpec testing is too fun'
|
||||||
|
topic3.title = 'Testing is main part of programming'
|
||||||
|
|
||||||
|
topic1.save!
|
||||||
|
topic2.save!
|
||||||
|
topic3.save!
|
||||||
|
|
||||||
|
get "/topics/messages-assigned/#{user.username}.json", params: { q: 'Testing' }
|
||||||
|
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic1.id, topic3.id])
|
||||||
|
|
||||||
|
get "/topics/group-topics-assigned/#{get_assigned_allowed_group_name}.json", params: { q: 'love' }
|
||||||
|
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic1.id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context '#messages_assigned' do
|
context '#messages_assigned' do
|
||||||
include_context 'A group that is allowed to assign'
|
include_context 'A group that is allowed to assign'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue