Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement nested assemblies navigation #13662

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
Improve parent assembly selector by showing hierarchy
  • Loading branch information
mllocs committed Nov 26, 2024
commit f7730d55f042bb08d5da5cf82787fa81dd798a1c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,34 @@ def processes_selected
end
end

# Public: A collection of Assemblies that can be selected as parent
# assemblies for another assembly; to be used in forms.
def parent_assemblies_for_select
@parent_assemblies_for_select ||= ParentAssembliesForSelect.for(current_organization, current_assembly)
# Public: select options representing a collection of Assemblies that
# can be selected as parent assemblies for another assembly; to be used in forms.
def parent_assemblies_options
options = []
root_assemblies = ParentAssembliesForSelect.for(current_organization, current_assembly).where(parent_id: nil).sort_by(&:weight)

root_assemblies.each do |assembly|
build_assembly_options(assembly, options)
end

options
end

private

# Recursively build the options for the assembly tree
def build_assembly_options(assembly, options, level = 0)
name = " #{" " * 4 * level} #{assembly.translated_title}".html_safe
options << [name, assembly.id]

# Skip the current assembly to avoid selecting a child as parent
if assembly == current_assembly
return
end

assembly.children.each do |child|
build_assembly_options(child, options, level + 1)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,7 @@
<% else %>
<div class="row column">
<%= form.select :parent_id,
options_from_collection_for_select(
parent_assemblies_for_select,
:id,
:translated_title,
selected: current_assembly.try(:parent_id)
),
parent_assemblies_options,
include_blank: t(".select_parent_assembly") %>
</div>
<% end %>
Expand Down
Loading