Update archives_controller.rb

let user can see only a title at index when he click on the one title not read more
This commit is contained in:
chiu 2019-09-06 14:26:34 +08:00
parent e77ca26b03
commit c36c9e9ab3
1 changed files with 171 additions and 118 deletions

View File

@ -4,6 +4,57 @@ class ArchivesController < ApplicationController
ArchiveSortOrder.new('sort_order' => false).save ArchiveSortOrder.new('sort_order' => false).save
end end
params = OrbitHelper.params params = OrbitHelper.params
if !params['title'].nil?
files_by_cateogry = ArchiveFile.where(is_hidden: false).group_by(&:category)
categories = files_by_cateogry.keys
cats_last = []
categories.each do |category|
url_to_edit = ""
flag = false
archives = []
files_by_cateogry[category].each do |archive|
if archive.title == params['title']
flag = true
statuses = archive.statuses_with_classname.collect do |status|
{
"status" => status["name"] || "",
"status-class" => "status-#{status['classname']}"
}
end
files = []
archive.archive_file_multiples.each do |file|
if file.choose_lang.include?(I18n.locale.to_s)
title = (file.file_title.blank? ? File.basename(file.file.path) : file.file_title) rescue ""
extension = file.file.file.extension.downcase rescue ""
files << {
"file-name" => title,
"file-type" => extension,
"file-url" => "/xhr/archive/download?file=#{file.id}"
}
end
end
archives << {
"archive-title" => archive.title,
"created_at" => archive.created_at.strftime('%Y%m%d').to_i,
"archive-url" => archive.url,
"url" => archive.url,
"statuses" => statuses,
"sort_number" => archive.sort_number,
"is_top" => (archive.is_top ? 1 : 0),
"files" => files
}
end
end
if flag
cats_last << {
"category-title" => category.title,
"archives" => archives,
"url_to_edit" => url_to_edit
}
end
end
@@total_pages = 1
else
if OrbitHelper.page_data_count > 0 if OrbitHelper.page_data_count > 0
OrbitHelper.set_page_data_count 0 OrbitHelper.set_page_data_count 0
page = Page.where(:page_id => params["page_id"]).first rescue nil page = Page.where(:page_id => params["page_id"]).first rescue nil
@ -123,6 +174,8 @@ class ArchivesController < ApplicationController
@@total_pages = 1 @@total_pages = 1
end end
end end
end
puts cats_last
{ {
"categories" => cats_last "categories" => cats_last
} }
@ -225,7 +278,7 @@ F cats = files_by_cateogry.keys.collect do |cat|
if archive.archive_file_multiples.count==0 if archive.archive_file_multiples.count==0
url = (archive[:url][OrbitHelper.get_site_locale].to_s.empty? ? 'javascript:void' : archive[:url][OrbitHelper.get_site_locale]) url = (archive[:url][OrbitHelper.get_site_locale].to_s.empty? ? 'javascript:void' : archive[:url][OrbitHelper.get_site_locale])
else else
url = archive.archive_file_multiples.count > 1 ? OrbitHelper.widget_more_url : "/xhr/archive/download?file=#{archive.archive_file_multiples.first.id}" url = archive.archive_file_multiples.count > 1 ? (OrbitHelper.widget_more_url + '?title=' + archive.title.to_s) : "/xhr/archive/download?file=#{archive.archive_file_multiples.first.id}"
end end
{ {
"archive-title" => archive.title, "archive-title" => archive.title,
@ -239,7 +292,7 @@ F cats = files_by_cateogry.keys.collect do |cat|
if archive.archive_file_multiples.count==0 if archive.archive_file_multiples.count==0
url = (archive[:url][OrbitHelper.get_site_locale].to_s.empty? ? 'javascript:void' : archive[:url][OrbitHelper.get_site_locale]) url = (archive[:url][OrbitHelper.get_site_locale].to_s.empty? ? 'javascript:void' : archive[:url][OrbitHelper.get_site_locale])
else else
url = archive.archive_file_multiples.count > 1 ? (OrbitHelper.widget_more_url + '?data_count=' + page_data_count.to_s) : "/xhr/archive/download?file=#{archive.archive_file_multiples.first.id}" url = archive.archive_file_multiples.count > 1 ? (OrbitHelper.widget_more_url + '?title=' + archive.title.to_s) : "/xhr/archive/download?file=#{archive.archive_file_multiples.first.id}"
end end
{ {
"archive-title" => archive.title, "archive-title" => archive.title,