From f83fb497410198da4f710705410c375716991ee0 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 7 Aug 2014 15:13:13 -0400 Subject: [PATCH] FIX: Category topic list should support search filter too --- .../controllers/discovery/topics.js.es6 | 1 + .../discovery_sortable_controller.js | 3 +- .../routes/build-category-route.js.es6 | 15 ++++--- .../discourse/routes/build-topic-route.js.es6 | 39 +++++++++++-------- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 index 3bbce016147..3085f0ee8f8 100644 --- a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 +++ b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 @@ -14,6 +14,7 @@ export default Discourse.DiscoveryController.extend({ order: 'default', ascending: false, status: null, + search: null, actions: { diff --git a/app/assets/javascripts/discourse/controllers/discovery_sortable_controller.js b/app/assets/javascripts/discourse/controllers/discovery_sortable_controller.js index 1a7ffaeaddc..d6b49389e8e 100644 --- a/app/assets/javascripts/discourse/controllers/discovery_sortable_controller.js +++ b/app/assets/javascripts/discourse/controllers/discovery_sortable_controller.js @@ -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') }); diff --git a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 index 04e90b4f3c4..04ddbbcac41 100644 --- a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 @@ -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); diff --git a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 index 7804d700855..d36561bc7a9 100644 --- a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 @@ -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; })));