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

bug/63461 Reminders: saving without entering a date or time throws an error but also unnecessarily clears the other field

Kabiru Mwenja48a359517275
diff --git a/app/components/work_packages/reminder/modal_body_component.rb b/app/components/work_packages/reminder/modal_body_component.rb
index 1b06316f337..84f3124d434 100644
--- a/app/components/work_packages/reminder/modal_body_component.rb
+++ b/app/components/work_packages/reminder/modal_body_component.rb
@@ -40,13 +40,15 @@ module WorkPackages
attr_reader :remindable, :reminder, :errors, :preset
- def initialize(remindable:, reminder:, errors: nil, preset: nil)
+ def initialize(remindable:, reminder:, errors: nil, preset: nil, remind_at_date: nil, remind_at_time: nil)
super
@remindable = remindable
@reminder = reminder
@errors = errors
@preset = preset
+ @remind_at_date = remind_at_date
+ @remind_at_time = remind_at_time
end
class << self
@@ -84,6 +86,11 @@ module WorkPackages
end
def remind_at_date_initial_value
+ if attribute_blank?(:remind_at_time) && @remind_at_date.present?
+ # If the time is not set, we return the date that was passed in
+ return @remind_at_date
+ end
+
return time_as_date(@reminder.remind_at) if @reminder.remind_at
return calculate_preset_date if @preset
@@ -91,6 +98,11 @@ module WorkPackages
end
def remind_at_time_initial_value
+ if attribute_blank?(:remind_at_date) && @remind_at_time.present?
+ # If the date is not set, we return the time that was passed in
+ return @remind_at_time
+ end
+
return format_time(@reminder.remind_at, include_date: false, format: "%H:%M") if @reminder.remind_at
DEFAULT_TIME
@@ -111,6 +123,11 @@ module WorkPackages
def time_as_date(time)
format_time_as_date(time, format: "%Y-%m-%d")
end
+
+ def attribute_blank?(attribute)
+ @errors.present? &&
+ @errors.any? { |error| error.attribute == attribute && error.type == :blank }
+ end
end
end
end
diff --git a/app/controllers/work_packages/reminders_controller.rb b/app/controllers/work_packages/reminders_controller.rb
index 2caec8c52fb..008aeba660a 100644
--- a/app/controllers/work_packages/reminders_controller.rb
+++ b/app/controllers/work_packages/reminders_controller.rb
@@ -59,7 +59,9 @@ class WorkPackages::RemindersController < ApplicationController
component: modal_component_class.new(
remindable: @work_package,
reminder: @reminder,
- errors: @errors
+ errors: @errors,
+ remind_at_date:,
+ remind_at_time:
)
)
@@ -82,7 +84,9 @@ class WorkPackages::RemindersController < ApplicationController
component: modal_component_class.new(
remindable: @work_package,
reminder: @reminder,
- errors: @errors
+ errors: @errors,
+ remind_at_date:,
+ remind_at_time:
)
)
diff --git a/spec/features/work_packages/reminders_spec.rb b/spec/features/work_packages/reminders_spec.rb
index 05534d3f7e9..7d0a6824770 100644
--- a/spec/features/work_packages/reminders_spec.rb
+++ b/spec/features/work_packages/reminders_spec.rb
@@ -259,8 +259,9 @@ RSpec.describe "Work package reminder modal",
expect(page).to have_css(".FormControl-inlineValidation", text: "Date can't be blank")
expect(page).to have_field("Time", with: "09:00")
+ one_week_from_now = 1.week.from_now
# Fill in the date and unset the time
- fill_in "Date", with: 1.week.from_now.to_date
+ fill_in "Date", with: one_week_from_now.to_date
fill_in "Time", with: ""
click_link_or_button "Set reminder"
@@ -268,15 +269,19 @@ RSpec.describe "Work package reminder modal",
# The error message is only on the time field
expect(page).to have_css(".FormControl-inlineValidation", text: "Time can't be blank")
expect(page).to have_no_css(".FormControl-inlineValidation", text: "Date can't be blank", wait: 0)
+ expect(page).to have_field("Date", with: one_week_from_now.to_date)
# Fill in the time but not the date
fill_in "Date", with: ""
- fill_in "Time", with: Time.zone.parse("05:00")
+ fill_in "Time", with: Time.use_zone(current_user.time_zone) { Time.zone.parse("05:00") }
click_link_or_button "Set reminder"
wait_for_network_idle
expect(page).to have_css(".FormControl-inlineValidation", text: "Date can't be blank.")
expect(page).to have_no_css(".FormControl-inlineValidation", text: "Time can't be blank.", wait: 0)
+ expect(page).to have_field("Time", with: Time.use_zone(current_user.time_zone) {
+ Time.zone.parse("05:00").localtime.strftime("%H:%M:%S")
+ })
end
end