8 Commits

17 changed files with 220 additions and 16 deletions

View File

@@ -9,6 +9,8 @@ gem 'sqlite3', '~> 1.6'
gem 'kramdown', '~> 2.4'
gem 'pandoc-ruby', '~> 2.1'
# Use rerun gem to auto-reload app
gem 'rerun'

View File

@@ -11,6 +11,7 @@ GEM
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
nio4r (2.5.8)
pandoc-ruby (2.1.7)
puma (6.1.1)
nio4r (~> 2.0)
rack (2.2.6.2)
@@ -43,6 +44,7 @@ PLATFORMS
DEPENDENCIES
kramdown (~> 2.4)
pandoc-ruby (~> 2.1)
puma (~> 6.1)
rerun
sequel (~> 5.66)

41
assets/coffee/wyrm.coffee Normal file
View File

@@ -0,0 +1,41 @@
$(document).ready(() ->
$('.channel-path').click((e) ->
newPath = prompt('New channel directory path', $(this).find('span').text())
if newPath
payload =
directory_path: newPath
channelId = $('#channel-id').val()
$.post('/channel/' + channelId + '/edit/directory_path', payload, (data) ->
if data == 'success'
$('.channel-path span').text(newPath)
)
)
$('.video-status').click((e) ->
newStatus = prompt('New video status', $(this).find('span').text())
if newStatus
newStatus = newStatus.toLowerCase()
payload =
status: newStatus
videoId = $('#video-id').val()
$.post('/video/' + videoId + '/edit/status', payload, (data) ->
if data == 'success'
$('.video-status span').text(capitalizeWord(newStatus))
)
)
$('.video-serial').click((e) ->
newSerial = prompt('New video serial number', $(this).find('span').text())
if newSerial
payload =
serial: newSerial
videoId = $('#video-id').val()
$.post('/video/' + videoId + '/edit/serial', payload, (data) ->
if data == 'success'
$('.video-serial span').text(newSerial)
)
)
)
capitalizeWord = (str) ->
return str.charAt(0).toUpperCase() + str.slice(1)

View File

@@ -92,6 +92,12 @@ hr{
font-style: italic;
}
.video-path{
margin-top: 10px;
font-size: 2rem;
text-decoration: underline;
}
.channel-description,
.video-description{
margin-top: 10px;
@@ -149,6 +155,17 @@ hr{
}
}
}
.channel-path,
.video-status,
.video-serial{
transition: background 230ms ease-in-out;
&:hover{
background: rgba(0, 0, 0, 0.1);
cursor: pointer;
}
}
}
}

View File

@@ -5,7 +5,7 @@ Sequel.migration do
primary_key :id
String :name, null: false
String :description
Integer :serial, null: false, unique: true
String :serial, null: false, default: 'wxyz'
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
end

View File

@@ -0,0 +1,11 @@
Sequel.migration do
up do
add_column(:videos, :status, String, default: 'backlog')
end
down do
drop_column(:videos, :status)
end
end

View File

@@ -0,0 +1,11 @@
Sequel.migration do
up do
add_column(:videos, :archived, TrueClass, default: false)
end
down do
drop_column(:videos, :archived)
end
end

View File

@@ -2,6 +2,19 @@ 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 0
end

View File

@@ -1,11 +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

View File

@@ -24,7 +24,9 @@ namespace '/channel' do
description: params[:channel_description]
)
# create supporting directory structure
Dir.mkdir(channel.directory_path)
channel.ensureDirectoryStructure()
redirect "/channel/#{channel.id}"
end
@@ -71,4 +73,23 @@ namespace '/channel' do
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[attrToEdit])
channel.videos.each do |v|
video_path = v.directory_path.sub(channel.directory_path, params[attrToEdit])
v.update(directory_path: video_path)
end
end
channel[attrToEdit.to_sym] = params[attrToEdit]
channel.save()
return "success"
end
end

View File

@@ -14,10 +14,17 @@ namespace '/video' do
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
:channels => channels,
:selected_channel => selected_channel
}
end
post '/create' do
@@ -25,6 +32,7 @@ namespace '/video' do
video_serial = params[:video_serial].to_s.rjust(4, '0')
video_path = File.join(
channel.directory_path,
'Main',
"##{video_serial} - #{params[:video_name]}"
)
@@ -37,7 +45,9 @@ namespace '/video' do
script: "# Introduction\n\n# Body\n\n# Conclusions"
)
# create supporting directory structure
Dir.mkdir(video_path)
video.ensureDirectoryStructure()
redirect "/video/#{video.id}"
end
@@ -72,6 +82,7 @@ namespace '/video' do
video_serial = params[:video_serial].to_s.rjust(4, '0')
video_path = File.join(
channel.directory_path,
'Main',
"##{video_serial} - #{params[:video_name]}"
)
@@ -95,13 +106,58 @@ namespace '/video' do
redirect "/video/#{video.id}"
end
get '/:video_id/delete' do
# find the video and delete it
post '/:video_id/edit/:attr' do
# find video and temporarily save the old video path
video = Video.where(id: params[:video_id]).first()
FileUtils.rm_rf(video.directory_path)
video.delete()
attrToEdit = params[:attr]
redirect '/video'
video[attrToEdit.to_sym] = params[attrToEdit]
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

