From 649329e420470bde9291d2c1783ff1c93e006920 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 14 Aug 2014 11:51:45 -0400 Subject: [PATCH] Add support for `max_posts` query param. Also make it easier to let Ember support query params for sorting our tables. Just add it in one place. --- .../controllers/discovery-sortable.js.es6 | 26 ++++++++++++++----- .../controllers/discovery/topics.js.es6 | 14 +++++++--- .../discourse/routes/build-topic-route.js.es6 | 8 +----- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/discovery-sortable.js.es6 b/app/assets/javascripts/discourse/controllers/discovery-sortable.js.es6 index 0061dcb4f0c..c48aa54ffa7 100644 --- a/app/assets/javascripts/discourse/controllers/discovery-sortable.js.es6 +++ b/app/assets/javascripts/discourse/controllers/discovery-sortable.js.es6 @@ -1,10 +1,24 @@ import DiscourseController from 'discourse/controllers/controller'; -export default DiscourseController.extend({ +// Just add query params here to have them automatically passed to topic list filters. +export var queryParams = { + order: { replace: true }, + ascending: { replace: true }, + status: { replace: true }, + state: { replace: true }, + search: { replace: true }, + max_posts: { replace: true } +}; + +// Basic controller options +var controllerOpts = { needs: ['discovery/topics'], - 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'), - search: Em.computed.alias('controllers.discovery/topics.search') + queryParams: Ember.keys(queryParams) +}; + +// Aliases for the values +controllerOpts.queryParams.forEach(function(p) { + controllerOpts[p] = Em.computed.alias('controllers.discovery/topics.' + p); }); + +export default DiscourseController.extend(controllerOpts); diff --git a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 index ba08050911c..6869f88f4ac 100644 --- a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 +++ b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 @@ -1,14 +1,13 @@ import DiscoveryController from 'discourse/controllers/discovery'; +import { queryParams } from 'discourse/controllers/discovery-sortable'; -export default DiscoveryController.extend({ +var controllerOpts = { needs: ['discovery'], bulkSelectEnabled: false, selected: [], order: 'default', ascending: false, - status: null, - search: null, actions: { @@ -149,4 +148,13 @@ export default DiscoveryController.extend({ loadMoreTopics: function() { return this.get('model').loadMore(); } +}; + +Ember.keys(queryParams).forEach(function(p) { + // If we don't have a default value, initialize it to null + if (typeof controllerOpts[p] === 'undefined') { + controllerOpts[p] = null; + } }); + +export default DiscoveryController.extend(controllerOpts); 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 d36561bc7a9..14b6a0017bd 100644 --- a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 @@ -1,12 +1,6 @@ // 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 } -}; +import { queryParams } from 'discourse/controllers/discovery-sortable'; export function filterQueryParams(params, defaultParams) { var findOpts = defaultParams || {};