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

Always jump to manually added dates except if the new month is already shown due to the two-month layout

Henriette Darge4c3b952869ed
diff --git a/frontend/src/app/shared/components/datepicker/datepicker.modal.service.ts b/frontend/src/app/shared/components/datepicker/datepicker.modal.service.ts
index 0d0b3aef938..2a4c55e02b1 100644
--- a/frontend/src/app/shared/components/datepicker/datepicker.modal.service.ts
+++ b/frontend/src/app/shared/components/datepicker/datepicker.modal.service.ts
@@ -209,15 +209,27 @@ export class DatepickerModalService {
/* eslint-disable no-param-reassign */
if (enforceDate) {
- datePicker.datepickerInstance.currentMonth = enforceDate.getMonth();
- datePicker.datepickerInstance.currentYear = enforceDate.getFullYear();
+ const enforcedMonth = enforceDate.getMonth();
+ const enforcedYear = enforceDate.getFullYear();
+ const monthDiff = enforcedMonth - currentMonth + 12 * (enforcedYear - currentYear);
+
+ if (Math.abs(monthDiff) > 1) {
+ datePicker.datepickerInstance.currentMonth = enforcedMonth;
+ datePicker.datepickerInstance.currentYear = enforcedYear;
+ } else {
+ this.keepCurrentlyActiveMonth(datePicker, currentMonth, currentYear);
+ }
} else {
- // Keep currently active month and avoid jump because of two-month layout
- datePicker.datepickerInstance.currentMonth = currentMonth;
- datePicker.datepickerInstance.currentYear = currentYear;
+ this.keepCurrentlyActiveMonth(datePicker, currentMonth, currentYear);
}
datePicker.datepickerInstance.redraw();
/* eslint-enable no-param-reassign */
}
+
+ private keepCurrentlyActiveMonth(datePicker:DatePicker, currentMonth:number, currentYear:number) {
+ // Keep currently active month and avoid jump because of two-month layout
+ datePicker.datepickerInstance.currentMonth = currentMonth;
+ datePicker.datepickerInstance.currentYear = currentYear;
+ }
}
diff --git a/frontend/src/app/shared/components/datepicker/datepicker.modal.ts b/frontend/src/app/shared/components/datepicker/datepicker.modal.ts
index f7cfe5041f0..ca4f2410098 100644
--- a/frontend/src/app/shared/components/datepicker/datepicker.modal.ts
+++ b/frontend/src/app/shared/components/datepicker/datepicker.modal.ts
@@ -177,7 +177,8 @@ export class DatePickerModalComponent extends OpModalComponent implements AfterV
if (val.length >= 8 || val.length === 0) {
this.dates[key] = val;
if (this.datepickerService.validDate(val) && this.datePickerInstance) {
- this.enforceManualChangesToDatepicker(false);
+ const dateValue = this.datepickerService.parseDate(val) || undefined;
+ this.enforceManualChangesToDatepicker(false, dateValue);
}
}
}