parent
f9bfac44c6
commit
31e0a645b6
|
@ -6,18 +6,11 @@ class ArchivesController < ApplicationController
|
||||||
ArchiveSortOrder.new('sort_order' => false).save
|
ArchiveSortOrder.new('sort_order' => false).save
|
||||||
end
|
end
|
||||||
params = OrbitHelper.params
|
params = OrbitHelper.params
|
||||||
all_categories_id = get_all_categories_id_sorted
|
|
||||||
puts all_categories_id
|
puts all_categories_id
|
||||||
if !params['title'].nil?
|
if !params['title'].nil?
|
||||||
files_by_cateogry = ArchiveFile.where(is_hidden: false).group_by(&:category)
|
files_by_cateogry = ArchiveFile.where(is_hidden: false).group_by(&:category)
|
||||||
categories = files_by_cateogry.keys
|
categories = files_by_cateogry.keys
|
||||||
categories_sort = []
|
categories_sort = get_sorted_cat_with_filter(categories,'orm')
|
||||||
all_categories_id.each do |cat_id|
|
|
||||||
category_selected = categories.select{|category| cat_id == category.id.to_s}
|
|
||||||
if category_selected.length!=0
|
|
||||||
categories_sort << category_selected[0]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
cats_last = []
|
cats_last = []
|
||||||
categories_sort.each do |category|
|
categories_sort.each do |category|
|
||||||
url_to_edit = ""
|
url_to_edit = ""
|
||||||
|
@ -77,13 +70,7 @@ class ArchivesController < ApplicationController
|
||||||
files_by_cateogry = ArchiveFile.where(is_hidden: false).filter_by_categories.filter_by_tags.group_by(&:category)
|
files_by_cateogry = ArchiveFile.where(is_hidden: false).filter_by_categories.filter_by_tags.group_by(&:category)
|
||||||
each_data_count = []
|
each_data_count = []
|
||||||
categories = files_by_cateogry.keys
|
categories = files_by_cateogry.keys
|
||||||
categories_sort = []
|
categories_sort = get_sorted_cat_with_filter(categories,'orm')
|
||||||
all_categories_id.each do |cat_id|
|
|
||||||
category_selected = categories.select{|category| cat_id == category.id.to_s}
|
|
||||||
if category_selected.length!=0
|
|
||||||
categories_sort << category_selected[0]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
cats = categories_sort.collect do |category|
|
cats = categories_sort.collect do |category|
|
||||||
url_to_edit = OrbitHelper.user_has_cateogry?(category) ? "/admin/archive_files?filters[category][]=#{category.id.to_s}" : ""
|
url_to_edit = OrbitHelper.user_has_cateogry?(category) ? "/admin/archive_files?filters[category][]=#{category.id.to_s}" : ""
|
||||||
archives = files_by_cateogry[category].collect do |archive|
|
archives = files_by_cateogry[category].collect do |archive|
|
||||||
|
@ -272,10 +259,9 @@ F cats = files_by_cateogry.keys.collect do |cat|
|
||||||
page_data_count = OrbitHelper.widget_data_count
|
page_data_count = OrbitHelper.widget_data_count
|
||||||
categories = OrbitHelper.widget_categories #data are categories' ids or 'all'
|
categories = OrbitHelper.widget_categories #data are categories' ids or 'all'
|
||||||
@categories = []
|
@categories = []
|
||||||
all_categories_id = get_all_categories_id_sorted
|
|
||||||
if categories.first == "all"
|
if categories.first == "all"
|
||||||
categories = OrbitHelper.widget_module_app.categories
|
categories = OrbitHelper.widget_module_app.categories
|
||||||
categories_sort = categories.select{|category| all_categories_id.include? category.id.to_s}
|
categories_sort = get_sorted_cat_with_filter(categories,'orm')
|
||||||
@categories = categories_sort.collect do |cat|
|
@categories = categories_sort.collect do |cat|
|
||||||
{
|
{
|
||||||
"title" => cat.title,
|
"title" => cat.title,
|
||||||
|
@ -283,10 +269,12 @@ F cats = files_by_cateogry.keys.collect do |cat|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
categories_sort = categories.select{|category| all_categories_id.include? category}
|
categories_sort = get_sorted_cat_with_filter(categories,'id')
|
||||||
categories_sort.each do |cat|
|
@categories = categories_sort.collect do |cat|
|
||||||
c = Category.find(cat)
|
{
|
||||||
@categories << {"title" => c.title, "id" => c.id.to_s}
|
"title" => cat.title,
|
||||||
|
"id" => cat.id.to_s
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
cats = @categories.collect do |cat|
|
cats = @categories.collect do |cat|
|
||||||
|
@ -334,17 +322,29 @@ F cats = files_by_cateogry.keys.collect do |cat|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
private
|
private
|
||||||
def self.get_total_pages
|
def get_sorted_cat_with_filter(categories,cat_type)
|
||||||
@@total_pages
|
|
||||||
end
|
|
||||||
def get_all_categories_id_sorted
|
|
||||||
all_categories_with_nil = ArchiveCategory.all.in(sort_number: nil)
|
all_categories_with_nil = ArchiveCategory.all.in(sort_number: nil)
|
||||||
all_categories_no_nil = ArchiveCategory.all.not_in(sort_number: nil).order_by(sort_number: 'desc')
|
all_categories_no_nil = ArchiveCategory.all.not_in(sort_number: nil).order_by(sort_number: 'desc')
|
||||||
all_categories_id = all_categories_no_nil.concat(all_categories_with_nil).collect do |cat|
|
all_categories_id = all_categories_no_nil.concat(all_categories_with_nil).collect do |cat|
|
||||||
cat.category_id.to_s
|
cat.category_id.to_s
|
||||||
end
|
end
|
||||||
all_categories_id
|
all_categories_id
|
||||||
end
|
categories_sort = []
|
||||||
|
all_categories_id.each do |cat_id|
|
||||||
|
if cat_type=='orm'
|
||||||
|
category_selected = categories.select{|category| cat_id == category.id.to_s}
|
||||||
|
elsif cat_type=='id'
|
||||||
|
category_selected = categories.select{|category| cat_id == category}
|
||||||
|
end
|
||||||
|
if category_selected.length!=0
|
||||||
|
categories_sort << category_selected[0]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
categories_sort
|
||||||
|
end
|
||||||
|
def self.get_total_pages
|
||||||
|
@@total_pages
|
||||||
|
end
|
||||||
def check_cat_sort_data
|
def check_cat_sort_data
|
||||||
categories_temp = ModuleApp.where(:key => "archive").first.categories
|
categories_temp = ModuleApp.where(:key => "archive").first.categories
|
||||||
categories_temp.each do |category|
|
categories_temp.each do |category|
|
||||||
|
|
Loading…
Reference in New Issue