Update archives_controller.rb

finish
This commit is contained in:
chiu 2019-09-19 22:13:49 +08:00
parent 7c0fa37235
commit c4dec8d0b4
1 changed files with 20 additions and 3 deletions

View File

@ -1,5 +1,13 @@
class ArchivesController < ApplicationController class ArchivesController < ApplicationController
def index def index
#the first 7 lines are write to avoid the categories to be not in the ArchiveCategory
categories_temp = ModuleApp.where(:key => "archive").first.categories
categories_temp.each do |category|
archive_cat = ArchiveCategory.all.select{ |value| value.category_id.to_s == category.id.to_s}
if archive_cat.length == 0
ArchiveCategory.create(category_id: category.id.to_s)
end
end
if ArchiveSortOrder.count == 0 if ArchiveSortOrder.count == 0
ArchiveSortOrder.new('sort_order' => false).save ArchiveSortOrder.new('sort_order' => false).save
end end
@ -7,9 +15,13 @@ class ArchivesController < ApplicationController
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
puts categories.inspect 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')
categories_sort = all_categories_no_nil.concat(all_categories_with_nil).collect do |cat|
categories.where(:_id => cat.category_id).first
end
cats_last = [] cats_last = []
categories.each do |category| categories_sort.each do |category|
url_to_edit = "" url_to_edit = ""
flag = false flag = false
archives = [] archives = []
@ -67,7 +79,12 @@ 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
cats = categories.collect do |category| 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')
categories_sort = all_categories_no_nil.concat(all_categories_with_nil).collect do |cat|
categories.where(:_id => cat.category_id).first
end
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|
statuses = archive.statuses_with_classname.collect do |status| statuses = archive.statuses_with_classname.collect do |status|