Skip to content

Commit

Permalink
removed non-orphans from root level of collections' hierarchy view
Browse files Browse the repository at this point in the history
in order to avoid redundancies only orphans - i.e. collections without a
parent collection - should appear at the root level

the current implementation seems rather brute-force, i.e. inefficient
and inelegant - there might be a better way

NB: Circular references (e.g. foo contains bar, bar contains foo) result
in the respective collections not being displayed at all, rendering them
inaccessible (unless they have a separate relationship to an orphan).
This was deemed a data-entry issue, thus not relevant here.
  • Loading branch information
FND committed Mar 3, 2011
1 parent 32cca84 commit 6bedf4f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/views/collections/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,19 @@
:format => :json)
-%>
<ul class="hybrid-treeview" data-url="<%= hcpath %>">
<%= render :partial => 'collection', :collection => @collections %>
<%-
# determine non-orphans (items with a parent)
children = []
@collections.each do |collection| # TODO: use #map along with #flatten?
if collection.subcollections.any?
children += collection.subcollections
end
end
children.uniq! # TODO: use Set?
# determine orphans (root-level items)
orphans = @collections.find_all do |collection|
not children.include? collection
end
-%>
<%= render :partial => 'collection', :collection => orphans %>
</ul>

0 comments on commit 6bedf4f

Please sign in to comment.