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

Pass `date_mode` from existing parameter into the component instead of trying to recalculate it again

Henriette Darged6dbb4e4408d
diff --git a/app/components/work_packages/date_picker/form_content_component.html.erb b/app/components/work_packages/date_picker/form_content_component.html.erb
index 7f1c31177d3..8869db9ad61 100644
--- a/app/components/work_packages/date_picker/form_content_component.html.erb
+++ b/app/components/work_packages/date_picker/form_content_component.html.erb
@@ -82,6 +82,7 @@
schedule_manually:,
is_schedulable: !disabled?,
is_milestone: milestone?,
+ date_mode:,
start_date_field_id: "work_package_start_date",
due_date_field_id: "work_package_due_date",
duration_field_id: "work_package_duration"
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 524b4c3ec37..55ef8c2f864 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
@@ -51,6 +51,8 @@ import { fromEvent } from 'rxjs';
import { filter } from 'rxjs/operators';
import * as _ from 'lodash';
+export type DateMode = 'single'|'range';
+
@Component({
selector: 'op-wp-modal-date-picker',
template: `
@@ -70,6 +72,7 @@ export class OpWpModalDatePickerComponent extends UntilDestroyedMixin implements
@Input() public isSchedulable:boolean = true;
@Input() public minimalSchedulingDate:Date|null;
+ @Input() public dateMode:DateMode;
@Input() startDateFieldId:string;
@Input() dueDateFieldId:string;
@@ -79,8 +82,6 @@ export class OpWpModalDatePickerComponent extends UntilDestroyedMixin implements
@ViewChild('flatpickrTarget') flatpickrTarget:ElementRef;
- fieldName:'start_date'|'due_date'|'duration' = 'start_date';
-
private datePickerInstance:DatePicker;
private startDateValue:Date|null;
private dueDateValue:Date|null;
@@ -119,7 +120,7 @@ export class OpWpModalDatePickerComponent extends UntilDestroyedMixin implements
event:CustomEvent<{
dates:Date[];
ignoreNonWorkingDays:boolean;
- mode:'single'|'range';
+ mode:DateMode;
}>,
) {
const details = event.detail;
@@ -138,7 +139,7 @@ export class OpWpModalDatePickerComponent extends UntilDestroyedMixin implements
}
}
- private isDifferentDates(dates:Date[], mode:'single'|'range'):boolean {
+ private isDifferentDates(dates:Date[], mode:DateMode):boolean {
const [start, end] = dates;
return mode === 'single'
? start.getTime() !== this.startDateValue?.getTime()
@@ -155,14 +156,13 @@ export class OpWpModalDatePickerComponent extends UntilDestroyedMixin implements
private initializeDatepicker() {
this.datePickerInstance?.destroy();
- this.fieldName = this.getActiveField();
this.datePickerInstance = new DatePicker(
this.injector,
'#flatpickr-input',
this.currentDates(),
{
- mode: this.mode,
+ mode: this.dateMode,
showMonths: this.deviceService.isMobile ? 1 : 2,
inline: true,
onReady: (_date, _datestr, instance) => {
@@ -186,22 +186,6 @@ 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.startDateValue !== null && this.fieldName === 'start_date') || (this.dueDateValue !== null && this.fieldName === 'due_date')) {
- return 'single';
- }
- }
-
- return 'range';
- }
-
private onFlatpickrChange(dates:Date[], _datestr:string, _instance:flatpickr.Instance) {
document.dispatchEvent(
new CustomEvent('date-picker:flatpickr-dates-changed', {
@@ -237,21 +221,4 @@ export class OpWpModalDatePickerComponent extends UntilDestroyedMixin implements
)
.subscribe(() => calendarContainer.classList.add('flatpickr-container-suppress-hover'));
}
-
- private getActiveField():'start_date'|'due_date'|'duration' {
- const activeField = document.getElementsByClassName('op-datepicker-modal--date-field_current')[0];
-
- if (!activeField) {
- return this.fieldName;
- }
-
- switch (activeField.id) {
- case this.dueDateFieldId:
- return 'due_date';
- case this.durationFieldId:
- return 'duration';
- default:
- return 'start_date';
- }
- }
}