2015-12-26 14:02:01 +00:00
|
|
|
class Admin::VlogsController < OrbitAdminController
|
|
|
|
|
|
|
|
def index
|
|
|
|
tags = @module_app.tags
|
|
|
|
categories = @module_app.categories.enabled
|
|
|
|
@filter_fields = filter_fields(categories, tags)
|
|
|
|
@filter_fields.delete(:status)
|
|
|
|
@table_fields = ["vlog.thumbnail", :category, :title, "vlog.uploaded_by"]
|
|
|
|
|
2016-01-12 10:13:55 +00:00
|
|
|
@vlogs = VLog.all
|
2015-12-26 14:02:01 +00:00
|
|
|
.order_by(sort)
|
|
|
|
.with_categories(filters("category"))
|
|
|
|
.with_tags(filters("tag"))
|
|
|
|
|
|
|
|
@vlogs = search_data(@vlogs,[:title]).page(params[:page]).per(10)
|
|
|
|
if request.xhr?
|
|
|
|
render :partial => "index"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@vlog = VLog.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
vlog = VLog.find(params[:id])
|
|
|
|
vlog.destroy
|
|
|
|
redirect_to admin_vlogs_path(:page => params[:page])
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@vlog = VLog.find(params[:id]) rescue nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
vlog = VLog.where(:uid => params[:id].split("-").last).first rescue nil
|
|
|
|
if !vlog.nil?
|
|
|
|
if params[:v_log][:type] == "upload"
|
2015-12-26 18:22:26 +00:00
|
|
|
if params[:video_temp_id].present?
|
|
|
|
old_video = vlog.v_log_video
|
|
|
|
old_video.destroy
|
|
|
|
video = VLogVideo.find(params[:video_temp_id]) rescue nil
|
|
|
|
video.v_log_id = vlog.id if !video.nil?
|
|
|
|
video.save
|
2015-12-26 14:02:01 +00:00
|
|
|
end
|
|
|
|
vlog.update_attributes(vlog_params)
|
|
|
|
vlog.save
|
|
|
|
elsif params[:v_log][:type] == "youtube"
|
|
|
|
p = vlog_params
|
|
|
|
p[:youtube_link] = format_url(p[:youtube_link]) if p[:youtube_link].present?
|
|
|
|
vlog = VLog.update_attributes(vlog_params)
|
|
|
|
vlog.save
|
|
|
|
end
|
|
|
|
end
|
2015-12-26 16:42:40 +00:00
|
|
|
redirect_to admin_vlogs_path(:page => params[:page])
|
2015-12-26 14:02:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
if params[:v_log][:type] == "upload"
|
|
|
|
vlog = VLog.create(vlog_params)
|
2015-12-26 18:22:26 +00:00
|
|
|
video = VLogVideo.find(params[:video_temp_id]) rescue nil
|
|
|
|
video.v_log_id = vlog.id if !video.nil?
|
|
|
|
video.save
|
2015-12-26 14:02:01 +00:00
|
|
|
elsif params[:v_log][:type] == "youtube"
|
|
|
|
p = vlog_params
|
|
|
|
p[:youtube_link] = format_url(p[:youtube_link]) if p[:youtube_link].present?
|
2015-12-26 18:22:26 +00:00
|
|
|
vlog = VLog.create(p)
|
2015-12-26 14:02:01 +00:00
|
|
|
end
|
|
|
|
redirect_to admin_vlogs_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def clear_temp_dir
|
2015-12-26 18:22:26 +00:00
|
|
|
video = VLogVideo.find(params[:video_id]) rescue nil
|
|
|
|
if !video.nil?
|
|
|
|
video.destroy
|
|
|
|
end
|
2015-12-26 14:02:01 +00:00
|
|
|
render :json => {"success" => true}.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_temp_dir_name
|
|
|
|
dirname = Digest::MD5.hexdigest(Time.now.to_s)
|
|
|
|
directory = "public/vlog_temp_files/#{dirname}"
|
|
|
|
FileUtils.mkdir_p(directory) unless File.exists?(directory)
|
2015-12-26 18:22:26 +00:00
|
|
|
path_to_file = "#{directory}/#{params[:filename]}"
|
|
|
|
File.open(path_to_file,"w")
|
|
|
|
video = VLogVideo.new
|
|
|
|
video.video = Rails.root.join(path_to_file).open
|
|
|
|
video.save
|
|
|
|
FileUtils.remove_dir(directory)
|
|
|
|
render :json => {"video_id" => video.id.to_s}.to_json
|
2015-12-26 14:02:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def upload_temp_file
|
|
|
|
file = params[:video_file]
|
2015-12-26 18:22:26 +00:00
|
|
|
video = VLogVideo.find(params[:video_id]) rescue nil
|
|
|
|
if !video.nil?
|
|
|
|
File.open(video.video.path,"ab"){ |f| f.write(file.read) }
|
|
|
|
end
|
2015-12-26 14:02:01 +00:00
|
|
|
render :json => {"success" => true}.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def vlog_params
|
|
|
|
p = params.require(:v_log).permit!
|
|
|
|
p[:create_user_id] = current_user.id if !p[:create_user_id].present?
|
|
|
|
p
|
|
|
|
end
|
|
|
|
|
|
|
|
def format_url(url)
|
|
|
|
uri = URI.parse(url)
|
|
|
|
ps = uri.query.split("&")
|
|
|
|
url_params = {}
|
|
|
|
ps.each do |p|
|
|
|
|
x = p.split("=")
|
|
|
|
url_params[x.first] = x.last
|
|
|
|
end
|
|
|
|
url = "http://www.youtube.com/embed/#{url_params["v"]}"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|