FEATURE: Allow sorting assigned topic lists
This commit is contained in:
parent
36adc0b14c
commit
6dbf3e2bcb
|
@ -3,6 +3,9 @@ import UserTopicsList from "discourse/controllers/user-topics-list";
|
|||
export default UserTopicsList.extend({
|
||||
user: Ember.inject.controller(),
|
||||
taskActions: Ember.inject.service(),
|
||||
queryParams: ["order", "ascending"],
|
||||
order: null,
|
||||
ascending: false,
|
||||
|
||||
actions: {
|
||||
unassign(topic) {
|
||||
|
@ -13,6 +16,15 @@ export default UserTopicsList.extend({
|
|||
reassign(topic) {
|
||||
const controller = this.taskActions.assign(topic);
|
||||
controller.set("model.onSuccess", () => this.send("changeAssigned"));
|
||||
},
|
||||
changeSort(sortBy) {
|
||||
if (sortBy === this.order) {
|
||||
this.toggleProperty("ascending");
|
||||
this.model.refreshSort(sortBy, this.ascending);
|
||||
} else {
|
||||
this.setProperties({ order: sortBy, ascending: false });
|
||||
this.model.refreshSort(sortBy, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -3,6 +3,9 @@ import UserTopicsList from "discourse/controllers/user-topics-list";
|
|||
export default UserTopicsList.extend({
|
||||
user: Ember.inject.controller(),
|
||||
taskActions: Ember.inject.service(),
|
||||
queryParams: ["order", "ascending"],
|
||||
order: null,
|
||||
ascending: false,
|
||||
|
||||
actions: {
|
||||
unassign(topic) {
|
||||
|
@ -13,6 +16,15 @@ export default UserTopicsList.extend({
|
|||
reassign(topic) {
|
||||
const controller = this.taskActions.assign(topic);
|
||||
controller.set("model.onSuccess", () => this.send("changeAssigned"));
|
||||
},
|
||||
changeSort(sortBy) {
|
||||
if (sortBy === this.order) {
|
||||
this.toggleProperty("ascending");
|
||||
this.model.refreshSort(sortBy, this.ascending);
|
||||
} else {
|
||||
this.setProperties({ order: sortBy, ascending: false });
|
||||
this.model.refreshSort(sortBy, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
|
||||
export default DiscourseRoute.extend({
|
||||
queryParams: {
|
||||
order: { refreshModel: true },
|
||||
ascending: { refreshModel: true }
|
||||
},
|
||||
|
||||
model(params) {
|
||||
let filter = null;
|
||||
if (params.filter !== "everyone") {
|
||||
|
@ -11,7 +16,11 @@ export default DiscourseRoute.extend({
|
|||
)}`;
|
||||
}
|
||||
return this.store.findFiltered("topicList", {
|
||||
filter: filter
|
||||
filter: filter,
|
||||
params: {
|
||||
order: params.order,
|
||||
ascending: params.ascending
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -1,17 +1,23 @@
|
|||
import UserTopicListRoute from "discourse/routes/user-topic-list";
|
||||
|
||||
export default UserTopicListRoute.extend({
|
||||
queryParams: {
|
||||
order: { refreshModel: true },
|
||||
ascending: { refreshModel: true }
|
||||
},
|
||||
userActionType: 16,
|
||||
noContentHelpKey: "discourse_assigns.no_assigns",
|
||||
|
||||
model() {
|
||||
model(params) {
|
||||
return this.store.findFiltered("topicList", {
|
||||
filter: `topics/messages-assigned/${this.modelFor("user").get(
|
||||
"username_lower"
|
||||
)}`,
|
||||
params: {
|
||||
// core is a bit odd here and is not sending an array, should be fixed
|
||||
exclude_category_ids: [-1]
|
||||
exclude_category_ids: [-1],
|
||||
order: params.order,
|
||||
ascending: params.ascending
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
selected=selected
|
||||
skipHeader=skipHeader
|
||||
tagsForUser=tagsForUser
|
||||
changeSort=changeSort
|
||||
unassign=unassign
|
||||
reassign=reassign
|
||||
onScroll=onScroll
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
incomingCount=incomingCount
|
||||
showInserted=(action "showInserted")
|
||||
tagsForUser=tagsForUser
|
||||
changeSort=(action 'changeSort')
|
||||
unassign=(action 'unassign')
|
||||
reassign=(action 'reassign')
|
||||
onScroll=saveScrollPosition
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
incomingCount=incomingCount
|
||||
showInserted=(action "showInserted")
|
||||
tagsForUser=tagsForUser
|
||||
changeSort=(action 'changeSort')
|
||||
unassign=(action 'unassign')
|
||||
reassign=(action 'reassign')
|
||||
onScroll=saveScrollPosition
|
||||
|
|
32
plugin.rb
32
plugin.rb
|
@ -217,9 +217,12 @@ after_initialize do
|
|||
WHERE name = 'assigned_to_id'
|
||||
AND value = ?)
|
||||
", user.id.to_s)
|
||||
|
||||
list = apply_ordering(list, options)
|
||||
|
||||
list = list.offset(per_page_setting * options[:page])
|
||||
.limit(per_page_setting)
|
||||
.offset(per_page_setting * options[:page])
|
||||
.order("topics.bumped_at DESC")
|
||||
|
||||
list = list.merge(secure)
|
||||
|
||||
create_list(:assigned, { unordered: true }, list)
|
||||
|
@ -234,8 +237,15 @@ after_initialize do
|
|||
|
||||
list_opts = build_topic_list_options
|
||||
list_opts[:page] = page
|
||||
list_opts[:ascending] = params[:ascending]
|
||||
list_opts[:order] = params[:order]
|
||||
|
||||
list = generate_list_for("messages_assigned", user, list_opts)
|
||||
list.more_topics_url = "/topics/messages-assigned/#{params[:username]}.json?page=#{page + 1}"
|
||||
|
||||
more_topics_url = "/topics/messages-assigned/#{params[:username]}.json?page=#{page + 1}"
|
||||
more_topics_url += "&ascending=#{params[:ascending]}&order=#{params[:order]}" if params[:order]
|
||||
|
||||
list.more_topics_url = more_topics_url
|
||||
respond_with_list(list)
|
||||
end
|
||||
|
||||
|
@ -247,9 +257,12 @@ after_initialize do
|
|||
WHERE name = 'assigned_to_id'
|
||||
AND value IN (SELECT user_id::varchar(255) from group_users where group_id = ?))
|
||||
", group.id.to_s)
|
||||
|
||||
list = apply_ordering(list, options)
|
||||
|
||||
list = list.offset(per_page_setting * options[:page])
|
||||
.limit(per_page_setting)
|
||||
.offset(per_page_setting * options[:page])
|
||||
.order("topics.bumped_at DESC")
|
||||
|
||||
list = list.merge(secure)
|
||||
|
||||
create_list(:assigned, { unordered: true }, list)
|
||||
|
@ -266,8 +279,15 @@ after_initialize do
|
|||
|
||||
list_opts = build_topic_list_options
|
||||
list_opts[:page] = page
|
||||
list_opts[:ascending] = params[:ascending]
|
||||
list_opts[:order] = params[:order]
|
||||
|
||||
list = generate_list_for("group_topics_assigned", group, list_opts)
|
||||
list.more_topics_url = "/topics/group-topics-assigned/#{params[:groupname]}.json?page=#{page + 1}"
|
||||
|
||||
more_topics_url = "/topics/group-topics-assigned/#{params[:groupname]}.json?page=#{page + 1}"
|
||||
more_topics_url += "&ascending=#{params[:ascending]}&order=#{params[:order]}" if params[:order]
|
||||
|
||||
list.more_topics_url = more_topics_url
|
||||
respond_with_list(list)
|
||||
end
|
||||
|
||||
|
|
|
@ -51,6 +51,8 @@ describe ListController do
|
|||
fab!(:post2) { Fabricate(:post) }
|
||||
fab!(:post3) { Fabricate(:post) }
|
||||
fab!(:topic) { post3.topic }
|
||||
fab!(:topic1) { post1.topic }
|
||||
fab!(:topic2) { post2.topic }
|
||||
|
||||
before do
|
||||
add_to_assign_allowed_group(user)
|
||||
|
@ -97,6 +99,99 @@ describe ListController do
|
|||
|
||||
expect(id).to eq(0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context '#sorting messages_assigned and group_topics_assigned' 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
|
||||
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
|
||||
|
||||
it 'group_topics_assigned returns sorted topicsList' do
|
||||
|
||||
topic1.bumped_at = Time.now
|
||||
topic2.bumped_at = 1.day.ago
|
||||
topic3.bumped_at = 3.day.ago
|
||||
|
||||
topic1.views = 3
|
||||
topic2.views = 5
|
||||
topic3.views = 1
|
||||
|
||||
topic1.posts_count = 3
|
||||
topic2.posts_count = 1
|
||||
topic3.posts_count = 5
|
||||
|
||||
topic1.reload
|
||||
topic2.reload
|
||||
topic3.reload
|
||||
|
||||
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])
|
||||
|
||||
get "/topics/group-topics-assigned/#{get_assigned_allowed_group_name}.json?order=views"
|
||||
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic3.id, topic1.id, topic2.id])
|
||||
|
||||
get "/topics/group-topics-assigned/#{get_assigned_allowed_group_name}.json?order=activity"
|
||||
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic3.id, topic2.id, topic1.id])
|
||||
|
||||
get "/topics/group-topics-assigned/#{get_assigned_allowed_group_name}.json?order=posts&ascending=true"
|
||||
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic3.id, topic1.id, topic2.id])
|
||||
|
||||
get "/topics/group-topics-assigned/#{get_assigned_allowed_group_name}.json?order=views&ascending=true"
|
||||
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic2.id, topic1.id, topic3.id])
|
||||
|
||||
get "/topics/group-topics-assigned/#{get_assigned_allowed_group_name}.json?order=activity&ascending=true"
|
||||
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([ topic1.id, topic2.id, topic3.id])
|
||||
end
|
||||
|
||||
it 'messages_assigned returns sorted topicsList' do
|
||||
|
||||
topic1.bumped_at = Time.now
|
||||
topic3.bumped_at = 3.day.ago
|
||||
|
||||
topic1.views = 3
|
||||
topic3.views = 1
|
||||
|
||||
topic1.posts_count = 3
|
||||
topic3.posts_count = 5
|
||||
|
||||
topic1.reload
|
||||
topic3.reload
|
||||
|
||||
get "/topics/messages-assigned/#{user.username}.json?order=posts"
|
||||
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic1.id, topic3.id])
|
||||
|
||||
get "/topics/messages-assigned/#{user.username}.json?order=views"
|
||||
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic3.id, topic1.id])
|
||||
|
||||
get "/topics/messages-assigned/#{user.username}.json?order=activity"
|
||||
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic3.id, topic1.id])
|
||||
|
||||
get "/topics/messages-assigned/#{user.username}.json?order=posts&ascending=true"
|
||||
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic3.id, topic1.id])
|
||||
|
||||
get "/topics/messages-assigned/#{user.username}.json?order=views&ascending=true"
|
||||
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic1.id, topic3.id])
|
||||
|
||||
get "/topics/messages-assigned/#{user.username}.json?order=activity&ascending=true"
|
||||
expect(JSON.parse(response.body)['topic_list']['topics'].map { |t| t['id'] }).to match_array([topic1.id, topic3.id])
|
||||
end
|
||||
end
|
||||
|
||||
context '#messages_assigned' do
|
||||
|
|
Loading…
Reference in New Issue