archive1/app/controllers/archives_controller.rb

146 lines
3.4 KiB
Ruby
Raw Normal View History

2014-05-14 11:52:06 +00:00
class ArchivesController < ApplicationController
def index
2014-05-14 11:52:06 +00:00
categories = OrbitHelper.page_categories
tags = OrbitHelper.page_tags
@tags = []
if tags.first == "all"
2014-05-14 11:52:06 +00:00
module_app = OrbitHelper.this_module_app
@tags = module_app.tags
2014-05-14 11:52:06 +00:00
else
tags.each do |tag|
@tags << Tag.find(tag)
2014-05-14 11:52:06 +00:00
end
end
2015-05-01 08:48:49 +00:00
files_by_cateogry = ArchiveFile.filter_by_categories.group_by(&:category)
cats = files_by_cateogry.keys.collect do |cat|
files_by_category_tag = files_by_cateogry[cat].group_by(&:tags)
files_by_category_tag.keys.each do |f|
if(!@tags.include?(f[0]))
files_by_category_tag.delete(f)
2014-05-14 11:52:06 +00:00
end
end
ts = files_by_category_tag.keys.collect do |t|
url_to_edit = OrbitHelper.user_has_cateogry?(cat) ? "/admin/archive_files?filters[category][]=#{cat.id.to_s}" : ""
archives = files_by_category_tag[t].collect do |archive|
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=>'asc').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 ""
# url = file.file.url rescue ""
files << {
"file-name" => title,
"file-type" => extension,
"file-url" => "/xhr/archive/download?file=#{file.id}"
}
end
2014-07-16 09:35:36 +00:00
end
{
"archive-title" => archive.title || "",
"statuses" => statuses,
"files" => files
}
end
2014-05-14 11:52:06 +00:00
{
"tag-name" => t[0].name,
"archives" => archives,
"url_to_edit" => url_to_edit
2014-05-14 11:52:06 +00:00
}
end
if(files_by_category_tag.empty?)
{
"category-title" => "",
"tags" => ts
}
else
{
"category-title" => cat.title || "",
"tags" => ts
}
end
2014-05-14 11:52:06 +00:00
end
{
2014-07-16 09:11:29 +00:00
"categories" => cats
2014-05-14 11:52:06 +00:00
}
end
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?
file.download_count = file.download_count + 1
file.save
redirect_to file.file.url and return
end
render :nothing => true
end
def widget
categories = OrbitHelper.widget_categories
@categories = []
tags = OrbitHelper.widget_tags
@tags = []
if tags.first == "all"
module_app = OrbitHelper.widget_module_app
@tags = module_app.tags
else
tags.each do |tag|
@tags << Tag.find(tag)
end
end
files_by_cateogry = ArchiveFile.filter_by_widget_categories.group_by(&:category)
cats = files_by_cateogry.keys.collect do |cat|
files_by_category_tag = files_by_cateogry[cat].group_by(&:tags)
files_by_category_tag.keys.each do |f|
if(!@tags.include?(f[0]))
files_by_category_tag.delete(f)
end
end
ts = files_by_category_tag.keys.collect do |t|
archives = files_by_category_tag[t].collect do |archive|
{
"archive-title" => archive.title,
"archive_url" => OrbitHelper.widget_more_url
}
end
{
"tag-name" => t[0].name,
"archives" => archives
}
end
{
"category-title" => cat.title,
"tags" => ts
}
end
{
"categories" => cats,
2014-05-24 11:37:07 +00:00
"extras" => {"widget-title" => "Archives","more_url"=>OrbitHelper.widget_more_url}
}
end
2014-05-14 11:52:06 +00:00
end