View File

@@ -21,7 +21,7 @@ unless ARGV.length == 1
end
channel = Channel.where(name: ARGV[0]).first()
channel_dir = channel.directory_path
channel_dir = File.join(channel.directory_path, 'Main')
subs = Dir["#{channel_dir}/*"]
subs.each do |d|
@@ -49,6 +49,8 @@ subs.each do |d|
script: "# Introduction\n\n# Body\n\n# Conclusions"
)
video.importScript()
puts "Successfully added video ##{video.serial} - #{video.name} for channel '#{channel.name}' to the database."
end
end

View File

@@ -1,6 +1,6 @@
<div class="row">
<div class="twelve columns">
<h1>Hardware Inventory List</h1>
<h1>Channel List</h1>
</div>
</div>

View File

@@ -6,6 +6,8 @@
<h4 class="channel-updated">Last updated at: <%= date_format(channel.updated_at) %></h4>
<% end %>
<p><a href="/video/create?channel=<%= channel.id %>">Create video project</a></p>
<p class="channel-description"><%= channel.description %></p>
</div>
@@ -57,3 +59,5 @@
<% end %>
</div>
</div>
<input type="hidden" id="channel-id" value="<%= channel.id %>">

View File

@@ -24,7 +24,7 @@
<label for="video_channel">Associated channel:</label>
<select class="u-full-width" id="video_channel" name="video_channel" required>
<% channels.each do |c| %>
<option value="<%= c.id %>"><%= c.name %></option>
<option value="<%= c.id %>" <%= 'selected' if c.id == selected_channel %>><%= c.name %></option>
<% end %>
</select>
</div>

View File

@@ -1,6 +1,6 @@
<div class="row">
<div class="twelve columns">
<h1>Hardware Inventory List</h1>
<h1>Video List</h1>
</div>
</div>

View File

@@ -1,18 +1,19 @@
<div id="video-header" class="row">
<div class="eight columns">
<h1 class="video-name"><%= video.name %></h1>
<h1 class="video-name"><%= video.name %></h1><%= '<h4>(archived)</h4>' if video.archived %>
<h4 class="video-created">Item added at: <%= date_format(video.created_at) %></h4>
<% if video.updated_at %>
<h4 class="video-updated">Last updated at: <%= date_format(video.updated_at) %></h4>
<% end %>
<h4 class="video-path"><%= video.directory_path %></h4>
<p class="video-description"><%= video.description %></p>
</div>
<div id="sidebar" class="four columns">
<div class="actions-bar">
<span><a href="/video/<%= video.id %>/edit">Edit <i class="fa-solid fa-pen-to-square"></i></a></span><span>
<a href="/video/<%= video.id %>/delete">Delete <i class="fa-solid fa-trash"></i></a></span>
<span><a href="/video/<%= video.id %>/edit">Edit <i class="fa-solid fa-pen-to-square"></i></a></span><% unless video.archived %><span><a href="/video/<%= video.id %>/archive">Archive <i class="fa-solid fa-box-archive"></i></a></span><% else %><span><a href="/video/<%= video.id %>/unarchive">Unarchive <i class="fa-solid fa-box-archive"></i></a></span>
<% end %>
</div>
<div class="video-channel">
<p>Channel: <a href="/channel/<%= video.channel.id %>"><span><%= video.channel.name %></span></a></p>
@@ -20,8 +21,8 @@
<div class="video-serial">
<p>Serial: <span><%= serialize(video.serial) %></span></p>
</div>
<div class="video-path">
<p><span><%= video.directory_path %></span></p>
<div class="video-status">
<p>Status: <span><%= video.status.capitalize() %></span></p>
</div>
<div class="script-controls">
<span><a href="/video/<%= video.id %>/script">View script <i class="fa-solid fa-scroll"></i></a></span><span>
@@ -41,3 +42,5 @@
</div>
</div>
</div>
<input type="hidden" id="video-id" value="<%= video.id %>">