basic admin interface

This commit is contained in:
Rimian Perkins 2019-09-14 12:56:28 +10:00
parent 8f4cb95cb5
commit 6fe149c4a5
11 changed files with 89 additions and 1 deletions

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
module DiscoursePatrons
class AdminController < ::Admin::AdminController
def index
payments = Payment.all
render_serialized(payments, PaymentSerializer)
end
end
end

View File

@ -0,0 +1,5 @@
# frozen_string_literal: true
class PaymentSerializer < ApplicationSerializer
attributes :payment_intent_id, :receipt_email, :url, :amount
end

View File

@ -0,0 +1,2 @@
export default Ember.Controller.extend({
});

View File

@ -0,0 +1,8 @@
export default {
resource: 'admin.adminPlugins',
path: '/plugins',
map() {
this.route('discourse-patrons');
}
};

View File

@ -0,0 +1,15 @@
import { ajax } from "discourse/lib/ajax";
export default Discourse.Route.extend({
model() {
return ajax("/patrons/admin", {
method: "get"
})
.then(results => {
console.log(12, results);
return results;
});
}
});

View File

@ -0,0 +1,23 @@
<h3>{{i18n 'discourse_patrons.title' site_name=siteSettings.title}}</h3>
<table class="table discourse_patrons_admin">
<thead>
<tr>
<th>{{i18n 'discourse_patrons.admin.table.head.user'}}</th>
<th>{{i18n 'discourse_patrons.admin.table.head.payment_intent_id'}}</th>
<th>{{i18n 'discourse_patrons.admin.table.head.receipt_email'}}</th>
<th>{{i18n 'discourse_patrons.admin.table.head.url'}}</th>
<th class="amount">{{i18n 'discourse_patrons.admin.table.head.amount'}}</th>
</tr>
</thead>
{{#each model as |payment|}}
<tr>
<td>{{payment.user_id}}</td>
<td>{{payment.payment_intent_id}}</td>
<td>{{payment.receipt_email}}</td>
<td>{{payment.url}}</td>
<td class="amount">{{payment.amount}}</td>
</tr>
{{/each}}
</table>

View File

@ -32,6 +32,12 @@
}
}
.discourse_patrons_admin {
.amount {
text-align: right;
}
}
.desc {
color: dark-light-choose($primary-medium, $secondary-medium);
font-size: 0.8em;

View File

@ -13,6 +13,7 @@ en:
discourse_patrons_amount_must_be_currency: "Currency amounts must be currencies without dollar symbol (eg 1.50)"
js:
discourse_patrons:
title: Discourse Patrons
nav_item: Payment
heading:
payment: Make a Payment
@ -35,3 +36,11 @@ en:
make_payment: Make payment
confirm_payment: Confirm payment
success: Go back
admin:
table:
head:
url: User
payment_intent_id: Payment Intent Id
receipt_email: Receipt Email
url: URL
amount: Amount

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
DiscoursePatrons::Engine.routes.draw do
get '/admin' => 'admin#index'
get '/' => 'patrons#index'
get '/:pid' => 'patrons#index'

View File

@ -2,7 +2,7 @@
# name: discourse-patrons
# about: Integrates Stripe into Discourse to allow visitors to make payments
# version: 1.1.0
# version: 1.2.0
# url: https://github.com/rimian/discourse-patrons
# authors: Rimian Perkins
@ -21,6 +21,12 @@ extend_content_security_policy(
script_src: ['https://js.stripe.com/v3/']
)
add_admin_route 'discourse_patrons.title', 'discourse-patrons'
Discourse::Application.routes.append do
get '/admin/plugins/discourse-patrons' => 'admin/plugins#index'
end
after_initialize do
::Stripe.api_version = "2019-08-14"
::Stripe.set_app_info('Discourse Patrons', version: '1.0.0', url: 'https://github.com/rimian/discourse-patrons')
@ -28,8 +34,10 @@ after_initialize do
[
"../lib/discourse_patrons/engine",
"../config/routes",
"../app/controllers/admin_controller",
"../app/controllers/patrons_controller",
"../app/models/payment",
"../app/serializers/payment_serializer",
].each { |path| require File.expand_path(path, __FILE__) }
Discourse::Application.routes.append do