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

Keep minimumDate for scheduling when reinitializing datepicker

Oliver Günther6e13c592d2b8
diff --git a/frontend/src/app/shared/components/datepicker/helpers/date-modal.helpers.ts b/frontend/src/app/shared/components/datepicker/helpers/date-modal.helpers.ts
index 784dc72b663..beaf5cfe4be 100644
--- a/frontend/src/app/shared/components/datepicker/helpers/date-modal.helpers.ts
+++ b/frontend/src/app/shared/components/datepicker/helpers/date-modal.helpers.ts
@@ -104,15 +104,16 @@ export function onDayCreate(
isNonWorkingDay:boolean,
isDayDisabled:boolean,
):void {
- if (ignoreNonWorkingDays && isNonWorkingDay) {
- dayElem.classList.add('flatpickr-non-working-day_enabled');
- } else if (!ignoreNonWorkingDays && isNonWorkingDay) {
- dayElem.classList.add('flatpickr-non-working-day');
- }
+ dayElem.setAttribute('data-iso-date', dayElem.dateObj.toISOString());
if (isDayDisabled) {
dayElem.classList.add('flatpickr-disabled');
+ return;
}
- dayElem.setAttribute('data-iso-date', dayElem.dateObj.toISOString());
+ if (ignoreNonWorkingDays && isNonWorkingDay) {
+ dayElem.classList.add('flatpickr-non-working-day_enabled');
+ } else if (!ignoreNonWorkingDays && isNonWorkingDay) {
+ dayElem.classList.add('flatpickr-non-working-day');
+ }
}
diff --git a/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.ts b/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.ts
index 4805813af48..48bd9812144 100644
--- a/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.ts
+++ b/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.ts
@@ -228,6 +228,8 @@ export class OpWpMultiDateFormComponent extends UntilDestroyedMixin implements A
private formUpdates$ = new Subject<FieldUpdates>();
+ private minimalSchedulingDate:Date|null = null;
+
constructor(
readonly injector:Injector,
readonly cdRef:ChangeDetectorRef,
@@ -289,8 +291,8 @@ export class OpWpMultiDateFormComponent extends UntilDestroyedMixin implements A
}
ngAfterViewInit():void {
- const init = (date:Date|null) => {
- this.initializeDatepicker(date);
+ const init = () => {
+ this.initializeDatepicker();
// Autofocus duration if that's what activated us
if (this.initialActivatedField === 'duration') {
@@ -299,14 +301,17 @@ export class OpWpMultiDateFormComponent extends UntilDestroyedMixin implements A
};
if (isNewResource(this.changeset.pristineResource)) {
- init(null);
+ init();
return;
}
this
.dateModalRelations
.getMinimalDateFromPreceeding()
- .subscribe((date) => init(date));
+ .subscribe((date) => {
+ this.minimalSchedulingDate = date;
+ init();
+ });
}
changeSchedulingMode():void {
@@ -459,7 +464,7 @@ export class OpWpMultiDateFormComponent extends UntilDestroyedMixin implements A
this.enforceManualChangesToDatepicker();
}
- private initializeDatepicker(minimalDate?:Date|null) {
+ private initializeDatepicker() {
this.datePickerInstance?.destroy();
this.datePickerInstance = new DatePicker(
this.injector,
@@ -499,7 +504,7 @@ export class OpWpMultiDateFormComponent extends UntilDestroyedMixin implements A
dayElem,
this.ignoreNonWorkingDays,
await this.datePickerInstance?.isNonWorkingDay(dayElem.dateObj),
- this.isDayDisabled(dayElem, minimalDate),
+ this.isDayDisabled(dayElem, this.minimalSchedulingDate),
);
},
},
diff --git a/spec/features/work_packages/datepicker/datepicker_follows_relation_spec.rb b/spec/features/work_packages/datepicker/datepicker_follows_relation_spec.rb
new file mode 100644
index 00000000000..a8c0979ce84
--- /dev/null
+++ b/spec/features/work_packages/datepicker/datepicker_follows_relation_spec.rb
@@ -0,0 +1,84 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require 'spec_helper'
+require 'support/edit_fields/edit_field'
+
+describe 'Datepicker logic on follow relationships',
+ js: true,
+ with_settings: { date_format: '%Y-%m-%d' } do
+ shared_let(:user) { create(:admin) }
+
+ shared_let(:type) { create(:type_bug) }
+ shared_let(:project) { create(:project, types: [type]) }
+ shared_let(:predecessor) do
+ create(:work_package,
+ type:, project:,
+ start_date: Date.parse('2023-02-01'),
+ due_date: Date.parse('2023-02-05'))
+ end
+ shared_let(:follower) { create(:work_package, type:, project:) }
+
+ shared_let(:relation) { create(:follows_relation, from: follower, to: predecessor) }
+
+ let(:work_packages_page) { Pages::FullWorkPackage.new(follower) }
+ let(:date_field) { work_packages_page.edit_field(:combinedDate) }
+ let(:datepicker) { date_field.datepicker }
+
+ before do
+ login_as(user)
+
+ work_packages_page.visit!
+ work_packages_page.ensure_page_loaded
+
+ date_field.activate!
+ date_field.expect_active!
+ # Wait for the datepicker to be initialized
+ datepicker.expect_visible
+ end
+
+ it 'keeps the minimum date from the predecessor when toggling NWD (Regression #46375)' do
+ datepicker.expect_ignore_non_working_days false
+ datepicker.expect_scheduling_mode false
+
+ datepicker.show_date '2023-02-05'
+ datepicker.expect_disabled Date.parse('2023-02-05')
+ datepicker.expect_disabled Date.parse('2023-02-04')
+ datepicker.expect_disabled Date.parse('2023-02-03')
+ datepicker.expect_disabled Date.parse('2023-02-02')
+ datepicker.expect_disabled Date.parse('2023-02-01')
+
+ datepicker.toggle_ignore_non_working_days
+ datepicker.expect_ignore_non_working_days true
+ datepicker.expect_disabled Date.parse('2023-02-05')
+ datepicker.expect_disabled Date.parse('2023-02-04')
+ datepicker.expect_disabled Date.parse('2023-02-03')
+ datepicker.expect_disabled Date.parse('2023-02-02')
+ datepicker.expect_disabled Date.parse('2023-02-01')
+ end
+end