video/app/controllers/admin/video_channels_controller.rb

62 lines
1.6 KiB
Ruby

class Admin::VideoChannelsController < OrbitAdminController
def index
@table_fields = [:title,:category,t('video.owner')]
@video_channels = VideoChannel.all
@tags = @module_app.tags
@categories = @module_app.categories
@filter_fields = filter_fields(@categories, @tags)
@video_channels = VideoChannel.order_by(sort).with_categories(filters("category")).with_tags(filters("tag"))
end
def new
@video_channel = VideoChannel.new
@tags = @module_app.tags
@categories = @module_app.categories
end
def create
@video_channel = VideoChannel.new(video_channel_vars)
@video_channel.save
redirect_to admin_video_channels_path
end
def edit
@video_channel = VideoChannel.find(params[:id])
if can_edit_or_delete?(@video_channel)
@tags = @module_app.tags
@categories = @module_app.categories
else
render_401
end
end
def show
@video_channel = VideoChannel.find(params[:id])
channel_id = @video_channel.channel_link.split("/")[-1]
uri = URI('https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=' + channel_id + '&key=AIzaSyCTFdyLgb7GJfrr1JOI3gvVslZFw7td2zQ')
@r = Net::HTTP.get(uri) # => String
@r = JSON.parse(@r)
end
def update
video_channel = VideoChannel.find(params[:id])
video_channel.update_attributes(video_channel_vars)
video_channel.save
redirect_to admin_video_channels_path
end
def destroy
video_channel = VideoChannel.find(params[:id])
video_channel.destroy
redirect_to admin_video_channels_path
end
def setup_vars
@module_app = ModuleApp.where(:key => "video").first
end
def video_channel_vars
params.require(:video_channel).permit!
end
end