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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Replace common service with specific scheduling service
Oliver Güntherd9232acd4ba4
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.tsindex 3cedfaa3d8c..bb14c7395bc 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@@ -51,11 +51,9 @@ import { ConfigurationService } from 'core-app/core/config/configuration.serviceimport { TimezoneService } from 'core-app/core/datetime/timezone.service';import { DayElement } from 'flatpickr/dist/types/instance';import flatpickr from 'flatpickr';-import { DatepickerModalService } from 'core-app/shared/components/datepicker/services/datepicker.modal.service';import {debounce,switchMap,- take,} from 'rxjs/operators';import { activeFieldContainerClassName } from 'core-app/shared/components/fields/edit/edit-form/edit-form';import {@@ -65,6 +63,14 @@ 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,+ onDayCreate,+ parseDate,+ setDates,+ validDate,+} from 'core-app/shared/components/datepicker/helpers/date-modal.helpers';export type DateKeys = 'start'|'end';export type DateFields = DateKeys|'duration';@@ -85,7 +91,7 @@ export type FieldUpdates =changeDetection: ChangeDetectionStrategy.OnPush,encapsulation: ViewEncapsulation.None,providers: [- DatepickerModalService,+ DateModalSchedulingService,DateModalRelationsService,],})@@ -96,7 +102,7 @@ export class MultiDateModalComponent extends OpModalComponent implements AfterVi@InjectField() halEditing:HalResourceEditingService;- @InjectField() datepickerService:DatepickerModalService;+ @InjectField() dateModalScheduling:DateModalSchedulingService;@InjectField() dateModalRelations:DateModalRelationsService;@@ -283,8 +289,8 @@ export class MultiDateModalComponent extends OpModalComponent implements AfterViupdateDate(key:DateKeys, val:string|null):void {// Expected minimal format YYYY-M-D => 8 characters OR emptyif (val !== null && (val.length >= 8 || val.length === 0)) {- if (this.datepickerService.validDate(val) && this.datePickerInstance) {- const dateValue = this.datepickerService.parseDate(val) || undefined;+ if (validDate(val) && this.datePickerInstance) {+ const dateValue = parseDate(val) || undefined;this.enforceManualChangesToDatepicker(false, dateValue);}}@@ -303,7 +309,7 @@ export class MultiDateModalComponent extends OpModalComponent implements AfterVi}setToday(key:DateKeys):void {- const today = this.datepickerService.parseDate(new Date());+ const today = parseDate(new Date());this.dates[key] = this.timezoneService.formattedISODate(today);if (today instanceof Date) {@@ -391,15 +397,13 @@ export class MultiDateModalComponent extends OpModalComponent implements AfterVithis.cdRef.detectChanges();},onDayCreate: (dObj:Date[], dStr:string, fp:flatpickr.Instance, dayElem:DayElement) => {- this- .datepickerService- .onDayCreate(- dayElem,- this.includeNonWorkingDays,- this.datePickerInstance?.weekdaysService.isNonWorkingDay(dayElem.dateObj),- minimalDate,- this.isDayDisabled(dayElem, minimalDate),- );+ onDayCreate(+ dayElem,+ this.includeNonWorkingDays,+ this.datePickerInstance?.weekdaysService.isNonWorkingDay(dayElem.dateObj),+ minimalDate,+ this.isDayDisabled(dayElem, minimalDate),+ );},},null,@@ -407,8 +411,8 @@ export class MultiDateModalComponent extends OpModalComponent implements AfterVi}private enforceManualChangesToDatepicker(toggleField = true, enforceDate?:Date) {- let startDate = this.datepickerService.parseDate(this.dates.start || '');- let endDate = this.datepickerService.parseDate(this.dates.end || '');+ let startDate = parseDate(this.dates.start || '');+ let endDate = parseDate(this.dates.end || '');if (startDate && endDate) {// If the start date is manually changed to be after the end date,@@ -428,7 +432,7 @@ export class MultiDateModalComponent extends OpModalComponent implements AfterVi}const dates = [startDate, endDate];- this.datepickerService.setDates(dates, this.datePickerInstance, enforceDate);+ setDates(dates, this.datePickerInstance, enforceDate);if (toggleField) {this.toggleCurrentActivatedField();@@ -449,8 +453,8 @@ export class MultiDateModalComponent extends OpModalComponent implements AfterVi3. Everything in between the current start and end date is dependent on the currently activated field.* */- const parsedStartDate = this.datepickerService.parseDate(this.dates.start || '') as Date;- const parsedEndDate = this.datepickerService.parseDate(this.dates.end || '') as Date;+ const parsedStartDate = parseDate(this.dates.start || '') as Date;+ const parsedEndDate = parseDate(this.dates.end || '') as Date;if (selectedDate < parsedStartDate) {this.overwriteDatePickerWithNewDates([selectedDate, parsedEndDate]);@@ -462,7 +466,7 @@ export class MultiDateModalComponent extends OpModalComponent implements AfterVithis.overwriteDatePickerWithNewDates([selectedDate, selectedDate]);this.toggleCurrentActivatedField();}- } else if (this.datepickerService.areDatesEqual(selectedDate, parsedStartDate) || this.datepickerService.areDatesEqual(selectedDate, parsedEndDate)) {+ } else if (areDatesEqual(selectedDate, parsedStartDate) || areDatesEqual(selectedDate, parsedEndDate)) {this.overwriteDatePickerWithNewDates([selectedDate, selectedDate]);} else {const newDates = this.isStateOfCurrentActivatedField('start') ? [selectedDate, parsedEndDate] : [parsedStartDate, selectedDate];@@ -501,7 +505,7 @@ export class MultiDateModalComponent extends OpModalComponent implements AfterVi}private overwriteDatePickerWithNewDates(dates:Date[]) {- this.datepickerService.setDates(dates, this.datePickerInstance);+ setDates(dates, this.datePickerInstance);this.handleDatePickerChange(dates);}@@ -544,10 +548,10 @@ export class MultiDateModalComponent extends OpModalComponent implements AfterVithis.includeNonWorkingDays = payload.ignoreNonWorkingDays;this.setDurationDaysFromUpstream(payload.duration);- const parsedStartDate = this.datepickerService.parseDate(this.dates.start) as Date;- const parsedEndDate = this.datepickerService.parseDate(this.dates.end) as Date;+ const parsedStartDate = parseDate(this.dates.start) as Date;+ const parsedEndDate = parseDate(this.dates.end) as Date;- this.datepickerService.setDates([parsedStartDate, parsedEndDate], this.datePickerInstance);+ setDates([parsedStartDate, parsedEndDate], this.datePickerInstance);this.cdRef.detectChanges();}diff --git a/frontend/src/app/shared/components/datepicker/services/date-modal-relations.service.ts b/frontend/src/app/shared/components/datepicker/services/date-modal-relations.service.tsindex 31166389991..a746c899f4c 100644--- a/frontend/src/app/shared/components/datepicker/services/date-modal-relations.service.ts+++ b/frontend/src/app/shared/components/datepicker/services/date-modal-relations.service.ts@@ -51,7 +51,7 @@ import {import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';import isNewResource from 'core-app/features/hal/helpers/is-new-resource';-import { DatepickerModalService } from 'core-app/shared/components/datepicker/services/datepicker.modal.service';+import { parseDate } from 'core-app/shared/components/datepicker/helpers/date-modal.helpers';@Injectable()export class DateModalRelationsService {@@ -102,7 +102,6 @@ export class DateModalRelationsService {constructor(@Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,private apiV3Service:ApiV3Service,- private datepickerService:DatepickerModalService,) {}getMinimalDateFromPreceeding():Observable<Date|null> {@@ -128,7 +127,7 @@ export class DateModalRelationsService {const relationDate = relation.dueDate || relation.date;// eslint-disable-next-line @typescript-eslint/no-non-null-assertion- const parsedRelationDate = this.datepickerService.parseDate(relationDate!);+ const parsedRelationDate = parseDate(relationDate!);if (!minimalDate || minimalDate < parsedRelationDate) {minimalDate = parsedRelationDate === '' ? null : parsedRelationDate;diff --git a/frontend/src/app/shared/components/datepicker/services/datepicker.modal.service.ts b/frontend/src/app/shared/components/datepicker/services/date-modal-scheduling.service.tssimilarity index 68%rename from frontend/src/app/shared/components/datepicker/services/datepicker.modal.service.tsrename to frontend/src/app/shared/components/datepicker/services/date-modal-scheduling.service.tsindex 5739b4aa292..9f9f8fcb4d0 100644--- a/frontend/src/app/shared/components/datepicker/services/datepicker.modal.service.ts+++ b/frontend/src/app/shared/components/datepicker/services/date-modal-scheduling.service.ts@@ -33,14 +33,32 @@ import {import { OpModalLocalsToken } from 'core-app/shared/components/modal/modal.service';import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';import { WorkPackageChangeset } from 'core-app/features/work-packages/components/wp-edit/work-package-changeset';+import { DateModalRelationsService } from 'core-app/shared/components/datepicker/services/date-modal-relations.service';+import { DayElement } from 'flatpickr/dist/types/instance';@Injectable()-export class DatepickerModalService {+export class DateModalSchedulingService {private changeset:WorkPackageChangeset = this.locals.changeset as WorkPackageChangeset;+ scheduleManually = !!this.changeset.value('scheduleManually');+constructor(@Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,+ readonly dateModalRelations:DateModalRelationsService,) {}+ toggleSchedulingMode():void {+ this.scheduleManually = !this.scheduleManually;+ }++ /**+ * 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);+ }}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.htmlindex 3ac528b9335..650c9afc010 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 @@<spot-text-fieldname="date"class="op-datepicker-modal--date-field"- [ngClass]="{ 'op-datepicker-modal--date-field_current': this.isSchedulable }"+ [ngClass]="{ 'op-datepicker-modal--date-field_current': this.dateModalScheduling.isSchedulable }"[(ngModel)]="date"(ngModelChange)="dateChangedManually$.next()"[showClearButton]="true"@@ -42,7 +42,7 @@</div></div><div class="form--field-extra-actions">- <a *ngIf="isSchedulable"+ <a *ngIf="dateModalScheduling.isSchedulable"(click)="setToday()"[textContent]="text.today"></a>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.tsindex be5f9b13add..dd89f6055c3 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@@ -51,7 +51,6 @@ import { ConfigurationService } from 'core-app/core/config/configuration.serviceimport { TimezoneService } from 'core-app/core/datetime/timezone.service';import { DayElement } from 'flatpickr/dist/types/instance';import flatpickr from 'flatpickr';-import { DatepickerModalService } from 'core-app/shared/components/datepicker/services/datepicker.modal.service';import {debounce,switchMap,@@ -66,7 +65,9 @@ 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 {+ onDayCreate,parseDate,+ setDates,validDate,} from 'core-app/shared/components/datepicker/helpers/date-modal.helpers';@@ -76,7 +77,7 @@ import {changeDetection: ChangeDetectionStrategy.OnPush,encapsulation: ViewEncapsulation.None,providers: [- DatepickerModalService,+ DateModalSchedulingService,DateModalRelationsService,],})@@ -87,7 +88,7 @@ export class SingleDateModalComponent extends OpModalComponent implements AfterV@InjectField() halEditing:HalResourceEditingService;- @InjectField() datepickerService:DatepickerModalService;+ @InjectField() dateModalScheduling:DateModalSchedulingService;@InjectField() dateModalRelations:DateModalRelationsService;@@ -154,7 +155,6 @@ export class SingleDateModalComponent extends OpModalComponent implements AfterVthis.changeset = locals.changeset as ResourceChangeset;this.htmlId = `wp-datepicker-${locals.fieldName as string}`;- this.scheduleManually = !!this.changeset.value('scheduleManually');this.includeNonWorkingDays = !!this.changeset.value('ignoreNonWorkingDays');this.date = this.changeset.value('date');@@ -192,7 +192,7 @@ export class SingleDateModalComponent extends OpModalComponent implements AfterV}changeSchedulingMode():void {- this.scheduleManually = !this.scheduleManually;+ this.dateModalScheduling.toggleSchedulingMode();this.initializeDatepicker();this.cdRef.detectChanges();}@@ -216,8 +216,8 @@ export class SingleDateModalComponent extends OpModalComponent implements AfterVthis.changeset.setValue('scheduleManually', this.scheduleManually);// Apply the dates if they could be changed- if (this.isSchedulable) {- this.changeset.setValue('date', this.date );+ if (this.dateModalScheduling.isSchedulable) {+ this.changeset.setValue('date', this.date);}this.closeMe();@@ -230,15 +230,15 @@ export class SingleDateModalComponent extends OpModalComponent implements AfterVupdateDate(val:string|null):void {// Expected minimal format YYYY-M-D => 8 characters OR emptyif (val !== null && (val.length >= 8 || val.length === 0)) {- if (this.datepickerService.validDate(val) && this.datePickerInstance) {- const dateValue = this.datepickerService.parseDate(val) || undefined;+ if (validDate(val) && this.datePickerInstance) {+ const dateValue = parseDate(val) || undefined;this.enforceManualChangesToDatepicker(dateValue);}}}setToday():void {- const today = this.datepickerService.parseDate(new Date()) as Date;+ const today = parseDate(new Date()) as Date;this.date = this.timezoneService.formattedISODate(today);this.enforceManualChangesToDatepicker(today);}@@ -253,13 +253,6 @@ export class SingleDateModalComponent extends OpModalComponent implements AfterV});}- /**- * Returns whether the user can alter the dates of the work package.- */- get isSchedulable():boolean {- return this.scheduleManually || !this.dateModalRelations.isParent;- }-private initializeDatepicker(minimalDate?:Date|null) {this.datePickerInstance?.destroy();this.datePickerInstance = new DatePicker(@@ -283,15 +276,13 @@ export class SingleDateModalComponent extends OpModalComponent implements AfterVthis.cdRef.detectChanges();},onDayCreate: (dObj:Date[], dStr:string, fp:flatpickr.Instance, dayElem:DayElement) => {- this- .datepickerService- .onDayCreate(- dayElem,- this.includeNonWorkingDays,- this.datePickerInstance?.weekdaysService.isNonWorkingDay(dayElem.dateObj),- minimalDate,- this.isDayDisabled(dayElem, minimalDate),- );+ onDayCreate(+ dayElem,+ this.includeNonWorkingDays,+ this.datePickerInstance?.weekdaysService.isNonWorkingDay(dayElem.dateObj),+ minimalDate,+ this.dateModalScheduling.isDayDisabled(dayElem, minimalDate),+ );},},null,@@ -299,18 +290,14 @@ export class SingleDateModalComponent extends OpModalComponent implements AfterV}private enforceManualChangesToDatepicker(enforceDate?:Date) {- const date = this.datepickerService.parseDate(this.date || '');- this.datepickerService.setDates(date, this.datePickerInstance, enforceDate);+ const date = parseDate(this.date || '');+ setDates(date, this.datePickerInstance, enforceDate);}private onDataChange() {this.onDataUpdated.emit(this.date || '');}- private isDayDisabled(dayElement:DayElement, minimalDate?:Date|null):boolean {- return !this.isSchedulable || (!this.scheduleManually && !!minimalDate && dayElement.dateObj <= minimalDate);- }-/*** Update the datepicker dates and properties from a form response* that includes derived/calculated values.@@ -324,7 +311,7 @@ export class SingleDateModalComponent extends OpModalComponent implements AfterVthis.date = payload.date;this.includeNonWorkingDays = payload.ignoreNonWorkingDays;- const parsedDate = this.datepickerService.parseDate(payload.date) as Date;+ const parsedDate = parseDate(payload.date) as Date;this.enforceManualChangesToDatepicker(parsedDate);}}