Skip to content

Commit

Permalink
Merge pull request #17576 from opf/merge-release/15.2-20250110091205
Browse files Browse the repository at this point in the history
Merge release/15.2 into dev
  • Loading branch information
cbliard authored Jan 10, 2025
2 parents 1fb9f41 + d45c960 commit 869ad9a
Show file tree
Hide file tree
Showing 129 changed files with 430 additions and 278 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ def initialize(work_package:, base_errors: nil)

def submit_url_options
{ method: :post,
url: work_package_children_path(@work_package) }
url: work_package_children_relations_path(@work_package) }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
if should_render_add_child?
menu.with_item(
label: t("#{I18N_NAMESPACE}.relations.label_child_singular").capitalize,
href: new_work_package_child_path(@work_package),
href: new_work_package_children_relation_path(@work_package),
test_selector: new_button_test_selector(relation_type: :child),
content_arguments: {
data: { turbo_stream: true }
Expand Down
47 changes: 34 additions & 13 deletions app/components/work_package_relations_tab/index_component.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# frozen_string_literal: true

# Component for rendering the relations tab content of a work package
#
# This includes:
# - Controls for adding new relations if the user has permission
# - Related work packages grouped by relation type (follows, precedes, blocks, etc.)
# - Child work packages
class WorkPackageRelationsTab::IndexComponent < ApplicationComponent
FRAME_ID = "work-package-relations-tab-content"
NEW_RELATION_ACTION_MENU = "new-relation-action-menu"
Expand All @@ -9,16 +15,22 @@ class WorkPackageRelationsTab::IndexComponent < ApplicationComponent
include Turbo::FramesHelper
include OpTurbo::Streamable

attr_reader :work_package, :relations, :children, :directionally_aware_grouped_relations, :scroll_to_id
attr_reader :work_package, :relations, :children, :directionally_aware_grouped_relations, :relation_to_scroll_to

def initialize(work_package:, relations:, children:, scroll_to_id: nil)
# Initialize the component with required data
#
# @param work_package [WorkPackage] The work package whose relations are being displayed
# @param relations [Array<Relation>] The relations associated with this work package
# @param children [Array<WorkPackage>] Child work packages
# @param relation_to_scroll_to [Relation, WorkPackage, nil] Optional relation or child to scroll to when rendering
def initialize(work_package:, relations:, children:, relation_to_scroll_to: nil)
super()

@work_package = work_package
@relations = relations
@children = children
@directionally_aware_grouped_relations = group_relations_by_directional_context
@scroll_to_id = scroll_to_id
@relation_to_scroll_to = relation_to_scroll_to
end

def self.wrapper_key
Expand All @@ -28,6 +40,8 @@ def self.wrapper_key
private

def should_render_add_child?
return false if @work_package.milestone?

helpers.current_user.allowed_in_project?(:manage_subtasks, @work_package.project)
end

Expand Down Expand Up @@ -72,24 +86,31 @@ def render_header(border_box, title, items)

def render_items(border_box, items)
items.each do |item|
related_work_package_id = find_related_work_package_id(item)
data_attribute = nil
if related_work_package_id.to_s == @scroll_to_id
data_attribute = {
controller: "work-packages--relations-tab--scroll",
application_target: "dynamic",
"work-packages--relations-tab--scroll-target": "scrollToRow"
}
end
border_box.with_row(
test_selector: row_test_selector(item),
data: data_attribute
data: data_attribute(item)
) do
yield(item)
end
end
end

def data_attribute(item)
if scroll_to?(item)
{
controller: "work-packages--relations-tab--scroll",
application_target: "dynamic",
"work-packages--relations-tab--scroll-target": "scrollToRow"
}
end
end

def scroll_to?(item)
relation_to_scroll_to \
&& item.id == relation_to_scroll_to.id \
&& item.instance_of?(relation_to_scroll_to.class)
end

def new_relation_path(relation_type:)
raise ArgumentError, "Invalid relation type: #{relation_type}" unless Relation::TYPES.key?(relation_type)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def edit_path

def destroy_path
if parent_child_relationship?
work_package_child_path(@work_package, @child)
work_package_children_relation_path(@work_package, @child)
else
work_package_relation_path(@work_package, @relation)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
form: FORM_ID,
data: { turbo: true },
type: :submit)) do
t(:button_save)
if @relation.id.present?
t(:button_save)
else
t(:button_add)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,75 +28,61 @@
# See COPYRIGHT and LICENSE files for more details.
#++

