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

Handle Milestones in new datepicker modal

Henriette Darge5745e78b36cd
diff --git a/app/components/work_packages/date_picker/dialog_content_component.html.erb b/app/components/work_packages/date_picker/dialog_content_component.html.erb
index 5d86879e897..68b5c74f1c9 100644
--- a/app/components/work_packages/date_picker/dialog_content_component.html.erb
+++ b/app/components/work_packages/date_picker/dialog_content_component.html.erb
@@ -88,6 +88,7 @@
ignore_non_working_days: work_package.ignore_non_working_days,
schedule_manually:,
is_schedulable: !disabled?,
+ is_milestone: work_package.is_milestone?,
field_name: focused_field,
start_date_field_id: "work_package_start_date",
due_date_field_id: "work_package_due_date"
diff --git a/app/controllers/work_packages/date_picker_controller.rb b/app/controllers/work_packages/date_picker_controller.rb
index bcc6f07fdc1..debb58ec950 100644
--- a/app/controllers/work_packages/date_picker_controller.rb
+++ b/app/controllers/work_packages/date_picker_controller.rb
@@ -141,6 +141,8 @@ class WorkPackages::DatePickerController < ApplicationController
def work_package_datepicker_params
if params[:work_package]
+ handle_milestone_dates
+
params.require(:work_package)
.slice(*allowed_touched_params)
.merge(schedule_manually:)
@@ -171,4 +173,12 @@ class WorkPackages::DatePickerController < ApplicationController
.call(wp_params)
end
end
+
+ def handle_milestone_dates
+ if work_package.is_milestone?
+ # Set the dueDate as the SetAttributesService will otherwise throw an error because the fields do not match
+ params.require(:work_package)[:due_date] = params.require(:work_package)[:start_date]
+ params.require(:work_package)[:due_date_touched] = "true"
+ end
+ end
end
diff --git a/app/forms/work_packages/date_picker/form.rb b/app/forms/work_packages/date_picker/form.rb
index 787007ff150..294e634f005 100644
--- a/app/forms/work_packages/date_picker/form.rb
+++ b/app/forms/work_packages/date_picker/form.rb
@@ -55,6 +55,7 @@ module WorkPackages
super()
@work_package = work_package
+ @is_milestone = work_package.milestone?
@focused_field = focused_field_by_selection(focused_field)
@touched_field_map = touched_field_map
@disabled = disabled
@@ -62,13 +63,21 @@ module WorkPackages
form do |query_form|
query_form.group(layout: :horizontal) do |group|
- text_field(group, name: :start_date, label: I18n.t("attributes.start_date"))
- text_field(group, name: :due_date, label: I18n.t("attributes.due_date"))
- text_field(group, name: :duration, label: I18n.t("activerecord.attributes.work_package.duration"), disabled: false)
- hidden_touched_field(group, name: :start_date)
- hidden_touched_field(group, name: :due_date)
- hidden_touched_field(group, name: :duration)
+ if @is_milestone
+ text_field(group, name: :start_date, label: I18n.t("attributes.date"))
+
+ hidden_touched_field(group, name: :start_date)
+ else
+ text_field(group, name: :start_date, label: I18n.t("attributes.start_date"))
+ text_field(group, name: :due_date, label: I18n.t("attributes.due_date"))
+ text_field(group, name: :duration, label: I18n.t("activerecord.attributes.work_package.duration"))
+
+ hidden_touched_field(group, name: :start_date)
+ hidden_touched_field(group, name: :due_date)
+ hidden_touched_field(group, name: :duration)
+ end
+
hidden_touched_field(group, name: :ignore_non_working_days)
group.fields_for(:initial) do |builder|
diff --git a/frontend/src/app/shared/components/datepicker/datepicker.module.ts b/frontend/src/app/shared/components/datepicker/datepicker.module.ts
index 5c422abc728..dc22fd0861e 100644
--- a/frontend/src/app/shared/components/datepicker/datepicker.module.ts
+++ b/frontend/src/app/shared/components/datepicker/datepicker.module.ts
@@ -8,7 +8,6 @@ import { CommonModule } from '@angular/common';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { OpModalSingleDatePickerComponent } from './modal-single-date-picker/modal-single-date-picker.component';
-import { OpWpSingleDateFormComponent } from './wp-single-date-form/wp-single-date-form.component';
import { OpBasicDatePickerModule } from './basic-datepicker.module';
import { OpSpotModule } from 'core-app/spot/spot.module';
import { OpenprojectModalModule } from '../modal/modal.module';
@@ -34,14 +33,12 @@ import { OpWpModalDatePickerComponent } from 'core-app/shared/components/datepic
declarations: [
OpModalSingleDatePickerComponent,
- OpWpSingleDateFormComponent,
OpDatePickerSheetComponent,
OpWpModalDatePickerComponent,
],
exports: [
OpModalSingleDatePickerComponent,
- OpWpSingleDateFormComponent,
OpBasicDatePickerModule,
OpDatePickerSheetComponent,
OpWpModalDatePickerComponent,
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 b3f23b08ee1..13f5db94c86 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
@@ -77,6 +77,8 @@ export class OpWpModalDatePickerComponent extends UntilDestroyedMixin implements
@Input() startDateFieldId:string;
@Input() dueDateFieldId:string;
+ @Input() isMilestone:boolean = false;
+
@ViewChild('flatpickrTarget') flatpickrTarget:ElementRef;
private datePickerInstance:DatePicker;
@@ -136,9 +138,9 @@ export class OpWpModalDatePickerComponent extends UntilDestroyedMixin implements
this.datePickerInstance = new DatePicker(
this.injector,
'#flatpickr-input',
- [this.startDate || '', this.dueDate || ''],
+ this.isMilestone ? this.startDate : [this.startDate || '', this.dueDate || ''],
{
- mode: 'range',
+ mode: this.isMilestone ? 'single' : 'range',
showMonths: this.deviceService.isMobile ? 1 : 2,
inline: true,
onReady: (_date, _datestr, instance) => {
@@ -147,17 +149,24 @@ export class OpWpModalDatePickerComponent extends UntilDestroyedMixin implements
this.ensureHoveredSelection(instance.calendarContainer);
},
onChange: (dates:Date[], _datestr, instance) => {
- if (this.fieldName === 'due_date') {
+ if (this.isMilestone) {
+ this.startDate = dates[0];
+ this.setDateFieldAndFocus(this.startDate, this.startDateFieldId, null);
+
+ instance.setDate(this.startDate);
+ } else if (this.fieldName === 'due_date') {
this.dueDate = dates[0];
this.setDateFieldAndFocus(this.dueDate, this.dueDateFieldId, this.startDateFieldId);
this.fieldName = 'start_date';
+
+ instance.setDate([this.startDate, this.dueDate]);
} else {
this.startDate = dates[0];
this.setDateFieldAndFocus(this.startDate, this.startDateFieldId, this.dueDateFieldId);
this.fieldName = 'due_date';
- }
- instance.setDate([this.startDate, this.dueDate]);
+ instance.setDate([this.startDate, this.dueDate]);
+ }
},
// eslint-disable-next-line @typescript-eslint/no-misused-promises
onDayCreate: async (dObj:Date[], dStr:string, fp:flatpickr.Instance, dayElem:DayElement) => {
diff --git a/frontend/src/app/shared/components/datepicker/wp-single-date-form/wp-single-date-form.component.html b/frontend/src/app/shared/components/datepicker/wp-single-date-form/wp-single-date-form.component.html
deleted file mode 100644
index 78876389694..00000000000
--- a/frontend/src/app/shared/components/datepicker/wp-single-date-form/wp-single-date-form.component.html
+++ /dev/null
@@ -1,78 +0,0 @@
-<form
- class="spot-container op-datepicker-modal"
- data-test-selector="op-datepicker-modal"
- [attr.id]="htmlId"
- #modalContainer
- data-indicator-name="modal"
- (submit)="doSave($event)"
- tabindex="0"
->
-<!-- TODO <op-datepicker-banner
- [scheduleManually]="scheduleManually"
- class="op-datepicker-modal&#45;&#45;banner"
- ></op-datepicker-banner>-->
-
- <div class="spot-container op-datepicker-modal--stretch-content">
-<!-- TODO
- <op-datepicker-scheduling-toggle
- class="spot-form-field"
- name="scheduleManually"
- [(ngModel)]="scheduleManually"
- (ngModelChange)="changeSchedulingMode()"
- ></op-datepicker-scheduling-toggle>
--->
-
- <op-datepicker-working-days-toggle
- class="spot-form-field"
- name="ignoreNonWorkingDays"
- [(ngModel)]="ignoreNonWorkingDays"
- (ngModelChange)="changeNonWorkingDays()"
- ></op-datepicker-working-days-toggle>
-
- <spot-form-field
- [label]="text.date"
- >
- <spot-text-field
- slot="input"
- name="date"
- class="op-datepicker-modal--date-field"
- [ngClass]="{ 'op-datepicker-modal--date-field_current': isSchedulable }"
- [(ngModel)]="date"
- (ngModelChange)="dateChangedManually$.next()"
- [showClearButton]="true"
- ></spot-text-field>
- <button
- slot="action"
- type="button"
- class="spot-link"
- [ngClass]="{ 'op-datepicker-modal--hidden-link': !isSchedulable }"
- (click)="setToday()"
- [textContent]="text.today">
- </button>
- </spot-form-field>
-
- <input
- #flatpickrTarget
- id="flatpickr-input"
- hidden
- >
- </div>
-
- <div class="spot-action-bar">
- <div class="spot-action-bar--right">
- <button
- type="button"
- (click)="doCancel()"
- class="spot-modal--cancel-button button spot-action-bar--action"
- data-test-selector="op-datepicker-modal--action"
- [textContent]="text.cancel"
- ></button>
- <button
- type="submit"
- class="button -primary spot-action-bar--action"
- data-test-selector="op-datepicker-modal--action"
- [textContent]="text.save"
- ></button>
- </div>
- </div>
-</form>
diff --git a/frontend/src/app/shared/components/datepicker/wp-single-date-form/wp-single-date-form.component.sass b/frontend/src/app/shared/components/datepicker/wp-single-date-form/wp-single-date-form.component.sass
deleted file mode 100644
index 1980fd09996..00000000000
--- a/frontend/src/app/shared/components/datepicker/wp-single-date-form/wp-single-date-form.component.sass
+++ /dev/null
@@ -1,6 +0,0 @@
-.op-wp-single-date-form
- height: 100%
- .op-modal-banner
- grid-template-columns: auto max-content !important
- .spot-icon, .op-modal-banner--subtitle
- display: none
\ No newline at end of file
diff --git a/frontend/src/app/shared/components/datepicker/wp-single-date-form/wp-single-date-form.component.ts b/frontend/src/app/shared/components/datepicker/wp-single-date-form/wp-single-date-form.component.ts
deleted file mode 100644
index da53a7a9408..00000000000
--- a/frontend/src/app/shared/components/datepicker/wp-single-date-form/wp-single-date-form.component.ts
+++ /dev/null
@@ -1,304 +0,0 @@
-//-- copyright
-// OpenProject is an open source project management software.
-// Copyright (C) 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.
-//++
-
-import {
- AfterViewInit,
- ChangeDetectionStrategy,
- ChangeDetectorRef,
- Component,
- ElementRef,
- EventEmitter,
- OnInit,
- Injector,
- Input,
- Output,
- ViewChild,
- ViewEncapsulation,
- HostBinding,
-} from '@angular/core';
-import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { DatePicker } from 'core-app/shared/components/datepicker/datepicker';
-import { HalResourceEditingService } from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';
-import { ResourceChangeset } from 'core-app/shared/components/fields/changeset/resource-changeset';
-import { ConfigurationService } from 'core-app/core/config/configuration.service';
-import { TimezoneService } from 'core-app/core/datetime/timezone.service';
-import { DayElement } from 'flatpickr/dist/types/instance';
-import flatpickr from 'flatpickr';
-import { debounce } from 'rxjs/operators';
-import {
- Subject,
- timer,
-} from 'rxjs';
-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 {
- mappedDate,
- onDayCreate,
- parseDate,
- setDates,
- validDate,
-} from 'core-app/shared/components/datepicker/helpers/date-modal.helpers';
-import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
-import { WorkPackageChangeset } from 'core-app/features/work-packages/components/wp-edit/work-package-changeset';
-import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
-import { DateModalSchedulingService } from '../services/date-modal-scheduling.service';
-import * as moment from 'moment-timezone';
-
-
-@Component({
- selector: 'op-wp-single-date-form',
- templateUrl: './wp-single-date-form.component.html',
- styleUrls: [
- './wp-single-date-form.component.sass',
- '../styles/datepicker.modal.sass',
- ],
- changeDetection: ChangeDetectionStrategy.OnPush,
- encapsulation: ViewEncapsulation.None,
- providers: [
- DateModalRelationsService,
- DateModalSchedulingService,
- ],
-})
-export class OpWpSingleDateFormComponent extends UntilDestroyedMixin implements AfterViewInit, OnInit {
- @HostBinding('class.op-wp-single-date-form') className = true;
-
- @Input('value') value = '';
-
- @Input() changeset:ResourceChangeset;
-
- @Output() cancel = new EventEmitter();
-
- @Output() save = new EventEmitter();
-
- @ViewChild('flatpickrTarget') flatpickrTarget:ElementRef;
-
- @ViewChild('modalContainer') modalContainer:ElementRef<HTMLElement>;
-
- text = {
- save: this.I18n.t('js.button_save'),
- cancel: this.I18n.t('js.button_cancel'),
- date: this.I18n.t('js.work_packages.properties.date'),
- placeholder: this.I18n.t('js.placeholders.default'),
- today: this.I18n.t('js.label_today'),
- };
-
- scheduleManually = false;
-
- ignoreNonWorkingDays = false;
-
- htmlId = '';
-
- date:string|null = null;
-
- dateChangedManually$ = new Subject<void>();
-
- private debounceDelay = 0; // will change after initial render
-
- private datePickerInstance:DatePicker;
-
- constructor(
- readonly configurationService:ConfigurationService,
- readonly apiV3Service:ApiV3Service,
- readonly cdRef:ChangeDetectorRef,
- readonly injector:Injector,
- readonly I18n:I18nService,
- readonly timezoneService:TimezoneService,
- readonly halEditing:HalResourceEditingService,
- readonly dateModalScheduling:DateModalSchedulingService,
- readonly dateModalRelations:DateModalRelationsService,
- ) {
- super();
- }
-
- ngOnInit():void {
- this.dateModalRelations.setChangeset(this.changeset as WorkPackageChangeset);
- this.dateModalScheduling.setChangeset(this.changeset as WorkPackageChangeset);
- this.scheduleManually = !!this.changeset.value('scheduleManually');
- this.ignoreNonWorkingDays = !!this.changeset.value('ignoreNonWorkingDays');
-
- if (!moment(this.value).isValid()) {
- this.value = '';
- this.date = '';
- return;
- }
- this.date = this.timezoneService.formattedISODate(this.value);
- }
-
- ngAfterViewInit():void {
- if (isNewResource(this.changeset.pristineResource)) {
- this.initializeDatepicker(null);
- } else {
- this
- .dateModalRelations
- .getMinimalDateFromPreceeding()
- .subscribe((date) => {
- this.initializeDatepicker(date);
- });
- }
-
- this
- .dateChangedManually$
- .pipe(
- // Avoid that the manual changes are moved to the datepicker too early.
- // The debounce is chosen quite large on purpose to catch the following case:
- // 1. date is for example 2022-07-15. The user wants to set the day value to the 19th.
- // 2. So he/she starts entering the finish date 2022-07-1 .
- // 3. This is already a valid date. Since it is before the date,the date would be changed automatically to the first without the debounce.
- // 4. The debounce gives the user enough time to type the last number "9" before the changes are converted to the datepicker and the start date would be affected.
- //
- // Debounce delay is 0 for initial display, and then set to 800
- debounce(() => timer(this.debounceDelay)),
- )
- .subscribe(() => {
- // set debounce delay to its real value
- this.debounceDelay = 800;
-
- // Always update the whole form to ensure that no values are lost/inconsistent
- this.updateDate(this.date);
- });
- }
-
- changeSchedulingMode():void {
- this.datePickerInstance?.datepickerInstance.redraw();
- 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.datePickerInstance?.datepickerInstance.redraw();
- this.cdRef.detectChanges();
- }
-
- doSave($event:Event):void {
- $event.preventDefault();
- // Apply the changed scheduling mode if any
- this.changeset.setValue('scheduleManually', this.scheduleManually);
-
- // Apply include NWD
- this.changeset.setValue('ignoreNonWorkingDays', this.ignoreNonWorkingDays);
-
- // Apply the dates if they could be changed
- if (this.isSchedulable) {
- this.changeset.setValue('date', mappedDate(this.date));
- }
-
- this.save.emit();
- }
-
- doCancel():void {
- this.cancel.emit();
- }
-
- updateDate(val:string|null):void {
- // Expected minimal format YYYY-M-D => 8 characters OR empty
- if (val !== null && (val.length >= 8 || val.length === 0)) {
- if (validDate(val) && this.datePickerInstance) {
- const dateValue = parseDate(val) || undefined;
- this.enforceManualChangesToDatepicker(dateValue);
- }
- }
- }
-
- setToday():void {
- const today = parseDate(new Date()) as Date;
- this.date = this.timezoneService.formattedISODate(today);
- this.enforceManualChangesToDatepicker(today);
- }
-
- private initializeDatepicker(minimalDate?:Date|null) {
- this.datePickerInstance?.destroy();
- this.datePickerInstance = new DatePicker(
- this.injector,
- '#flatpickr-input',
- this.date || '',
- {
- mode: 'single',
- showMonths: 1,
- inline: true,
- onReady: (_date:Date[], _datestr:string, instance:flatpickr.Instance) => {
- instance.calendarContainer.classList.add('op-datepicker-modal--flatpickr-instance');
- },
- onChange: (dates:Date[]) => {
- if (dates.length > 0) {
- this.date = this.timezoneService.formattedISODate(dates[0]);
- this.enforceManualChangesToDatepicker(dates[0]);
- }
-
- this.cdRef.detectChanges();
- },
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
- onDayCreate: async (dObj:Date[], dStr:string, fp:flatpickr.Instance, dayElem:DayElement) => {
- onDayCreate(
- dayElem,
- this.ignoreNonWorkingDays,
- await this.datePickerInstance?.isNonWorkingDay(dayElem.dateObj),
- this.isDayDisabled(dayElem, minimalDate),
- );
- },
- },
- this.flatpickrTarget.nativeElement,
- );
- }
-
- private enforceManualChangesToDatepicker(enforceDate?:Date) {
- const date = parseDate(this.date || '');
- setDates(date, this.datePickerInstance, enforceDate);
-
- if (date) {
- this.date = this.timezoneService.formattedISODate(date);
- }
- }
-
- /**
- * Update the datepicker dates and properties from a form response
- * that includes derived/calculated values.
- *
- * @param form
- * @private
- */
- private updateDatesFromForm(form:FormResource):void {
- const payload = form.payload as { date:string, ignoreNonWorkingDays:boolean };
-
- this.date = payload.date;
- this.ignoreNonWorkingDays = payload.ignoreNonWorkingDays;
-
- const parsedDate = parseDate(payload.date) as Date;
- this.enforceManualChangesToDatepicker(parsedDate);
- }
-}
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.html b/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.html
index 6b97748c11f..aa8eea2efbd 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.html
+++ b/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.html
@@ -13,15 +13,7 @@
/>
<ng-container slot="body">
- <op-wp-single-date-form
- *ngIf="opened && !isMultiDate"
- [value]="dates"
- [changeset]="change"
- (save)="save()"
- (cancel)="cancel()"
- ></op-wp-single-date-form>
-
- <turbo-frame *ngIf="turboFrameSrc && opened && isMultiDate"
+ <turbo-frame *ngIf="turboFrameSrc && opened"
[src]="turboFrameSrc"
opModalWithTurboContent
[change]="change"
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.ts
index a2e7e0ba82f..37ac8316003 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.ts
+++ b/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.ts
@@ -53,10 +53,6 @@ export class CombinedDateEditFieldComponent extends DatePickerEditFieldComponent
super.ngOnInit();
}
- get isMultiDate():boolean {
- return !this.change.schema.isMilestone;
- }
-
public onInputClick(event:MouseEvent) {
event.stopPropagation();
}