Skip to content

Commit

Permalink
Code improvements for #2385
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvieed committed Jun 16, 2022
1 parent fdb42ba commit 64b77fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions app/controllers/article_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def list
# Create a 2D array of articles/subjects for each category
# where the articles are sorted alphabetically vertically
# instead of horizontally -- so, going down each column
@vertical_articles = Array.new(@categories.length()) # Holds articles for each category
@categories.each_with_index do |category, i|
@vertical_articles = {} # Holds articles for each category
@categories.each do |category|
articles = category.articles_list(@collection) # The articles for this category
@vertical_articles[i] = sort_vertically(articles)
@vertical_articles[category] = sort_vertically(articles)
end

# Do the same for uncategorized articles
Expand Down Expand Up @@ -347,7 +347,7 @@ def gis_truncated?(params, dec)
end

def sort_vertically(articles)
rows = (articles.length() % LIST_NUM_COLUMNS == 0) ? (articles.length() / LIST_NUM_COLUMNS) : (articles.length() / LIST_NUM_COLUMNS + 1)
rows = (articles.length().to_f / LIST_NUM_COLUMNS).ceil
vertical_articles = Array.new(rows) { Array.new(LIST_NUM_COLUMNS) } # 2D array of articles

row = 0
Expand Down
6 changes: 3 additions & 3 deletions app/views/article/list.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
li: a.tree-item(href="#category-none") Uncategorized

.category-articles
-@categories.each_with_index do |category, i|
-@categories.each do |category|
dl.category-article(id="category-#{category.id}")
dt
.headline
Expand Down Expand Up @@ -47,8 +47,8 @@
-if category.articles_list(@collection).empty?
p.acenter.fglight There are no subjects for the category selected
-else
-@vertical_articles[i].each do |l|
-l.each do |article|
-@vertical_articles[category].each do |row|
-row.each do |article|
-unless article.nil?
p[*language_attrs(@collection)]
=link_to article.title, collection_article_show_path(@collection.owner, @collection, article.id)
Expand Down

0 comments on commit 64b77fa

Please sign in to comment.