Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add special logic for edge case in which only one date is given and the user wants to modify exactly that

Henriette Dargec04486c8693d
diff --git a/frontend/src/app/shared/components/datepicker/wp-modal-date-picker/wp-modal-date-picker.component.ts b/frontend/src/app/shared/components/datepicker/wp-modal-date-picker/wp-modal-date-picker.component.ts
index 23c63827926..3bec749ed47 100644
--- a/frontend/src/app/shared/components/datepicker/wp-modal-date-picker/wp-modal-date-picker.component.ts
+++ b/frontend/src/app/shared/components/datepicker/wp-modal-date-picker/wp-modal-date-picker.component.ts
@@ -107,6 +107,7 @@ export class OpWpModalDatePickerComponent extends UntilDestroyedMixin implements
this.initializeDatepickerSubject.next();
document.addEventListener('date-picker:input-changed', this.changeListener.bind(this));
+ document.addEventListener('date-picker:input-focused', this.focusListener.bind(this));
}
// eslint-disable-next-line @angular-eslint/use-lifecycle-interface
@@ -114,6 +115,7 @@ export class OpWpModalDatePickerComponent extends UntilDestroyedMixin implements
super.ngOnDestroy();
document.removeEventListener('date-picker:input-changed', this.changeListener.bind(this));
+ document.removeEventListener('date-picker:input-focused', this.focusListener.bind(this));
}
changeListener(event:CustomEvent) {
@@ -138,6 +140,17 @@ export class OpWpModalDatePickerComponent extends UntilDestroyedMixin implements
this.initializeDatepickerSubject.next();
}
+ focusListener(event:CustomEvent) {
+ const details = (event.detail as { field:string });
+
+ if (`work_package[${this.fieldName}]` !== details.field) {
+ // In case a different field is focused, we re-initialize the datepicker to allow for example
+ // * disabling different dates
+ // * switching between single and range mode in certain edge case (see getter for mode below)
+ this.initializeDatepickerSubject.next();
+ }
+ }
+
private toDate(date:string):Date|null {
if (date) {
return new Date(date);
@@ -151,6 +164,7 @@ export class OpWpModalDatePickerComponent extends UntilDestroyedMixin implements
private initializeDatepicker() {
this.datePickerInstance?.destroy();
+ this.fieldName = this.getActiveField();
const ignoreNonWorkingDaysTemp = this.ignoreNonWorkingDays;
this.datePickerInstance = new DatePicker(
@@ -158,7 +172,7 @@ export class OpWpModalDatePickerComponent extends UntilDestroyedMixin implements
'#flatpickr-input',
this.currentDates(),
{
- mode: this.isMilestone ? 'single' : 'range',
+ mode: this.mode,
showMonths: this.deviceService.isMobile ? 1 : 2,
inline: true,
onReady: (_date, _datestr, instance) => {
@@ -182,6 +196,22 @@ export class OpWpModalDatePickerComponent extends UntilDestroyedMixin implements
);
}
+ private get mode():'single'|'range' {
+ if (this.isMilestone) {
+ return 'single';
+ }
+
+ // This is a very special case in which only one date is set, and we want to modify exactly that date again.
+ // Then it does not make sense to display a range as we are only changing one date
+ if (this.currentDates().length === 1) {
+ if ((this.startDate !== null && this.fieldName === 'start_date') || (this.dueDate !== null && this.fieldName === 'due_date')) {
+ return 'single';
+ }
+ }
+
+ return 'range';
+ }
+
private onFlatpickrChange(dates:Date[], _datestr:string, instance:flatpickr.Instance) {
this.fieldName = this.getActiveField();
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts
index cb9c5a18a91..9ca48678975 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts
@@ -91,8 +91,16 @@ export default class PreviewController extends DialogPreviewController {
},
);
- (newHighlightedField as HTMLElement).classList.add('op-datepicker-modal--date-field_current');
- (newHighlightedField as HTMLElement).dataset.qaHighlighted = 'true';
+ (newHighlightedField as HTMLInputElement).classList.add('op-datepicker-modal--date-field_current');
+ (newHighlightedField as HTMLInputElement).dataset.qaHighlighted = 'true';
+
+ document.dispatchEvent(
+ new CustomEvent('date-picker:input-focused', {
+ detail: {
+ field: (newHighlightedField as HTMLInputElement).name,
+ },
+ }),
+ );
}
}