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:
parent
e77ca26b03
commit
c36c9e9ab3
|
@ -4,125 +4,178 @@ class ArchivesController < ApplicationController
|
||||||
ArchiveSortOrder.new('sort_order' => false).save
|
ArchiveSortOrder.new('sort_order' => false).save
|
||||||
end
|
end
|
||||||
params = OrbitHelper.params
|
params = OrbitHelper.params
|
||||||
if OrbitHelper.page_data_count > 0
|
if !params['title'].nil?
|
||||||
OrbitHelper.set_page_data_count 0
|
files_by_cateogry = ArchiveFile.where(is_hidden: false).group_by(&:category)
|
||||||
page = Page.where(:page_id => params["page_id"]).first rescue nil
|
categories = files_by_cateogry.keys
|
||||||
if !page.nil?
|
cats_last = []
|
||||||
page.data_count = 0
|
categories.each do |category|
|
||||||
page.save
|
url_to_edit = ""
|
||||||
end
|
flag = false
|
||||||
end
|
archives = []
|
||||||
files_by_cateogry = ArchiveFile.where(is_hidden: false).filter_by_categories.filter_by_tags.group_by(&:category)
|
files_by_cateogry[category].each do |archive|
|
||||||
each_data_count = []
|
if archive.title == params['title']
|
||||||
categories = files_by_cateogry.keys
|
flag = true
|
||||||
cats = categories.collect do |category|
|
statuses = archive.statuses_with_classname.collect do |status|
|
||||||
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|
|
"status" => status["name"] || "",
|
||||||
statuses = archive.statuses_with_classname.collect do |status|
|
"status-class" => "status-#{status['classname']}"
|
||||||
{
|
}
|
||||||
"status" => status["name"] || "",
|
end
|
||||||
"status-class" => "status-#{status['classname']}"
|
files = []
|
||||||
}
|
archive.archive_file_multiples.each do |file|
|
||||||
end
|
if file.choose_lang.include?(I18n.locale.to_s)
|
||||||
files = []
|
title = (file.file_title.blank? ? File.basename(file.file.path) : file.file_title) rescue ""
|
||||||
archive.archive_file_multiples.each do |file|
|
extension = file.file.file.extension.downcase rescue ""
|
||||||
if file.choose_lang.include?(I18n.locale.to_s)
|
files << {
|
||||||
title = (file.file_title.blank? ? File.basename(file.file.path) : file.file_title) rescue ""
|
"file-name" => title,
|
||||||
extension = file.file.file.extension.downcase rescue ""
|
"file-type" => extension,
|
||||||
files << {
|
"file-url" => "/xhr/archive/download?file=#{file.id}"
|
||||||
"file-name" => title,
|
}
|
||||||
"file-type" => extension,
|
end
|
||||||
"file-url" => "/xhr/archive/download?file=#{file.id}"
|
end
|
||||||
}
|
archives << {
|
||||||
end
|
"archive-title" => archive.title,
|
||||||
end
|
"created_at" => archive.created_at.strftime('%Y%m%d').to_i,
|
||||||
{
|
"archive-url" => archive.url,
|
||||||
"archive-title" => archive.title,
|
"url" => archive.url,
|
||||||
"created_at" => archive.created_at.strftime('%Y%m%d').to_i,
|
"statuses" => statuses,
|
||||||
"archive-url" => archive.url,
|
"sort_number" => archive.sort_number,
|
||||||
"url" => archive.url,
|
"is_top" => (archive.is_top ? 1 : 0),
|
||||||
"statuses" => statuses,
|
"files" => files
|
||||||
"sort_number" => archive.sort_number,
|
}
|
||||||
"is_top" => (archive.is_top ? 1 : 0),
|
end
|
||||||
"files" => files
|
end
|
||||||
}
|
if flag
|
||||||
end
|
cats_last << {
|
||||||
each_data_count.push(archives.length)
|
"category-title" => category.title,
|
||||||
sorted = archives.sort_by{|k,v| -k["sort_number"].to_i}
|
"archives" => archives,
|
||||||
sorted = sorted.sort{|k,v| v["is_top"] <=> k["is_top"]}
|
"url_to_edit" => url_to_edit
|
||||||
{
|
}
|
||||||
"category-title" => category.title,
|
end
|
||||||
"archives" => sorted,
|
|
||||||
"url_to_edit" => url_to_edit
|
|
||||||
}
|
|
||||||
end
|
|
||||||
if ArchiveSortOrder.first['sort_order'] #Order with ascending
|
|
||||||
cats = cats.collect do |cat|
|
|
||||||
Hash[cat.map{|k,v| [k,k=='archives' ? (v.sort_by{|tp| [(tp['sort_number'].nil? ? Float::INFINITY : tp['sort_number'].to_i),-tp['created_at']]}) : v] }]
|
|
||||||
end
|
|
||||||
else
|
|
||||||
cats = cats.collect do |cat|
|
|
||||||
Hash[cat.map{|k,v| [k,k=='archives' ? (v.sort_by{|tp| [(tp['sort_number'].nil? ? Float::INFINITY : -tp['sort_number'].to_i),-tp['created_at']]}) : v] }]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if params[:data_count].to_i <=0
|
|
||||||
page_data_count = 0
|
|
||||||
else
|
|
||||||
page_data_count = params[:data_count].to_i
|
|
||||||
end
|
|
||||||
if params[:page_no].nil?
|
|
||||||
page_no = 1
|
|
||||||
else
|
|
||||||
page_no = params[:page_no].to_i
|
|
||||||
end
|
|
||||||
if page_data_count != 0
|
|
||||||
all_data_count = 0
|
|
||||||
data_start = -1
|
|
||||||
data_end = -1
|
|
||||||
for i in 0...each_data_count.length
|
|
||||||
all_data_count_before = all_data_count
|
|
||||||
all_data_count += each_data_count[i]
|
|
||||||
if ( data_start == -1 && (all_data_count > (page_no - 1) * page_data_count) )
|
|
||||||
data_start = i
|
|
||||||
data_start_first = (page_no - 1) * page_data_count - all_data_count_before
|
|
||||||
end
|
|
||||||
if ( data_end == -1 && (all_data_count > (page_no * page_data_count - 1)) )
|
|
||||||
data_end = i
|
|
||||||
data_end_last = (page_no * page_data_count - 1) - all_data_count_before
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if ( data_end == -1 && data_start != -1)
|
@@total_pages = 1
|
||||||
data_end = i
|
else
|
||||||
data_end_last = -1
|
if OrbitHelper.page_data_count > 0
|
||||||
end
|
OrbitHelper.set_page_data_count 0
|
||||||
if data_start!=-1 && page_no>=1
|
page = Page.where(:page_id => params["page_id"]).first rescue nil
|
||||||
cats_last = []
|
if !page.nil?
|
||||||
for i in data_start..data_end
|
page.data_count = 0
|
||||||
if data_start != data_end
|
page.save
|
||||||
if i==data_start
|
end
|
||||||
cats_last << Hash[cats[i].map{|k,v| [k , (k=='archives' ? v[data_start_first..-1] : v)]}]
|
end
|
||||||
elsif i==data_end
|
files_by_cateogry = ArchiveFile.where(is_hidden: false).filter_by_categories.filter_by_tags.group_by(&:category)
|
||||||
cats_last << Hash[cats[i].map{|k,v| [k , (k=='archives' ? v[0..data_end_last] : v)]}]
|
each_data_count = []
|
||||||
else
|
categories = files_by_cateogry.keys
|
||||||
cats_last << cats[i]
|
cats = categories.collect do |category|
|
||||||
end
|
url_to_edit = OrbitHelper.user_has_cateogry?(category) ? "/admin/archive_files?filters[category][]=#{category.id.to_s}" : ""
|
||||||
else
|
archives = files_by_cateogry[category].collect do |archive|
|
||||||
cats_last << Hash[cats[i].map{|k,v| [k,(k=='archives' ? v[data_start_first..data_end_last] : v)]}]
|
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
|
||||||
|
{
|
||||||
|
"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
|
||||||
|
each_data_count.push(archives.length)
|
||||||
|
sorted = archives.sort_by{|k,v| -k["sort_number"].to_i}
|
||||||
|
sorted = sorted.sort{|k,v| v["is_top"] <=> k["is_top"]}
|
||||||
|
{
|
||||||
|
"category-title" => category.title,
|
||||||
|
"archives" => sorted,
|
||||||
|
"url_to_edit" => url_to_edit
|
||||||
|
}
|
||||||
|
end
|
||||||
|
if ArchiveSortOrder.first['sort_order'] #Order with ascending
|
||||||
|
cats = cats.collect do |cat|
|
||||||
|
Hash[cat.map{|k,v| [k,k=='archives' ? (v.sort_by{|tp| [(tp['sort_number'].nil? ? Float::INFINITY : tp['sort_number'].to_i),-tp['created_at']]}) : v] }]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
cats = cats.collect do |cat|
|
||||||
|
Hash[cat.map{|k,v| [k,k=='archives' ? (v.sort_by{|tp| [(tp['sort_number'].nil? ? Float::INFINITY : -tp['sort_number'].to_i),-tp['created_at']]}) : v] }]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if params[:data_count].to_i <=0
|
||||||
|
page_data_count = 0
|
||||||
|
else
|
||||||
|
page_data_count = params[:data_count].to_i
|
||||||
|
end
|
||||||
|
if params[:page_no].nil?
|
||||||
|
page_no = 1
|
||||||
|
else
|
||||||
|
page_no = params[:page_no].to_i
|
||||||
|
end
|
||||||
|
if page_data_count != 0
|
||||||
|
all_data_count = 0
|
||||||
|
data_start = -1
|
||||||
|
data_end = -1
|
||||||
|
for i in 0...each_data_count.length
|
||||||
|
all_data_count_before = all_data_count
|
||||||
|
all_data_count += each_data_count[i]
|
||||||
|
if ( data_start == -1 && (all_data_count > (page_no - 1) * page_data_count) )
|
||||||
|
data_start = i
|
||||||
|
data_start_first = (page_no - 1) * page_data_count - all_data_count_before
|
||||||
|
end
|
||||||
|
if ( data_end == -1 && (all_data_count > (page_no * page_data_count - 1)) )
|
||||||
|
data_end = i
|
||||||
|
data_end_last = (page_no * page_data_count - 1) - all_data_count_before
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if ( data_end == -1 && data_start != -1)
|
||||||
|
data_end = i
|
||||||
|
data_end_last = -1
|
||||||
|
end
|
||||||
|
if data_start!=-1 && page_no>=1
|
||||||
|
cats_last = []
|
||||||
|
for i in data_start..data_end
|
||||||
|
if data_start != data_end
|
||||||
|
if i==data_start
|
||||||
|
cats_last << Hash[cats[i].map{|k,v| [k , (k=='archives' ? v[data_start_first..-1] : v)]}]
|
||||||
|
elsif i==data_end
|
||||||
|
cats_last << Hash[cats[i].map{|k,v| [k , (k=='archives' ? v[0..data_end_last] : v)]}]
|
||||||
|
else
|
||||||
|
cats_last << cats[i]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
cats_last << Hash[cats[i].map{|k,v| [k,(k=='archives' ? v[data_start_first..data_end_last] : v)]}]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
cats_last = [Hash[cats[0].map{|k,v| [k,'']}]]
|
||||||
end
|
end
|
||||||
else
|
@@total_pages = (all_data_count.to_f / page_data_count).ceil
|
||||||
cats_last = [Hash[cats[0].map{|k,v| [k,'']}]]
|
else
|
||||||
end
|
if page_no!=1
|
||||||
@@total_pages = (all_data_count.to_f / page_data_count).ceil
|
cats_last = [Hash[cats[0].map{|k,v| [k,'']}]]
|
||||||
else
|
@@total_pages = 0
|
||||||
if page_no!=1
|
else
|
||||||
cats_last = [Hash[cats[0].map{|k,v| [k,'']}]]
|
cats_last = cats
|
||||||
@@total_pages = 0
|
@@total_pages = 1
|
||||||
else
|
end
|
||||||
cats_last = cats
|
end
|
||||||
@@total_pages = 1
|
end
|
||||||
end
|
puts cats_last
|
||||||
end
|
|
||||||
{
|
{
|
||||||
"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,
|
||||||
|
|
Loading…
Reference in New Issue