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
Connect the datepicker to the input fields
Dombi Attila8e56509b49d1
diff --git a/app/forms/projects/life_cycles/form.rb b/app/forms/projects/life_cycles/form.rbindex 10ce34e6eb9..4fc9ae2e4e7 100644--- a/app/forms/projects/life_cycles/form.rb+++ b/app/forms/projects/life_cycles/form.rb@@ -46,10 +46,7 @@ module Projects::LifeCyclesdef datepicker_attributes{inset: true,- datepicker_options: {- inDialog: Overviews::ProjectPhases::EditDialogComponent::DIALOG_ID,- data: { action: "change->overview--project-life-cycles-form#previewForm" }- },+ data: { action: "overview--project-life-cycles-form#previewForm" },wrapper_data_attributes: {"qa-field-name": qa_field_name}@@ -57,12 +54,28 @@ module Projects::LifeCyclesenddef start_date_input(form)- input_attributes = { name: :start_date, label: attribute_name(:start_date) }+ data = datepicker_attributes[:data]+ value = model.start_date || model.start_date_before_type_cast+ input_attributes = {+ name: :start_date,+ label: attribute_name(:start_date),+ value:,+ data: data.merge("overview--project-life-cycles-form-target": "startDate"),+ show_clear_button: value.present?+ }form.text_field **datepicker_attributes, **input_attributesenddef finish_date_input(form)- input_attributes = { name: :finish_date, label: attribute_name(:finish_date) }+ data = datepicker_attributes[:data]+ value = model.finish_date || model.finish_date_before_type_cast+ input_attributes = {+ name: :finish_date,+ label: attribute_name(:finish_date),+ value:,+ data: data.merge("overview--project-life-cycles-form-target": "finishDate"),+ show_clear_button: value.present?+ }form.text_field **datepicker_attributes, **input_attributesend@@ -73,9 +86,10 @@ module Projects::LifeCyclestype: :number,inset: true,value: model.duration,- trailing_visual: { text: { text: I18n.t("datetime.units.day", count: model.duration) } }+ trailing_visual: { text: { text: I18n.t("datetime.units.day", count: model.duration) } },+ data: { "overview--project-life-cycles-form-target": "duration" },+ show_clear_button: model.duration.present?}- # binding.pryform.text_field **input_attributesendenddiff --git a/frontend/src/stimulus/controllers/dynamic/overview/project-life-cycles-form.controller.ts b/frontend/src/stimulus/controllers/dynamic/overview/project-life-cycles-form.controller.tsindex 6b525477046..3fe57142791 100644--- a/frontend/src/stimulus/controllers/dynamic/overview/project-life-cycles-form.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/overview/project-life-cycles-form.controller.ts@@ -28,19 +28,87 @@* ++*/+import { TimezoneService } from 'core-app/core/datetime/timezone.service';import FormPreviewController from '../../form-preview.controller';+import {+ debounce,+ DebouncedFunc,+} from 'lodash';export default class ProjectLifeCyclesFormController extends FormPreviewController {- previewForm(event:Event) {- const target = event.target as HTMLElement;- if (this.datePickerVisible(target)) {- return; // flatpickr is still open, do not submit yet.+ private timezoneService:TimezoneService;+ private handleFlatpickrDatesChangedBound = this.handleFlatpickrDatesChanged.bind(this);+ private updateFlatpickrCalendarBound = this.updateFlatpickrCalendar.bind(this);+ private previewForm:DebouncedFunc<() => void>;++ static targets = ['startDate', 'finishDate', 'duration'];++ declare readonly startDateTarget:HTMLInputElement;+ declare readonly finishDateTarget:HTMLInputElement;+ declare readonly durationTarget:HTMLInputElement;++ async connect() {+ super.connect();++ this.previewForm = debounce(() => {+ void this.submit();+ }, 200);++ const context = await window.OpenProject.getPluginContext();+ this.timezoneService = context.services.timezone;++ document.addEventListener('date-picker:flatpickr-dates-changed', this.handleFlatpickrDatesChangedBound);+ document.addEventListener('turbo:before-stream-render', this.updateFlatpickrCalendarBound);+ }++ disconnect() {+ document.removeEventListener('date-picker:flatpickr-dates-changed', this.handleFlatpickrDatesChangedBound);+ document.removeEventListener('turbo:before-stream-render', this.updateFlatpickrCalendarBound);+ }++ private updateFlatpickrCalendar() {+ const dates:Date[] = _.compact([+ this.toDate(this.startDateTarget.value), this.toDate(this.finishDateTarget.value),+ ]);+ const ignoreNonWorkingDays = false;+ const mode = this.mode();++ document.dispatchEvent(+ new CustomEvent('date-picker:flatpickr-set-values', {+ detail: {+ dates,+ ignoreNonWorkingDays,+ mode,+ },+ }),+ );+ }++ private mode():'single'|'range' {+ if (this.startDateTarget.disabled) {+ return 'single';}+ return 'range';+ }- void this.submit();+ handleFlatpickrDatesChanged(event:CustomEvent<{ dates:Date[] }>) {+ const dates = event.detail.dates;+ this.startDateTarget.value = this.dateToIso(dates[0]);+ this.finishDateTarget.value = this.dateToIso(dates[1]);+ this.previewForm();}- datePickerVisible(element:HTMLElement) {- return element.classList.contains('active');+ private dateToIso(date:Date|null):string {+ if (date) {+ return this.timezoneService.utcDateToISODateString(date);+ }+ return '';+ }++ private toDate(date:string|null):Date|null {+ if (date && /^\d{4}-\d{2}-\d{2}$/.test(date)) {+ return new Date(date);+ }+ return null;}}diff --git a/modules/overviews/app/components/overviews/project_phases/edit_component.html.erb b/modules/overviews/app/components/overviews/project_phases/edit_component.html.erbindex 97314527397..c89b529593e 100644--- a/modules/overviews/app/components/overviews/project_phases/edit_component.html.erb+++ b/modules/overviews/app/components/overviews/project_phases/edit_component.html.erb@@ -12,7 +12,8 @@turbo: true,turbo_stream: true,"test-selector": "async-dialog-content"- }+ },+ html: { autocomplete: "off" }) do |f|flex_layout do |flex|flex.with_row do@@ -25,8 +26,6 @@due_date: model.finish_date,ignore_non_working_days: false,schedule_manually: true,- is_schedulable: true,- is_milestone: false,date_mode: "range",start_date_field_id: "project_phase_start_date",due_date_field_id: "project_phase_finish_date",diff --git a/modules/overviews/app/components/overviews/project_phases/item_component.sass b/modules/overviews/app/components/overviews/project_phases/item_component.sassindex 74d6222edce..a7c8cf1fdf2 100644--- a/modules/overviews/app/components/overviews/project_phases/item_component.sass+++ b/modules/overviews/app/components/overviews/project_phases/item_component.sass@@ -11,3 +11,6 @@ a.hover-input, a.hover-input:visited@media (hover: hover)&:hoverborder-color: var(--borderColor-default) !important++.FormControl-input-trailingAction + .FormControl-input-trailingVisualWrap+ margin-right: var(--base-size-20)