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

Add toggling behaviour for single date mode

Henriette Darge4159242a79f2
diff --git a/app/components/work_packages/date_picker/date_form_component.html.erb b/app/components/work_packages/date_picker/date_form_component.html.erb
index 556611367e6..a22bf8723b7 100644
--- a/app/components/work_packages/date_picker/date_form_component.html.erb
+++ b/app/components/work_packages/date_picker/date_form_component.html.erb
@@ -1,15 +1,20 @@
<%=
- grid_layout("wp-datepicker-dialog-date-form", tag: :div) do |body|
+ grid_layout("wp-datepicker-dialog-date-form",
+ tag: :div,
+ data: { "application-target": "dynamic",
+ controller: "work-packages--date-picker--date-form" }) do |body|
body.with_area("start-date") do
flex_layout do |start_date|
start_date.with_row(classes: container_classes(:start_date, :button)) do
- render(Primer::ButtonComponent.new(classes: "wp-datepicker-dialog-date-form--add-button")) do |button|
+ render(Primer::ButtonComponent.new(classes: "wp-datepicker-dialog-date-form--add-button",
+ data: { action: "work-packages--date-picker--date-form#toggleStartDateFieldVisibility" })) do |button|
button.with_leading_visual_icon(icon: :plus)
I18n.t("attributes.start_date")
end
end
- start_date.with_row(classes: container_classes(:start_date, :text_field)) do
+ start_date.with_row(classes: container_classes(:start_date, :text_field),
+ data: { "work-packages--date-picker--date-form-target": "startDateFieldContainer" } ) do
render(Primer::Alpha::TextField.new(**text_field_options(name: :start_date, label: I18n.t("attributes.start_date"))))
end
end
@@ -18,13 +23,15 @@
body.with_area("due-date") do
flex_layout do |due_date|
due_date.with_row(classes: container_classes(:due_date, :button)) do
- render(Primer::ButtonComponent.new(classes: "wp-datepicker-dialog-date-form--add-button")) do |button|
+ render(Primer::ButtonComponent.new(classes: "wp-datepicker-dialog-date-form--add-button",
+ data: { action: "work-packages--date-picker--date-form#toggleDueDateFieldVisibility" })) do |button|
button.with_leading_visual_icon(icon: :plus)
I18n.t("attributes.due_date")
end
end
- due_date.with_row(classes: container_classes(:due_date, :text_field)) do
+ due_date.with_row(classes: container_classes(:due_date, :text_field),
+ data: { "work-packages--date-picker--date-form-target": "dueDateFieldContainer" }) do
render(Primer::Alpha::TextField.new(**text_field_options(name: :due_date, label: I18n.t("attributes.due_date"))))
end
end
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/date-form.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/date-form.controller.ts
new file mode 100644
index 00000000000..b79d8d1f2ce
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/date-form.controller.ts
@@ -0,0 +1,64 @@
+/*
+ * -- 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 { Controller } from '@hotwired/stimulus';
+
+export default class DateFormController extends Controller {
+ static targets = [
+ 'startDateFieldContainer',
+ 'dueDateFieldContainer',
+ ];
+
+ declare readonly startDateFieldContainerTarget:HTMLElement;
+
+ declare readonly dueDateFieldContainerTarget:HTMLElement;
+
+ toggleStartDateFieldVisibility(e:Event) {
+ this.hideButton(e.target as HTMLElement);
+
+ this.startDateFieldContainerTarget.classList.remove('wp-datepicker-dialog-date-form--field-container_hidden');
+ this.startDateFieldContainerTarget.querySelector('input')?.focus();
+ }
+
+ toggleDueDateFieldVisibility(e:Event) {
+ this.hideButton(e.target as HTMLElement);
+
+ this.dueDateFieldContainerTarget.classList.remove('wp-datepicker-dialog-date-form--field-container_hidden');
+ this.dueDateFieldContainerTarget.querySelector('input')?.focus();
+ }
+
+ hideButton(button:HTMLElement) {
+ const closestFieldContainer = button.closest('.wp-datepicker-dialog-date-form--field-container');
+
+ if (closestFieldContainer) {
+ closestFieldContainer.classList.add('wp-datepicker-dialog-date-form--field-container_hidden');
+ }
+ }
+}
diff --git a/frontend/src/stimulus/setup.ts b/frontend/src/stimulus/setup.ts
index 23e1d7e13d1..804ce33ff2f 100644
--- a/frontend/src/stimulus/setup.ts
+++ b/frontend/src/stimulus/setup.ts
@@ -15,6 +15,7 @@ import FlashController from './controllers/flash.controller';
import OpProjectsZenModeController from './controllers/dynamic/projects/zen-mode.controller';
import PasswordConfirmationDialogController from './controllers/password-confirmation-dialog.controller';
import PreviewController from './controllers/dynamic/work-packages/date-picker/preview.controller';
+import DateFormController from './controllers/dynamic/work-packages/date-picker/date-form.controller';
import KeepScrollPositionController from './controllers/keep-scroll-position.controller';
import PatternInputController from './controllers/pattern-input.controller';
import HoverCardTriggerController from './controllers/hover-card-trigger.controller';
@@ -49,5 +50,6 @@ instance.register('show-when-value-selected', OpShowWhenValueSelectedController)
instance.register('table-highlighting', TableHighlightingController);
instance.register('projects-zen-mode', OpProjectsZenModeController);
instance.register('work-packages--date-picker--preview', PreviewController);
+instance.register('work-packages--date-picker--date-form', DateFormController);
instance.register('keep-scroll-position', KeepScrollPositionController);
instance.register('pattern-input', PatternInputController);