From ca62cad04e1503c4d8542759418e7b43b87f6770 Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Sun, 15 Sep 2019 21:00:39 +1000 Subject: [PATCH] order the payments in admin --- app/controllers/admin_controller.rb | 12 +++++++++++- .../admin-plugins-discourse-patrons.js.es6 | 9 ++++++++- .../routes/admin-plugins-discourse-patrons.js.es6 | 11 +++++++++-- .../templates/admin/plugins-discourse-patrons.hbs | 4 ++-- .../discourse_patrons/admin_controller_spec.rb | 3 --- 5 files changed, 30 insertions(+), 9 deletions(-) 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 @@ {{i18n 'discourse_patrons.admin.table.head.user'}} {{i18n 'discourse_patrons.admin.table.head.payment_intent'}} {{i18n 'discourse_patrons.admin.table.head.receipt_email'}} - {{i18n 'created'}} - {{i18n 'discourse_patrons.admin.table.head.amount'}} + {{i18n 'created'}} + {{i18n 'discourse_patrons.admin.table.head.amount'}} {{#each model as |payment|}} diff --git a/spec/controllers/discourse_patrons/admin_controller_spec.rb b/spec/controllers/discourse_patrons/admin_controller_spec.rb index 8eea86b..b22c212 100644 --- a/spec/controllers/discourse_patrons/admin_controller_spec.rb +++ b/spec/controllers/discourse_patrons/admin_controller_spec.rb @@ -9,8 +9,5 @@ module DiscoursePatrons it 'is a subclass of AdminController' do expect(DiscoursePatrons::AdminController < Admin::AdminController).to eq(true) end - - # TODO authenticate - it 'has payments' end end