diff --git a/assets/coffee/wyrm.coffee b/assets/coffee/wyrm.coffee index 352c02e..4bbc3ba 100644 --- a/assets/coffee/wyrm.coffee +++ b/assets/coffee/wyrm.coffee @@ -1,24 +1,39 @@ $(document).ready(() -> + $('.channel-path').click((e) -> + newPath = prompt('New channel directory path', $('.channel-path').val()) + 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', $('.video-status').val()) + 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', $('.video-serial').val()) + if newSerial + payload = + serial: newSerial + videoId = $('#video-id').val() + $.post('/video/' + videoId + '/edit/serial', payload, (data) -> + if data == 'success' + $('.video-serial span').text(newSerial) + ) ) ) diff --git a/assets/styles/drake.scss b/assets/styles/drake.scss index 21a3347..9d1467a 100644 --- a/assets/styles/drake.scss +++ b/assets/styles/drake.scss @@ -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; diff --git a/lib/routes/channel.rb b/lib/routes/channel.rb index ba258ea..f5af0c8 100644 --- a/lib/routes/channel.rb +++ b/lib/routes/channel.rb @@ -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 diff --git a/views/channel/view.erb b/views/channel/view.erb index b627de5..0d2ddaf 100644 --- a/views/channel/view.erb +++ b/views/channel/view.erb @@ -59,3 +59,5 @@ <% end %> + + diff --git a/views/video/view.erb b/views/video/view.erb index 6eeeca2..fc31694 100644 --- a/views/video/view.erb +++ b/views/video/view.erb @@ -5,6 +5,7 @@ <% if video.updated_at %>

Last updated at: <%= date_format(video.updated_at) %>

<% end %> +

<%= video.directory_path %>

<%= video.description %>

@@ -23,9 +24,6 @@

Status: <%= video.status.capitalize() %>

-
-

<%= video.directory_path %>

-
View script Edit script