templates, plans

This commit is contained in:
Rimian Perkins 2019-10-21 15:28:45 +11:00
parent 2dbcda49c3
commit c6dd47d328
11 changed files with 96 additions and 20 deletions

View File

@ -9,7 +9,7 @@ module DiscoursePatrons
def index
begin
plans = ::Stripe::Plan.list
plans = ::Stripe::Plan.list(product_params)
render_json_dump plans.data
@ -56,6 +56,12 @@ module DiscoursePatrons
return render_json_error e.message
end
end
private
def product_params
{ product: params[:product_id] } if params[:product_id]
end
end
end
end

View File

@ -31,8 +31,7 @@ module DiscoursePatrons
private
def subscription_ok(subscription)
# ['active', 'trialing'].include?(subscription[:status])
false
['active', 'trialing'].include?(subscription[:status])
end
end
end

View File

@ -1,23 +1,31 @@
export default {
resource: "admin.adminPlugins",
path: "/plugins",
map() {
this.route("discourse-patrons", function() {
this.route("dashboard");
this.route("products", function() {
this.route("plans", { path: "/:product-id/plans" }, function() {
this.route("show", { path: "/:plan-id" });
});
this.route("show", { path: "/:product-id" });
});
// this.route("products", function() {
// this.route("plans", { path: "/:product-id/plans" }, function() {
// this.route("show", { path: ":plan-id" });
// });
// this.route("show", { path: "/:product-id" });
// });
this.route("products", function() {
this.route("show", { path: "/:product-id" }, function() {
// this.route("plans");
this.route("plans", function() {
this.route("show", { path: "/:plan-id" });
});
});
});
// this.route("plans", function() {
// this.route("show", { path: "/:plan-id" });
// });
this.route("subscriptions");
});
}

View File

@ -23,8 +23,8 @@ const AdminPlan = Discourse.Model.extend({
});
AdminPlan.reopenClass({
findAll() {
return ajax("/patrons/admin/plans", { method: "get" }).then(result =>
findAll(data) {
return ajax("/patrons/admin/plans", { method: "get", data }).then(result =>
result.map(plan => AdminPlan.create(plan))
);
},

View File

@ -0,0 +1,24 @@
import AdminPlan from "discourse/plugins/discourse-patrons/discourse/models/admin-plan";
import AdminProduct from "discourse/plugins/discourse-patrons/discourse/models/admin-product";
export default Discourse.Route.extend({
templateName: 'admin-plugins-discourse-patrons-plans-show',
model(params) {
console.log('product plans', params);
// const id = params['plan-id'];
// let plan;
//
// if(id === 'new') {
// plan = AdminPlan.create();
// }
// else {
// plan = AdminPlan.find(id);
// }
//
// const products = AdminProduct.findAll();
//
// return Ember.RSVP.hash({ plan, products });
}
});

View File

@ -1,20 +1,25 @@
import AdminProduct from "discourse/plugins/discourse-patrons/discourse/models/admin-product";
import AdminPlan from "discourse/plugins/discourse-patrons/discourse/models/admin-plan";
import Group from "discourse/models/group";
export default Discourse.Route.extend({
model(params) {
const id = params['product-id'];
let product;
console.log('products show', params);
if(id === 'new') {
const product_id = params['product-id'];
let product;
let plans = [];
if(product_id === 'new') {
product = AdminProduct.create({ active: true, isNew: true });
}
else {
product = AdminProduct.find(id);
product = AdminProduct.find(product_id);
plans = AdminPlan.findAll({ product_id });
}
const groups = Group.findAll({ ignore_automatic: true });
return Ember.RSVP.hash({ product, groups });
return Ember.RSVP.hash({ plans, product, groups });
}
});

View File

@ -28,6 +28,33 @@
</p>
</form>
<h4>{{i18n 'discourse_patrons.admin.plans.title'}}</h4>
<p>
<table class="table discourse-patrons-admin">
<thead>
<th>{{i18n 'discourse_patrons.admin.plans.plan.plan_id'}}</th>
<th>{{i18n 'discourse_patrons.admin.plans.plan.nickname.title'}}</th>
<th>{{i18n 'discourse_patrons.admin.plans.plan.interval'}}</th>
<th class="td-right">
{{#link-to "adminPlugins.discourse-patrons.products.show.plans.show" model.product.id "new" class="btn"}}
{{i18n 'discourse_patrons.admin.plans.operations.add'}}
{{/link-to}}
</th>
</thead>
{{#each model.plans as |plan|}}
<tr>
<td>{{plan.id}}</td>
<td>{{plan.nickname}}</td>
<td>{{plan.interval}}</td>
<td>{{plan.amount}}</td>
</tr>
{{/each}}
</table>
</p>
<hr>
<div class="buttons">
{{#if model.product.isNew}}
{{d-button label="discourse_patrons.admin.products.operations.create" action="createProduct" icon="plus"}}

View File

@ -78,9 +78,9 @@ en:
description: This is the discourse user group the customer gets added to when the subscription is created.
active: Active
plans:
title: Plans
title: Pricing Plans
operations:
create: Create New Plan
add: Add New Plan
new: New Plan
destroy:
confirm: Are you sure you want to destroy this plan?

View File

@ -28,6 +28,8 @@ Discourse::Application.routes.append do
get '/admin/plugins/discourse-patrons/dashboard' => 'admin/plugins#index'
get '/admin/plugins/discourse-patrons/products' => 'admin/plugins#index'
get '/admin/plugins/discourse-patrons/products/:product_id' => 'admin/plugins#index'
get '/admin/plugins/discourse-patrons/products/:product_id/plans' => 'admin/plugins#index'
get '/admin/plugins/discourse-patrons/products/:product_id/plans/:plan_id' => 'admin/plugins#index'
get '/admin/plugins/discourse-patrons/subscriptions' => 'admin/plugins#index'
get '/admin/plugins/discourse-patrons/plans' => 'admin/plugins#index'
get '/admin/plugins/discourse-patrons/plans/:plan_id' => 'admin/plugins#index'

View File

@ -66,9 +66,14 @@ module DiscoursePatrons
describe "index" do
it "lists the plans" do
::Stripe::Plan.expects(:list)
::Stripe::Plan.expects(:list).with(nil)
get "/patrons/admin/plans.json"
end
it "lists the plans for the product" do
::Stripe::Plan.expects(:list).with(product: 'prod_id123')
get "/patrons/admin/plans.json", params: { product_id: 'prod_id123' }
end
end
describe "create" do