This commit is contained in:
BoHung Chiu 2021-10-07 18:25:43 +08:00
parent 110fa90581
commit 75b24a6cd0
3 changed files with 30 additions and 7 deletions

View File

@ -95,6 +95,7 @@ class ArchivesController < ApplicationController
end end
if tags == ["all"] 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.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 end
if params[:data_count].to_i <=0 if params[:data_count].to_i <=0
page_data_count = 0 page_data_count = 0
@ -111,12 +112,32 @@ class ArchivesController < ApplicationController
group_archive_files = {} group_archive_files = {}
cats = [] cats = []
each_data_count = [] each_data_count = []
archive_files_ids = archive_files.pluck(:id)
archive_files_ids_count = archive_files_ids.count
tags.each do |tag_id| tags.each do |tag_id|
tag = Tag.find(tag_id) rescue nil tag_name = ""
next if tag.nil? if tag_id
url_to_edit = OrbitHelper.current_user ? "/admin/archive_files?filters[tags][]=#{tag_id}" : "" tag = Tag.find(tag_id) rescue nil
taggings = Tagging.where(:tag_id=>tag_id).pluck(:taggable_id) next if tag.nil?
archives = archive_files.where(:id.in=>taggings).to_a 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 serial_number = 0
if archives.count != 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| 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) each_data_count.push(archives.length)
sorted = archives sorted = archives
cats << { cats << {
"category-title" => Tag.find(tag_id).name, "category-title" => tag_name,
"archives" => sorted, "archives" => sorted,
"url_to_edit" => url_to_edit "url_to_edit" => url_to_edit
} }
@ -230,7 +251,7 @@ class ArchivesController < ApplicationController
each_data_count.push(archives.length) each_data_count.push(archives.length)
sorted = archives sorted = archives
{ {
"category-title" => category.title, "category-title" => (categories.count > 1 ? category.title : ""),
"archives" => sorted, "archives" => sorted,
"url_to_edit" => url_to_edit "url_to_edit" => url_to_edit
} }

View File

@ -2,6 +2,7 @@ en:
restful_actions: restful_actions:
categories_order: Categories Order categories_order: Categories Order
archive: archive:
other: Other
serial_number: "Serial Number" serial_number: "Serial Number"
url_text: "URL Text" url_text: "URL Text"
url_text_hint: "URL Text, default: link" url_text_hint: "URL Text, default: link"

View File

@ -2,6 +2,7 @@ zh_tw:
restful_actions: restful_actions:
categories_order: 類別排序 categories_order: 類別排序
archive: archive:
other: 其他
serial_number: "編號" serial_number: "編號"
url_text: "連結文字" url_text: "連結文字"
url_text_hint: "連結文字預設為link" url_text_hint: "連結文字預設為link"