plan model with destroy and find

This commit is contained in:
Rimian Perkins 2019-10-08 19:37:22 +11:00
parent 6f9195a7d4
commit 19a03aa2ca
6 changed files with 56 additions and 15 deletions

View File

@ -1,20 +1,21 @@
import { ajax } from "discourse/lib/ajax";
import computed from "ember-addons/ember-computed-decorators";
import DiscourseURL from "discourse/lib/url";
import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan";
export default Ember.Controller.extend({
@computed("model.plans")
plans(plans) {
return plans.filter(plan => !plan.deleted);
},
actions: {
deletePlan(id) {
return ajax(`/patrons/admin/plans/${id}`, { method: "delete" });
destroyPlan(plan) {
plan.destroy().then(() =>
this.controllerFor("adminBackupsIndex")
.get("model")
.removeObject(backup)
);
},
editPlan(id) {
return DiscourseURL.redirectTo(`/admin/plugins/discourse-patrons/plans/${id}`);
return DiscourseURL.redirectTo(
`/admin/plugins/discourse-patrons/plans/${id}`
);
}
}
});

View File

@ -0,0 +1,14 @@
import { ajax } from "discourse/lib/ajax";
const Plan = Discourse.Model.extend({
destroy() { }
});
Plan.reopenClass({
find() {
return ajax("/patrons/admin/plans", { method: "get" })
.then(result => result.plans.map(plan => Plan.create(plan)));
}
});
export default Plan;

View File

@ -1,7 +1,24 @@
import { ajax } from "discourse/lib/ajax";
import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan";
export default Discourse.Route.extend({
model() {
return ajax("/patrons/admin/plans", { method: "get" });
return Plan.find();
},
actions: {
destroyPlan(plan) {
bootbox.confirm(
I18n.t("discourse-patrons.plans.operations.destroy.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
confirmed => {
if (confirmed) {
this.controllerFor("adminPluginsDiscoursePatronsPlansIndex")
.get("model")
.removeObject(plan);
}
}
);
}
}
});

View File

@ -1,2 +1 @@
export default Discourse.Route.extend({});

View File

@ -8,15 +8,22 @@
<th>{{i18n 'discourse_patrons.admin.plans.plan.interval'}}</th>
<th>{{i18n 'discourse_patrons.admin.plans.plan.amount'}}</th>
</thead>
{{#each plans as |plan|}}
{{#each model as |plan|}}
<tr>
<td>{{plan.id}}</td>
<td>{{plan.nickname}}</td>
<td>{{plan.interval}}</td>
<td>{{plan.amount}}</td>
<td>
{{d-button action=(action "editPlan" plan.id) icon="far-edit" class="btn no-text btn-icon"}}
{{d-button action=(action "deletePlan" plan.id) icon="trash-alt" class="btn-danger btn no-text btn-icon"}}
{{d-button
action=(action "editPlan" plan.id)
icon="far-edit"
class="btn no-text btn-icon"}}
{{d-button
action=(route-action "destroyPlan")
actionParam=plan
icon="trash-alt"
class="btn-danger btn no-text btn-icon"}}
</td>
</tr>
{{/each}}

View File

@ -60,5 +60,8 @@ en:
nickname: Nickname
interval: Interval
amount: Amount
operations:
destroy:
confirm: Are you sure you want to destroy this plan?
subscriptions:
title: Subscriptions