format dates for plan and product list

This commit is contained in:
Rimian Perkins 2019-10-22 16:35:41 +11:00
parent c26ce1fc80
commit 5cce5f2b84
7 changed files with 36 additions and 17 deletions

View File

@ -1,7 +1,15 @@
import { popupAjaxError } from "discourse/lib/ajax-error";
export default Ember.Controller.extend({
redirect() {
this.transitionToRoute("adminPlugins.discourse-patrons.products");
},
actions: {
cancelProduct() {
this.redirect();
},
createProduct() {
// TODO: set default group name beforehand
if (this.get("model.product.metadata.group_name") === undefined) {
@ -13,18 +21,14 @@ export default Ember.Controller.extend({
this.get("model.product")
.save()
.then(() => {
this.transitionToRoute("adminPlugins.discourse-patrons.products");
})
.then(() => this.redirect())
.catch(popupAjaxError);
},
updateProduct() {
this.get("model.product")
.update()
.then(() => {
this.transitionToRoute("adminPlugins.discourse-patrons.products");
})
.then(() => this.redirect())
.catch(popupAjaxError);
}
}

View File

@ -1,3 +1,4 @@
import computed from "ember-addons/ember-computed-decorators";
import { ajax } from "discourse/lib/ajax";
const AdminPlan = Discourse.Model.extend({
@ -6,6 +7,11 @@ const AdminPlan = Discourse.Model.extend({
amount: 0,
intervals: ["day", "week", "month", "year"],
@computed("created")
createdFormatted(created) {
return moment.unix(created).format();
},
destroy() {
return ajax(`/patrons/admin/plans/${this.id}`, { method: "delete" });
},

View File

@ -1,9 +1,15 @@
import computed from "ember-addons/ember-computed-decorators";
import { ajax } from "discourse/lib/ajax";
const AdminProduct = Discourse.Model.extend({
isNew: false,
metadata: {},
@computed("created")
createdFormatted(created) {
return moment.unix(created).format();
},
destroy() {
return ajax(`/patrons/admin/products/${this.id}`, { method: "delete" });
},

View File

@ -1,17 +1,24 @@
<p class="btn-right">
{{#link-to 'adminPlugins.discourse-patrons.products.show' 'new' class="btn btn-primary"}}
{{d-icon "plus"}}
<span>{{i18n 'discourse_patrons.admin.products.operations.new'}}</span>
{{/link-to}}
</p>
<table class="table discourse-patrons-admin">
<thead>
<th>{{i18n 'discourse_patrons.admin.products.product.product_id'}}</th>
<th>{{i18n 'discourse_patrons.admin.products.product.name'}}</th>
<th>{{i18n 'discourse_patrons.admin.products.product.group'}}</th>
<th>{{i18n 'discourse_patrons.admin.products.product.created_at'}}</th>
<th>{{i18n 'discourse_patrons.admin.products.product.active'}}</th>
<th></th>
</thead>
{{#each model as |product|}}
<tr>
<td>{{product.id}}</td>
<td>{{product.name}}</td>
<td>{{product.metadata.group_name}}</td>
<td>{{format-date product.createdFormatted}}</td>
<td>{{product.active}}</td>
<td class="td-right">
{{#link-to "adminPlugins.discourse-patrons.products.show" product.id class="btn no-text btn-icon"}}

View File

@ -32,9 +32,9 @@
<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'}}</th>
<th>{{i18n 'discourse_patrons.admin.plans.plan.interval'}}</th>
<th>{{i18n 'discourse_patrons.admin.plans.plan.created_at'}}</th>
<th>{{i18n 'discourse_patrons.admin.plans.plan.amount'}}</th>
<th class="td-right">
{{#link-to "adminPlugins.discourse-patrons.products.show.plans.show" model.product.id "new" class="btn"}}
@ -44,9 +44,9 @@
</thead>
{{#each model.plans as |plan|}}
<tr>
<td>{{plan.id}}</td>
<td>{{plan.nickname}}</td>
<td>{{plan.interval}}</td>
<td>{{format-date plan.createdFormatted}}</td>
<td>{{plan.amount}}</td>
<td class="td-right">
{{#link-to "adminPlugins.discourse-patrons.products.show.plans.show" model.product.id plan.id class="btn no-text btn-icon"}}
@ -67,6 +67,7 @@
<hr>
<div class="pull-right">
{{d-button label="cancel" action=(action "cancelProduct") icon="times"}}
{{#if model.product.isNew}}
{{d-button label="discourse_patrons.admin.products.operations.create" action="createProduct" icon="plus"}}
{{else}}

View File

@ -1,9 +1,2 @@
<p class="btn-right">
{{#link-to 'adminPlugins.discourse-patrons.products.show' 'new' class="btn btn-primary"}}
{{d-icon "plus"}}
<span>{{i18n 'discourse_patrons.admin.products.operations.new'}}</span>
{{/link-to}}
</p>
{{outlet}}

View File

@ -76,6 +76,7 @@ en:
group: User Group
group_help: This is the discourse user group the customer gets added to when the subscription is created.
active: Active
created_at: Created
plans:
title: Pricing Plans
operations:
@ -94,6 +95,7 @@ en:
amount: Amount
trial: Trial Period Days
trial_help: Subscriptions to this plan will automatically start with a free trial of this length
created_at: Created
subscriptions:
title: Subscriptions
subscription: