From c456d64aae83afe9d0b91cad423e28e9d28a3738 Mon Sep 17 00:00:00 2001 From: Henriette Darge Date: Tue, 17 Dec 2024 15:02:28 +0100 Subject: [PATCH] Revert commit d2a6ba2a04fe038f4f008214997e931091971cea --- .../dialog_content_component.html.erb | 13 +++----- .../date_picker/dialog_content_component.rb | 32 ------------------- app/forms/work_packages/date_picker/form.rb | 21 ++++-------- 3 files changed, 11 insertions(+), 55 deletions(-) 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 58f5a9977984..96124d1026ca 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 @@ -62,7 +62,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: !ignore_non_working_days?, + checked: !work_package.ignore_non_working_days, disabled: disabled?, value: 0, unchecked_value: 1, @@ -77,18 +77,15 @@ work_package:, focused_field:, touched_field_map:, - disabled: disabled?, - start_date:, - due_date:, - duration:)) + disabled: disabled?)) end body.with_row(mb: 3) do helpers.angular_component_tag "opce-wp-modal-date-picker", inputs: { - start_date: start_date, - due_date: due_date, - ignore_non_working_days: ignore_non_working_days?, + start_date: work_package.start_date, + due_date: work_package.due_date, + ignore_non_working_days: work_package.ignore_non_working_days, schedule_manually:, is_schedulable: !disabled? } 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 4916005679a9..fe83b97af4fc 100644 --- a/app/components/work_packages/date_picker/dialog_content_component.rb +++ b/app/components/work_packages/date_picker/dialog_content_component.rb @@ -64,38 +64,6 @@ def disabled? !schedule_manually end - 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 09c979982ee0..174763ee43f1 100644 --- a/app/forms/work_packages/date_picker/form.rb +++ b/app/forms/work_packages/date_picker/form.rb @@ -49,9 +49,6 @@ def before_render attr_reader :work_package def initialize(work_package:, - start_date:, - due_date:, - duration:, disabled:, focused_field: :start_date, touched_field_map: {}) @@ -60,17 +57,14 @@ def initialize(work_package:, @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 @disabled = disabled end form do |query_form| query_form.group(layout: :horizontal) do |group| - 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) + 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) @@ -91,11 +85,10 @@ def focused_field_by_selection(field) def text_field(group, name:, - label:, - value:) + label:) text_field_options = default_field_options(name).merge( name:, - value: field_value(name, value), + value: field_value(name), disabled: @disabled, label:, validation_message: validation_message(name) @@ -131,12 +124,10 @@ def touched(name) @touched_field_map["#{name}_touched"] || false end - def field_value(name, value = nil) + def field_value(name) 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 @work_package.public_send(name) end