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 12788bdb76d0..b4cdd78822b4 100644 --- a/app/components/work_package_relations_tab/relation_component.html.erb +++ b/app/components/work_package_relations_tab/relation_component.html.erb @@ -58,20 +58,44 @@ flex_layout do |flex| end end - if should_display_start_and_end_dates? - flex.with_row(flex_layout: true, align_items: :center, mb: 2) 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, mb: 2) 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 + lag_as_text(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 + lag_as_text(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..08e1452e02c5 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? && relation.lag != 0 + end + + def should_display_dates_row? return false if parent_child_relationship? relation.follows? || relation.precedes? @@ -91,6 +95,10 @@ def destroy_path end end + def lag_as_text(lag) + "#{I18n.t('work_package_relations_tab.lag.subject')}: #{I18n.t('datetime.distance_in_words.x_days', count: lag)}" + end + def action_menu_test_selector "op-relation-row-#{underlying_resource_id}-action-menu" end 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 0a6f63688a42..83879e8a97c6 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| @@ -58,6 +59,17 @@ label: Relation.human_attribute_name(:description), autofocus: relation.persisted? ) + + if lag_shown + my_form.text_field( + name: :lag, + type: :number, + min: 0, + label: I18n.t("work_package_relations_tab.lag.title"), + 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 938ce175ddf6..264d08770fab 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 @@ -64,4 +64,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..354204222c66 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -716,6 +716,10 @@ en: label_add_x: "Add %{x}" label_edit_x: "Edit %{x}" label_add_description: "Add description" + lag: + subject: "Lag" + title: "Lag (in days)" + 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" diff --git a/spec/features/work_packages/details/relations/primerized_relations_spec.rb b/spec/features/work_packages/details/relations/primerized_relations_spec.rb index 56bc66d3699e..7fa9a4236185 100644 --- a/spec/features/work_packages/details/relations/primerized_relations_spec.rb +++ b/spec/features/work_packages/details/relations/primerized_relations_spec.rb @@ -142,10 +142,13 @@ def label_for_relation_type(relation_type) relation_row = relations_tab.expect_relation(relation_follows) - relations_tab.add_description_to_relation(relation_follows, "Discovered relations have descriptions!") + relations_tab.edit_relation_description(relation_follows, "Discovered relations have descriptions!") - # Reflects new description + relations_tab.edit_lag_of_relation(relation_follows, 5) + + # Reflects new description and lag expect(relation_row).to have_text("Discovered relations have descriptions!") + expect(relation_row).to have_text("5 days") # Unchanged tabs.expect_counter("relations", 4) @@ -171,6 +174,17 @@ def label_for_relation_type(relation_type) end end + it "does not show the lag field for all relation types" do + scroll_to_element relations_panel + + relations_tab.open_relation_dialog(relation_relates) + + within "##{WorkPackageRelationsTab::WorkPackageRelationDialogComponent::DIALOG_ID}" do + expect(page).to have_field("Work package", readonly: true) + expect(page).to have_no_field("Lag") + end + end + context "with the shown WorkPackage being the 'to' relation part" do let(:another_wp) { create(:work_package, type: type2, subject: "related to main") } diff --git a/spec/support/components/work_packages/relations.rb b/spec/support/components/work_packages/relations.rb index 2c992d574349..cceac6de06af 100644 --- a/spec/support/components/work_packages/relations.rb +++ b/spec/support/components/work_packages/relations.rb @@ -168,7 +168,7 @@ def add_relation(type:, relatable:, description: nil) find_row(target_wp) end - def add_description_to_relation(relatable, description) + def edit_relation_description(relatable, description) open_relation_dialog(relatable) within "##{WorkPackageRelationsTab::WorkPackageRelationDialogComponent::DIALOG_ID}" do @@ -183,14 +183,14 @@ def add_description_to_relation(relatable, description) end end - def edit_relation_description(relatable, description) + def edit_lag_of_relation(relatable, lag) open_relation_dialog(relatable) within "##{WorkPackageRelationsTab::WorkPackageRelationDialogComponent::DIALOG_ID}" do expect(page).to have_field("Work package", readonly: true) - expect(page).to have_field("Description") + expect(page).to have_field("Lag") - fill_in "Description", with: description + fill_in "Lag", with: lag click_link_or_button "Save"