Skip to content

Commit

Permalink
Merge 64b77fa into 87a6e37
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvieed committed Jun 16, 2022
2 parents 87a6e37 + 64b77fa commit 5a33bec
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
37 changes: 35 additions & 2 deletions app/controllers/article_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ArticleController < ApplicationController

DEFAULT_ARTICLES_PER_GRAPH = 40
GIS_DECIMAL_PRECISION = 5
LIST_NUM_COLUMNS = 3

def authorized?
unless user_signed_in?
Expand All @@ -24,9 +25,23 @@ def list
# 2. List should be displayed within the category treeview
# 3. Uncategorized articles should be listed below
if @collection.is_a?(DocumentSet)
@uncategorized_articles = @collection.articles.joins('LEFT JOIN articles_categories ac ON articles.id = ac.article_id').where('ac.category_id IS NULL')
@uncategorized_articles = @collection.articles.joins('LEFT JOIN articles_categories ac ON articles.id = ac.article_id').where('ac.category_id IS NULL').reorder(:title)
else
@uncategorized_articles = @collection.articles.where.not(:id => @collection.articles.joins(:categories).pluck(:id))
@uncategorized_articles = @collection.articles.where.not(:id => @collection.articles.joins(:categories).pluck(:id)).reorder(:title)
end

# 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 = {} # Holds articles for each category
@categories.each do |category|
articles = category.articles_list(@collection) # The articles for this category
@vertical_articles[category] = sort_vertically(articles)
end

# Do the same for uncategorized articles
if @uncategorized_articles.present?
@uncategorized_articles = sort_vertically(@uncategorized_articles)
end
end

Expand Down Expand Up @@ -318,6 +333,24 @@ def gis_truncated?(params, dec)
if lat_dec > dec || lon_dec > dec then return true else return false end
end

def sort_vertically(articles)
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
col = 0
articles.each do |article|
vertical_articles[row][col] = article
row+=1 # Go down a row each time
if row == rows # When you reach the bottom, move to the next column
col+= 1
row = 0
end
end

return vertical_articles
end

private

def article_params
Expand Down
22 changes: 16 additions & 6 deletions app/views/article/list.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,26 @@
-if category.articles_list(@collection).empty?
p.acenter.fglight There are no subjects for the category selected
-else
-category.articles_list(@collection).each do |article|
p[*language_attrs(@collection)]
=link_to article.title, collection_article_show_path(@collection.owner, @collection, article.id)
-@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)
-else
p.hidden
a.hidden a
-if @uncategorized_articles.present?
dl.category-article#category-none
dt: h3 Uncategorized subjects
dd
-@uncategorized_articles.each do |article|
p[*language_attrs(@collection)]
=link_to article.title, collection_article_show_path(@collection.owner, @collection, article.id)
-@uncategorized_articles.each do |l|
-l.each do |article|
-unless article.nil?
p[*language_attrs(@collection)]
=link_to article.title, collection_article_show_path(@collection.owner, @collection, article.id)
-else
p.hidden
a.hidden a
-else
-add_category = link_to 'Create the first category', category_add_new_path(:collection_id => @collection.slug), 'data-litebox' => ''
.nodata
Expand Down

0 comments on commit 5a33bec

Please sign in to comment.