Moved lib/ to app/
This commit is contained in:
26
app/config.rb
Normal file
26
app/config.rb
Normal file
@ -0,0 +1,26 @@
|
||||
require 'yaml'
|
||||
|
||||
class Config
|
||||
|
||||
DEFAULT_CONFIG = 'data/defaults.yaml'
|
||||
|
||||
def initialize(config_path)
|
||||
@data = YAML::load_file(DEFAULT_CONFIG)
|
||||
|
||||
if File.exists?(config_path)
|
||||
@data.merge!(YAML::load_file(config_path))
|
||||
end
|
||||
end
|
||||
|
||||
def get(key, depth = 0)
|
||||
bits = key.split('.')
|
||||
value = @data
|
||||
|
||||
bits.each do |bit|
|
||||
value = value[bit]
|
||||
end
|
||||
|
||||
return value
|
||||
end
|
||||
|
||||
end
|
25
app/helpers.rb
Normal file
25
app/helpers.rb
Normal file
@ -0,0 +1,25 @@
|
||||
module Helpers
|
||||
|
||||
def nullable(value)
|
||||
if (value) and (value != '')
|
||||
return value
|
||||
else
|
||||
return 'N/a'
|
||||
end
|
||||
end
|
||||
|
||||
def date_format(date)
|
||||
dt = date.to_datetime
|
||||
return dt.strftime('%B %d, %Y, %I:%M:%S %p')
|
||||
end
|
||||
|
||||
def date_format_input(date)
|
||||
dt = date.to_datetime
|
||||
return dt.strftime('%Y-%m-%dT%H:%M:%S')
|
||||
end
|
||||
|
||||
def serialize(num)
|
||||
return num.to_s.rjust(4, '0')
|
||||
end
|
||||
|
||||
end
|
22
app/models/channel.rb
Normal file
22
app/models/channel.rb
Normal file
@ -0,0 +1,22 @@
|
||||
class Channel < Sequel::Model
|
||||
|
||||
one_to_many :videos
|
||||
|
||||
def ensureDirectoryStructure()
|
||||
sub_dirs = ['Archive', 'Channel Documents', 'Main', 'Shorts']
|
||||
sub_dirs.each do |d|
|
||||
sub_path = File.join(
|
||||
@values[:directory_path],
|
||||
d
|
||||
)
|
||||
unless Dir.exist?(sub_path)
|
||||
Dir.mkdir(sub_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def openProjects()
|
||||
return self.videos_dataset.exclude(status: 'published').exclude(archived: true).all()
|
||||
end
|
||||
|
||||
end
|
32
app/models/video.rb
Normal file
32
app/models/video.rb
Normal file
@ -0,0 +1,32 @@
|
||||
require 'kramdown'
|
||||
require 'pandoc-ruby'
|
||||
|
||||
class Video < Sequel::Model
|
||||
|
||||
many_to_one :channel
|
||||
|
||||
def ensureDirectoryStructure()
|
||||
sub_dirs = ['Audio', 'B-Roll', 'Clips', 'Images', 'Export']
|
||||
sub_dirs.each do |d|
|
||||
sub_path = File.join(
|
||||
@values[:directory_path],
|
||||
d
|
||||
)
|
||||
unless Dir.exist?(sub_path)
|
||||
Dir.mkdir(sub_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def parseScript()
|
||||
return Kramdown::Document.new(@values[:script]).to_html
|
||||
end
|
||||
|
||||
def importScript()
|
||||
scripts = Dir.glob("#{@values[:directory_path]}/*Script.docx")
|
||||
script_content = PandocRuby.convert([scripts[0].dump()], from: :docx, to: :markdown)
|
||||
@values[:script] = script_content
|
||||
self.save()
|
||||
end
|
||||
|
||||
end
|
5
app/routes.rb
Normal file
5
app/routes.rb
Normal file
@ -0,0 +1,5 @@
|
||||
require_relative 'routes/index.rb'
|
||||
|
||||
require_relative 'routes/channel.rb'
|
||||
|
||||
require_relative 'routes/video.rb'
|
97
app/routes/channel.rb
Normal file
97
app/routes/channel.rb
Normal file
@ -0,0 +1,97 @@
|
||||
class StageManager
|
||||
class ChannelController
|
||||
|
||||
get '/' do
|
||||
redirect '/channel/list'
|
||||
end
|
||||
get '/list' do
|
||||
channels = Channel.reverse(:updated_at).all()
|
||||
erb :'channel/list', :locals => {
|
||||
:title => 'List of channels',
|
||||
:channels => channels
|
||||
}
|
||||
end
|
||||
|
||||
get '/create' do
|
||||
erb :'channel/create', :locals => {
|
||||
:title => 'Create new channel',
|
||||
:base_directory => $conf.get('stgm.base_directory')
|
||||
}
|
||||
end
|
||||
post '/create' do
|
||||
channel = Channel.create(
|
||||
name: params[:channel_name],
|
||||
directory_path: params[:channel_dir],
|
||||
description: params[:channel_description]
|
||||
)
|
||||
|
||||
# create supporting directory structure
|
||||
Dir.mkdir(channel.directory_path)
|
||||
channel.ensureDirectoryStructure()
|
||||
|
||||
redirect "/channel/#{channel.id}"
|
||||
end
|
||||
|
||||
get '/:channel_id' do
|
||||
channel = Channel.where(id: params[:channel_id]).first()
|
||||
channel_videos = channel.videos_dataset.reverse(:updated_at).limit(10).all()
|
||||
erb :'channel/view', :locals => {
|
||||
:title => channel.name,
|
||||
:channel => channel,
|
||||
:channel_videos => channel_videos
|
||||
}
|
||||
end
|
||||
|
||||
get '/:channel_id/edit' do
|
||||
channel = Channel.where(id: params[:channel_id]).first()
|
||||
erb :'channel/edit', :locals => {
|
||||
:title => "Editing: #{channel.name}",
|
||||
:channel => channel
|
||||
}
|
||||
end
|
||||
post '/:channel_id/edit' do
|
||||
# get channel model and save old directory path
|
||||
channel = Channel.where(id: params[:channel_id]).first()
|
||||
old_path = channel.directory_path
|
||||
|
||||
# edit channel model
|
||||
channel.update(
|
||||
name: params[:channel_name],
|
||||
directory_path: params[:channel_dir],
|
||||
description: params[:channel_description]
|
||||
)
|
||||
|
||||
# edit associate videos' directory paths
|
||||
channel.videos.each do |v|
|
||||
video_path = v.directory_path.sub(old_path, channel.directory_path)
|
||||
v.update(directory_path: video_path)
|
||||
end
|
||||
|
||||
# rename channel directory
|
||||
File.rename(old_path, channel.directory_path)
|
||||
|
||||
# redirect user
|
||||
redirect "/channel/#{channel.id}"
|
||||
end
|
||||
|
||||
post '/:channel_id/edit/:attr' do
|
||||
# find channel and temporarily save the old channel path
|
||||
channel = Channel.where(id: params[:channel_id]).first()
|
||||
attrToEdit = params[:attr]
|
||||
|
||||
if attrToEdit == 'directory_path'
|
||||
File.rename(channel.directory_path, params[:value])
|
||||
channel.videos.each do |v|
|
||||
video_path = v.directory_path.sub(channel.directory_path, params[:value])
|
||||
v.update(directory_path: video_path)
|
||||
end
|
||||
end
|
||||
|
||||
channel[attrToEdit.to_sym] = params[:value]
|
||||
channel.save()
|
||||
|
||||
return "success"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
15
app/routes/index.rb
Normal file
15
app/routes/index.rb
Normal file
@ -0,0 +1,15 @@
|
||||
class StageManager
|
||||
class IndexController
|
||||
|
||||
get '/' do
|
||||
channels = Channel.reverse(:updated_at).limit(10).all()
|
||||
videos = Video.reverse(:updated_at).limit(10).all()
|
||||
erb :index, :locals => {
|
||||
:title => 'Dashboard',
|
||||
:channels => channels,
|
||||
:videos => videos
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
193
app/routes/video.rb
Normal file
193
app/routes/video.rb
Normal file
@ -0,0 +1,193 @@
|
||||
require 'fileutils'
|
||||
|
||||
class StageManager
|
||||
class VideoController
|
||||
|
||||
get '/' do
|
||||
redirect '/video/list'
|
||||
end
|
||||
get '/list' do
|
||||
videos = Video.reverse(:updated_at).all()
|
||||
erb :'video/list', :locals => {
|
||||
:title => 'List of videos',
|
||||
:videos => videos
|
||||
}
|
||||
end
|
||||
|
||||
get '/create' do
|
||||
# check if there's a channel specified
|
||||
selected_channel = false
|
||||
if params.has_key?(:channel)
|
||||
selected_channel = params[:channel].to_i()
|
||||
end
|
||||
|
||||
channels = Channel.all()
|
||||
erb :'video/create', :locals => {
|
||||
:title => 'Create new video',
|
||||
:channels => channels,
|
||||
:selected_channel => selected_channel
|
||||
}
|
||||
end
|
||||
post '/create' do
|
||||
channel = Channel.where(id: params[:video_channel]).first()
|
||||
video_serial = params[:video_serial].to_s.rjust(4, '0')
|
||||
video_path = File.join(
|
||||
channel.directory_path,
|
||||
'Main',
|
||||
"##{video_serial} - #{params[:video_name]}"
|
||||
)
|
||||
|
||||
video = Video.create(
|
||||
serial: params[:video_serial],
|
||||
name: params[:video_name],
|
||||
channel_id: params[:video_channel],
|
||||
directory_path: video_path,
|
||||
description: params[:video_description],
|
||||
script: "# Introduction\n\n# Body\n\n# Conclusions"
|
||||
)
|
||||
|
||||
# create supporting directory structure
|
||||
Dir.mkdir(video_path)
|
||||
video.ensureDirectoryStructure()
|
||||
|
||||
redirect "/video/#{video.id}"
|
||||
end
|
||||
|
||||
get '/:video_id' do
|
||||
video = Video.where(id: params[:video_id]).first()
|
||||
erb :'video/view', :locals => {
|
||||
:title => video.name,
|
||||
:video => video
|
||||
}
|
||||
end
|
||||
|
||||
get '/:video_id/script' do
|
||||
video = Video.where(id: params[:video_id]).first()
|
||||
erb :'video/script', :locals => {
|
||||
:title => "Script: #{video.name}",
|
||||
:video => video
|
||||
}
|
||||
end
|
||||
|
||||
get '/:video_id/edit' do
|
||||
video = Video.where(id: params[:video_id]).first()
|
||||
channels = Channel.all()
|
||||
erb :'video/edit', :locals => {
|
||||
:title => "Editing: #{video.name}",
|
||||
:video => video,
|
||||
:channels => channels
|
||||
}
|
||||
end
|
||||
post '/:video_id/edit' do
|
||||
channel = Channel.where(id: params[:video_channel]).first()
|
||||
video_serial = params[:video_serial].to_s.rjust(4, '0')
|
||||
video_path = File.join(
|
||||
channel.directory_path,
|
||||
'Main',
|
||||
"##{video_serial} - #{params[:video_name]}"
|
||||
)
|
||||
|
||||
# find video and temporarily save the old video path
|
||||
video = Video.where(id: params[:video_id]).first()
|
||||
old_path = video.directory_path
|
||||
|
||||
# edit video attributes
|
||||
video.update(
|
||||
name: params[:video_name],
|
||||
serial: params[:video_serial],
|
||||
channel_id: params[:video_channel],
|
||||
directory_path: video_path,
|
||||
description: params[:video_description]
|
||||
)
|
||||
|
||||
# rename the video project directory
|
||||
File.rename(old_path, video_path)
|
||||
|
||||
# redirect the user
|
||||
redirect "/video/#{video.id}"
|
||||
end
|
||||
|
||||
post '/:video_id/edit/:attr' do
|
||||
# find video and temporarily save the old video path
|
||||
video = Video.where(id: params[:video_id]).first()
|
||||
attrToEdit = params[:attr]
|
||||
|
||||
# if we update the video's serial, we need to also update the directory path
|
||||
if attrToEdit == 'serial'
|
||||
old_path = video.directory_path
|
||||
new_path = video.directory_path.sub("##{video.serial}", "##{params[:value]}")
|
||||
File.rename(old_path, new_path)
|
||||
video[:directory_path] = new_path
|
||||
end
|
||||
|
||||
video[attrToEdit.to_sym] = params[:value]
|
||||
video.save()
|
||||
|
||||
return "success"
|
||||
end
|
||||
|
||||
get '/:video_id/archive' do
|
||||
# find the video
|
||||
video = Video.where(id: params[:video_id]).first()
|
||||
video_base = File.basename(video.directory_path)
|
||||
|
||||
# move project to channel's archive
|
||||
archive_dir = File.join(
|
||||
video.channel.directory_path,
|
||||
'Archive',
|
||||
video_base
|
||||
)
|
||||
FileUtils.mv(video.directory_path, archive_dir)
|
||||
|
||||
# mark the video as archived and update directory
|
||||
video.update(
|
||||
directory_path: archive_dir,
|
||||
archived: true
|
||||
)
|
||||
|
||||
redirect '/video/' + video.id.to_s()
|
||||
end
|
||||
get '/:video_id/unarchive' do
|
||||
# find the video
|
||||
video = Video.where(id: params[:video_id]).first()
|
||||
video_base = File.basename(video.directory_path)
|
||||
|
||||
# move project to channel's archive
|
||||
active_dir = File.join(
|
||||
video.channel.directory_path,
|
||||
'Main',
|
||||
video_base
|
||||
)
|
||||
FileUtils.mv(video.directory_path, active_dir)
|
||||
|
||||
# mark the video as archived and update directory
|
||||
video.update(
|
||||
directory_path: active_dir,
|
||||
archived: false
|
||||
)
|
||||
|
||||
redirect '/video/' + video.id.to_s()
|
||||
end
|
||||
|
||||
get '/:video_id/edit/script' do
|
||||
video = Video.where(id: params[:video_id]).first()
|
||||
erb :'video/edit-script', :locals => {
|
||||
:title => "Editing script: #{video.name}",
|
||||
:video => video
|
||||
}
|
||||
end
|
||||
post '/:video_id/edit/script' do
|
||||
# find video and temporarily save the old video path
|
||||
video = Video.where(id: params[:video_id]).first()
|
||||
|
||||
# edit video attributes
|
||||
video.update(
|
||||
script: params[:video_script]
|
||||
)
|
||||
|
||||
# redirect the user
|
||||
redirect "/video/#{video.id}"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user