Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ben/lmb 1288 end date mandatarissen #465

Merged
merged 17 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would name the argument isMandatarisEndDate or something, endOfDay could be anything so to speak

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is this is not exclusive to mandatarissen, so I do keep it a bit abstract so it is useful in other cases as well. e.g. for bestuursorganen in de tijd.

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(this.args.value).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"}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add a getter in the mandataris model for a formattedStartDate and end date?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context is always a bit different, so quite difficult to implement

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no lets keep this in the templates as is, it's nice to know what format you'll get there

</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
8 changes: 4 additions & 4 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()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you can just change the sign here. getTime returns the time since epoch in milliseconds. i don't think the equals matters right? And the logic is still good because the mandataris is still in function until the end of the day?

return this.mandatarisStatus.endedState;
}
return this.args.mandataris.status;
Expand Down Expand Up @@ -197,7 +198,7 @@ export default class MandatarissenUpdateState extends Component {
(await this.args.mandataris.vervangerVan) || [];
}

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

await this.mandatarisService.createNewLidmaatschap(
Expand All @@ -218,8 +219,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 @@ -12,6 +12,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 @@ -13,3 +13,7 @@ export const EXT = new Namespace('http://mu.semte.ch/vocabularies/ext/');
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 async function endOfDay(date) {
if (date) {
return moment(date).utc().add(1, 'days').startOf('day').toDate();
} else {
return moment().utc().add(1, 'days').startOf('day').toDate();
}
}

export async 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