DEV: Update to new prettier standards

This commit is contained in:
Justin DiRose 2020-09-16 09:53:50 -05:00
parent d60c5b6d54
commit 7e753d45bd
No known key found for this signature in database
GPG Key ID: 4B811FB264021800
45 changed files with 1741 additions and 141 deletions

3
.gitignore vendored
View File

@ -3,3 +3,6 @@ gems
log
.byebug_history
/.idea
node_modules/
.bundle/
auto_generated

View File

@ -8,5 +8,5 @@ export default Button.extend({
this.classNameBindings = this.classNameBindings.concat(
"selected:btn-primary"
);
}
},
});

View File

@ -10,6 +10,6 @@ export default Component.extend({
actions: {
clickPlan(plan) {
this.set("selectedPlan", plan.id);
}
}
},
},
});

View File

@ -18,6 +18,6 @@ export default Component.extend({
planClick() {
this.clickPlan(this.plan);
return false;
}
}
},
},
});

View File

@ -13,5 +13,5 @@ export default Component.extend({
@discourseComputed()
isLoggedIn() {
return User.current();
}
},
});

View File

@ -5,5 +5,5 @@ export default Component.extend({
this._super(...arguments);
this.cardElement.mount("#card-element");
},
didDestroyElement() {}
didDestroyElement() {},
});

View File

@ -14,6 +14,6 @@ export default Controller.extend({
}
this.set("order", order);
}
}
},
},
});

View File

@ -7,6 +7,6 @@ export default Controller.extend({
return DiscourseURL.redirectTo(
`/admin/plugins/discourse-subscriptions/plans/${id}`
);
}
}
},
},
});

View File

@ -15,6 +15,6 @@ export default Controller.extend({
this.transitionToRoute("adminPlugins.discourse-subscriptions.plans");
})
.catch(popupAjaxError);
}
}
},
},
});

View File

@ -19,7 +19,7 @@ export default Controller.extend({
{ id: "GBP", name: "GBP" },
{ id: "USD", name: "USD" },
{ id: "INR", name: "INR" },
{ id: "BRL", name: "BRL" }
{ id: "BRL", name: "BRL" },
];
},
@ -29,7 +29,7 @@ export default Controller.extend({
{ id: "day", name: "day" },
{ id: "week", name: "week" },
{ id: "month", name: "month" },
{ id: "year", name: "year" }
{ id: "year", name: "year" },
];
},
@ -60,14 +60,14 @@ export default Controller.extend({
// TODO: set default group name beforehand
if (this.get("model.plan.metadata.group_name") === undefined) {
this.set("model.plan.metadata", {
group_name: this.get("model.groups.firstObject.name")
group_name: this.get("model.groups.firstObject.name"),
});
}
this.get("model.plan")
.save()
.then(() => this.redirect(this.productId))
.catch(data =>
.catch((data) =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
);
},
@ -76,9 +76,9 @@ export default Controller.extend({
this.get("model.plan")
.update()
.then(() => this.redirect(this.productId))
.catch(data =>
.catch((data) =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
);
}
}
},
},
});

View File

