DEV: migrate routes to the new @action pattern (#102)

This commit is contained in:
Andrei Prigorshnev 2022-01-06 12:32:09 +01:00 committed by GitHub
parent 9256a45c2a
commit 45780a1ebc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 103 additions and 107 deletions

View File

@ -1,14 +1,14 @@
import Route from "@ember/routing/route";
import AdminCoupon from "discourse/plugins/discourse-subscriptions/discourse/models/admin-coupon";
import { action } from "@ember/object";
export default Route.extend({
model() {
return AdminCoupon.list();
},
actions: {
reloadModel() {
this.refresh();
},
@action
reloadModel() {
this.refresh();
},
});

View File

@ -1,37 +1,37 @@
import Route from "@ember/routing/route";
import AdminProduct from "discourse/plugins/discourse-subscriptions/discourse/models/admin-product";
import I18n from "I18n";
import { action } from "@ember/object";
export default Route.extend({
model() {
return AdminProduct.findAll();
},
actions: {
destroyProduct(product) {
bootbox.confirm(
I18n.t(
"discourse_subscriptions.admin.products.operations.destroy.confirm"
),
I18n.t("no_value"),
I18n.t("yes_value"),
(confirmed) => {
if (confirmed) {
product
.destroy()
.then(() => {
this.controllerFor(
"adminPluginsDiscourseSubscriptionsProductsIndex"
)
.get("model")
.removeObject(product);
})
.catch((data) =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
);
}
@action
destroyProduct(product) {
bootbox.confirm(
I18n.t(
"discourse_subscriptions.admin.products.operations.destroy.confirm"
),
I18n.t("no_value"),
I18n.t("yes_value"),
(confirmed) => {
if (confirmed) {
product
.destroy()
.then(() => {
this.controllerFor(
"adminPluginsDiscourseSubscriptionsProductsIndex"
)
.get("model")
.removeObject(product);
})
.catch((data) =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
);
}
);
},
}
);
},
});

View File

@ -3,6 +3,7 @@ import AdminProduct from "discourse/plugins/discourse-subscriptions/discourse/mo
import AdminPlan from "discourse/plugins/discourse-subscriptions/discourse/models/admin-plan";
import I18n from "I18n";
import { hash } from "rsvp";
import { action } from "@ember/object";
export default Route.extend({
model(params) {
@ -20,31 +21,28 @@ export default Route.extend({
return hash({ plans, product });
},
actions: {
destroyPlan(plan) {
bootbox.confirm(
I18n.t(
"discourse_subscriptions.admin.plans.operations.destroy.confirm"
),
I18n.t("no_value"),
I18n.t("yes_value"),
(confirmed) => {
if (confirmed) {
plan
.destroy()
.then(() => {
this.controllerFor(
"adminPluginsDiscourseSubscriptionsProductsShow"
)
.get("model.plans")
.removeObject(plan);
})
.catch((data) =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
);
}
@action
destroyPlan(plan) {
bootbox.confirm(
I18n.t("discourse_subscriptions.admin.plans.operations.destroy.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
(confirmed) => {
if (confirmed) {
plan
.destroy()
.then(() => {
this.controllerFor(
"adminPluginsDiscourseSubscriptionsProductsShow"
)
.get("model.plans")
.removeObject(plan);
})
.catch((data) =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
);
}
);
},
}
);
},
});

View File

@ -1,31 +1,29 @@
import I18n from "I18n";
import Route from "@ember/routing/route";
import AdminSubscription from "discourse/plugins/discourse-subscriptions/discourse/models/admin-subscription";
import { action } from "@ember/object";
export default Route.extend({
model() {
return AdminSubscription.find();
},
actions: {
cancelSubscription(model) {
const subscription = model.subscription;
const refund = model.refund;
subscription.set("loading", true);
subscription
.destroy(refund)
.then((result) => {
subscription.set("status", result.status);
this.send("closeModal");
bootbox.alert(I18n.t("discourse_subscriptions.admin.canceled"));
})
.catch((data) =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
)
.finally(() => {
subscription.set("loading", false);
this.refresh();
});
},
@action
cancelSubscription(model) {
const subscription = model.subscription;
const refund = model.refund;
subscription.set("loading", true);
subscription
.destroy(refund)
.then((result) => {
subscription.set("status", result.status);
this.send("closeModal");
bootbox.alert(I18n.t("discourse_subscriptions.admin.canceled"));
})
.catch((data) => bootbox.alert(data.jqXHR.responseJSON.errors.join("\n")))
.finally(() => {
subscription.set("loading", false);
this.refresh();
});
},
});

View File

@ -1,14 +1,14 @@
import Route from "@ember/routing/route";
import { action } from "@ember/object";
export default Route.extend({
actions: {
showSettings() {
const controller = this.controllerFor("adminSiteSettings");
this.transitionTo("adminSiteSettingsCategory", "plugins").then(() => {
controller.set("filter", "plugin:discourse-subscriptions campaign");
controller.set("_skipBounce", true);
controller.filterContentNow("plugins");
});
},
@action
showSettings() {
const controller = this.controllerFor("adminSiteSettings");
this.transitionTo("adminSiteSettingsCategory", "plugins").then(() => {
controller.set("filter", "plugin:discourse-subscriptions campaign");
controller.set("_skipBounce", true);
controller.filterContentNow("plugins");
});
},
});

View File

@ -1,6 +1,7 @@
import Route from "@ember/routing/route";
import UserSubscription from "discourse/plugins/discourse-subscriptions/discourse/models/user-subscription";
import I18n from "I18n";
import { action } from "@ember/object";
export default Route.extend({
templateName: "user/billing/subscriptions",
@ -9,31 +10,30 @@ export default Route.extend({
return UserSubscription.findAll();
},
actions: {
cancelSubscription(subscription) {
bootbox.confirm(
I18n.t(
"discourse_subscriptions.user.subscriptions.operations.destroy.confirm"
),
I18n.t("no_value"),
I18n.t("yes_value"),
(confirmed) => {
if (confirmed) {
subscription.set("loading", true);
@action
cancelSubscription(subscription) {
bootbox.confirm(
I18n.t(
"discourse_subscriptions.user.subscriptions.operations.destroy.confirm"
),
I18n.t("no_value"),
I18n.t("yes_value"),
(confirmed) => {
if (confirmed) {
subscription.set("loading", true);
subscription
.destroy()
.then((result) => subscription.set("status", result.status))
.catch((data) =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
)
.finally(() => {
subscription.set("loading", false);
this.refresh();
});
}
subscription
.destroy()
.then((result) => subscription.set("status", result.status))
.catch((data) =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
)
.finally(() => {
subscription.set("loading", false);
this.refresh();
});
}
);
},
}
);
},
});