diff --git a/app/assets/javascripts/discourse/controllers/users.js.es6 b/app/assets/javascripts/discourse/controllers/users.js.es6 index 631be71d7..8ff6e6e49 100644 --- a/app/assets/javascripts/discourse/controllers/users.js.es6 +++ b/app/assets/javascripts/discourse/controllers/users.js.es6 @@ -1,11 +1,16 @@ export default Ember.Controller.extend({ - queryParams: ['period', 'order', 'asc'], + queryParams: ['period', 'order', 'asc', 'name'], period: 'weekly', order: 'likes_received', asc: null, + name: '', showTimeRead: Ember.computed.equal('period', 'all'), + _setName: Discourse.debounce(function() { + this.set('name', this.get('nameInput')); + }, 500).observes('nameInput'), + actions: { loadMore() { this.get('model').loadMore(); diff --git a/app/assets/javascripts/discourse/lib/debounce.js b/app/assets/javascripts/discourse/lib/debounce.js index 571e146ae..583e8bb9b 100644 --- a/app/assets/javascripts/discourse/lib/debounce.js +++ b/app/assets/javascripts/discourse/lib/debounce.js @@ -2,11 +2,6 @@ Debounce a Javascript function. This means if it's called many times in a time limit it should only be executed once (at the end of the limit counted from the last call made). Original function will be called with the context and arguments from the last call made. - - @method debounce - @module Discourse - @param {function} func The function to debounce - @param {Number} wait how long to wait **/ Discourse.debounce = function(func, wait) { var self, args; diff --git a/app/assets/javascripts/discourse/routes/users.js.es6 b/app/assets/javascripts/discourse/routes/users.js.es6 index d30e57097..e033ae08e 100644 --- a/app/assets/javascripts/discourse/routes/users.js.es6 +++ b/app/assets/javascripts/discourse/routes/users.js.es6 @@ -2,18 +2,31 @@ export default Discourse.Route.extend({ queryParams: { period: { refreshModel: true }, order: { refreshModel: true }, - asc: { refreshModel: true } + asc: { refreshModel: true }, + name: { refreshModel: true, replace: true } }, refreshQueryWithoutTransition: true, + resetController(controller, isExiting, transition) { + if (isExiting) { + controller.setProperties({ + period: 'weekly', + order: 'likes_received', + asc: null, + name: '' + }); + } + }, + model(params) { // If we refresh via `refreshModel` set the old model to loading - this._period = params.period; + this._params = params; return this.store.find('directoryItem', params); }, setupController(controller, model) { - controller.setProperties({ model, period: this._period }); + const params = this._params; + controller.setProperties({ model, period: params.period, nameInput: params.name }); } }); diff --git a/app/assets/javascripts/discourse/templates/users.hbs b/app/assets/javascripts/discourse/templates/users.hbs index c486a9995..83d9e8993 100644 --- a/app/assets/javascripts/discourse/templates/users.hbs +++ b/app/assets/javascripts/discourse/templates/users.hbs @@ -1,11 +1,14 @@