@ -10,7 +10,7 @@ export default Controller.extend({
createProduct() {
this.get("model.product")
.save()
.then(product => {
.then((product) => {
this.transitionToRoute(
"adminPlugins.discourse-subscriptions.products.show",
product.id
@ -28,6 +28,6 @@ export default Controller.extend({
);
})
.catch(popupAjaxError);
}
}
},
},
});

View File

@ -23,16 +23,16 @@ export default Controller.extend({
},
createSubscription(plan) {
return this.stripe.createToken(this.get("cardElement")).then(result => {
return this.stripe.createToken(this.get("cardElement")).then((result) => {
if (result.error) {
return result;
} else {
const customer = Customer.create({ source: result.token.id });
return customer.save().then(c => {
return customer.save().then((c) => {
const subscription = Subscription.create({
customer: c.id,
plan: plan.get("id")
plan: plan.get("id"),
});
return subscription.save();
@ -44,7 +44,7 @@ export default Controller.extend({
handleAuthentication(plan, transaction) {
return this.stripe
.confirmCardPayment(transaction.payment_intent.client_secret)
.then(result => {
.then((result) => {
if (
result.paymentIntent &&
result.paymentIntent.status === "succeeded"
@ -86,7 +86,7 @@ export default Controller.extend({
let transaction = this.createSubscription(plan);
transaction
.then(result => {
.then((result) => {
if (result.error) {
bootbox.alert(result.error.message || result.error);
} else if (
@ -96,7 +96,7 @@ export default Controller.extend({
const transactionId = result.id;
const planId = this.selectedPlan;
this.handleAuthentication(plan, result).then(
authenticationResult => {
(authenticationResult) => {
if (authenticationResult && !authenticationResult.error) {
return Transaction.finalize(transactionId, planId).then(
() => {
@ -110,10 +110,10 @@ export default Controller.extend({
this._advanceSuccessfulTransaction(plan);
}
})
.catch(result => {
.catch((result) => {
bootbox.alert(result.errorThrown);
this.set("loading", false);
});
}
}
},
},
});

View File

@ -3,12 +3,12 @@ export default {
path: "/plugins",
map() {
this.route("discourse-subscriptions", function() {
this.route("discourse-subscriptions", function () {
this.route("dashboard");
this.route("products", function() {
this.route("show", { path: "/:product-id" }, function() {
this.route("plans", function() {
this.route("products", function () {
this.route("show", { path: "/:product-id" }, function () {
this.route("plans", function () {
this.route("show", { path: "/:plan-id" });
});
});
@ -16,5 +16,5 @@ export default {
this.route("subscriptions");
});
}
},
};

View File

@ -2,9 +2,9 @@ export default {
resource: "user",
path: "users/:username",
map() {
this.route("billing", function() {
this.route("billing", function () {
this.route("payments");
this.route("subscriptions");
});
}
},
};

View File

@ -1,6 +1,6 @@
import Helper from "@ember/component/helper";
export default Helper.helper(function(params) {
export default Helper.helper(function (params) {
let currencySign;
switch (params[0]) {
@ -24,5 +24,5 @@ export default Helper.helper(function(params) {
currencySign = "$";
}
return currencySign + params.map(p => p.toUpperCase()).join(" ");
return currencySign + params.map((p) => p.toUpperCase()).join(" ");
});

View File

@ -2,7 +2,7 @@ import { registerUnbound } from "discourse-common/lib/helpers";
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
import { htmlSafe } from "@ember/template";
registerUnbound("format-unix-date", function(timestamp) {
registerUnbound("format-unix-date", function (timestamp) {
if (timestamp) {
const date = new Date(moment.unix(timestamp).format());
@ -10,7 +10,7 @@ registerUnbound("format-unix-date", function(timestamp) {
autoUpdatingRelativeAge(date, {
format: "medium",
title: true,
leaveAgo: true
leaveAgo: true,
})
);
}

View File

@ -1,6 +1,6 @@
import Helper from "@ember/component/helper";
export default Helper.helper(function(params) {
export default Helper.helper(function (params) {
const payment = params[0];
return `<a href=\"${payment.url}\">${payment.payment_intent_id}</a>`;

View File

@ -1,7 +1,7 @@
import { registerUnbound } from "discourse-common/lib/helpers";
import User from "discourse/models/user";
export default registerUnbound("user-viewing-self", function(model) {
export default registerUnbound("user-viewing-self", function (model) {
if (User.current()) {
return (
User.current().username.toLowerCase() === model.username.toLowerCase()

View File

@ -4,7 +4,7 @@ import I18n from "I18n";
export default {
name: "setup-subscriptions",
initialize(container) {
withPluginApi("0.8.11", api => {
withPluginApi("0.8.11", (api) => {
const siteSettings = container.lookup("site-settings:main");
const isNavLinkEnabled =
siteSettings.discourse_subscriptions_extra_nav_subscribe;
@ -12,9 +12,9 @@ export default {
api.addNavigationBarItem({
name: "subscribe",
displayName: I18n.t("discourse_subscriptions.navigation.subscribe"),
href: "/s"
href: "/s",
});
}
});
}
},
};

View File

@ -29,7 +29,7 @@ const AdminPlan = Plan.extend({
type: this.type,
product: this.product,
metadata: this.metadata,
active: this.active
active: this.active,
};
return ajax("/s/admin/plans", { method: "post", data });
@ -40,25 +40,25 @@ const AdminPlan = Plan.extend({
nickname: this.nickname,
trial_period_days: this.parseTrialPeriodDays,
metadata: this.metadata,
active: this.active
active: this.active,
};
return ajax(`/s/admin/plans/${this.id}`, { method: "patch", data });
}
},
});
AdminPlan.reopenClass({
findAll(data) {
return ajax("/s/admin/plans", { method: "get", data }).then(result =>
result.map(plan => AdminPlan.create(plan))
return ajax("/s/admin/plans", { method: "get", data }).then((result) =>
result.map((plan) => AdminPlan.create(plan))
);
},
find(id) {
return ajax(`/s/admin/plans/${id}`, { method: "get" }).then(plan =>
return ajax(`/s/admin/plans/${id}`, { method: "get" }).then((plan) =>
AdminPlan.create(plan)
);
}
},
});
export default AdminPlan;

View File

@ -14,13 +14,13 @@ const AdminProduct = EmberObject.extend({
name: this.name,
statement_descriptor: this.statement_descriptor,
metadata: this.metadata,
active: this.active
active: this.active,
};
return ajax("/s/admin/products", {
method: "post",
data
}).then(product => AdminProduct.create(product));
data,
}).then((product) => AdminProduct.create(product));
},
update() {
@ -28,31 +28,31 @@ const AdminProduct = EmberObject.extend({
name: this.name,
statement_descriptor: this.statement_descriptor,
metadata: this.metadata,
active: this.active
active: this.active,
};
return ajax(`/s/admin/products/${this.id}`, {
method: "patch",
data
data,
});
}
},
});
AdminProduct.reopenClass({
findAll() {
return ajax("/s/admin/products", { method: "get" }).then(result => {
return ajax("/s/admin/products", { method: "get" }).then((result) => {
if (result === null) {
return { unconfigured: true };
}
return result.map(product => AdminProduct.create(product));
return result.map((product) => AdminProduct.create(product));
});
},
find(id) {
return ajax(`/s/admin/products/${id}`, {
method: "get"
}).then(product => AdminProduct.create(product));
}
method: "get",
}).then((product) => AdminProduct.create(product));
},
});
export default AdminProduct;

View File

@ -21,22 +21,24 @@ const AdminSubscription = EmberObject.extend({
destroy() {
return ajax(`/s/admin/subscriptions/${this.id}`, {
method: "delete"
}).then(result => AdminSubscription.create(result));
}
method: "delete",
}).then((result) => AdminSubscription.create(result));
},
});
AdminSubscription.reopenClass({
find() {
return ajax("/s/admin/subscriptions", {
method: "get"
}).then(result => {
method: "get",
}).then((result) => {
if (result === null) {
return { unconfigured: true };
}
return result.map(subscription => AdminSubscription.create(subscription));
return result.map((subscription) =>
AdminSubscription.create(subscription)
);
});
}
},
});
export default AdminSubscription;

View File

@ -4,11 +4,11 @@ import EmberObject from "@ember/object";
const Customer = EmberObject.extend({
save() {
const data = {
source: this.source
source: this.source,
};
return ajax("/s/customers", { method: "post", data });
}
},
});
export default Customer;

View File

@ -9,11 +9,11 @@ Group.reopenClass({
find() {
return ajax(`/groups/${this.subscriptionGroup}`, { method: "get" }).then(
result => {
(result) => {
return Group.create(result.group);
}
);
}
},
});
export default Group;

View File

@ -11,7 +11,7 @@ const Plan = EmberObject.extend({
const decimal = parseFloat(value) * 100;
this.set("unit_amount", decimal);
return value;
}
},
}),
@discourseComputed("recurring.interval")
billingInterval(interval) {
@ -21,15 +21,15 @@ const Plan = EmberObject.extend({
@discourseComputed("amountDollars", "currency", "billingInterval")
subscriptionRate(amountDollars, currency, interval) {
return `${amountDollars} ${currency.toUpperCase()} / ${interval}`;
}
},
});
Plan.reopenClass({
findAll(data) {
return ajax("/s/plans", { method: "get", data }).then(result =>
result.map(plan => Plan.create(plan))
return ajax("/s/plans", { method: "get", data }).then((result) =>
result.map((plan) => Plan.create(plan))
);
}
},
});
export default Plan;

View File

@ -5,16 +5,16 @@ const Product = EmberObject.extend({});
Product.reopenClass({
findAll() {
return ajax("/s/products", { method: "get" }).then(result =>
result.map(product => Product.create(product))
return ajax("/s/products", { method: "get" }).then((result) =>
result.map((product) => Product.create(product))
);
},
find(id) {
return ajax(`/s/products/${id}`, { method: "get" }).then(product =>
return ajax(`/s/products/${id}`, { method: "get" }).then((product) =>
Product.create(product)
);
}
},
});
export default Product;

View File

@ -11,19 +11,19 @@ const Subscription = EmberObject.extend({
save() {
const data = {
customer: this.customer,
plan: this.plan
plan: this.plan,
};
return ajax("/s/subscriptions", { method: "post", data });
}
},
});
Subscription.reopenClass({
findAll() {
return ajax("/s/subscriptions", { method: "get" }).then(result =>
result.map(subscription => Subscription.create(subscription))
return ajax("/s/subscriptions", { method: "get" }).then((result) =>
result.map((subscription) => Subscription.create(subscription))
);
}
},
});
export default Subscription;

View File

@ -4,9 +4,9 @@ export default {
finalize(transaction, plan) {
const data = {
transaction: transaction,
plan: plan
plan: plan,
};
return ajax("/s/subscriptions/finalize", { method: "post", data });
}
},
};

View File

@ -6,17 +6,17 @@ const UserPayment = EmberObject.extend({
@discourseComputed("amount")
amountDollars(amount) {
return parseFloat(amount / 100).toFixed(2);
}
},
});
UserPayment.reopenClass({
findAll() {
return ajax("/s/user/payments", { method: "get" }).then(result =>
result.map(payment => {
return ajax("/s/user/payments", { method: "get" }).then((result) =>
result.map((payment) => {
return UserPayment.create(payment);
})
);
}
},
});
export default UserPayment;

View File

@ -21,20 +21,20 @@ const UserSubscription = EmberObject.extend({
destroy() {
return ajax(`/s/user/subscriptions/${this.id}`, {
method: "delete"
}).then(result => UserSubscription.create(result));
}
method: "delete",
}).then((result) => UserSubscription.create(result));
},
});
UserSubscription.reopenClass({
findAll() {
return ajax("/s/user/subscriptions", { method: "get" }).then(result =>
result.map(subscription => {
return ajax("/s/user/subscriptions", { method: "get" }).then((result) =>
result.map((subscription) => {
subscription.plan = Plan.create(subscription.plan);
return UserSubscription.create(subscription);
})
);
}
},
});
export default UserSubscription;

View File

@ -2,5 +2,5 @@ export default {
resource: "user.userActivity",
map() {
this.route("payments");
}
},
};

View File

@ -4,11 +4,11 @@ import { ajax } from "discourse/lib/ajax";
export default Route.extend({
queryParams: {
order: {
refreshModel: true
refreshModel: true,
},
descending: {
refreshModel: true
}
refreshModel: true,
},
},
model(params) {
@ -16,8 +16,8 @@ export default Route.extend({
method: "get",
data: {
order: params.order,
descending: params.descending
}
}).then(results => results);
}
descending: params.descending,
},
}).then((results) => results);
},
});

View File

@ -4,5 +4,5 @@ import AdminPlan from "discourse/plugins/discourse-subscriptions/discourse/model
export default Route.extend({
model() {
return AdminPlan.findAll();
}
},
});

View File

@ -15,7 +15,7 @@ export default Route.extend({
),
I18n.t("no_value"),
I18n.t("yes_value"),
confirmed => {
(confirmed) => {
if (confirmed) {
product
.destroy()
@ -26,12 +26,12 @@ export default Route.extend({
.get("model")
.removeObject(product);
})
.catch(data =>
.catch((data) =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
);
}
}
);
}
}
},
},
});

View File

@ -19,10 +19,10 @@ export default Route.extend({
type: "recurring",
isRecurring: true,
currency: Discourse.SiteSettings.discourse_subscriptions_currency,
product: product.get("id")
product: product.get("id"),
});
} else {
plan = AdminPlan.find(id).then(result => {
plan = AdminPlan.find(id).then((result) => {
result.isRecurring = result.type === "recurring";
return result;
@ -41,8 +41,8 @@ export default Route.extend({
into: "adminPlugins.discourse-subscriptions.products",
outlet: "main",
controller:
"adminPlugins.discourse-subscriptions.products.show.plans.show"
"adminPlugins.discourse-subscriptions.products.show.plans.show",
}
);
}
},
});

View File

@ -28,7 +28,7 @@ export default Route.extend({
),
I18n.t("no_value"),
I18n.t("yes_value"),
confirmed => {
(confirmed) => {
if (confirmed) {
plan
.destroy()
@ -39,12 +39,12 @@ export default Route.extend({
.get("model.plans")
.removeObject(plan);
})
.catch(data =>
.catch((data) =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
);
}
}
);
}
}
},
},
});

View File

@ -15,14 +15,14 @@ export default Route.extend({
),
I18n.t("no_value"),
I18n.t("yes_value"),
confirmed => {
(confirmed) => {
if (confirmed) {
subscription.set("loading", true);
subscription
.destroy()
.then(result => subscription.set("status", result.status))
.catch(data =>
.then((result) => subscription.set("status", result.status))
.catch((data) =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
)
.finally(() => {
@ -31,6 +31,6 @@ export default Route.extend({
}
}
);
}
}
},
},
});

View File

@ -4,5 +4,5 @@ import Product from "discourse/plugins/discourse-subscriptions/discourse/models/
export default Route.extend({
model() {
return Product.findAll();
}
},
});

View File

@ -11,5 +11,5 @@ export default Route.extend({
const plans = Plan.findAll({ product_id });
return hash({ plans, product });
}
},
});

View File

@ -5,5 +5,5 @@ export default Route.extend({
redirect() {
this.transitionTo("user.billing.subscriptions");
}
},
});

View File

@ -6,5 +6,5 @@ export default Route.extend({
model() {
return UserPayment.findAll();
}
},
});

View File

@ -17,14 +17,14 @@ export default Route.extend({
),
I18n.t("no_value"),
I18n.t("yes_value"),
confirmed => {
(confirmed) => {
if (confirmed) {
subscription.set("loading", true);
subscription
.destroy()
.then(result => subscription.set("status", result.status))
.catch(data =>
.then((result) => subscription.set("status", result.status))
.catch((data) =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
)
.finally(() => {
@ -34,6 +34,6 @@ export default Route.extend({
}
}
);
}
}
},
},
});

View File

@ -9,5 +9,5 @@ export default Route.extend({
} else {
controller.setProperties({ model });
}
}
},
});

View File

@ -1,5 +1,5 @@
export default function() {
this.route("s", function() {
export default function () {
this.route("s", function () {
this.route("show", { path: "/:subscription-id" });
});
}

1595
yarn.lock Normal file

File diff suppressed because it is too large Load Diff