From c6dd47d32801ebdff86b6efc8c18deae1e3bfa1b Mon Sep 17 00:00:00 2001
From: Rimian Perkins
Date: Mon, 21 Oct 2019 15:28:45 +1100
Subject: [PATCH] templates, plans
---
app/controllers/admin/plans_controller.rb | 8 +++++-
app/controllers/subscriptions_controller.rb | 3 +--
.../discourse-patrons-route-map.js.es6 | 22 ++++++++++-----
.../discourse/models/admin-plan.js.es6 | 4 +--
...se-patrons-products-show-plans-show.js.es6 | 24 +++++++++++++++++
...ins-discourse-patrons-products-show.js.es6 | 15 +++++++----
...urse-patrons-products-show-plans-show.hbs} | 0
...lugins-discourse-patrons-products-show.hbs | 27 +++++++++++++++++++
config/locales/client.en.yml | 4 +--
plugin.rb | 2 ++
spec/requests/admin/plans_controller_spec.rb | 7 ++++-
11 files changed, 96 insertions(+), 20 deletions(-)
create mode 100644 assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show-plans-show.js.es6
rename assets/javascripts/discourse/templates/admin/{plugins-discourse-patrons-plans-show.hbs => plugins-discourse-patrons-products-show-plans-show.hbs} (100%)
diff --git a/app/controllers/admin/plans_controller.rb b/app/controllers/admin/plans_controller.rb
index 086ac77..7e4f2e0 100644
--- a/app/controllers/admin/plans_controller.rb
+++ b/app/controllers/admin/plans_controller.rb
@@ -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
diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb
index f7989a4..940251b 100644
--- a/app/controllers/subscriptions_controller.rb
+++ b/app/controllers/subscriptions_controller.rb
@@ -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
diff --git a/assets/javascripts/discourse/discourse-patrons-route-map.js.es6 b/assets/javascripts/discourse/discourse-patrons-route-map.js.es6
index 4572342..0fa8290 100644
--- a/assets/javascripts/discourse/discourse-patrons-route-map.js.es6
+++ b/assets/javascripts/discourse/discourse-patrons-route-map.js.es6
@@ -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");
});
}
diff --git a/assets/javascripts/discourse/models/admin-plan.js.es6 b/assets/javascripts/discourse/models/admin-plan.js.es6
index e759e8a..3c632d9 100644
--- a/assets/javascripts/discourse/models/admin-plan.js.es6
+++ b/assets/javascripts/discourse/models/admin-plan.js.es6
@@ -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))
);
},
diff --git a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show-plans-show.js.es6 b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show-plans-show.js.es6
new file mode 100644
index 0000000..d462526
--- /dev/null
+++ b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show-plans-show.js.es6
@@ -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 });
+ }
+});
diff --git a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show.js.es6 b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show.js.es6
index 9a22327..55b13c1 100644
--- a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show.js.es6
+++ b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons-products-show.js.es6
@@ -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 });
}
});
diff --git a/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-plans-show.hbs b/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-products-show-plans-show.hbs
similarity index 100%
rename from assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-plans-show.hbs
rename to assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-products-show-plans-show.hbs
diff --git a/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-products-show.hbs b/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-products-show.hbs
index 5bcb086..86c68eb 100644
--- a/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-products-show.hbs
+++ b/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-products-show.hbs
@@ -28,6 +28,33 @@
+{{i18n 'discourse_patrons.admin.plans.title'}}
+
+
+
+
+ {{i18n 'discourse_patrons.admin.plans.plan.plan_id'}} |
+ {{i18n 'discourse_patrons.admin.plans.plan.nickname.title'}} |
+ {{i18n 'discourse_patrons.admin.plans.plan.interval'}} |
+
+ {{#link-to "adminPlugins.discourse-patrons.products.show.plans.show" model.product.id "new" class="btn"}}
+ {{i18n 'discourse_patrons.admin.plans.operations.add'}}
+ {{/link-to}}
+ |
+
+ {{#each model.plans as |plan|}}
+
+ {{plan.id}} |
+ {{plan.nickname}} |
+ {{plan.interval}} |
+ {{plan.amount}} |
+
+ {{/each}}
+
+
+
+
+
{{#if model.product.isNew}}
{{d-button label="discourse_patrons.admin.products.operations.create" action="createProduct" icon="plus"}}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 61d29e6..5b22547 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -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?
diff --git a/plugin.rb b/plugin.rb
index d773072..3bcba5a 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -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'
diff --git a/spec/requests/admin/plans_controller_spec.rb b/spec/requests/admin/plans_controller_spec.rb
index 89fe072..8561793 100644
--- a/spec/requests/admin/plans_controller_spec.rb
+++ b/spec/requests/admin/plans_controller_spec.rb
@@ -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