FEATURE: Allow sorting assigned topic lists

FEATURE: Allow sorting assigned topic lists

diff --git a/assets/javascripts/discourse-assign/controllers/group-assigned-show.js.es6 b/assets/javascripts/discourse-assign/controllers/group-assigned-show.js.es6
index 7ca8c5f..059a2fa 100644
--- a/assets/javascripts/discourse-assign/controllers/group-assigned-show.js.es6
+++ b/assets/javascripts/discourse-assign/controllers/group-assigned-show.js.es6
@@ -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);
+      }
     }
   }
 });
diff --git a/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6 b/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6
index 7ca8c5f..059a2fa 100644
--- a/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6
+++ b/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6
@@ -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);
+      }
     }
   }
 });
diff --git a/assets/javascripts/discourse-assign/routes/group-assigned-show.js.es6 b/assets/javascripts/discourse-assign/routes/group-assigned-show.js.es6
index c1d8f1e..f525851 100644
--- a/assets/javascripts/discourse-assign/routes/group-assigned-show.js.es6
+++ b/assets/javascripts/discourse-assign/routes/group-assigned-show.js.es6
@@ -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
+      }
     });
   },
 
diff --git a/assets/javascripts/discourse-assign/routes/user-activity-assigned.js.es6 b/assets/javascripts/discourse-assign/routes/user-activity-assigned.js.es6
index 1171434..171a14c 100644
--- a/assets/javascripts/discourse-assign/routes/user-activity-assigned.js.es6
+++ b/assets/javascripts/discourse-assign/routes/user-activity-assigned.js.es6
@@ -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
       }
     });
   },
diff --git a/assets/javascripts/discourse/templates/components/basic-assigned-topic-list.hbs b/assets/javascripts/discourse/templates/components/basic-assigned-topic-list.hbs
index 6d35127..d4d15d8 100644
--- a/assets/javascripts/discourse/templates/components/basic-assigned-topic-list.hbs
+++ b/assets/javascripts/discourse/templates/components/basic-assigned-topic-list.hbs
@@ -17,6 +17,7 @@
                           selected=selected
                           skipHeader=skipHeader
                           tagsForUser=tagsForUser
+                          changeSort=changeSort
                           unassign=unassign
                           reassign=reassign
                           onScroll=onScroll
diff --git a/assets/javascripts/discourse/templates/group-topics-list.hbs b/assets/javascripts/discourse/templates/group-topics-list.hbs
index 4d3237a..7746af7 100644
--- a/assets/javascripts/discourse/templates/group-topics-list.hbs
+++ b/assets/javascripts/discourse/templates/group-topics-list.hbs
@@ -8,6 +8,7 @@
                               incomingCount=incomingCount
                               showInserted=(action "showInserted")
                               tagsForUser=tagsForUser
+                              changeSort=(action 'changeSort')
                               unassign=(action 'unassign')
                               reassign=(action 'reassign')
                               onScroll=saveScrollPosition
diff --git a/assets/javascripts/discourse/templates/user-assigned-topics.hbs b/assets/javascripts/discourse/templates/user-assigned-topics.hbs
index 5b25af2..01f999d 100644
--- a/assets/javascripts/discourse/templates/user-assigned-topics.hbs
+++ b/assets/javascripts/discourse/templates/user-assigned-topics.hbs
@@ -8,6 +8,7 @@
                               incomingCount=incomingCount
                               showInserted=(action "showInserted")
                               tagsForUser=tagsForUser
+                              changeSort=(action 'changeSort')
                               unassign=(action 'unassign')
                               reassign=(action 'reassign')
                               onScroll=saveScrollPosition
diff --git a/plugin.rb b/plugin.rb
index 3ca94a7..7ff7004 100644
--- a/plugin.rb
+++ b/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'

[... diff too long, it was truncated ...]

GitHub sha: 6dbf3e2b

1 Like

This commit appears in #89 which was merged by davidtaylorhq.