95 lines
2.6 KiB
Ruby
95 lines
2.6 KiB
Ruby
class ArchivesController < ApplicationController
|
|
def index
|
|
categories = OrbitHelper.page_categories
|
|
@categories = []
|
|
if categories.first == "all"
|
|
module_app = OrbitHelper.this_module_app
|
|
@categories = module_app.categories
|
|
else
|
|
categories.each do |cat|
|
|
@categories << Category.find(cat)
|
|
end
|
|
end
|
|
cats = @categories.collect do |cat|
|
|
url_to_edit = OrbitHelper.user_has_cateogry?(cat) ? "/admin/archive_files?filters[category][]=#{cat.id.to_s}" : ""
|
|
archives = ArchiveFile.where(:category_id => cat.id).order_by(:sort_number=>'asc').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').collect do |file|
|
|
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 ""
|
|
{
|
|
"file-name" => title,
|
|
"file-type" => extension,
|
|
"file-url" => "/xhr/archive/download?file=#{file.id}"
|
|
}
|
|
end
|
|
|
|
{
|
|
"archive-title" => archive.title || "",
|
|
"statuses" => statuses,
|
|
"files" => files
|
|
}
|
|
end
|
|
{
|
|
"category-title" => cat.title || "",
|
|
"archives" => archives ,
|
|
"url_to_edit" => url_to_edit
|
|
}
|
|
end
|
|
{
|
|
"categories" => cats
|
|
}
|
|
end
|
|
|
|
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 = []
|
|
if categories.first == "all"
|
|
module_app = OrbitHelper.widget_module_app
|
|
@categories = module_app.categories.collect do |cat|
|
|
{
|
|
"title" => cat.title,
|
|
"id" => cat.id.to_s
|
|
}
|
|
end
|
|
else
|
|
categories.each do |cat|
|
|
c = Category.find(cat)
|
|
@categories << {"title" => c.title, "id" => c.id.to_s}
|
|
end
|
|
end
|
|
cats = @categories.collect do |cat|
|
|
archives = ArchiveFile.can_display.where(:category_id => cat["id"]).collect do |archive|
|
|
{
|
|
"archive-title" => archive.title,
|
|
"archive_url" => OrbitHelper.widget_more_url
|
|
}
|
|
end
|
|
{
|
|
"category-title" => cat["title"],
|
|
"archives" => archives
|
|
}
|
|
end
|
|
{
|
|
"categories" => cats,
|
|
"extras" => {"widget-title" => "Archives","more_url"=>OrbitHelper.widget_more_url}
|
|
}
|
|
end
|
|
end |