Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

add invisible relations the mediator, define a new data type for returning visible, invisible relations and their type

Behrokh Satarnejad3c5dd0dfdc19
diff --git a/app/components/work_package_relations_tab/relations_mediator.rb b/app/components/work_package_relations_tab/relations_mediator.rb
index 8c21e51e730..d8032b2d959 100644
--- a/app/components/work_package_relations_tab/relations_mediator.rb
+++ b/app/components/work_package_relations_tab/relations_mediator.rb
@@ -29,21 +29,55 @@
#++
class WorkPackageRelationsTab::RelationsMediator
+ RelationGroup = Data.define(:type, :visible_relations, :invisible_relations)
+
attr_reader :work_package
def initialize(work_package:)
@work_package = work_package
end
- def relations
- @relations ||= work_package.relations.includes(:to, :from).visible
+ def visible_relations
+ @visible_relations ||= work_package.relations.includes(:to, :from).visible
end
def children
@children ||= work_package.children.visible
end
+ def invisible_relations
+ @invisible_relations = work_package.relations.includes(:to, :from).where.not(id: @visible_relations.select(:id))
+ end
+
+ def directionally_aware_grouped_relations
+ # Collect all unique relation types
+ all_relation_types = collect_all_relation_types
+
+ # Group visible and invisible relations by type
+ all_relation_types.map do |type|
+ RelationGroup.new(
+ type: type,
+ visible_relations: filter_relations_by_type(visible_relations, type),
+ invisible_relations: filter_relations_by_type(invisible_relations, type)
+ )
+ end
+ end
+
def any_relations?
- relations.any? || children.any?
+ visible_relations.any? || invisible_relations.any? || children.any?
+ end
+
+ private
+
+ def collect_all_relation_types
+ (visible_relations + invisible_relations).map do |relation|
+ relation.relation_type_for(work_package)
+ end.uniq
+ end
+
+ def filter_relations_by_type(relations, type)
+ relations.select do |relation|
+ relation.relation_type_for(work_package) == type
+ end
end
end