vlog/app/controllers/vlogs_controller.rb

74 lines
2.1 KiB
Ruby
Raw Normal View History

2015-12-26 14:02:01 +00:00
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
2015-12-26 14:07:37 +00:00
def widget
2017-04-13 07:42:29 +00:00
vlog = VLog.all.filter_by_widget_categories.sample(1).first
2017-04-13 07:36:41 +00:00
if vlog.type == "upload" && !vlog.v_log_video.nil?
video = "<video src='#{vlog.v_log_video.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
{
"video" => video,
"extras" => {"widget-title"=>t(:web_resource),"more_url" => OrbitHelper.widget_more_url}
}
2015-12-26 14:07:37 +00:00
end
2015-12-26 14:02:01 +00:00
def show
params = OrbitHelper.params
vlog = VLog.where(:uid => params[:uid]).first
2015-12-26 18:22:26 +00:00
if vlog.type == "upload" && !vlog.v_log_video.nil?
video = "<video src='#{vlog.v_log_video.video.url}' controls> Your browser does not support the <code>video</code> element.</video>"
2015-12-26 14:02:01 +00:00
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