diff --git a/app/controllers/archives_controller.rb b/app/controllers/archives_controller.rb index 0fae38c..2ecce79 100644 --- a/app/controllers/archives_controller.rb +++ b/app/controllers/archives_controller.rb @@ -95,6 +95,7 @@ class ArchivesController < ApplicationController end 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 << nil end if params[:data_count].to_i <=0 page_data_count = 0 @@ -111,12 +112,32 @@ class ArchivesController < ApplicationController group_archive_files = {} cats = [] each_data_count = [] + archive_files_ids = archive_files.pluck(:id) + archive_files_ids_count = archive_files_ids.count tags.each do |tag_id| - tag = Tag.find(tag_id) rescue nil - next if tag.nil? - url_to_edit = OrbitHelper.current_user ? "/admin/archive_files?filters[tags][]=#{tag_id}" : "" - taggings = Tagging.where(:tag_id=>tag_id).pluck(:taggable_id) - archives = archive_files.where(:id.in=>taggings).to_a + tag_name = "" + if tag_id + tag = Tag.find(tag_id) rescue nil + next if tag.nil? + url_to_edit = OrbitHelper.current_user ? "/admin/archive_files?filters[tags][]=#{tag_id}" : "" + taggings = Tagging.where(:tag_id=>tag_id).pluck(:taggable_id) + archives = archive_files.where(:id.in=>taggings).to_a + archive_files_ids = archive_files_ids - archives.map{|a| a.id} + tag_name = Tag.find(tag_id).name + else + if categories.count == 1 + url_to_edit = OrbitHelper.current_user ? "/admin/archive_files?filters[category][]=#{categories[0]}" : "" + else + url_to_edit = OrbitHelper.current_user ? "/admin/archive_files" : "" + end + archives = [] + if tags.count > 1 && archive_files_ids_count != archive_files_ids.count + tag_name = I18n.t("archive.other") + archives = archive_files.where(:id.in=>archive_files_ids).to_a + else + archives = archive_files.to_a + end + end serial_number = 0 if archives.count != 0 archives = archives.sort_by{|k| [(k["is_top"] ? 0 : 1) ,(k["sort_number"].nil? ? Float::INFINITY : sort_order * k["sort_number"].to_i),-k["created_at"].to_i]}.map.with_index do |archive,idx| @@ -167,7 +188,7 @@ class ArchivesController < ApplicationController each_data_count.push(archives.length) sorted = archives cats << { - "category-title" => Tag.find(tag_id).name, + "category-title" => tag_name, "archives" => sorted, "url_to_edit" => url_to_edit } @@ -230,7 +251,7 @@ class ArchivesController < ApplicationController each_data_count.push(archives.length) sorted = archives { - "category-title" => category.title, + "category-title" => (categories.count > 1 ? category.title : ""), "archives" => sorted, "url_to_edit" => url_to_edit } diff --git a/config/locales/en.yml b/config/locales/en.yml index 11cac90..dd6a711 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,6 +2,7 @@ en: restful_actions: categories_order: Categories Order archive: + other: Other serial_number: "Serial Number" url_text: "URL Text" url_text_hint: "URL Text, default: link" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index c415979..5ffc7d3 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -2,6 +2,7 @@ zh_tw: restful_actions: categories_order: 類別排序 archive: + other: 其他 serial_number: "編號" url_text: "連結文字" url_text_hint: "連結文字,預設為link"