From dbf25dfe47a8504dc23953a144b07a21fa6a10a1 Mon Sep 17 00:00:00 2001 From: Jonas Van Hoof Date: Mon, 9 Dec 2024 16:57:17 +0100 Subject: [PATCH 1/7] lmb-858: create component that will show the warnings for the mandatarissen of the table for min and max mandatees --- ...-amount-mandatarissen-for-orgaan-alert.hbs | 18 ++++ ...g-amount-mandatarissen-for-orgaan-alert.js | 95 +++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs create mode 100644 app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js diff --git a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs new file mode 100644 index 000000000..9fe27c964 --- /dev/null +++ b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs @@ -0,0 +1,18 @@ + +{{#if (and this.warningMessages this.currentShownWarning)}} +
+ +
+ {{#if this.hasMoreThanOneMessage}} +
+ + +
+ {{/if}} +

+ {{this.currentShownWarning}} +

+
+
+
+{{/if}} \ No newline at end of file diff --git a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js new file mode 100644 index 000000000..c77bb6015 --- /dev/null +++ b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js @@ -0,0 +1,95 @@ +import Component from '@glimmer/component'; + +import { action } from '@ember/object'; +import { A } from '@ember/array'; +import { tracked } from '@glimmer/tracking'; +import { service } from '@ember/service'; + +import { task } from 'ember-concurrency'; + +export default class VerkiezingenWarningAmountMandatarissenForOrgaanAlertComponent extends Component { + @service store; + + @tracked mandaatValueMapping; + @tracked warningMessages = A(); + + constructor() { + super(...arguments); + this.getMaxAnMinNumberForMandaten.perform(); + } + + getMaxAnMinNumberForMandaten = task(async () => { + if (!this.args.bestuursorgaanInTijd) { + return; + } + + const mandaten = await this.store.query('mandaat', { + 'filter[bevat-in][:uri:]': this.args.bestuursorgaanInTijd.uri, + }); + this.mandaatValueMapping = new Map(); + for (const mandaat of mandaten) { + this.mandaatValueMapping.set(mandaat.id, { + label: (await mandaat.bestuursfunctie).label, + min: mandaat.minAantalHouders, + max: mandaat.maxAantalHouders, + warning: null, + }); + } + await this.updateMappingWithMessages(); + }); + + @action + async updateMappingWithMessages() { + await Promise.all( + Array.from( + this.mandaatValueMapping ?? [], + // eslint-disable-next-line no-unused-vars + async ([key, value]) => { + if (!value.max) { + return; + } + const totalForMandaat = this.args.mandatarissen.filter((m) => { + return m.get('bekleedt.id') === key; + }).length; + if (totalForMandaat > value.max) { + this.setMessageForMandaat( + key, + `Teveel mandatarissen gevonden voor mandaat ${value.label} (${totalForMandaat} van ${value.max})` + ); + } else { + this.setMessageForMandaat(key, null); + } + } + ) + ); + this.warningMessages.clear(); + this.warningMessages.pushObjects( + Array.from( + this.mandaatValueMapping ?? [], + // eslint-disable-next-line no-unused-vars + ([key, value]) => value.message + ).filter((m) => m) + ); + } + + setMessageForMandaat(mandaatId, message) { + if (!mandaatId) { + return; + } + + const current = this.mandaatValueMapping.get(mandaatId); + delete current.message; + this.mandaatValueMapping.set(mandaatId, { + ...current, + message, + }); + } + + get currentShownWarning() { + return this.warningMessages.at(0) ?? null; + } + + get hasMoreThanOneMessage() { + return this.warningMessages.length > 1; + } +} From 331aec26d5980883fe1cfcf42471950b79dee4e0 Mon Sep 17 00:00:00 2001 From: Jonas Van Hoof Date: Mon, 9 Dec 2024 16:57:43 +0100 Subject: [PATCH 2/7] lmb-858: show the warning alert component for every IV bestuursorgaan in tijd --- app/components/verkiezingen/prepare-legislatuur-section.hbs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/components/verkiezingen/prepare-legislatuur-section.hbs b/app/components/verkiezingen/prepare-legislatuur-section.hbs index 2d179facc..b068d61e4 100644 --- a/app/components/verkiezingen/prepare-legislatuur-section.hbs +++ b/app/components/verkiezingen/prepare-legislatuur-section.hbs @@ -94,6 +94,10 @@ + + From 43a9882425c2f30e3787169530fa2dcb844f180e Mon Sep 17 00:00:00 2001 From: Jonas Van Hoof Date: Mon, 9 Dec 2024 21:03:06 +0100 Subject: [PATCH 3/7] lmb-858: can go though the warning messages messages --- ...rning-amount-mandatarissen-for-orgaan-alert.hbs | 14 ++++++++++++-- ...arning-amount-mandatarissen-for-orgaan-alert.js | 12 ++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs index 9fe27c964..a153a20d9 100644 --- a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs +++ b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs @@ -5,8 +5,18 @@
{{#if this.hasMoreThanOneMessage}}
- - + +
{{/if}}

diff --git a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js index c77bb6015..7bcf3cf72 100644 --- a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js +++ b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js @@ -85,6 +85,18 @@ export default class VerkiezingenWarningAmountMandatarissenForOrgaanAlertCompone }); } + @action + next() { + const current = this.warningMessages.shiftObject(); + this.warningMessages.pushObject(current); + } + + @action + previous() { + const current = this.warningMessages.popObject(); + this.warningMessages.unshiftObject(current); + } + get currentShownWarning() { return this.warningMessages.at(0) ?? null; } From 5769820aa0c8ff451479108ed566609d0111a31b Mon Sep 17 00:00:00 2001 From: Jonas Van Hoof Date: Mon, 9 Dec 2024 21:25:31 +0100 Subject: [PATCH 4/7] lmb-858: when the mapping is not completed it gets recalled --- ...g-amount-mandatarissen-for-orgaan-alert.js | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js index 7bcf3cf72..d0ab8994c 100644 --- a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js +++ b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js @@ -5,7 +5,7 @@ import { A } from '@ember/array'; import { tracked } from '@glimmer/tracking'; import { service } from '@ember/service'; -import { task } from 'ember-concurrency'; +import { task, timeout } from 'ember-concurrency'; export default class VerkiezingenWarningAmountMandatarissenForOrgaanAlertComponent extends Component { @service store; @@ -20,7 +20,7 @@ export default class VerkiezingenWarningAmountMandatarissenForOrgaanAlertCompone getMaxAnMinNumberForMandaten = task(async () => { if (!this.args.bestuursorgaanInTijd) { - return; + throw new Error('Geen bestuursorgaan meegegeven aan component.'); } const mandaten = await this.store.query('mandaat', { @@ -40,9 +40,20 @@ export default class VerkiezingenWarningAmountMandatarissenForOrgaanAlertCompone @action async updateMappingWithMessages() { + if ( + !this.mandaatValueMapping && + this.getMaxAnMinNumberForMandaten.isRunning + ) { + // This could be better + await timeout(250); + await this.updateMappingWithMessages(); + } + + this.warningMessages.clear(); + await Promise.all( Array.from( - this.mandaatValueMapping ?? [], + this.mandaatValueMapping, // eslint-disable-next-line no-unused-vars async ([key, value]) => { if (!value.max) { @@ -51,25 +62,16 @@ export default class VerkiezingenWarningAmountMandatarissenForOrgaanAlertCompone const totalForMandaat = this.args.mandatarissen.filter((m) => { return m.get('bekleedt.id') === key; }).length; + let message = null; if (totalForMandaat > value.max) { - this.setMessageForMandaat( - key, - `Teveel mandatarissen gevonden voor mandaat ${value.label} (${totalForMandaat} van ${value.max})` - ); - } else { - this.setMessageForMandaat(key, null); + message = `Teveel mandatarissen gevonden voor mandaat "${value.label}" (${totalForMandaat} van ${value.max})`; } + + this.setMessageForMandaat(key, message); + message ? this.warningMessages.pushObject(message) : null; } ) ); - this.warningMessages.clear(); - this.warningMessages.pushObjects( - Array.from( - this.mandaatValueMapping ?? [], - // eslint-disable-next-line no-unused-vars - ([key, value]) => value.message - ).filter((m) => m) - ); } setMessageForMandaat(mandaatId, message) { From 3d0a88a4c6860b69e8fff1c8c43e677bf5ec80f2 Mon Sep 17 00:00:00 2001 From: Jonas Van Hoof Date: Mon, 9 Dec 2024 21:43:59 +0100 Subject: [PATCH 5/7] lmb-858: add a position for the warning so the user sees how many there are --- ...-amount-mandatarissen-for-orgaan-alert.hbs | 51 ++++++++++++------- ...g-amount-mandatarissen-for-orgaan-alert.js | 17 +++++-- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs index a153a20d9..94a7abcd8 100644 --- a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs +++ b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs @@ -2,25 +2,38 @@ {{#if (and this.warningMessages this.currentShownWarning)}}

-
- {{#if this.hasMoreThanOneMessage}} -
- - -
- {{/if}} -

- {{this.currentShownWarning}} +

+
+ {{#if this.hasMoreThanOneMessage}} +
+ + +
+ {{/if}} + {{#if this.hasMoreThanOneMessage}} + +

+ {{this.currentShownWarning.message}} +

+ {{/if}} +
+ +

+ {{this.currentShownWarning.position}} + van + {{this.warningMessages.length}}

diff --git a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js index d0ab8994c..b2d87b777 100644 --- a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js +++ b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js @@ -63,19 +63,26 @@ export default class VerkiezingenWarningAmountMandatarissenForOrgaanAlertCompone return m.get('bekleedt.id') === key; }).length; let message = null; + let messagePositionInArray = null; if (totalForMandaat > value.max) { - message = `Teveel mandatarissen gevonden voor mandaat "${value.label}" (${totalForMandaat} van ${value.max})`; + message = `${totalForMandaat} van maximum ${value.max} mandataris(sen) gevonden voor mandaat "${value.label}".`; + messagePositionInArray = this.warningMessages.length + 1; } - this.setMessageForMandaat(key, message); - message ? this.warningMessages.pushObject(message) : null; + this.setMessageForMandaat(key, message, messagePositionInArray); + message + ? this.warningMessages.pushObject({ + message: message, + position: messagePositionInArray, + }) + : null; } ) ); } - setMessageForMandaat(mandaatId, message) { - if (!mandaatId) { + setMessageForMandaat(mandaatId, message, messagePositionInArray) { + if (!mandaatId || !messagePositionInArray) { return; } From 323a63da994e49cc8c7fb6187f887981ecdc1712 Mon Sep 17 00:00:00 2001 From: Jonas Van Hoof Date: Mon, 9 Dec 2024 21:57:21 +0100 Subject: [PATCH 6/7] lmb-858: refresh the tables in IV and only show 1 van X when there are more than 1 --- .../prepare-legislatuur-section.js | 4 +-- ...-amount-mandatarissen-for-orgaan-alert.hbs | 25 +++++++++---------- ...g-amount-mandatarissen-for-orgaan-alert.js | 13 +++++----- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/app/components/verkiezingen/prepare-legislatuur-section.js b/app/components/verkiezingen/prepare-legislatuur-section.js index da1584a89..677b11ed9 100644 --- a/app/components/verkiezingen/prepare-legislatuur-section.js +++ b/app/components/verkiezingen/prepare-legislatuur-section.js @@ -142,7 +142,6 @@ export default class PrepareLegislatuurSectionComponent extends Component { 'Er ging iets mis bij het overzetten van de mandatarissen.' ); }); - this.installatievergadering.forceRecomputeBCSD(); this.getMandatarissen.perform({ updated: true }); this.router.refresh(); // not doing this breaks burgemeester selector synchronization }); @@ -182,10 +181,9 @@ export default class PrepareLegislatuurSectionComponent extends Component { async onCreate({ instanceId }) { this.editMode = null; const mandataris = await this.store.findRecord('mandataris', instanceId); - await this.getMandatarissen.perform({ added: [mandataris] }); await this.fractieApi.updateCurrentFractie(instanceId); await this.mandatarisService.removeDanglingFractiesInPeriod(instanceId); - this.installatievergadering.forceRecomputeBCSD(); + await this.getMandatarissen.perform({ added: [mandataris] }); } @action diff --git a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs index 94a7abcd8..a80acac85 100644 --- a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs +++ b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs @@ -20,21 +20,20 @@ />
{{/if}} - {{#if this.hasMoreThanOneMessage}} - -

- {{this.currentShownWarning.message}} -

- {{/if}} +

+ {{this.currentShownWarning.message}} +

+ {{#if this.hasMoreThanOneMessage}} +

+ {{this.currentShownWarning.position}} + van + {{this.warningMessages.length}} +

+ {{/if}} -

- {{this.currentShownWarning.position}} - van - {{this.warningMessages.length}} -

diff --git a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js index b2d87b777..081410cd7 100644 --- a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js +++ b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js @@ -70,12 +70,12 @@ export default class VerkiezingenWarningAmountMandatarissenForOrgaanAlertCompone } this.setMessageForMandaat(key, message, messagePositionInArray); - message - ? this.warningMessages.pushObject({ - message: message, - position: messagePositionInArray, - }) - : null; + if (message) { + this.warningMessages.pushObject({ + message: message, + position: messagePositionInArray, + }); + } } ) ); @@ -97,6 +97,7 @@ export default class VerkiezingenWarningAmountMandatarissenForOrgaanAlertCompone @action next() { const current = this.warningMessages.shiftObject(); + console.log({ current }); this.warningMessages.pushObject(current); } From 3ed6bac300a58bfbd7a1fb5fbc97e9acf26e6b24 Mon Sep 17 00:00:00 2001 From: Jonas Van Hoof Date: Tue, 10 Dec 2024 09:09:31 +0100 Subject: [PATCH 7/7] lmb-858: also show a warning for not having the minimum --- .../warning-amount-mandatarissen-for-orgaan-alert.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js index 081410cd7..d04c7810f 100644 --- a/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js +++ b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js @@ -65,7 +65,11 @@ export default class VerkiezingenWarningAmountMandatarissenForOrgaanAlertCompone let message = null; let messagePositionInArray = null; if (totalForMandaat > value.max) { - message = `${totalForMandaat} van maximum ${value.max} mandataris(sen) gevonden voor mandaat "${value.label}".`; + message = `Teveel mandaten gevonden voor "${value.label}". ${totalForMandaat} van maximum ${value.max}`; + messagePositionInArray = this.warningMessages.length + 1; + } + if (totalForMandaat < value.min) { + message = `Te weinig mandaten gevonden voor "${value.label}". (${totalForMandaat}/${value.min})`; messagePositionInArray = this.warningMessages.length + 1; }