From c7a295137c30980be7ed7677576ee2d1ecc2c043 Mon Sep 17 00:00:00 2001 From: Henriette Darge Date: Thu, 28 Nov 2024 11:02:10 +0100 Subject: [PATCH] Show and edit the Lag for follows/precedes relationships --- .../relation_component.html.erb | 50 ++++++++++++++----- .../relation_component.rb | 6 ++- ...k_package_relation_form_component.html.erb | 10 ++++ .../work_package_relation_form_component.rb | 4 ++ .../work_package_relations_controller.rb | 4 +- config/locales/en.yml | 3 ++ 6 files changed, 62 insertions(+), 15 deletions(-) diff --git a/app/components/work_package_relations_tab/relation_component.html.erb b/app/components/work_package_relations_tab/relation_component.html.erb index 2c2dc4acf5dd..bb28ae6614c2 100644 --- a/app/components/work_package_relations_tab/relation_component.html.erb +++ b/app/components/work_package_relations_tab/relation_component.html.erb @@ -60,20 +60,46 @@ flex_layout do |flex| end end - if should_display_start_and_end_dates? - flex.with_row(flex_layout: true, align_items: :center) do |start_and_end_dates_row| - start_and_end_dates_row.with_column(mr: 1) do - icon = if follows? - :calendar - elsif precedes? - :pin - end + if should_display_dates_row? + flex.with_row(flex_layout: true, align_items: :center, color: :muted) do |dates_row| + if precedes? && lag_present? + dates_row.with_column(mr: 1) do + render(Primer::Beta::Octicon.new(icon: "arrow-both")) + end + dates_row.with_column(mr: 3) do + render(Primer::Beta::Text.new) do + "#{I18n.t("work_package_relations_tab.lag.title")}: #{I18n.t('datetime.distance_in_words.x_days', + count: relation.lag)}" + end + end + end + + if related_work_package.start_date.present? || related_work_package.due_date.present? + dates_row.with_column(mr: 1) do + icon = if follows? + :calendar + elsif precedes? + :pin + end - render(Primer::Beta::Octicon.new(icon:, color: :muted)) + render(Primer::Beta::Octicon.new(icon:)) + end + dates_row.with_column do + render(Primer::Beta::Text.new) do + "#{format_date(related_work_package.start_date)} - #{format_date(related_work_package.due_date)}" + end + end end - start_and_end_dates_row.with_column do - render(Primer::Beta::Text.new(color: :muted)) do - "#{format_date(related_work_package.start_date)} - #{format_date(related_work_package.due_date)}" + + if follows? && lag_present? + dates_row.with_column(ml: 3, mr: 1) do + render(Primer::Beta::Octicon.new(icon: "arrow-both")) + end + dates_row.with_column(mr: 1) do + render(Primer::Beta::Text.new) do + "#{I18n.t("work_package_relations_tab.lag.title")}: #{I18n.t('datetime.distance_in_words.x_days', + count: relation.lag)}" + end end end end diff --git a/app/components/work_package_relations_tab/relation_component.rb b/app/components/work_package_relations_tab/relation_component.rb index efed86f893f4..18305fceb005 100644 --- a/app/components/work_package_relations_tab/relation_component.rb +++ b/app/components/work_package_relations_tab/relation_component.rb @@ -61,7 +61,11 @@ def should_display_description? relation.description.present? end - def should_display_start_and_end_dates? + def lag_present? + relation.lag.present? + end + + def should_display_dates_row? return false if parent_child_relationship? relation.follows? || relation.precedes? diff --git a/app/components/work_package_relations_tab/work_package_relation_form_component.html.erb b/app/components/work_package_relations_tab/work_package_relation_form_component.html.erb index ea3d88f96afe..0a997994e8c4 100644 --- a/app/components/work_package_relations_tab/work_package_relation_form_component.html.erb +++ b/app/components/work_package_relations_tab/work_package_relation_form_component.html.erb @@ -19,6 +19,7 @@ # These are not available inside the render_inline_form block # so we need to re-define them here. Figure out solution for this. relation = @relation + lag_shown = show_lag? to_id_field_value = relation.to.present? ? "#{related_work_package.type.name.upcase} ##{related_work_package.id} - #{related_work_package.subject}" : nil url = ::API::V3::Utilities::PathHelper::ApiV3Path.work_package_available_relation_candidates(@work_package.id, type: relation.relation_type_for(@work_package)) render_inline_form(f) do |my_form| @@ -57,6 +58,15 @@ name: :description, label: Relation.human_attribute_name(:description), ) + + if lag_shown + my_form.text_field( + name: :lag, + label: Relation.human_attribute_name(:lag), + caption: I18n.t("work_package_relations_tab.lag.caption"), + input_width: :small, + ) + end end end end %> diff --git a/app/components/work_package_relations_tab/work_package_relation_form_component.rb b/app/components/work_package_relations_tab/work_package_relation_form_component.rb index 7dd778e13ac7..eff05c34b78a 100644 --- a/app/components/work_package_relations_tab/work_package_relation_form_component.rb +++ b/app/components/work_package_relations_tab/work_package_relation_form_component.rb @@ -59,4 +59,8 @@ def submit_url_options url: work_package_relations_path(@work_package) } end end + + def show_lag? + @relation.relation_type == Relation::TYPE_PRECEDES || @relation.relation_type == Relation::TYPE_FOLLOWS + end end diff --git a/app/controllers/work_package_relations_controller.rb b/app/controllers/work_package_relations_controller.rb index 837e4e10a190..38095515fae5 100644 --- a/app/controllers/work_package_relations_controller.rb +++ b/app/controllers/work_package_relations_controller.rb @@ -121,12 +121,12 @@ def set_relation def create_relation_params params.require(:relation) - .permit(:relation_type, :to_id, :description) + .permit(:relation_type, :to_id, :description, :lag) .merge(from_id: @work_package.id) end def update_relation_params params.require(:relation) - .permit(:description) + .permit(:description, :lag) end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 9657cfe546b0..387c253df5d9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -716,6 +716,9 @@ en: label_add_x: "Add %{x}" label_edit_x: "Edit %{x}" label_add_description: "Add description" + lag: + title: "Lag" + caption: "The gap in number of working days in between the two work packages" relations: label_relates_singular: "related to" label_relates_plural: "related to"