Skip to content

Commit

Permalink
Merge pull request #3421 from manyfold3d/dynamic-file-group-size
Browse files Browse the repository at this point in the history
Dynamically set file grouping size based on number of files
  • Loading branch information
Floppy authored Jan 17, 2025
2 parents 56018e7 + 4804f60 commit 9780d6e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/helpers/models_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ModelsHelper
def group(files)
return {} if files.empty?
sections = {}
min_section_size = 2
min_section_size = [2, (files.count * 0.05).round].max
min_prefix_length = 3
names = files.map { |it| it.filename.downcase }
slice = names.map(&:length).max
Expand Down
4 changes: 2 additions & 2 deletions app/views/models/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<%= render partial: "file", collection: @groups.delete(nil) %>
</div>
<% @groups.each_pair do |group, files| %>
<h3><a name="<%= group.parameterize %>"><%= group.careful_titleize %></a></h3>
<h3><a name="<%= group.parameterize %>"><%= group.strip.careful_titleize %>*</a></h3>
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 mb-4">
<%= render partial: "file", collection: files %>
</div>
Expand Down Expand Up @@ -134,7 +134,7 @@
<a href="#files">Top</a>
<ul>
<% @groups.each_pair do |group, files| %>
<li><a href="#<%= group.parameterize %>"><%= group.careful_titleize %></a></li>
<li><a href="#<%= group.parameterize %>"><%= group.strip.careful_titleize %>*</a></li>
<% end %>
</ul>
<%= link_to t(".files_card.bulk_edit"), bulk_edit_model_model_files_path(@model), class: "btn btn-secondary" if policy(@model).edit? %>
Expand Down

0 comments on commit 9780d6e

Please sign in to comment.