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.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}} | +