order the payments in admin

This commit is contained in:
Rimian Perkins 2019-09-15 21:00:39 +10:00
parent 85a90b091c
commit ca62cad04e
5 changed files with 30 additions and 9 deletions

View File

@ -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

View File

@ -1,5 +1,12 @@
export default Ember.Controller.extend({
queryParams: ["order"],
order: null,
actions: {
loadMore() {}
loadMore() {},
orderPayments(order) {
this.set("order", order);
}
}
});

View File

@ -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);
}
});

View File

@ -9,8 +9,8 @@
<th>{{i18n 'discourse_patrons.admin.table.head.user'}}</th>
<th>{{i18n 'discourse_patrons.admin.table.head.payment_intent'}}</th>
<th>{{i18n 'discourse_patrons.admin.table.head.receipt_email'}}</th>
<th>{{i18n 'created'}}</th>
<th class="amount">{{i18n 'discourse_patrons.admin.table.head.amount'}}</th>
<th onclick={{action "orderPayments" "created_at"}} class="sortable">{{i18n 'created'}}</th>
<th class="amount" onclick={{action "orderPayments" "amount"}} class="sortable amount">{{i18n 'discourse_patrons.admin.table.head.amount'}}</th>
</tr>
</thead>
{{#each model as |payment|}}

View File

@ -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