4 Commits

10 changed files with 76 additions and 21 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)

View File

@ -1,24 +1,39 @@
$(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').toLowerCase()
payload =
status: newStatus
videoId = $('#video-id').val()
$.post('/video/' + videoId + '/edit/status', payload, (data) ->
if data == 'success'
$('.video-status span').text(capitalizeWord(newStatus))
)
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')
payload =
serial: newSerial
videoId = $('#video-id').val()
$.post('/video/' + videoId + '/edit/serial', payload, (data) ->
if data == 'success'
$('.video-serial span').text(newSerial)
)
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)
)
)
)

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;
@ -150,6 +156,7 @@ hr{
}
}
.channel-path,
.video-status,
.video-serial{
transition: background 230ms ease-in-out;

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

@ -1,4 +1,5 @@
require 'kramdown'
require 'pandoc-ruby'
class Video < Sequel::Model
@ -21,4 +22,11 @@ class Video < Sequel::Model
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

@ -73,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

@ -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

@ -59,3 +59,5 @@
<% end %>
</div>
</div>
<input type="hidden" id="channel-id" value="<%= channel.id %>">

View File

@ -5,6 +5,7 @@
<% 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>
@ -23,9 +24,6 @@
<div class="video-status">
<p>Status: <span><%= video.status.capitalize() %></span></p>
</div>
<div class="video-path">
<p><span><%= video.directory_path %></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>
<a href="/video/<%= video.id %>/edit/script">Edit script <i class="fa-solid fa-pen-to-square"></i></a></span>