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

This commit is contained in:
Ahmed Gagan 2020-09-09 22:58:14 +05:30 committed by GitHub
parent 17f59992ab
commit 43c68f6ffd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 7 deletions

View File

@ -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();

View File

@ -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);
}
},
});

View File

@ -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
},
});
},

View File

@ -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