mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 16:33:59 +08:00
FIX: Category topic list should support search filter too
This commit is contained in:
parent
7c65adfd6f
commit
f83fb49741
|
@ -14,6 +14,7 @@ export default Discourse.DiscoveryController.extend({
|
|||
order: 'default',
|
||||
ascending: false,
|
||||
status: null,
|
||||
search: null,
|
||||
|
||||
actions: {
|
||||
|
||||
|
|
|
@ -3,5 +3,6 @@ Discourse.DiscoverySortableController = Discourse.Controller.extend({
|
|||
queryParams: ['order', 'ascending', 'status', 'state', 'search'],
|
||||
order: Em.computed.alias('controllers.discovery/topics.order'),
|
||||
ascending: Em.computed.alias('controllers.discovery/topics.ascending'),
|
||||
status: Em.computed.alias('controllers.discovery/topics.status')
|
||||
status: Em.computed.alias('controllers.discovery/topics.status'),
|
||||
search: Em.computed.alias('controllers.discovery/topics.search')
|
||||
});
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
// A helper function to create a category route with parameters
|
||||
import { queryParams, filterQueryParams } from 'discourse/routes/build-topic-route';
|
||||
|
||||
export default function(filter, params) {
|
||||
return Discourse.Route.extend({
|
||||
queryParams: queryParams,
|
||||
|
||||
model: function(modelParams) {
|
||||
return Discourse.Category.findBySlug(modelParams.slug, modelParams.parentSlug);
|
||||
},
|
||||
|
@ -43,17 +47,12 @@ export default function(filter, params) {
|
|||
},
|
||||
|
||||
_retrieveTopicList: function(model, transaction) {
|
||||
var queryParams = transaction.queryParams,
|
||||
listFilter = "category/" + Discourse.Category.slugFor(model) + "/l/" + filter,
|
||||
var listFilter = "category/" + Discourse.Category.slugFor(model) + "/l/" + filter,
|
||||
self = this;
|
||||
|
||||
params = params || {};
|
||||
var findOpts = filterQueryParams(transaction.queryParams, params);
|
||||
|
||||
if (queryParams && queryParams.order) { params.order = queryParams.order; }
|
||||
if (queryParams && queryParams.ascending) { params.ascending = queryParams.ascending; }
|
||||
if (queryParams && queryParams.status) { params.status = queryParams.status; }
|
||||
|
||||
return Discourse.TopicList.list(listFilter, params).then(function(list) {
|
||||
return Discourse.TopicList.list(listFilter, findOpts).then(function(list) {
|
||||
var tracking = Discourse.TopicTrackingState.current();
|
||||
if (tracking) {
|
||||
tracking.sync(list, listFilter);
|
||||
|
|
|
@ -1,13 +1,26 @@
|
|||
// A helper to build a topic route for a filter
|
||||
|
||||
export var queryParams = {
|
||||
sort: { replace: true },
|
||||
ascending: { replace: true },
|
||||
status: { replace: true },
|
||||
state: { replace: true },
|
||||
search: { replace: true }
|
||||
};
|
||||
|
||||
export function filterQueryParams(params, defaultParams) {
|
||||
var findOpts = defaultParams || {};
|
||||
if (params) {
|
||||
Ember.keys(queryParams).forEach(function(opt) {
|
||||
if (params[opt]) { findOpts[opt] = params[opt]; }
|
||||
});
|
||||
}
|
||||
return findOpts;
|
||||
}
|
||||
|
||||
export default function(filter) {
|
||||
return Discourse.Route.extend({
|
||||
queryParams: {
|
||||
sort: { replace: true },
|
||||
ascending: { replace: true },
|
||||
status: { replace: true },
|
||||
state: { replace: true },
|
||||
search: { replace: true }
|
||||
},
|
||||
queryParams: queryParams,
|
||||
|
||||
beforeModel: function() {
|
||||
this.controllerFor('navigation/default').set('filterMode', filter);
|
||||
|
@ -15,18 +28,10 @@ export default function(filter) {
|
|||
|
||||
model: function(data, transaction) {
|
||||
|
||||
var params = transaction.queryParams;
|
||||
|
||||
// attempt to stop early cause we need this to be called before .sync
|
||||
Discourse.ScreenTrack.current().stop();
|
||||
|
||||
var findOpts = {};
|
||||
if(params){
|
||||
_.keys(this.queryParams).forEach(function(opt) {
|
||||
if (params[opt]) { findOpts[opt] = params[opt]; }
|
||||
});
|
||||
}
|
||||
|
||||
var findOpts = filterQueryParams(transaction.queryParams);
|
||||
return Discourse.TopicList.list(filter, findOpts).then(function(list) {
|
||||
var tracking = Discourse.TopicTrackingState.current();
|
||||
if (tracking) {
|
||||
|
@ -39,7 +44,7 @@ export default function(filter) {
|
|||
|
||||
setupController: function(controller, model, trans) {
|
||||
|
||||
controller.setProperties(Em.getProperties(trans, _.keys(this.queryParams).map(function(v){
|
||||
controller.setProperties(Em.getProperties(trans, _.keys(queryParams).map(function(v){
|
||||
return 'queryParams.' + v;
|
||||
})));
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user