vlog/app/controllers/vlogs_controller.rb

67 lines
1.6 KiB
Ruby

class VlogsController < ApplicationController
def index
vlogs = VLog.all.order_by(:created_at=>'desc').filter_by_categories.filter_by_tags.collect do |vlog|
{
"thumbnail" => (vlog.type == "youtube" ? vlog.youtube_thumbnail : vlog.thumbnail),
"title" => vlog.title,
"username" => (!vlog.create_user_id.nil? ? User.find(vlog.create_user_id).name : ""),
"url_to_show" => OrbitHelper.url_to_show(vlog.to_param)
}
end
heads = ["vlog.thumbnail", :title, "vlog.uploaded_by"].collect do |title|
{
"column-title" => t(title)
}
end
{
"heads" => heads,
"vlogs" => vlogs
}
end
def widget
{
"extras" => {}
}
end
def show
params = OrbitHelper.params
vlog = VLog.where(:uid => params[:uid]).first
if vlog.type == "upload" && (!vlog.video.url.nil? || vlog.video.url != "")
video = "<video src='#{vlog.video.url}' controls> Your browser does not support the <code>video</code> element.</video>"
elsif vlog.type == "youtube" && !vlog.youtube_link.nil?
video = "<iframe src='#{vlog.youtube_link}' allowfullscreen frameborder='0'></iframe>"
end
files = vlog.v_log_files.collect do |file|
title = (file.title.blank? ? File.basename(file.file.path) : file.title) rescue ""
{
"title" => title,
"link" => "/xhr/vlogfiles/download?file=#{file.id}"
}
end
{
"files" => files,
"data" => {
"title" => vlog.title,
"subtitle" => vlog.subtitle,
"type" => vlog.type,
"video" => video
}
}
end
def download_file
file_id = params[:file]
file = VLogFile.find(file_id) rescue nil
if !file.nil?
redirect_to file.file.url and return
end
render :nothing => true
end
end