date format and product description

This commit is contained in:
Rimian Perkins 2019-11-01 12:30:19 +11:00
parent 86c77a7395
commit e3ac6f7dac
18 changed files with 53 additions and 41 deletions

View File

@ -73,10 +73,13 @@ module DiscoursePatrons
private
def product_params
params.permit!
{
name: params[:name],
active: params[:active],
statement_descriptor: params[:statement_descriptor]
statement_descriptor: params[:statement_descriptor],
metadata: { description: params.dig(:metadata, :description) }
}
end
end

View File

@ -0,0 +1,16 @@
import { registerUnbound } from "discourse-common/lib/helpers";
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
registerUnbound("format-unix-date", function(timestamp) {
if (timestamp) {
const date = new Date(moment.unix(timestamp).format());
return new Handlebars.SafeString(
autoUpdatingRelativeAge(date, {
format: "medium",
title: true,
leaveAgo: true
})
);
}
});

View File

@ -10,11 +10,6 @@ const AdminPlan = Plan.extend({
intervals: ["day", "week", "month", "year"],
metadata: {},
@computed("created")
createdFormatted(created) {
return moment.unix(created).format();
},
@computed("trial_period_days")
parseTrialPeriodDays(trial_period_days) {
if (trial_period_days) {

View File

@ -1,15 +1,9 @@
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,12 +1,6 @@
import computed from "ember-addons/ember-computed-decorators";
import { ajax } from "discourse/lib/ajax";
const AdminSubscription = Discourse.Model.extend({
@computed("created")
createdFormatted(created) {
return moment.unix(created).format();
}
});
const AdminSubscription = Discourse.Model.extend({});
AdminSubscription.reopenClass({
find() {

View File

@ -1,12 +1,6 @@
import computed from "ember-addons/ember-computed-decorators";
import { ajax } from "discourse/lib/ajax";
const Invoice = Discourse.Model.extend({
@computed("created")
createdFormatted(created) {
return moment.unix(created).format();
}
});
const Invoice = Discourse.Model.extend({});
Invoice.reopenClass({
findAll() {

View File

@ -17,8 +17,6 @@ const Plan = Discourse.Model.extend({
subscriptionRate(amountDollars, currency, interval) {
return `$${amountDollars} ${currency.toUpperCase()} / ${interval}`;
}
});
Plan.reopenClass({

View File

@ -3,11 +3,6 @@ import { ajax } from "discourse/lib/ajax";
import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan";
const Subscription = Discourse.Model.extend({
@computed("created")
createdFormatted(created) {
return moment.unix(created).format();
},
@computed("status")
canceled(status) {
return status === "canceled";

View File

@ -11,13 +11,15 @@
<thead>
<th>{{i18n 'discourse_patrons.admin.products.product.name'}}</th>
<th>{{i18n 'discourse_patrons.admin.products.product.created_at'}}</th>
<th>{{i18n 'discourse_patrons.admin.products.product.updated_at'}}</th>
<th class="td-right">{{i18n 'discourse_patrons.admin.products.product.active'}}</th>
<th></th>
</thead>
{{#each model as |product|}}
<tr>
<td>{{product.name}}</td>
<td>{{format-date product.createdFormatted}}</td>
<td>{{format-unix-date product.created}}</td>
<td>{{format-unix-date product.updated}}</td>
<td class="td-right">{{product.active}}</td>
<td class="td-right">
{{#link-to "adminPlugins.discourse-patrons.products.show" product.id class="btn no-text btn-icon"}}

View File

@ -5,6 +5,15 @@
<label for="name">{{i18n 'discourse_patrons.admin.products.product.name'}}</label>
{{input type="text" name="name" value=model.product.name}}
</p>
<p>
<label for="description">
{{i18n 'discourse_patrons.admin.products.product.description'}}
</label>
{{textarea name="description" value=model.product.metadata.description class="discourse-patrons-admin-textarea"}}
<div class="control-instructions">
{{i18n 'discourse_patrons.admin.products.product.description_help'}}
</div>
</p>
<p>
<label for="statement_descriptor">
{{i18n 'discourse_patrons.admin.products.product.statement_descriptor'}}
@ -42,7 +51,7 @@
<tr>
<td>{{plan.nickname}}</td>
<td>{{plan.interval}}</td>
<td>{{format-date plan.createdFormatted}}</td>
<td>{{format-unix-date plan.created}}</td>
<td>{{plan.metadata.group_name}}</td>
<td>{{plan.active}}</td>
<td class="td-right">{{format-currency plan.currency plan.amountDollars}}</td>

View File

@ -13,7 +13,7 @@
<td>{{subscription.customer}}</td>
<td>{{subscription.plan.id}}</td>
<td>{{subscription.status}}</td>
<td class="td-right">{{format-date subscription.createdFormatted}}</td>
<td class="td-right">{{format-unix-date subscription.created}}</td>
</tr>
{{/each}}
</table>

View File

@ -13,7 +13,7 @@
<tr>
<td>{{invoice.amount_paid}}</td>
<td>{{invoice.number}}</td>
<td>{{format-date invoice.createdFormatted}}</td>
<td>{{format-unix-date invoice.created}}</td>
<td class="td-right">
<a href="{{invoice.invoice_pdf}}" class="btn btn-icon">
{{d-icon "download"}}

View File

@ -13,7 +13,7 @@
<tr>
<td>{{invoice.amount_paid}}</td>
<td>{{invoice.number}}</td>
<td>{{format-date invoice.createdFormatted}}</td>
<td>{{format-unix-date invoice.created}}</td>
<td class="td-right">
<a href="{{invoice.invoice_pdf}}" class="btn btn-icon">
{{d-icon "download"}}

View File

@ -15,7 +15,7 @@
<td>{{subscription.id}}</td>
<td>{{subscription.plan.subscriptionRate}}</td>
<td>{{subscription.status}}</td>
<td>{{format-date subscription.createdFormatted}}</td>
<td>{{format-unix-date subscription.created}}</td>
<td class="td-right">{{d-button disabled=subscription.canceled label="cancel" action=(route-action "cancelSubscription" subscription) icon="times"}}</td>
</tr>
{{/each}}

View File

@ -33,6 +33,10 @@ table.discourse-patrons-user-table {
font-size: 0.8em;
}
.discourse-patrons-admin-textarea {
width: 80%;
}
#stripe-elements {
border: 1px $primary-low-mid solid;
padding: 10px;

View File

@ -91,8 +91,11 @@ en:
statement_descriptor: Statement Descriptor
statement_descriptor_help: Extra information about a product which will appear on your customers credit card statement.
plan_help: Create a pricing plan to subscribe customers to this product
description: Description
description_help: This describes your subscription product.
active: Active
created_at: Created
updated_at: Updated
product_help: Before cutomers can subscribe to your site, you need to create at least one product and an associated plan.
plans:
title: Pricing Plans

View File

@ -78,6 +78,11 @@ module DiscoursePatrons
::Stripe::Product.expects(:create).with(has_key(:statement_descriptor)).never
post "/patrons/admin/products.json", params: { statement_descriptor: '' }
end
it 'has a description' do
::Stripe::Product.expects(:create).with(has_entry(metadata: { description: 'Oi, I think he just said bless be all the bignoses!' }))
post "/patrons/admin/products.json", params: { metadata: { description: 'Oi, I think he just said bless be all the bignoses!' }}
end
end
describe 'show' do

View File

@ -11,13 +11,13 @@ module DiscoursePatrons
end
it "orders and serialises the plans" do
::Stripe::Plan.expects(:list).returns({
::Stripe::Plan.expects(:list).returns(
data: [
{ id: 'plan_id123', amount: 1220, currency: 'aud', interval: 'year', metadata: {} },
{ id: 'plan_id234', amount: 1399, currency: 'usd', interval: 'year', metadata: {} },
{ id: 'plan_id678', amount: 1000, currency: 'aud', interval: 'week', metadata: {} }
]
})
)
get "/patrons/plans.json"