From 1e00f070d89535a51ce3d7678333ce3d992d32ad Mon Sep 17 00:00:00 2001 From: Niels Vandekeybus Date: Wed, 15 Sep 2021 11:23:03 +0200 Subject: [PATCH 1/2] correctly delete vote --- app/components/treatment/voting/modal.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/components/treatment/voting/modal.js b/app/components/treatment/voting/modal.js index a1c9ee905..70d92a66c 100644 --- a/app/components/treatment/voting/modal.js +++ b/app/components/treatment/voting/modal.js @@ -86,10 +86,11 @@ export default class TreatmentVotingModalComponent extends Component { this.editMode = true; } @task - removeStemming = function* (stemming) { - stemming.deleteRecord(); - yield stemming.save(); + *removeStemming(stemming) { + yield stemming.destroyRecord(); + this.stemmingen = this.stemmingen.reject((x) => x === stemming); } + @action onCancelEdit() { this.editMode = false; From b1710a725380660c434acdac55b4b4ec76ff621e Mon Sep 17 00:00:00 2001 From: Niels Vandekeybus Date: Wed, 15 Sep 2021 11:24:14 +0200 Subject: [PATCH 2/2] use generator methods instead of fields in vote modal while working on a bug in this class I noticed the tasks where defined as variables, which wans't inline with how we usually write these. --- app/components/treatment/voting/modal.js | 53 ++++++++++++------------ 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/app/components/treatment/voting/modal.js b/app/components/treatment/voting/modal.js index 70d92a66c..b2edd49dd 100644 --- a/app/components/treatment/voting/modal.js +++ b/app/components/treatment/voting/modal.js @@ -32,13 +32,13 @@ export default class TreatmentVotingModalComponent extends Component { @restartableTask /** @type {import("ember-concurrency").Task} */ - fetchStemmingen = function* () { + *fetchStemmingen() { this.stemmingen = (yield this.args.behandeling.stemmingen).sortBy('position'); - }; + } @task /** @type {import("ember-concurrency").Task} */ - saveStemming = function* () { + *saveStemming() { const isNew = this.editStemming.stemming.isNew; if(isNew) { @@ -51,40 +51,39 @@ export default class TreatmentVotingModalComponent extends Component { this.args.behandeling.save(); } yield this.fetchStemmingen.perform(); - - this.onCancelEdit(); - }; + this.onCancelEdit(); + } @task /** @type {import("ember-concurrency").Task} */ - addStemming = - /** @this {TreatmentVotingModalComponent} */ - function* () { - const richTreatment = yield this.store.query("behandeling-van-agendapunt", { - "filter[:id:]": this.args.behandeling.id, - include: "aanwezigen.bekleedt.bestuursfunctie" - }); - const participants = richTreatment.firstObject.aanwezigen; + *addStemming() { + const richTreatment = yield this.store.query("behandeling-van-agendapunt", { + "filter[:id:]": this.args.behandeling.id, + include: "aanwezigen.bekleedt.bestuursfunctie" + }); + const participants = richTreatment.firstObject.aanwezigen; + + const stemmingToEdit = this.store.createRecord("stemming", { + onderwerp: "", + geheim: false, + aantalVoorstanders: 0, + aantalTegenstanders: 0, + aantalOnthouders: 0, + gevolg: "", + }); + this.editMode = true; + stemmingToEdit.aanwezigen.pushObjects(participants); + stemmingToEdit.stemmers.pushObjects(participants); + this.editStemming.stemming = stemmingToEdit; + } - const stemmingToEdit = this.store.createRecord("stemming", { - onderwerp: "", - geheim: false, - aantalVoorstanders: 0, - aantalTegenstanders: 0, - aantalOnthouders: 0, - gevolg: "", - }); - this.editMode = true; - stemmingToEdit.aanwezigen.pushObjects(participants); - stemmingToEdit.stemmers.pushObjects(participants); - this.editStemming.stemming = stemmingToEdit; - }; @action toggleEditStemming(stemming) { this.editStemming.stemming = stemming; this.editMode = true; } + @task *removeStemming(stemming) { yield stemming.destroyRecord();