2014-05-14 11:52:06 +00:00
|
|
|
class ArchivesController < ApplicationController
|
2022-04-08 03:20:21 +00:00
|
|
|
def self.custom_widget_data
|
|
|
|
ac = ActionController::Base.new
|
|
|
|
ac.render_to_string("archives/custom_widget_data",:locals=>{:@custom_data_field=>@custom_data_field,:@field_name=>@field_name})
|
|
|
|
end
|
2020-05-26 12:48:24 +00:00
|
|
|
#avoid the categories to be not in the ArchiveCategory
|
2020-09-24 06:55:17 +00:00
|
|
|
def serve_cmap
|
|
|
|
serve_path=File.expand_path("../../assets/javascripts/archive/pdf/bcmaps/#{params[:file_name]}.#{params[:extension]}",__FILE__)
|
|
|
|
if Dir.glob(serve_path).length != 0
|
|
|
|
send_file(serve_path, type: "application/octet-stream")
|
|
|
|
else
|
2020-12-22 05:23:37 +00:00
|
|
|
render :file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => :not_found, :content_type => 'text/html' and return
|
2020-09-24 06:55:17 +00:00
|
|
|
end
|
|
|
|
end
|
2020-05-26 12:44:36 +00:00
|
|
|
def index
|
2022-04-08 03:20:21 +00:00
|
|
|
page = OrbitHelper.page rescue nil
|
|
|
|
unless page
|
|
|
|
page = Page.where(url:params['url']).first
|
|
|
|
end
|
2019-09-05 07:15:45 +00:00
|
|
|
params = OrbitHelper.params
|
2021-09-09 06:35:19 +00:00
|
|
|
@@total_pages = 1
|
2022-04-08 03:20:21 +00:00
|
|
|
in_class = ""
|
|
|
|
custom_data_field = page.custom_data_field rescue nil
|
|
|
|
if custom_data_field && custom_data_field["expanded"] == "yes"
|
|
|
|
in_class = "in"
|
|
|
|
end
|
2021-09-22 04:27:02 +00:00
|
|
|
cats_last = []
|
2021-09-29 14:06:59 +00:00
|
|
|
sort_order = (ArchiveSortOrder.first['sort_order'] rescue false) ? 1 : -1 #Order with ascending
|
2019-09-06 06:26:34 +00:00
|
|
|
if !params['title'].nil?
|
2021-01-18 06:49:00 +00:00
|
|
|
files_by_category = ArchiveFile.where(is_hidden: false).order_by(:created_at => "desc").group_by(&:category)
|
|
|
|
categories = files_by_category.keys
|
2019-09-20 14:01:26 +00:00
|
|
|
categories_sort = get_sorted_cat_with_filter(categories,'orm')
|
|
|
|
categories_sort.each do |category|
|
2019-09-06 06:26:34 +00:00
|
|
|
url_to_edit = ""
|
|
|
|
flag = false
|
|
|
|
archives = []
|
2021-09-29 14:06:59 +00:00
|
|
|
serial_number = 0
|
|
|
|
files_by_category[category].each_with_index do |archive,idx|
|
2019-09-06 06:26:34 +00:00
|
|
|
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 = []
|
2019-11-14 12:45:17 +00:00
|
|
|
archive.archive_file_multiples.order_by(:sort_number=>'desc').each do |file|
|
2019-09-06 06:26:34 +00:00
|
|
|
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 ""
|
2021-09-29 14:06:59 +00:00
|
|
|
serial_number += 1
|
2019-09-06 06:26:34 +00:00
|
|
|
files << {
|
|
|
|
"file-name" => title,
|
|
|
|
"file-type" => extension,
|
2021-09-29 14:06:59 +00:00
|
|
|
"file-url" => "/xhr/archive/download?file=#{file.id}",
|
|
|
|
"serial_number" => serial_number
|
2019-09-06 06:26:34 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2021-09-29 10:43:34 +00:00
|
|
|
if archive.urls.present?
|
|
|
|
archive.urls.each_with_index do |url,i|
|
2021-09-29 14:06:59 +00:00
|
|
|
serial_number += 1
|
2021-09-29 10:43:34 +00:00
|
|
|
files << {
|
|
|
|
"file-name" => archive.title,
|
|
|
|
"file-type" => archive.get_url_text(i),
|
2021-09-29 14:06:59 +00:00
|
|
|
"file-url" => url,
|
|
|
|
"serial_number" => serial_number
|
2021-09-29 10:43:34 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2019-09-06 06:26:34 +00:00
|
|
|
archives << {
|
|
|
|
"archive-title" => archive.title,
|
2021-03-23 09:50:53 +00:00
|
|
|
"description" => archive.description,
|
2019-09-06 06:26:34 +00:00
|
|
|
"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),
|
2021-09-29 14:06:59 +00:00
|
|
|
"files" => files,
|
|
|
|
"idx" => (idx + 1)
|
2019-09-06 06:26:34 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if flag
|
|
|
|
cats_last << {
|
|
|
|
"category-title" => category.title,
|
|
|
|
"archives" => archives,
|
|
|
|
"url_to_edit" => url_to_edit
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if OrbitHelper.page_data_count > 0
|
|
|
|
OrbitHelper.set_page_data_count 0
|
|
|
|
page = Page.where(:page_id => params["page_id"]).first rescue nil
|
|
|
|
if !page.nil?
|
|
|
|
page.data_count = 0
|
|
|
|
page.save
|
|
|
|
end
|
|
|
|
end
|
2021-09-22 04:27:02 +00:00
|
|
|
categories = OrbitHelper.page_categories
|
|
|
|
tags = OrbitHelper.page_tags
|
|
|
|
module_app = ModuleApp.where(:key=>'archive').first
|
|
|
|
if categories == ["all"]
|
|
|
|
categories = module_app.categories.pluck(:id).map(&:to_s)
|
|
|
|
end
|
|
|
|
if tags == ["all"]
|
2021-09-29 11:34:56 +00:00
|
|
|
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}
|
2021-10-07 10:25:43 +00:00
|
|
|
tags << nil
|
2021-09-22 04:27:02 +00:00
|
|
|
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 (tags.count > 1 && categories.count <= 1 rescue false)
|
|
|
|
archive_files = ArchiveFile.where(is_hidden: false,:title.nin=>["",nil]).filter_by_categories.order_by(:created_at => "desc")
|
|
|
|
group_archive_files = {}
|
|
|
|
cats = []
|
|
|
|
each_data_count = []
|
2021-10-07 10:25:43 +00:00
|
|
|
archive_files_ids = archive_files.pluck(:id)
|
|
|
|
archive_files_ids_count = archive_files_ids.count
|
2021-09-22 04:27:02 +00:00
|
|
|
tags.each do |tag_id|
|
2021-10-07 10:25:43 +00:00
|
|
|
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
|
2021-09-29 14:06:59 +00:00
|
|
|
serial_number = 0
|
2021-09-22 04:27:02 +00:00
|
|
|
if archives.count != 0
|
2021-09-30 03:44:39 +00:00
|
|
|
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|
|
2021-09-22 04:27:02 +00:00
|
|
|
statuses = archive.statuses_with_classname.collect do |status|
|
|
|
|
{
|
|
|
|
"status" => status["name"] || "",
|
|
|
|
"status-class" => "status-#{status['classname']}"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
files = []
|
|
|
|
archive.archive_file_multiples.order_by(:sort_number=>'desc').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 ""
|
2021-09-29 14:06:59 +00:00
|
|
|
serial_number += 1
|
2021-09-22 04:27:02 +00:00
|
|
|
files << {
|
|
|
|
"file-name" => title,
|
|
|
|
"file-type" => extension,
|
2021-09-29 14:06:59 +00:00
|
|
|
"file-url" => "/xhr/archive/download?file=#{file.id}",
|
|
|
|
"serial_number" => serial_number
|
2021-09-22 04:27:02 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2021-09-29 11:30:09 +00:00
|
|
|
if archive.urls.present?
|
|
|
|
archive.urls.each_with_index do |url,i|
|
2021-09-29 14:06:59 +00:00
|
|
|
serial_number += 1
|
2021-09-29 11:30:09 +00:00
|
|
|
files << {
|
|
|
|
"file-name" => archive.title,
|
|
|
|
"file-type" => archive.get_url_text(i),
|
2021-09-29 14:06:59 +00:00
|
|
|
"file-url" => url,
|
|
|
|
"serial_number" => serial_number
|
2021-09-29 11:30:09 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2021-09-22 04:27:02 +00:00
|
|
|
{
|
|
|
|
"archive-title" => archive.title,
|
|
|
|
"description" => archive.description,
|
|
|
|
"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),
|
2021-09-29 14:06:59 +00:00
|
|
|
"files" => files,
|
|
|
|
"idx" => (idx + 1)
|
2021-09-22 04:27:02 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
each_data_count.push(archives.length)
|
2021-09-29 14:06:59 +00:00
|
|
|
sorted = archives
|
2021-09-22 04:27:02 +00:00
|
|
|
cats << {
|
2021-10-07 10:25:43 +00:00
|
|
|
"category-title" => tag_name,
|
2021-09-22 04:27:02 +00:00
|
|
|
"archives" => sorted,
|
|
|
|
"url_to_edit" => url_to_edit
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
cats_last = cats
|
|
|
|
else
|
|
|
|
files_by_category = ArchiveFile.where(is_hidden: false,:title.nin=>["",nil]).filter_by_categories.filter_by_tags.order_by(:created_at => "desc").group_by(&:category)
|
2019-09-06 06:26:34 +00:00
|
|
|
each_data_count = []
|
2021-01-18 06:49:00 +00:00
|
|
|
categories = files_by_category.keys
|
2019-09-20 14:01:26 +00:00
|
|
|
categories_sort = get_sorted_cat_with_filter(categories,'orm')
|
|
|
|
cats = categories_sort.collect do |category|
|
2019-09-06 06:26:34 +00:00
|
|
|
url_to_edit = OrbitHelper.user_has_cateogry?(category) ? "/admin/archive_files?filters[category][]=#{category.id.to_s}" : ""
|
2021-09-29 14:06:59 +00:00
|
|
|
serial_number = 0
|
2021-09-30 03:44:39 +00:00
|
|
|
archives = files_by_category[category].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]}.collect.with_index do |archive,idx|
|
2019-09-06 06:26:34 +00:00
|
|
|
statuses = archive.statuses_with_classname.collect do |status|
|
|
|
|
{
|
|
|
|
"status" => status["name"] || "",
|
|
|
|
"status-class" => "status-#{status['classname']}"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
files = []
|
2019-11-18 12:36:24 +00:00
|
|
|
archive.archive_file_multiples.order_by(:sort_number=>'desc').each do |file|
|
2019-09-06 06:26:34 +00:00
|
|
|
if file.choose_lang.include?(I18n.locale.to_s)
|
2021-09-29 14:06:59 +00:00
|
|
|
serial_number += 1
|
2019-09-06 06:26:34 +00:00
|
|
|
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,
|
2021-09-29 14:06:59 +00:00
|
|
|
"file-url" => "/xhr/archive/download?file=#{file.id}",
|
|
|
|
"serial_number" => serial_number
|
2019-09-06 06:26:34 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2021-09-29 10:43:34 +00:00
|
|
|
if archive.urls.present?
|
|
|
|
archive.urls.each_with_index do |url,i|
|
2021-09-29 14:06:59 +00:00
|
|
|
serial_number += 1
|
2021-09-29 10:43:34 +00:00
|
|
|
files << {
|
|
|
|
"file-name" => archive.title,
|
|
|
|
"file-type" => archive.get_url_text(i),
|
2021-09-29 14:06:59 +00:00
|
|
|
"file-url" => url,
|
|
|
|
"serial_number" => serial_number
|
2021-09-29 10:43:34 +00:00
|
|
|
}
|
|
|
|
end
|
2021-03-23 11:01:49 +00:00
|
|
|
end
|
2019-09-06 06:26:34 +00:00
|
|
|
{
|
|
|
|
"archive-title" => archive.title,
|
2021-03-23 09:50:53 +00:00
|
|
|
"description" => archive.description,
|
2019-09-06 06:26:34 +00:00
|
|
|
"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),
|
2021-09-29 14:06:59 +00:00
|
|
|
"files" => files,
|
|
|
|
"idx" => (idx + 1)
|
2019-09-06 06:26:34 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
each_data_count.push(archives.length)
|
2021-09-29 14:06:59 +00:00
|
|
|
sorted = archives
|
2019-09-06 06:26:34 +00:00
|
|
|
{
|
2021-10-07 10:25:43 +00:00
|
|
|
"category-title" => (categories.count > 1 ? category.title : ""),
|
2019-09-06 06:26:34 +00:00
|
|
|
"archives" => sorted,
|
|
|
|
"url_to_edit" => url_to_edit
|
|
|
|
}
|
|
|
|
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
|
2019-09-05 07:15:45 +00:00
|
|
|
end
|
2019-09-06 06:26:34 +00:00
|
|
|
else
|
|
|
|
cats_last = [Hash[cats[0].map{|k,v| [k,'']}]]
|
|
|
|
end
|
|
|
|
@@total_pages = (all_data_count.to_f / page_data_count).ceil
|
|
|
|
else
|
|
|
|
if page_no!=1
|
|
|
|
cats_last = [Hash[cats[0].map{|k,v| [k,'']}]]
|
|
|
|
@@total_pages = 0
|
|
|
|
else
|
|
|
|
cats_last = cats
|
|
|
|
@@total_pages = 1
|
2019-09-05 07:15:45 +00:00
|
|
|
end
|
2019-09-06 06:26:34 +00:00
|
|
|
end
|
2021-09-22 04:27:02 +00:00
|
|
|
end
|
2019-09-06 06:26:34 +00:00
|
|
|
end
|
2014-05-14 11:52:06 +00:00
|
|
|
{
|
2021-03-23 09:50:53 +00:00
|
|
|
"categories" => cats_last,
|
2021-09-22 04:27:02 +00:00
|
|
|
"extras" =>{
|
2021-09-29 14:06:59 +00:00
|
|
|
"serial_number-head" => I18n.t("archive.serial_number"),
|
2021-09-22 04:27:02 +00:00
|
|
|
"date-head" => I18n.t("archive.updated_at"),
|
2021-09-29 14:06:59 +00:00
|
|
|
"title-head" => I18n.t(:name),
|
2021-09-22 04:27:02 +00:00
|
|
|
"description-head"=>I18n.t("archive.description"),
|
2022-04-08 03:20:21 +00:00
|
|
|
"file-head" =>I18n.t("archive.download_file"),
|
|
|
|
"in_class" => in_class
|
2021-09-22 04:27:02 +00:00
|
|
|
}
|
2014-05-14 11:52:06 +00:00
|
|
|
}
|
|
|
|
end
|
2014-05-23 06:00:49 +00:00
|
|
|
|
2015-03-18 09:59:03 +00:00
|
|
|
def download_file
|
|
|
|
file_id = params[:file]
|
|
|
|
file = ArchiveFileMultiple.find(file_id) rescue nil
|
|
|
|
if !file.nil?
|
2020-05-17 13:30:39 +00:00
|
|
|
file.download_count = file.download_count + 1
|
|
|
|
file.save
|
|
|
|
@url = file.file.url
|
|
|
|
begin
|
|
|
|
@path = file.file.file.file rescue ""
|
|
|
|
@filename = @path.split("/").last
|
|
|
|
@ext = @path.split("/").last.to_s.split(".").last
|
2020-05-20 03:52:25 +00:00
|
|
|
if @ext == "png" || @ext == "jpg" || @ext == "bmp" || @ext == "pdf"
|
2020-05-17 13:30:39 +00:00
|
|
|
render "download_file",:layout=>false
|
|
|
|
else
|
2021-06-21 05:25:01 +00:00
|
|
|
if (current_site.accessibility_mode rescue false)
|
|
|
|
render "redirect_to_file",:layout=>false
|
|
|
|
else
|
|
|
|
send_file(@path)
|
|
|
|
end
|
2020-05-17 13:30:39 +00:00
|
|
|
end
|
|
|
|
rescue
|
|
|
|
redirect_to @url
|
|
|
|
end
|
|
|
|
else
|
|
|
|
render :file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => :not_found
|
|
|
|
end
|
2015-03-18 09:59:03 +00:00
|
|
|
end
|
|
|
|
|
2015-08-18 09:57:16 +00:00
|
|
|
def group_by_category
|
|
|
|
cat_id = OrbitHelper.widget_categories.map {|cat_id| cat_id.to_s}
|
2015-07-17 07:29:41 +00:00
|
|
|
if OrbitHelper.widget_tags.first == "all"
|
2021-01-18 06:49:00 +00:00
|
|
|
files_by_category = ArchiveFile.where(:category_id.in => OrbitHelper.widget_categories).with_tags(OrbitHelper.widget_module_app.tags.collect{|tag| tag.id.to_s}).asc(:sort_number).group_by(&:category)
|
2015-07-17 07:29:41 +00:00
|
|
|
else
|
2021-01-18 06:49:00 +00:00
|
|
|
files_by_category = ArchiveFile.where(:category_id.in => OrbitHelper.widget_categories).with_tags(OrbitHelper.widget_tags).asc(:sort_number).group_by(&:category)
|
2015-07-17 07:29:41 +00:00
|
|
|
end
|
2021-01-18 06:49:00 +00:00
|
|
|
cats = files_by_category.keys.collect do |cat|
|
|
|
|
files_by_category_tag = files_by_category[cat].group_by(&:tags)
|
2015-07-17 07:29:41 +00:00
|
|
|
|
2015-07-20 02:40:46 +00:00
|
|
|
ts = []
|
2015-08-18 09:57:16 +00:00
|
|
|
archive_counts = 0
|
2015-07-20 02:40:46 +00:00
|
|
|
files_by_category_tag.keys.each do |t|
|
|
|
|
archives = []
|
2015-08-18 09:57:16 +00:00
|
|
|
archive_counts = archive_counts + 1
|
2015-07-20 02:40:46 +00:00
|
|
|
files_by_category_tag[t].each_with_index do |archive,index|
|
|
|
|
a = {
|
2015-07-15 07:24:15 +00:00
|
|
|
"archive-title" => archive.title,
|
2021-03-23 09:50:53 +00:00
|
|
|
"description" => archive.description,
|
2019-03-06 10:31:13 +00:00
|
|
|
"archive-url" => archive.url,
|
2015-08-18 10:00:52 +00:00
|
|
|
"archive_url" => OrbitHelper.widget_more_url
|
2015-07-15 07:24:15 +00:00
|
|
|
}
|
2015-07-20 02:40:46 +00:00
|
|
|
|
|
|
|
if t.count > 1
|
|
|
|
t.each do |inner_tag|
|
|
|
|
index = ts.index{|tot| tot["tag-name"] == inner_tag.name}
|
|
|
|
if !index.nil?
|
2015-08-18 09:57:16 +00:00
|
|
|
break if ts[index]["archives"].count >= OrbitHelper.widget_data_count
|
2015-07-20 02:40:46 +00:00
|
|
|
ts[index]["archives"] << a
|
|
|
|
else
|
2015-08-18 09:57:16 +00:00
|
|
|
break if archives.count >= OrbitHelper.widget_data_count
|
2015-07-20 02:40:46 +00:00
|
|
|
archives << a
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2015-08-18 09:57:16 +00:00
|
|
|
break if archives.count >= OrbitHelper.widget_data_count
|
2015-07-20 02:40:46 +00:00
|
|
|
archives << a
|
2015-07-15 07:24:15 +00:00
|
|
|
end
|
2015-08-18 09:57:16 +00:00
|
|
|
|
2015-07-20 02:40:46 +00:00
|
|
|
end
|
|
|
|
ts << {
|
|
|
|
"tag-name" => (t[0].name rescue ""),
|
|
|
|
"archives" => archives
|
2015-08-18 09:57:16 +00:00
|
|
|
} if !archives.blank? && archive_counts < OrbitHelper.widget_data_count
|
2014-05-23 06:00:49 +00:00
|
|
|
end
|
|
|
|
{
|
2015-07-15 07:24:15 +00:00
|
|
|
"category-title" => cat.title,
|
|
|
|
"tags" => ts
|
2014-05-23 06:00:49 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"categories" => cats,
|
2019-09-05 07:15:45 +00:00
|
|
|
"extras" => {"widget-title" => "Archives","more_url" => OrbitHelper.widget_more_url}
|
2014-05-23 06:00:49 +00:00
|
|
|
}
|
|
|
|
end
|
2015-08-18 09:57:16 +00:00
|
|
|
|
|
|
|
def widget
|
2019-09-05 07:15:45 +00:00
|
|
|
page_data_count = OrbitHelper.widget_data_count
|
2019-09-20 14:01:26 +00:00
|
|
|
categories = OrbitHelper.widget_categories #data are categories' ids or 'all'
|
2015-08-18 09:57:16 +00:00
|
|
|
@categories = []
|
|
|
|
if categories.first == "all"
|
2019-09-20 14:01:26 +00:00
|
|
|
categories = OrbitHelper.widget_module_app.categories
|
|
|
|
categories_sort = get_sorted_cat_with_filter(categories,'orm')
|
|
|
|
@categories = categories_sort.collect do |cat|
|
2015-08-18 09:57:16 +00:00
|
|
|
{
|
|
|
|
"title" => cat.title,
|
|
|
|
"id" => cat.id.to_s
|
|
|
|
}
|
|
|
|
end
|
|
|
|
else
|
2019-09-20 14:01:26 +00:00
|
|
|
categories_sort = get_sorted_cat_with_filter(categories,'id')
|
|
|
|
@categories = categories_sort.collect do |cat|
|
|
|
|
{
|
|
|
|
"title" => cat.title,
|
|
|
|
"id" => cat.id.to_s
|
|
|
|
}
|
2015-08-18 09:57:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
cats = @categories.collect do |cat|
|
2021-01-18 07:23:46 +00:00
|
|
|
if ArchiveSortOrder.first.sort_order #Order with ascending
|
2019-09-05 07:15:45 +00:00
|
|
|
archives_all = ArchiveFile.can_display.where(:category_id => cat["id"]).filter_by_tags(OrbitHelper.widget_tags)
|
|
|
|
temp_with_nil = archives_all.in(sort_number: nil).order_by(created_at: 'desc')
|
|
|
|
temp_no_nil = archives_all.not_in(sort_number: nil).order_by(sort_number: 'asc',created_at: 'desc')
|
|
|
|
archives_temp = temp_no_nil.concat(temp_with_nil)
|
|
|
|
archives = archives_temp.collect do |archive|
|
|
|
|
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])
|
|
|
|
else
|
2019-09-06 06:26:34 +00:00
|
|
|
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}"
|
2019-09-05 07:15:45 +00:00
|
|
|
end
|
|
|
|
{
|
|
|
|
"archive-title" => archive.title,
|
2021-03-23 09:50:53 +00:00
|
|
|
"description" => archive.description,
|
2019-09-05 07:15:45 +00:00
|
|
|
"archive-url" => archive.url,
|
|
|
|
"archive_url" => url
|
|
|
|
}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
archives_temp = ArchiveFile.can_display.where(:category_id => cat["id"]).filter_by_tags(OrbitHelper.widget_tags).order_by(sort_number: 'desc',created_at: 'desc')
|
|
|
|
archives = archives_temp.collect do |archive|
|
|
|
|
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])
|
|
|
|
else
|
2019-09-06 06:26:34 +00:00
|
|
|
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}"
|
2019-09-05 07:15:45 +00:00
|
|
|
end
|
|
|
|
{
|
|
|
|
"archive-title" => archive.title,
|
2021-03-23 09:50:53 +00:00
|
|
|
"description" => archive.description,
|
2019-09-05 07:15:45 +00:00
|
|
|
"archive-url" => archive.url,
|
|
|
|
"archive_url" => url
|
|
|
|
}
|
|
|
|
end
|
2015-08-18 09:57:16 +00:00
|
|
|
end
|
|
|
|
{
|
|
|
|
"category-title" => cat["title"],
|
2017-09-25 07:01:00 +00:00
|
|
|
"category-id" => cat["id"],
|
2015-08-18 09:57:16 +00:00
|
|
|
"archives" => archives
|
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"categories" => cats,
|
2019-09-05 07:15:45 +00:00
|
|
|
"extras" => {"widget-title" => "Archives","more_url" => (OrbitHelper.widget_more_url + '?data_count=' + page_data_count.to_s)}
|
2015-08-18 09:57:16 +00:00
|
|
|
}
|
|
|
|
end
|
2019-09-05 07:15:45 +00:00
|
|
|
private
|
2019-09-20 14:01:26 +00:00
|
|
|
def get_sorted_cat_with_filter(categories,cat_type)
|
2020-06-11 09:22:34 +00:00
|
|
|
all_categories_with_nil = ArchiveCategory.all.in(sort_number: nil).uniq{|c| c.category_id }.to_a rescue []
|
2021-01-18 07:23:46 +00:00
|
|
|
sort_method = ArchiveSortOrder.first.sort_order ? 'asc' : 'desc'
|
|
|
|
all_categories_no_nil = ArchiveCategory.all.not_in(sort_number: nil).order_by(sort_number: sort_method).uniq{|c| c.category_id }.to_a rescue []
|
2019-09-20 14:01:26 +00:00
|
|
|
all_categories_id = all_categories_no_nil.concat(all_categories_with_nil).collect do |cat|
|
|
|
|
cat.category_id.to_s
|
|
|
|
end
|
|
|
|
if cat_type=='id'
|
|
|
|
categories_temp = ModuleApp.where(:key => "archive").first.categories
|
|
|
|
categories = categories_temp.select{|cat| categories.include? cat.id.to_s}
|
|
|
|
end
|
|
|
|
categories_sort = []
|
|
|
|
all_categories_id.each do |cat_id|
|
|
|
|
category_selected = categories.select{|category| cat_id == category.id.to_s}
|
|
|
|
if category_selected.length!=0
|
|
|
|
categories_sort << category_selected[0]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
categories_sort
|
|
|
|
end
|
|
|
|
def self.get_total_pages
|
|
|
|
@@total_pages
|
|
|
|
end
|
2021-09-09 06:35:19 +00:00
|
|
|
end
|