Skip to content

Commit

Permalink
Revert commit d2a6ba2
Browse files Browse the repository at this point in the history
  • Loading branch information
HDinger committed Dec 17, 2024
1 parent fce7dfe commit c456d64
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 6 additions & 15 deletions app/forms/work_packages/date_picker/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {})
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c456d64

Please sign in to comment.