From e3ac6f7dacf748d5521ca9b913b01b20370ee333 Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Fri, 1 Nov 2019 12:30:19 +1100 Subject: [PATCH] date format and product description --- app/controllers/admin/products_controller.rb | 5 ++++- .../discourse/helpers/format-unix-date.js.es6 | 16 ++++++++++++++++ .../discourse/models/admin-plan.js.es6 | 5 ----- .../discourse/models/admin-product.js.es6 | 6 ------ .../discourse/models/admin-subscription.js.es6 | 8 +------- .../javascripts/discourse/models/invoice.js.es6 | 8 +------- assets/javascripts/discourse/models/plan.js.es6 | 2 -- .../discourse/models/subscription.js.es6 | 5 ----- .../plugins-discourse-patrons-products-index.hbs | 4 +++- .../plugins-discourse-patrons-products-show.hbs | 11 ++++++++++- .../plugins-discourse-patrons-subscriptions.hbs | 2 +- .../discourse/templates/user/billing.hbs | 2 +- .../discourse/templates/user/invoices.hbs | 2 +- .../discourse/templates/user/subscriptions.hbs | 2 +- assets/stylesheets/common/discourse-patrons.scss | 4 ++++ config/locales/client.en.yml | 3 +++ spec/requests/admin/products_controller_spec.rb | 5 +++++ spec/requests/plans_controller_spec.rb | 4 ++-- 18 files changed, 53 insertions(+), 41 deletions(-) create mode 100644 assets/javascripts/discourse/helpers/format-unix-date.js.es6 diff --git a/app/controllers/admin/products_controller.rb b/app/controllers/admin/products_controller.rb index 66ffd03..4edea66 100644 --- a/app/controllers/admin/products_controller.rb +++ b/app/controllers/admin/products_controller.rb @@ -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 diff --git a/assets/javascripts/discourse/helpers/format-unix-date.js.es6 b/assets/javascripts/discourse/helpers/format-unix-date.js.es6 new file mode 100644 index 0000000..630b328 --- /dev/null +++ b/assets/javascripts/discourse/helpers/format-unix-date.js.es6 @@ -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 + }) + ); + } +}); diff --git a/assets/javascripts/discourse/models/admin-plan.js.es6 b/assets/javascripts/discourse/models/admin-plan.js.es6 index 2a29256..f5b0c4d 100644 --- a/assets/javascripts/discourse/models/admin-plan.js.es6 +++ b/assets/javascripts/discourse/models/admin-plan.js.es6 @@ -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) { diff --git a/assets/javascripts/discourse/models/admin-product.js.es6 b/assets/javascripts/discourse/models/admin-product.js.es6 index b40846f..cd48e2f 100644 --- a/assets/javascripts/discourse/models/admin-product.js.es6 +++ b/assets/javascripts/discourse/models/admin-product.js.es6 @@ -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" }); }, diff --git a/assets/javascripts/discourse/models/admin-subscription.js.es6 b/assets/javascripts/discourse/models/admin-subscription.js.es6 index 6fd6bfd..9ef13f7 100644 --- a/assets/javascripts/discourse/models/admin-subscription.js.es6 +++ b/assets/javascripts/discourse/models/admin-subscription.js.es6 @@ -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() { diff --git a/assets/javascripts/discourse/models/invoice.js.es6 b/assets/javascripts/discourse/models/invoice.js.es6 index f4a447b..65e017f 100644 --- a/assets/javascripts/discourse/models/invoice.js.es6 +++ b/assets/javascripts/discourse/models/invoice.js.es6 @@ -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() { diff --git a/assets/javascripts/discourse/models/plan.js.es6 b/assets/javascripts/discourse/models/plan.js.es6 index 79a4d7a..f0d2956 100644 --- a/assets/javascripts/discourse/models/plan.js.es6 +++ b/assets/javascripts/discourse/models/plan.js.es6 @@ -17,8 +17,6 @@ const Plan = Discourse.Model.extend({ subscriptionRate(amountDollars, currency, interval) { return `$${amountDollars} ${currency.toUpperCase()} / ${interval}`; } - - }); Plan.reopenClass({ diff --git a/assets/javascripts/discourse/models/subscription.js.es6 b/assets/javascripts/discourse/models/subscription.js.es6 index 6946ae6..2231b25 100644 --- a/assets/javascripts/discourse/models/subscription.js.es6 +++ b/assets/javascripts/discourse/models/subscription.js.es6 @@ -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"; diff --git a/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-products-index.hbs b/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-products-index.hbs index 9eb8bf5..3de8aa8 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-products-index.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-products-index.hbs @@ -11,13 +11,15 @@ {{i18n 'discourse_patrons.admin.products.product.name'}} {{i18n 'discourse_patrons.admin.products.product.created_at'}} + {{i18n 'discourse_patrons.admin.products.product.updated_at'}} {{i18n 'discourse_patrons.admin.products.product.active'}} {{#each model as |product|}} {{product.name}} - {{format-date product.createdFormatted}} + {{format-unix-date product.created}} + {{format-unix-date product.updated}} {{product.active}} {{#link-to "adminPlugins.discourse-patrons.products.show" product.id class="btn no-text btn-icon"}} 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 bf8d666..da68d31 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 @@ -5,6 +5,15 @@ {{input type="text" name="name" value=model.product.name}}

+

+ + {{textarea name="description" value=model.product.metadata.description class="discourse-patrons-admin-textarea"}} +

+ {{i18n 'discourse_patrons.admin.products.product.description_help'}} +
+