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

Fix manual scheduling toggle on parent

Oliver Güntherbd4c160d6fef
diff --git a/frontend/src/app/shared/components/datepicker/multi-date-modal/multi-date.modal.ts b/frontend/src/app/shared/components/datepicker/multi-date-modal/multi-date.modal.ts
index 78dfb33bfb4..036d9ad1deb 100644
--- a/frontend/src/app/shared/components/datepicker/multi-date-modal/multi-date.modal.ts
+++ b/frontend/src/app/shared/components/datepicker/multi-date-modal/multi-date.modal.ts
@@ -66,7 +66,6 @@ import {
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { FormResource } from 'core-app/features/hal/resources/form-resource';
import { DateModalRelationsService } from 'core-app/shared/components/datepicker/services/date-modal-relations.service';
-import { DateModalSchedulingService } from 'core-app/shared/components/datepicker/services/date-modal-scheduling.service';
import {
areDatesEqual,
mappedDate,
@@ -103,7 +102,6 @@ export type FieldUpdates =
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
providers: [
- DateModalSchedulingService,
DateModalRelationsService,
],
})
@@ -114,8 +112,6 @@ export class MultiDateModalComponent extends OpModalComponent implements AfterVi
@InjectField() halEditing:HalResourceEditingService;
- @InjectField() dateModalScheduling:DateModalSchedulingService;
-
@InjectField() dateModalRelations:DateModalRelationsService;
@InjectField() deviceService:DeviceService;
@@ -505,7 +501,7 @@ export class MultiDateModalComponent extends OpModalComponent implements AfterVi
this.ignoreNonWorkingDays,
await this.datePickerInstance?.isNonWorkingDay(dayElem.dateObj),
minimalDate,
- this.dateModalScheduling.isDayDisabled(dayElem, minimalDate),
+ this.isDayDisabled(dayElem, minimalDate),
);
},
},
diff --git a/frontend/src/app/shared/components/datepicker/single-date-modal/single-date.modal.html b/frontend/src/app/shared/components/datepicker/single-date-modal/single-date.modal.html
index 8a805f2702f..ea1aa243f00 100644
--- a/frontend/src/app/shared/components/datepicker/single-date-modal/single-date.modal.html
+++ b/frontend/src/app/shared/components/datepicker/single-date-modal/single-date.modal.html
@@ -34,7 +34,7 @@
slot="input"
name="date"
class="op-datepicker-modal--date-field"
- [ngClass]="{ 'op-datepicker-modal--date-field_current': this.dateModalScheduling.isSchedulable }"
+ [ngClass]="{ 'op-datepicker-modal--date-field_current': this.isSchedulable }"
[(ngModel)]="date"
(ngModelChange)="dateChangedManually$.next()"
[showClearButton]="true"
@@ -43,7 +43,7 @@
slot="action"
type="button"
class="spot-link"
- [ngClass]="{ 'op-datepicker-modal--hidden-link': !dateModalScheduling.isSchedulable }"
+ [ngClass]="{ 'op-datepicker-modal--hidden-link': !isSchedulable }"
(click)="setToday()"
[textContent]="text.today">
</button>
diff --git a/frontend/src/app/shared/components/datepicker/single-date-modal/single-date.modal.ts b/frontend/src/app/shared/components/datepicker/single-date-modal/single-date.modal.ts
index 1f82bf30694..4ae08a58ebe 100644
--- a/frontend/src/app/shared/components/datepicker/single-date-modal/single-date.modal.ts
+++ b/frontend/src/app/shared/components/datepicker/single-date-modal/single-date.modal.ts
@@ -63,7 +63,6 @@ import {
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { FormResource } from 'core-app/features/hal/resources/form-resource';
import { DateModalRelationsService } from 'core-app/shared/components/datepicker/services/date-modal-relations.service';
-import { DateModalSchedulingService } from 'core-app/shared/components/datepicker/services/date-modal-scheduling.service';
import {
mappedDate,
onDayCreate,
@@ -79,7 +78,6 @@ import { DeviceService } from 'core-app/core/browser/device.service';
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
providers: [
- DateModalSchedulingService,
DateModalRelationsService,
],
})
@@ -90,8 +88,6 @@ export class SingleDateModalComponent extends OpModalComponent implements AfterV
@InjectField() halEditing:HalResourceEditingService;
- @InjectField() dateModalScheduling:DateModalSchedulingService;
-
@InjectField() dateModalRelations:DateModalRelationsService;
@InjectField() deviceService:DeviceService;
@@ -196,6 +192,17 @@ export class SingleDateModalComponent extends OpModalComponent implements AfterV
this.cdRef.detectChanges();
}
+ /**
+ * Returns whether the user can alter the dates of the work package.
+ */
+ get isSchedulable():boolean {
+ return this.scheduleManually || !this.dateModalRelations.isParent;
+ }
+
+ isDayDisabled(dayElement:DayElement, minimalDate?:Date|null):boolean {
+ return !this.isSchedulable || (!this.scheduleManually && !!minimalDate && dayElement.dateObj <= minimalDate);
+ }
+
changeNonWorkingDays():void {
this.initializeDatepicker();
@@ -217,7 +224,7 @@ export class SingleDateModalComponent extends OpModalComponent implements AfterV
this.changeset.setValue('ignoreNonWorkingDays', this.ignoreNonWorkingDays);
// Apply the dates if they could be changed
- if (this.dateModalScheduling.isSchedulable) {
+ if (this.isSchedulable) {
this.changeset.setValue('date', mappedDate(this.date));
}
@@ -288,7 +295,7 @@ export class SingleDateModalComponent extends OpModalComponent implements AfterV
this.ignoreNonWorkingDays,
await this.datePickerInstance?.isNonWorkingDay(dayElem.dateObj),
minimalDate,
- this.dateModalScheduling.isDayDisabled(dayElem, minimalDate),
+ this.isDayDisabled(dayElem, minimalDate),
);
},
},
diff --git a/spec/features/work_packages/datepicker/datepicker_parent_spec.rb b/spec/features/work_packages/datepicker/datepicker_parent_spec.rb
index 8a5fe7a82ec..fc01e640547 100644
--- a/spec/features/work_packages/datepicker/datepicker_parent_spec.rb
+++ b/spec/features/work_packages/datepicker/datepicker_parent_spec.rb
@@ -75,6 +75,15 @@ describe 'Datepicker logic on parents',
it 'disables the non working days options' do
datepicker.expect_ignore_non_working_days_disabled
+ datepicker.expect_scheduling_mode false
+
+ first_monday = Time.zone.today.beginning_of_month.next_occurring(:monday)
+ datepicker.expect_disabled(first_monday)
+
+ datepicker.toggle_scheduling_mode
+ datepicker.expect_scheduling_mode true
+
+ datepicker.expect_not_disabled(first_monday)
end
end
end
diff --git a/spec/support/components/datepicker/datepicker.rb b/spec/support/components/datepicker/datepicker.rb
index 6715f064f8c..898cf6263af 100644
--- a/spec/support/components/datepicker/datepicker.rb
+++ b/spec/support/components/datepicker/datepicker.rb
@@ -117,5 +117,29 @@ module Components
expect(page).to have_selector(".flatpickr-day.flatpickr-non-working-day[aria-label='#{label}']",
wait: 20)
end
+
+ ##
+ # Expect the given date to be non working
+ def expect_working(date)
+ label = date.strftime('%B %-d, %Y')
+ expect(page).to have_selector(".flatpickr-day:not(.flatpickr-non-working-day)[aria-label='#{label}']",
+ wait: 20)
+ end
+
+ ##
+ # Expect the given date to be non working
+ def expect_disabled(date)
+ label = date.strftime('%B %-d, %Y')
+ expect(page).to have_selector(".flatpickr-day.flatpickr-disabled[aria-label='#{label}']",
+ wait: 20)
+ end
+
+ ##
+ # Expect the given date to be non working
+ def expect_not_disabled(date)
+ label = date.strftime('%B %-d, %Y')
+ expect(page).to have_selector(".flatpickr-day:not(.flatpickr-disabled)[aria-label='#{label}']",
+ wait: 20)
+ end
end
end