diff --git a/app/controllers/archives_controller.rb b/app/controllers/archives_controller.rb index 9d740e1..5eb5b0d 100644 --- a/app/controllers/archives_controller.rb +++ b/app/controllers/archives_controller.rb @@ -73,8 +73,9 @@ class ArchivesController < ApplicationController if categories == ["all"] categories = module_app.categories.pluck(:id).map(&:to_s) end + org_tags = tags if tags == ["all"] - tags = module_app.tags.sort_by{|tag| ((module_app.asc rescue true) ? tag.sort_number.to_i : -tag.sort_number.to_i)}.map{|tag| tag.id.to_s} + tags = module_app.tags.map{|tag| tag.id.to_s} tags << nil end if params[:data_count].to_i > 0 @@ -134,63 +135,63 @@ class ArchivesController < ApplicationController end cats_last = cats else - files_by_category = ArchiveFile.can_display.filter_by_categories(categories, false).filter_by_tags(tags).sorted.group_by(&:category) - each_data_count = [] - categories = files_by_category.keys - categories_sort = get_sorted_cat_with_filter(categories, :orm) - cats = categories_sort.collect.with_index do |category, cat_idx| - url_to_edit = OrbitHelper.user_has_cateogry?(category) ? "/admin/archive_files?filters[category][]=#{category.id.to_s}" : "" - serial_number = 0 - archives = files_by_category[category].collect.with_index do |archive,idx| - data, serial_number, idx = archive.get_frontend_data(locale, serial_number, idx) - data - end - each_data_count.push(archives.length) - sorted = archives - { - "category-id" => category.id, - "category-title" => (categories.count > 1 ? category.title : ""), - "archives" => sorted, - "url_to_edit" => url_to_edit - } - end - if page_data_count != 0 - # all_data_count = 0 - data_start = -1 - data_end = -1 - page_data_end = page_no * page_data_count #Not include end - page_data_start = page_data_end - page_data_count - # all_data_count = each_data_count.sum - cats_last = [] - counter = 0 - cats.each do |cat_data| - start_idx = page_data_start - counter - end_idx = page_data_end - counter - archives = cat_data['archives'] - archives_count = archives.count - counter += archives_count - if start_idx >= archives_count - next - elsif start_idx < 0 - start_idx = 0 - end - archives = archives[start_idx...end_idx] - if archives && archives.count > 0 - cat_data['archives'] = archives - cats_last << cat_data + files_by_category = ArchiveFile.can_display.filter_by_categories(categories, false).filter_by_tags(org_tags).sorted.group_by(&:category) + each_data_count = [] + categories = files_by_category.keys + categories_sort = get_sorted_cat_with_filter(categories, :orm) + cats = categories_sort.collect.with_index do |category, cat_idx| + url_to_edit = OrbitHelper.user_has_cateogry?(category) ? "/admin/archive_files?filters[category][]=#{category.id.to_s}" : "" + serial_number = 0 + archives = files_by_category[category].collect.with_index do |archive,idx| + data, serial_number, idx = archive.get_frontend_data(locale, serial_number, idx) + data end + each_data_count.push(archives.length) + sorted = archives + { + "category-id" => category.id, + "category-title" => (categories.count > 1 ? category.title : ""), + "archives" => sorted, + "url_to_edit" => url_to_edit + } end - @@total_pages = (counter.to_f / page_data_count).ceil - else - if page_no!=1 - cats_last = [Hash[cats[0].map{|k,v| [k,'']}]] - @@total_pages = 0 + if page_data_count != 0 + # all_data_count = 0 + data_start = -1 + data_end = -1 + page_data_end = page_no * page_data_count #Not include end + page_data_start = page_data_end - page_data_count + # all_data_count = each_data_count.sum + cats_last = [] + counter = 0 + cats.each do |cat_data| + start_idx = page_data_start - counter + end_idx = page_data_end - counter + archives = cat_data['archives'] + archives_count = archives.count + counter += archives_count + if start_idx >= archives_count + next + elsif start_idx < 0 + start_idx = 0 + end + archives = archives[start_idx...end_idx] + if archives && archives.count > 0 + cat_data['archives'] = archives + cats_last << cat_data + end + end + @@total_pages = (counter.to_f / page_data_count).ceil else - cats_last = cats - @@total_pages = 1 + if page_no != 1 + cats_last = [Hash[cats[0].map{|k,v| [k,'']}]] + @@total_pages = 0 + else + cats_last = cats + @@total_pages = 1 + end end end - end end if cats_last.count != 0 cats_last.each_with_index do |h, i|