From 47350476823b200b6e19faf52a966694fd6e8990 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Mon, 6 Mar 2023 17:59:58 -0500 Subject: [PATCH] Added status attribute to videos; added ability to edit video status and serial independently --- assets/coffee/wyrm.coffee | 26 ++++++++++++++++++++++++++ assets/styles/drake.scss | 10 ++++++++++ db/migrations/0005_add_video_status.rb | 11 +++++++++++ lib/routes/video.rb | 11 +++++++++++ views/video/view.erb | 5 +++++ 5 files changed, 63 insertions(+) create mode 100644 assets/coffee/wyrm.coffee create mode 100644 db/migrations/0005_add_video_status.rb diff --git a/assets/coffee/wyrm.coffee b/assets/coffee/wyrm.coffee new file mode 100644 index 0000000..352c02e --- /dev/null +++ b/assets/coffee/wyrm.coffee @@ -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) diff --git a/assets/styles/drake.scss b/assets/styles/drake.scss index 138be37..21a3347 100644 --- a/assets/styles/drake.scss +++ b/assets/styles/drake.scss @@ -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; + } + } } } diff --git a/db/migrations/0005_add_video_status.rb b/db/migrations/0005_add_video_status.rb new file mode 100644 index 0000000..4c35ac4 --- /dev/null +++ b/db/migrations/0005_add_video_status.rb @@ -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 diff --git a/lib/routes/video.rb b/lib/routes/video.rb index 69a78d0..289bb62 100644 --- a/lib/routes/video.rb +++ b/lib/routes/video.rb @@ -99,6 +99,17 @@ 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/delete' do # find the video and delete it video = Video.where(id: params[:video_id]).first() diff --git a/views/video/view.erb b/views/video/view.erb index 0fa742e..6fe7016 100644 --- a/views/video/view.erb +++ b/views/video/view.erb @@ -20,6 +20,9 @@

Serial: <%= serialize(video.serial) %>

+
+

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

+

<%= video.directory_path %>

@@ -41,3 +44,5 @@ + +