class WorkPackageChildrenController < ApplicationController
class WorkPackageChildrenRelationsController < ApplicationController
include OpTurbo::ComponentStream
include OpTurbo::DialogStreamHelper

before_action :set_work_package

before_action :authorize # Short-circuit early if not authorized

before_action :set_child, except: %i[new create]
before_action :set_relations, except: %i[new create]

def new
component = WorkPackageRelationsTab::AddWorkPackageChildDialogComponent
.new(work_package: @work_package)
respond_with_dialog(component)
end

def create
target_work_package_id = params[:work_package][:id]
target_child_work_package = WorkPackage.find(target_work_package_id)
child = WorkPackage.find(params[:work_package][:id])
service_result = set_relation(child:, parent: @work_package)

target_child_work_package.parent = @work_package
respond_with_relations_tab_update(service_result, relation_to_scroll_to: service_result.result)
end

if target_child_work_package.save
@children = @work_package.children.visible
@relations = @work_package.relations.visible
def destroy
child = WorkPackage.find(params[:id])
service_result = set_relation(child:, parent: nil)

component = WorkPackageRelationsTab::IndexComponent.new(
work_package: @work_package,
relations: @relations,
children: @children,
scroll_to_id: target_work_package_id
)
replace_via_turbo_stream(component:)
render_success_flash_message_via_turbo_stream(message: I18n.t(:notice_successful_update))
respond_with_turbo_streams
end
respond_with_relations_tab_update(service_result)
end

def destroy
@child.parent = nil
private

if @child.save
def set_relation(child:, parent:)
WorkPackages::UpdateService.new(user: current_user, model: child)
.call(parent:)
end

def respond_with_relations_tab_update(service_result, **)
if service_result.success?
@work_package.reload
@children = @work_package.children.visible
component = WorkPackageRelationsTab::IndexComponent.new(
work_package: @work_package,
relations: @relations,
children: @children
relations: @work_package.relations.visible,
children: @work_package.children.visible,
**
)
replace_via_turbo_stream(component:)
render_success_flash_message_via_turbo_stream(message: I18n.t(:notice_successful_update))

respond_with_turbo_streams
else
respond_with_turbo_streams(status: :unprocessable_entity)
end
end

private

def set_work_package
@work_package = WorkPackage.find(params[:work_package_id])
@project = @work_package.project
end

def set_child
@child = WorkPackage.find(params[:id])
end

def set_relations
@relations = @work_package.relations.visible
end
end
14 changes: 7 additions & 7 deletions app/controllers/work_package_relations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ def create
.call(create_relation_params)

if service_result.success?
target_work_package_id = params[:relation][:to_id]
@work_package.reload
component = WorkPackageRelationsTab::IndexComponent.new(work_package: @work_package,
relations: @work_package.relations,
children: @work_package.children,
scroll_to_id: target_work_package_id)
relations: @work_package.relations.visible,
children: @work_package.children.visible,
relation_to_scroll_to: service_result.result)
replace_via_turbo_stream(component:)
respond_with_turbo_streams
else
Expand All @@ -82,8 +81,8 @@ def update
if service_result.success?
@work_package.reload
component = WorkPackageRelationsTab::IndexComponent.new(work_package: @work_package,
relations: @work_package.relations,
children: @work_package.children)
relations: @work_package.relations.visible,
children: @work_package.children.visible)
replace_via_turbo_stream(component:)
respond_with_turbo_streams
else
Expand All @@ -95,11 +94,12 @@ def destroy
service_result = Relations::DeleteService.new(user: current_user, model: @relation).call

if service_result.success?
@children = WorkPackage.where(parent_id: @work_package.id)
@children = WorkPackage.where(parent_id: @work_package.id).visible
@relations = @work_package
.relations
.reload
.includes(:to, :from)
.visible

