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 @@ + + 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 new file mode 100644 index 000000000..a80acac85 --- /dev/null +++ b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.hbs @@ -0,0 +1,40 @@ + +{{#if (and this.warningMessages this.currentShownWarning)}} +
+ +
+
+ {{#if this.hasMoreThanOneMessage}} +
+ + +
+ {{/if}} +

+ {{this.currentShownWarning.message}} +

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

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

+ {{/if}} + +
+
+
+{{/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..d04c7810f --- /dev/null +++ b/app/components/verkiezingen/warning-amount-mandatarissen-for-orgaan-alert.js @@ -0,0 +1,121 @@ +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, timeout } 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) { + throw new Error('Geen bestuursorgaan meegegeven aan component.'); + } + + 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() { + 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, + // 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; + let message = null; + let messagePositionInArray = null; + if (totalForMandaat > value.max) { + 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; + } + + this.setMessageForMandaat(key, message, messagePositionInArray); + if (message) { + this.warningMessages.pushObject({ + message: message, + position: messagePositionInArray, + }); + } + } + ) + ); + } + + setMessageForMandaat(mandaatId, message, messagePositionInArray) { + if (!mandaatId || !messagePositionInArray) { + return; + } + + const current = this.mandaatValueMapping.get(mandaatId); + delete current.message; + this.mandaatValueMapping.set(mandaatId, { + ...current, + message, + }); + } + + @action + next() { + const current = this.warningMessages.shiftObject(); + console.log({ current }); + this.warningMessages.pushObject(current); + } + + @action + previous() { + const current = this.warningMessages.popObject(); + this.warningMessages.unshiftObject(current); + } + + get currentShownWarning() { + return this.warningMessages.at(0) ?? null; + } + + get hasMoreThanOneMessage() { + return this.warningMessages.length > 1; + } +}