Compare commits
6 Commits
aea9415bbd
...
v0.1.0
Author | SHA1 | Date | |
---|---|---|---|
414cabb9f8 | |||
9b6e38a313 | |||
4735047682 | |||
f243452783 | |||
a2f2224b96 | |||
89ebf5c792 |
5
Rakefile
5
Rakefile
@@ -7,6 +7,11 @@ namespace :db do
|
||||
task :migrate do
|
||||
%x{sequel -m 'db/migrations/' 'sqlite://data/stgm.db'}
|
||||
end
|
||||
|
||||
task :import do
|
||||
channel = ENV['channel']
|
||||
puts %x{ruby scan.rb "#{channel}"}
|
||||
end
|
||||
end
|
||||
|
||||
namespace :server do
|
||||
|
26
assets/coffee/wyrm.coffee
Normal file
26
assets/coffee/wyrm.coffee
Normal file
@@ -0,0 +1,26 @@
|
||||
$(document).ready(() ->
|
||||
$('.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))
|
||||
)
|
||||
)
|
||||
|
||||
$('.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)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
capitalizeWord = (str) ->
|
||||
return str.charAt(0).toUpperCase() + str.slice(1)
|
@@ -149,6 +149,16 @@ hr{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.video-status,
|
||||
.video-serial{
|
||||
transition: background 230ms ease-in-out;
|
||||
|
||||
&:hover{
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
11
db/migrations/0005_add_video_status.rb
Normal file
11
db/migrations/0005_add_video_status.rb
Normal 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
|
11
db/migrations/0006_add_video_archive.rb
Normal file
11
db/migrations/0006_add_video_archive.rb
Normal 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
|
@@ -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
|
||||
|
@@ -4,6 +4,19 @@ 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
|
||||
|
@@ -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
|
||||
|
@@ -1,3 +1,5 @@
|
||||
require 'fileutils'
|
||||
|
||||
namespace '/video' do
|
||||
|
||||
get '' do
|
||||
@@ -12,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
|
||||
@@ -23,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]}"
|
||||
)
|
||||
|
||||
@@ -35,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
|
||||
@@ -70,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]}"
|
||||
)
|
||||
|
||||
@@ -93,6 +106,60 @@ namespace '/video' do
|
||||
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]
|
||||
|
||||
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
|
||||
video = Video.where(id: params[:video_id]).first()
|
||||
erb :'video/edit-script', :locals => {
|
||||
|
54
scan.rb
Executable file
54
scan.rb
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require 'pathname'
|
||||
require 'sequel'
|
||||
|
||||
require_relative 'lib/config.rb'
|
||||
|
||||
# Load configuration file
|
||||
$conf = Config.new(File.join(__dir__, 'data/defaults.yaml'))
|
||||
|
||||
# Load the Sequel timestamps plugin
|
||||
Sequel::Model.plugin :timestamps
|
||||
# Initialize Sequel gem for database actions
|
||||
DB = Sequel.connect(adapter: $conf.get('database.adapter'), database: $conf.get('database.database'))
|
||||
# Load models
|
||||
require_relative 'lib/models/channel.rb'
|
||||
require_relative 'lib/models/video.rb'
|
||||
|
||||
unless ARGV.length == 1
|
||||
abort 'You must supply a channel name!'
|
||||
end
|
||||
|
||||
channel = Channel.where(name: ARGV[0]).first()
|
||||
channel_dir = channel.directory_path
|
||||
subs = Dir["#{channel_dir}/*"]
|
||||
|
||||
subs.each do |d|
|
||||
# get folder basename
|
||||
dir_name = File.basename(d)
|
||||
|
||||
# parse video serial from folder name
|
||||
serial_raw = dir_name[0..5].strip()
|
||||
video_serial = serial_raw[1..-1]
|
||||
|
||||
# parse video name from folder name
|
||||
video_name = dir_name.split(' - ')[1]
|
||||
|
||||
# check if a video by the same serial number exists for the channel
|
||||
db_results = Video.where(serial: video_serial, channel_id: channel.id).all()
|
||||
|
||||
# add video project to DB if there's no existing project
|
||||
if db_results.length == 0
|
||||
video = Video.create(
|
||||
serial: video_serial,
|
||||
name: video_name,
|
||||
channel_id: channel.id,
|
||||
directory_path: d,
|
||||
description: 'TODO - imported from storage.',
|
||||
script: "# Introduction\n\n# Body\n\n# Conclusions"
|
||||
)
|
||||
|
||||
puts "Successfully added video ##{video.serial} - #{video.name} for channel '#{channel.name}' to the database."
|
||||
end
|
||||
end
|
@@ -1,6 +1,6 @@
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<h1>Hardware Inventory List</h1>
|
||||
<h1>Channel List</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@@ -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>
|
||||
|
||||
|
@@ -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>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<h1>Hardware Inventory List</h1>
|
||||
<h1>Video List</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<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>
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
<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,6 +20,9 @@
|
||||
<div class="video-serial">
|
||||
<p>Serial: <span><%= serialize(video.serial) %></span></p>
|
||||
</div>
|
||||
<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>
|
||||
@@ -41,3 +44,5 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" id="video-id" value="<%= video.id %>">
|
||||
|
Reference in New Issue
Block a user