component = WorkPackageRelationsTab::IndexComponent.new(work_package: @work_package,
relations: @relations,
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/work_package_relations_tab_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ class WorkPackageRelationsTabController < ApplicationController
before_action :authorize_global

def index
@children = WorkPackage.where(parent_id: @work_package.id)
@children = WorkPackage.where(parent_id: @work_package.id).visible
@relations = @work_package
.relations
.visible
.includes(:to, :from)

component = WorkPackageRelationsTab::IndexComponent.new(
Expand Down
2 changes: 1 addition & 1 deletion app/menus/notifications/menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def inbox_menu
end

def reason_filters
%w[mentioned assigned responsible watched dateAlert shared reminder].map do |reason|
%w[mentioned assigned responsible watched dateAlert reminder shared].map do |reason|
count = unread_by_reason[reason]
menu_item(title: I18n.t("notifications.reasons.#{reason}"),
icon_key: reason,
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/menus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@
{ tab: :relations },
skip_permissions_check: true,
badge: ->(work_package:, **) {
work_package.relations.count + work_package.children.count
work_package.relations.visible.count + work_package.children.visible.count
},
caption: :"js.work_packages.tabs.relations"
menu.push :watchers,
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@

wpt.permission :manage_subtasks,
{
work_package_children: %i[new create destroy]
work_package_children_relations: %i[new create destroy]
},
permissible_on: :project,
dependencies: :view_work_packages
Expand Down
2 changes: 1 addition & 1 deletion config/locales/crowdin/af.yml
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ af:
lag:
subject: "Lag"
title: "Lag (in days)"
caption: "The gap in number of working days in between the two work packages"
caption: "The minimum number of working days to keep in between the two work packages."
relations:
label_relates_singular: "related to"
label_relates_plural: "related to"
Expand Down
2 changes: 1 addition & 1 deletion config/locales/crowdin/ar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ ar:
lag:
subject: "Lag"
title: "Lag (in days)"
caption: "The gap in number of working days in between the two work packages"
caption: "The minimum number of working days to keep in between the two work packages."
relations:
label_relates_singular: "related to"
label_relates_plural: "related to"
Expand Down
2 changes: 1 addition & 1 deletion config/locales/crowdin/az.yml
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ az:
lag:
subject: "Lag"
title: "Lag (in days)"
caption: "The gap in number of working days in between the two work packages"
caption: "The minimum number of working days to keep in between the two work packages."
relations:
label_relates_singular: "related to"
label_relates_plural: "related to"
Expand Down
2 changes: 1 addition & 1 deletion config/locales/crowdin/be.yml
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ be:
lag:
subject: "Lag"
title: "Lag (in days)"
caption: "The gap in number of working days in between the two work packages"
caption: "The minimum number of working days to keep in between the two work packages."
relations:
label_relates_singular: "related to"
label_relates_plural: "related to"
Expand Down
2 changes: 1 addition & 1 deletion config/locales/crowdin/bg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ bg:
lag:
subject: "Lag"
title: "Lag (in days)"
caption: "The gap in number of working days in between the two work packages"
caption: "The minimum number of working days to keep in between the two work packages."
relations:
label_relates_singular: "related to"
label_relates_plural: "related to"
Expand Down
2 changes: 1 addition & 1 deletion config/locales/crowdin/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ ca:
lag:
subject: "Lag"
title: "Lag (in days)"
caption: "The gap in number of working days in between the two work packages"
caption: "The minimum number of working days to keep in between the two work packages."
relations:
label_relates_singular: "related to"
label_relates_plural: "related to"
Expand Down
2 changes: 1 addition & 1 deletion config/locales/crowdin/ckb-IR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ ckb-IR:
lag:
subject: "Lag"
title: "Lag (in days)"
caption: "The gap in number of working days in between the two work packages"
caption: "The minimum number of working days to keep in between the two work packages."
relations:
label_relates_singular: "related to"
label_relates_plural: "related to"
Expand Down
2 changes: 1 addition & 1 deletion config/locales/crowdin/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ cs:
lag:
subject: "Zpožďování"
title: "Zpoždění (ve dnech)"
caption: "The gap in number of working days in between the two work packages"
caption: "The minimum number of working days to keep in between the two work packages."
relations:
label_relates_singular: "související s"
label_relates_plural: "související s"
Expand Down
2 changes: 1 addition & 1 deletion config/locales/crowdin/da.yml
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ da:
lag:
subject: "Lag"
title: "Lag (in days)"
caption: "The gap in number of working days in between the two work packages"
caption: "The minimum number of working days to keep in between the two work packages."
relations:
label_relates_singular: "related to"
label_relates_plural: "related to"
Expand Down
2 changes: 1 addition & 1 deletion config/locales/crowdin/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ de:
lag:
subject: "Verzögerung"
title: "Verzögerung (in Tagen)"
caption: "Die Anzahl der Arbeitstage, die zwischen den beiden Arbeitspaketen liegen"
caption: "The minimum number of working days to keep in between the two work packages."
relations:
label_relates_singular: "Beziehung mit"
label_relates_plural: "Beziehungen mit"
Expand Down
Loading

0 comments on commit 869ad9a

Please sign in to comment.