templates and routes for subscriptions

This commit is contained in:
Rimian Perkins 2019-09-23 15:01:03 +10:00
parent 8b61747fbd
commit e004a18071
11 changed files with 96 additions and 68 deletions

View File

@ -8,6 +8,10 @@ module DiscoursePatrons
render_serialized(payments, PaymentSerializer)
end
def subscriptions
head 200
end
private
def payments_order

View File

@ -0,0 +1,18 @@
export default Ember.Controller.extend({
queryParams: ["order", "descending"],
order: null,
descending: true,
actions: {
loadMore() {},
orderPayments(order) {
if (order === this.get("order")) {
this.toggleProperty("descending");
}
this.set("order", order);
}
}
});

View File

@ -1,17 +1,3 @@
export default Ember.Controller.extend({
queryParams: ["order", "descending"],
order: null,
descending: true,
actions: {
loadMore() {},
orderPayments(order) {
if (order === this.get("order")) {
this.toggleProperty("descending");
}
this.set("order", order);
}
}
});

View File

@ -2,6 +2,8 @@ export default {
resource: "admin.adminPlugins",
path: "/plugins",
map() {
this.route("discourse-patrons");
this.route("discourse-patrons", function() {
this.route("subscriptions");
});
}
};

View File

@ -0,0 +1,22 @@
import { ajax } from "discourse/lib/ajax";
export default Discourse.Route.extend({
queryParams: {
order: {
refreshModel: true
},
descending: {
refreshModel: true
}
},
model(params) {
return ajax("/patrons/admin", {
method: "get",
data: {
order: params.order,
descending: params.descending
}
}).then(results => results);
}
});

View File

@ -1,22 +1,3 @@
import { ajax } from "discourse/lib/ajax";
export default Discourse.Route.extend({
queryParams: {
order: {
refreshModel: true
},
descending: {
refreshModel: true
}
},
model(params) {
return ajax("/patrons/admin", {
method: "get",
data: {
order: params.order,
descending: params.descending
}
}).then(results => results);
}
});

View File

@ -0,0 +1,34 @@
<h3>Payments</h3>
{{#load-more selector=".discourse-patrons-admin tr" action=(action "loadMore")}}
{{#if model}}
<table class="table discourse-patrons-admin">
<thead>
<tr>
<th>{{i18n 'discourse_patrons.admin.payment_history.table.head.user'}}</th>
<th>{{i18n 'discourse_patrons.admin.payment_history.table.head.payment_intent'}}</th>
<th>{{i18n 'discourse_patrons.admin.payment_history.table.head.receipt_email'}}</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.payment_history.table.head.amount'}}</th>
</tr>
</thead>
{{#each model as |payment|}}
<tr>
<td>
{{#link-to "adminUser.index" payment.user_id payment.username}}
{{payment.username}}
{{/link-to}}
</td>
<td>
{{#link-to "patrons.show" payment.payment_intent_id}}
{{{payment.payment_intent_id}}}
{{/link-to}}
</td>
<td>{{payment.receipt_email}}</td>
<td>{{{format-duration payment.created_at_age}}}</td>
<td class="amount">{{payment.amount_currency}}</td>
</tr>
{{/each}}
</table>
{{/if}}
{{/load-more}}

View File

@ -0,0 +1,3 @@
<h3>Subscriptions</h3>

View File

@ -1,35 +1,13 @@
<h2>{{i18n 'discourse_patrons.title' site_name=siteSettings.title}}</h2>
{{#load-more selector=".discourse-patrons-admin tr" action=(action "loadMore")}}
{{#if model}}
<table class="table discourse-patrons-admin">
<thead>
<tr>
<th>{{i18n 'discourse_patrons.admin.payment_history.table.head.user'}}</th>
<th>{{i18n 'discourse_patrons.admin.payment_history.table.head.payment_intent'}}</th>
<th>{{i18n 'discourse_patrons.admin.payment_history.table.head.receipt_email'}}</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.payment_history.table.head.amount'}}</th>
</tr>
</thead>
{{#each model as |payment|}}
<tr>
<td>
{{#link-to "adminUser.index" payment.user_id payment.username}}
{{payment.username}}
{{/link-to}}
</td>
<td>
{{#link-to "patrons.show" payment.payment_intent_id}}
{{{payment.payment_intent_id}}}
{{/link-to}}
</td>
<td>{{payment.receipt_email}}</td>
<td>{{{format-duration payment.created_at_age}}}</td>
<td class="amount">{{payment.amount_currency}}</td>
</tr>
{{/each}}
</table>
{{/if}}
{{/load-more}}
{{#link-to 'adminPlugins.discourse-patrons'}}
Payments
{{/link-to}}
{{#link-to 'adminPlugins.discourse-patrons.subscriptions'}}
Subscriptions
{{/link-to}}
<hr>
{{outlet}}

View File

@ -4,6 +4,5 @@ DiscoursePatrons::Engine.routes.draw do
get '/admin' => 'admin#index'
get '/' => 'patrons#index'
get '/:pid' => 'patrons#show'
resources :patrons, only: [:index, :create]
end

View File

@ -25,6 +25,7 @@ add_admin_route 'discourse_patrons.title', 'discourse-patrons'
Discourse::Application.routes.append do
get '/admin/plugins/discourse-patrons' => 'admin/plugins#index'
get '/admin/plugins/discourse-patrons/subscriptions' => 'admin/plugins#index'
end
after_initialize do