diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 6236370..8f3db55 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -3,9 +3,19 @@ module DiscoursePatrons class AdminController < ::Admin::AdminController def index - payments = Payment.all + payments = Payment.all.order(payments_order) render_serialized(payments, PaymentSerializer) end + + private + + def payments_order + if %w(created_at amount).include?(params[:order]) + params[:order].to_sym + else + :created_at + end + end end end diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons.js.es6 index a642f81..2d1ddde 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons.js.es6 @@ -1,5 +1,12 @@ export default Ember.Controller.extend({ + queryParams: ["order"], + order: null, + actions: { - loadMore() {} + loadMore() {}, + + orderPayments(order) { + this.set("order", order); + } } }); diff --git a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons.js.es6 b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons.js.es6 index 2682176..257b954 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons.js.es6 +++ b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons.js.es6 @@ -1,9 +1,16 @@ import { ajax } from "discourse/lib/ajax"; export default Discourse.Route.extend({ - model() { + queryParams: { + order: { + refreshModel: true + } + }, + + model(params) { return ajax("/patrons/admin", { - method: "get" + method: "get", + data: { order: params.order } }).then(results => results); } }); diff --git a/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons.hbs b/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons.hbs index 805b53d..7db57b2 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons.hbs @@ -9,8 +9,8 @@