Fix manual scheduling toggle on parent

pull/11978/merge
Oliver Günther 2 years ago
parent 83b5aea12c
commit bd4c160d6f
  1. 6
      frontend/src/app/shared/components/datepicker/multi-date-modal/multi-date.modal.ts
  2. 4
      frontend/src/app/shared/components/datepicker/single-date-modal/single-date.modal.html
  3. 19
      frontend/src/app/shared/components/datepicker/single-date-modal/single-date.modal.ts
  4. 9
      spec/features/work_packages/datepicker/datepicker_parent_spec.rb
  5. 24
      spec/support/components/datepicker/datepicker.rb

@ -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),
);
},
},

@ -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>

@ -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),
);
},
},

@ -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

@ -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

Loading…
Cancel
Save