FEATURE: Allow filtering topics in the user assigned list (#108)

FEATURE: Allow filtering topics in the user assigned list (#108)

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 efb1fb3..5ea1aaf 100644
--- a/assets/javascripts/discourse-assign/controllers/group-assigned-show.js.es6
+++ b/assets/javascripts/discourse-assign/controllers/group-assigned-show.js.es6
@@ -1,5 +1,6 @@
 import UserTopicsList from "discourse/controllers/user-topics-list";
 import { debounce } from "@ember/runloop";
+import discourseComputed from "discourse-common/utils/decorators";
 import { INPUT_DELAY } from "discourse-common/config/environment";
 
 export default UserTopicsList.extend({
@@ -11,6 +12,11 @@ export default UserTopicsList.extend({
 
   queryParams: ["order", "ascending", "q"],
 
+  @discourseComputed("q")
+  searchTerm(q) {
+    return q;
+  },
+
   _setSearchTerm(searchTerm) {
     this.set("q", searchTerm);
     this.refreshModel();
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 15ca1e2..79299b3 100644
--- a/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6
+++ b/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6
@@ -1,11 +1,42 @@
 import UserTopicsList from "discourse/controllers/user-topics-list";
+import { debounce } from "@ember/runloop";
+import discourseComputed from "discourse-common/utils/decorators";
+import { INPUT_DELAY } from "discourse-common/config/environment";
 
 export default UserTopicsList.extend({
   user: Ember.inject.controller(),
   taskActions: Ember.inject.service(),
-  queryParams: ["order", "ascending"],
+  queryParams: ["order", "ascending", "q"],
   order: null,
   ascending: false,
+  q: "",
+
+  @discourseComputed("q")
+  searchTerm(q) {
+    return q;
+  },
+
+  _setSearchTerm(searchTerm) {
+    this.set("q", searchTerm);
+    this.refreshModel();
+  },
+
+  refreshModel() {
+    this.set("loading", true);
+    this.store
+      .findFiltered("topicList", {
+        filter: this.model.filter,
+        params: {
+          order: this.order,
+          ascending: this.ascending,
+          q: this.q
+        }
+      })
+      .then(result => this.set("model", result))
+      .finally(() => {
+        this.set("loading", false);
+      });
+  },
 
   actions: {
     unassign(topic) {
@@ -20,11 +51,14 @@ export default UserTopicsList.extend({
     changeSort(sortBy) {
       if (sortBy === this.order) {
         this.toggleProperty("ascending");
-        this.model.refreshSort(sortBy, this.ascending);
+        this.refreshModel();
       } else {
         this.setProperties({ order: sortBy, ascending: false });
-        this.model.refreshSort(sortBy, false);
+        this.refreshModel();
       }
     },
+    onChangeFilter(value) {
+      debounce(this, this._setSearchTerm, value, INPUT_DELAY * 2);
+    }
   },
 });
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 ce448ba..d892350 100644
--- a/assets/javascripts/discourse-assign/routes/user-activity-assigned.js.es6
+++ b/assets/javascripts/discourse-assign/routes/user-activity-assigned.js.es6
@@ -2,10 +2,7 @@ import I18n from "I18n";
 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",
 
@@ -19,6 +16,7 @@ export default UserTopicListRoute.extend({
         exclude_category_ids: [-1],
         order: params.order,
         ascending: params.ascending,
+        q: params.q
       },
     });
   },
diff --git a/assets/javascripts/discourse/templates/user-assigned-topics.hbs b/assets/javascripts/discourse/templates/user-assigned-topics.hbs
index 92c9501..28528c5 100644
--- a/assets/javascripts/discourse/templates/user-assigned-topics.hbs
+++ b/assets/javascripts/discourse/templates/user-assigned-topics.hbs
@@ -1,3 +1,13 @@
+<div class="topic-search-div">
+  <div class="form-horizontal bookmark-search-form">
+    {{input type="text"
+        value=searchTerm
+        placeholder=(i18n "discourse_assign.topic_search_placeholder")
+        input=(action "onChangeFilter" value="target.value")
+        autocomplete="discourse"}}
+  </div>
+</div>
+
 {{#load-more class="paginated-topics-list" selector=".paginated-topics-list .topic-list tr" action=(action "loadMore")}}
   {{basic-assigned-topic-list
     topicList=model

GitHub sha: 43c68f6f

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