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.
This commit is contained in:
Robin Ward 2014-08-14 11:51:45 -04:00
parent 4dfe5fd1ca
commit 649329e420
3 changed files with 32 additions and 16 deletions

View File

@ -1,10 +1,24 @@
import DiscourseController from 'discourse/controllers/controller'; 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'], needs: ['discovery/topics'],
queryParams: ['order', 'ascending', 'status', 'state', 'search'], queryParams: Ember.keys(queryParams)
order: Em.computed.alias('controllers.discovery/topics.order'), };
ascending: Em.computed.alias('controllers.discovery/topics.ascending'),
status: Em.computed.alias('controllers.discovery/topics.status'), // Aliases for the values
search: Em.computed.alias('controllers.discovery/topics.search') controllerOpts.queryParams.forEach(function(p) {
controllerOpts[p] = Em.computed.alias('controllers.discovery/topics.' + p);
}); });
export default DiscourseController.extend(controllerOpts);

View File

@ -1,14 +1,13 @@
import DiscoveryController from 'discourse/controllers/discovery'; import DiscoveryController from 'discourse/controllers/discovery';
import { queryParams } from 'discourse/controllers/discovery-sortable';
export default DiscoveryController.extend({ var controllerOpts = {
needs: ['discovery'], needs: ['discovery'],
bulkSelectEnabled: false, bulkSelectEnabled: false,
selected: [], selected: [],
order: 'default', order: 'default',
ascending: false, ascending: false,
status: null,
search: null,
actions: { actions: {
@ -149,4 +148,13 @@ export default DiscoveryController.extend({
loadMoreTopics: function() { loadMoreTopics: function() {
return this.get('model').loadMore(); 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);

View File

@ -1,12 +1,6 @@
// A helper to build a topic route for a filter // A helper to build a topic route for a filter
export var queryParams = { import { queryParams } from 'discourse/controllers/discovery-sortable';
sort: { replace: true },
ascending: { replace: true },
status: { replace: true },
state: { replace: true },
search: { replace: true }
};
export function filterQueryParams(params, defaultParams) { export function filterQueryParams(params, defaultParams) {
var findOpts = defaultParams || {}; var findOpts = defaultParams || {};