Skip to content

Commit

Permalink
Merge pull request #465 from lblod/ben/lmb-1288-end-date-mandatarissen
Browse files Browse the repository at this point in the history
Ben/lmb 1288 end date mandatarissen
  • Loading branch information
Rahien authored Jan 28, 2025
2 parents 09070d8 + 670c0ca commit 9ae75f5
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 22 deletions.
18 changes: 16 additions & 2 deletions app/components/date-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import moment from 'moment';

import { INPUT_DEBOUNCE, NULL_DATE } from 'frontend-lmb/utils/constants';
import { action } from '@ember/object';
import {
displayEndOfDay,
endOfDay,
} from 'frontend-lmb/utils/date-manipulation';

export default class DateInputComponent extends Component {
elementId = `date-${guidFor(this)}`;
Expand Down Expand Up @@ -56,6 +60,9 @@ export default class DateInputComponent extends Component {
}

processDate(date) {
if (this.args?.endOfDay) {
date = endOfDay(date);
}
if (!isValidDate(date)) {
this.invalidErrorMessage = `Datum is ongeldig.`;
this.errorMessage = null;
Expand Down Expand Up @@ -110,8 +117,15 @@ export default class DateInputComponent extends Component {
@action
setupDateValue() {
if (this.args.value && isValidDate(this.args.value)) {
this.dateInputString = moment(this.args.value).format('DD-MM-YYYY');
this.processDate(this.args.value);
let date;
if (this.args?.endOfDay) {
date = displayEndOfDay(this.args.value);
this.dateInputString = moment(date).format('DD-MM-YYYY');
} else {
date = moment(this.args.value).toDate();
this.dateInputString = moment(this.args.value).format('DD-MM-YYYY');
}
this.processDate(date);
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/components/mandatarissen/history-row.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{moment-format @mandataris.start "DD-MM-YYYY"}}
</td>
<td>
{{moment-format @mandataris.einde "DD-MM-YYYY"}}
{{moment-format @mandataris.displayEinde "DD-MM-YYYY"}}
</td>
<td>
{{@mandataris.status.label}}
Expand Down
2 changes: 1 addition & 1 deletion app/components/mandatarissen/mandataris-card.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<div class="au-c-description-label">Einde periode</div>
<div class="au-c-description-value au-u-margin-top-tiny">
{{#if @mandataris.einde}}
{{moment-format @mandataris.einde "DD-MM-YYYY"}}
{{moment-format @mandataris.displayEinde "DD-MM-YYYY"}}
{{else}}
heden
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion app/components/mandatarissen/mandataris-summary.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{{moment-format @mandataris.start "DD-MM-YYYY"}}
{{#if @mandataris.einde}}
{{moment-format @mandataris.einde "DD-MM-YYYY"}}
{{moment-format @mandataris.displayEinde "DD-MM-YYYY"}}
{{else}}
heden
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion app/components/mandatarissen/replacement-select.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
this.overlappingMandate.einde
(concat
" en einddatum "
(moment-format this.overlappingMandate.einde "DD-MM-YYYY")
(moment-format this.overlappingMandate.displayEinde "DD-MM-YYYY")
)
}}. Door verder te gaan zal dit mandaat aangeduid worden als vervanging
van het huidige mandaat.
Expand Down
2 changes: 1 addition & 1 deletion app/components/mandatarissen/update-state.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{{moment-format @mandataris.start "DD-MM-YYYY"}}
{{#if @mandataris.einde}}
tot
{{moment-format @mandataris.einde "DD-MM-YYYY"}}
{{moment-format @mandataris.displayEinde "DD-MM-YYYY"}}
{{/if}}
</div>
</div>
Expand Down
11 changes: 6 additions & 5 deletions app/components/mandatarissen/update-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
notBurgemeesterStates,
} from 'frontend-lmb/utils/well-known-uris';
import { isRequiredForBestuursorgaan } from 'frontend-lmb/utils/is-fractie-selector-required';
import { endOfDay } from 'frontend-lmb/utils/date-manipulation';

export default class MandatarissenUpdateState extends Component {
@tracked newStatus = null;
Expand Down Expand Up @@ -104,7 +105,7 @@ export default class MandatarissenUpdateState extends Component {
if (!this.args.mandataris.einde) {
return this.args.mandataris.status;
}
if (this.args.mandataris.einde.getTime() < new Date().getTime()) {
if (this.args.mandataris.einde.getTime() <= new Date().getTime()) {
return this.mandatarisStatus.endedState;
}
return this.args.mandataris.status;
Expand Down Expand Up @@ -163,12 +164,13 @@ export default class MandatarissenUpdateState extends Component {

async changeMandatarisState() {
const endDate = this.args.mandataris.einde;
const dateOfAction = endOfDay(this.date);

const newMandatarisProps = await this.mandatarisService.createNewProps(
this.args.mandataris,
{
rangorde: this.rangorde,
start: this.date,
start: dateOfAction,
einde: endDate,
status: this.newStatus,
publicationStatus: await getDraftPublicationStatus(this.store),
Expand Down Expand Up @@ -197,7 +199,7 @@ export default class MandatarissenUpdateState extends Component {
(await this.args.mandataris.vervangerVan) || [];
}

this.args.mandataris.einde = this.date;
this.args.mandataris.einde = dateOfAction;
await Promise.all([newMandataris.save(), this.args.mandataris.save()]);

await this.mandatarisService.createNewLidmaatschap(
Expand All @@ -218,8 +220,7 @@ export default class MandatarissenUpdateState extends Component {
}

async endMandataris() {
this.args.mandataris.einde = this.date;

this.args.mandataris.einde = endOfDay(this.date);
return await this.args.mandataris.save();
}

Expand Down
6 changes: 3 additions & 3 deletions app/components/organen/bekrachtig-mandataris-table.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@
<td>
<Mandaat::MandatarisStatusPill @mandataris={{row.mandataris}} />
</td>
<td class={{if (is-in-past row.mandataris.einde) "au-u-muted"}}>
<td class={{if (is-in-past row.mandataris.displayEinde) "au-u-muted"}}>
{{moment-format row.mandataris.start "DD-MM-YYYY"}}</td>
<td class={{if (is-in-past row.mandataris.einde) "au-u-muted"}}>
{{moment-format row.mandataris.einde "DD-MM-YYYY"}}</td>
<td class={{if (is-in-past row.mandataris.displayEinde) "au-u-muted"}}>
{{moment-format row.mandataris.displayEinde "DD-MM-YYYY"}}</td>
<td>
<Mandaat::PublicatieStatusPill
@mandataris={{row.mandataris}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{{moment-format mandataris.start "DD-MM-YYYY"}}
{{#if mandataris.einde}}
-
{{moment-format mandataris.einde "DD-MM-YYYY"}}
{{moment-format mandataris.displayEinde "DD-MM-YYYY"}}
{{/if}}
</span>
</PowerSelectMultiple>
Expand Down
1 change: 1 addition & 0 deletions app/components/rdf-input-fields/rdf-date-input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@from={{this.from}}
@to={{this.to}}
@showFormatHelpText={{@show}}
@endOfDay={{this.endOfDay}}
/>

{{#each this.errors as |error|}}
Expand Down
13 changes: 12 additions & 1 deletion app/components/rdf-input-fields/rdf-date-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@lblod/submission-form-helpers';

import { replaceSingleFormValue } from 'frontend-lmb/utils/replaceSingleFormValue';
import { EXT, SHACL } from 'frontend-lmb/rdf/namespaces';
import { EXT, FIELD_OPTION, SHACL } from 'frontend-lmb/rdf/namespaces';
import { loadBestuursorgaanPeriodFromContext } from 'frontend-lmb/utils/form-context/application-context-meta-ttl';

export default class RdfDateInputComponent extends InputFieldComponent {
Expand All @@ -21,10 +21,12 @@ export default class RdfDateInputComponent extends InputFieldComponent {
@tracked date;
@tracked from;
@tracked to;
@tracked endOfDay;

constructor() {
super(...arguments);
this.loadProvidedValue();
this.loadOptions();
}

async loadProvidedValue() {
Expand Down Expand Up @@ -56,6 +58,15 @@ export default class RdfDateInputComponent extends InputFieldComponent {
}
}

loadOptions() {
this.endOfDay = !!this.args.formStore.any(
this.args.field.uri,
FIELD_OPTION('endOfDay'),
undefined,
this.args.graphs.formGraph
);
}

@action
onUpdate(date) {
replaceSingleFormValue(this.storeOptions, date);
Expand Down
2 changes: 1 addition & 1 deletion app/components/verkiezingen/draft-mandataris-list.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
{{moment-format row.start "DD-MM-YYYY"}}
</td>
<td>
{{moment-format row.einde "DD-MM-YYYY"}}
{{moment-format row.displayEinde "DD-MM-YYYY"}}
</td>
{{/if}}
{{#unless @readOnly}}
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/mandatarissen/persoon/mandaten.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { task } from 'ember-concurrency';
import { getDraftPublicationStatus } from 'frontend-lmb/utils/get-mandataris-status';
import { showSuccessToast } from 'frontend-lmb/utils/toasts';

import { endOfDay } from 'frontend-lmb/utils/date-manipulation';

export default class MandatarissenPersoonMandatenController extends Controller {
@service router;
@service toaster;
Expand Down Expand Up @@ -125,7 +127,7 @@ export default class MandatarissenPersoonMandatenController extends Controller {
newMandataris.id
);

mandataris.einde = dateNow;
mandataris.einde = endOfDay(dateNow);
await mandataris.save();
}

Expand Down
8 changes: 8 additions & 0 deletions app/models/mandataris.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
import moment from 'moment';
import { MANDATARIS_EDIT_FORM_ID } from 'frontend-lmb/utils/well-known-ids';
import { JSON_API_TYPE } from 'frontend-lmb/utils/constants';
import { displayEndOfDay } from 'frontend-lmb/utils/date-manipulation';

export default class MandatarisModel extends Model {
@attr rangorde;
Expand Down Expand Up @@ -92,6 +93,13 @@ export default class MandatarisModel extends Model {
);
}

get displayEinde() {
if (!this.einde) {
return this.einde;
}
return displayEndOfDay(this.einde);
}

get isActive() {
if (!this.einde) {
return true;
Expand Down
4 changes: 4 additions & 0 deletions app/rdf/namespaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ export const PROV = new Namespace('http://www.w3.org/ns/prov#');
export const ORG = new Namespace('http://www.w3.org/ns/org#');
export const MANDAAT = new Namespace('http://data.vlaanderen.be/ns/mandaat#');
export const LMB = new Namespace('http://lblod.data.gift/vocabularies/lmb/');

export const FIELD_OPTION = new Namespace(
'http://lblod.data.gift/vocabularies/form-field-options/'
);
13 changes: 13 additions & 0 deletions app/utils/date-manipulation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import moment from 'moment';

export function endOfDay(date) {
if (date) {
return moment(date).add(1, 'days').startOf('day').utc().toDate();
} else {
return moment().add(1, 'days').startOf('day').utc().toDate();
}
}

export function displayEndOfDay(date) {
return moment(date).subtract(1, 'days').toDate();
}
6 changes: 3 additions & 3 deletions app/utils/fold-mandatarisses.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function updateFoldedMandataris(mandataris, foldedMandataris) {
function buildFoldedMandataris(mandataris) {
return {
foldedStart: mandataris.start,
foldedEnd: mandataris.einde,
foldedEnd: mandataris.displayEinde,
mandataris,
};
}
Expand All @@ -124,7 +124,7 @@ function updateFoldedEnd(mandataris, foldedMandataris) {
} else {
foldedMandataris.foldedEnd = moment.max(
moment(foldedMandataris.foldedEnd),
moment(mandataris.einde)
moment(mandataris.displayEinde)
);
}
}
Expand All @@ -133,7 +133,7 @@ function updateMandataris(mandataris, foldedMandataris) {
// Keep the one with the latest end date. If the end date is null,
// we assume this is the latest one.
if (
moment(mandataris.einde).isSame(foldedMandataris.foldedEnd) ||
moment(mandataris.displayEinde).isSame(foldedMandataris.foldedEnd) ||
!mandataris.einde
) {
foldedMandataris.mandataris = mandataris;
Expand Down

0 comments on commit 9ae75f5

Please sign in to comment.