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

Preserve values when updating the content via turboStream

Henriette Darge25f2ac2d299e
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 2d46a89fe5d..6b10303e45f 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
@@ -58,7 +58,7 @@
first_row.with_column(mb: 1) do
render(Primer::Alpha::CheckBox.new(name: "work_package[ignore_non_working_days]",
label: I18n.t("work_packages.datepicker_modal.ignore_non_working_days.title"),
- checked: !work_package.ignore_non_working_days,
+ checked: !ignore_non_working_days?,
value: 0,
unchecked_value: 1,
data: { "work-packages--date-picker--preview-target": "fieldInput",
@@ -71,15 +71,18 @@
render(WorkPackages::DatePicker::Form.new(f,
work_package:,
focused_field:,
- touched_field_map:))
+ touched_field_map:,
+ start_date:,
+ due_date:,
+ duration:))
end
body.with_row(mb: 3) do
helpers.angular_component_tag "opce-wp-modal-date-picker",
inputs: {
- start_date: work_package.start_date,
- due_date: work_package.due_date,
- ignore_non_working_days: work_package.ignore_non_working_days,
+ start_date: start_date,
+ due_date: due_date,
+ ignore_non_working_days: ignore_non_working_days?,
schedule_manually:,
is_schedulable: true # TODO
}
diff --git a/app/components/work_packages/date_picker/dialog_content_component.rb b/app/components/work_packages/date_picker/dialog_content_component.rb
index 5a789c5d205..300258d886a 100644
--- a/app/components/work_packages/date_picker/dialog_content_component.rb
+++ b/app/components/work_packages/date_picker/dialog_content_component.rb
@@ -48,6 +48,38 @@ module WorkPackages
private
+ def ignore_non_working_days?
+ if params[:work_package].present? && params[:work_package][:ignore_non_working_days].present?
+ ActiveModel::Type::Boolean.new.cast((params[:work_package][:ignore_non_working_days]))
+ else
+ work_package.ignore_non_working_days
+ end
+ end
+
+ def start_date
+ if params[:work_package].present? && params[:work_package][:start_date].present?
+ params[:work_package][:start_date]
+ else
+ work_package.start_date
+ end
+ end
+
+ def due_date
+ if params[:work_package].present? && params[:work_package][:due_date].present?
+ params[:work_package][:due_date]
+ else
+ work_package.due_date
+ end
+ end
+
+ def duration
+ if params[:work_package].present? && params[:work_package][:duration].present?
+ params[:work_package][:duration]
+ else
+ work_package.duration
+ end
+ end
+
def show_banner?
true # TODO
end
diff --git a/app/forms/work_packages/date_picker/form.rb b/app/forms/work_packages/date_picker/form.rb
index e99e658617b..a3918f5086f 100644
--- a/app/forms/work_packages/date_picker/form.rb
+++ b/app/forms/work_packages/date_picker/form.rb
@@ -49,20 +49,23 @@ module WorkPackages
attr_reader :work_package
def initialize(work_package:,
- focused_field: :start_date,
+ start_date:, due_date:, duration:, focused_field: :start_date,
touched_field_map: {})
super()
@work_package = work_package
@focused_field = focused_field_by_selection(focused_field)
@touched_field_map = touched_field_map
+ @start_date = start_date
+ @due_date = due_date
+ @duration = duration
end
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"))
+ text_field(group, name: :start_date, label: I18n.t("attributes.start_date"), value: @start_date)
+ text_field(group, name: :due_date, label: I18n.t("attributes.due_date"), value: @due_date)
+ text_field(group, name: :duration, label: I18n.t("activerecord.attributes.work_package.duration"), value: @duration)
hidden_touched_field(group, name: :start_date)
hidden_touched_field(group, name: :due_date)
@@ -83,10 +86,11 @@ module WorkPackages
def text_field(group,
name:,
- label:)
+ label:,
+ value:)
text_field_options = default_field_options(name).merge(
name:,
- value: field_value(name),
+ value: field_value(name, value),
label:,
validation_message: validation_message(name)
)
@@ -121,12 +125,13 @@ module WorkPackages
@touched_field_map["#{name}_touched"] || false
end
- def field_value(name)
+ def field_value(name, value = nil)
errors = @work_package.errors.where(name)
if (user_value = errors.map { |error| error.options[:value] }.find { !_1.nil? })
user_value
+ elsif value.present?
+ value
else
- # TODO
@work_package.public_send(name)
end
end