Added Rubocop to project; corrected style errors

This commit is contained in:
2023-03-18 11:35:52 -04:00
parent f27154b705
commit 9c91bcb6cb
16 changed files with 151 additions and 93 deletions

View File

@ -1,8 +1,11 @@
# frozen_string_literal: true
class StageManager
# Controller to handle API v1 routes
class ApiV1Controller
get '/health' do
json :status => 'success'
json status: 'success'
end
get '/channels' do
@ -16,4 +19,4 @@ class StageManager
end
end
end
end

View File

@ -1,4 +1,7 @@
# frozen_string_literal: true
class StageManager
# Channel that handles channel top-level routes
class ChannelController
get '/' do
@ -6,16 +9,16 @@ class StageManager
end
get '/list' do
channels = Channel.reverse(:updated_at).all()
erb :'channel/list', :locals => {
:title => 'List of channels',
:channels => channels
erb :'channel/list', locals: {
title: 'List of channels',
channels: channels
}
end
get '/create' do
erb :'channel/create', :locals => {
:title => 'Create new channel',
:base_directory => $conf.get('stgm.base_directory')
erb :'channel/create', locals: {
title: 'Create new channel',
base_directory: $conf.get('stgm.base_directory')
}
end
post '/create' do
@ -27,7 +30,7 @@ class StageManager
# create supporting directory structure
Dir.mkdir(channel.directory_path)
channel.ensureDirectoryStructure()
channel.ensure_directory_structure()
redirect "/channel/#{channel.id}"
end
@ -35,18 +38,18 @@ class StageManager
get '/:channel_id' do
channel = Channel.where(id: params[:channel_id]).first()
channel_videos = channel.videos_dataset.reverse(:updated_at).limit(10).all()
erb :'channel/view', :locals => {
:title => channel.name,
:channel => channel,
:channel_videos => channel_videos
erb :'channel/view', locals: {
title: channel.name,
channel: channel,
channel_videos: channel_videos
}
end
get '/:channel_id/edit' do
channel = Channel.where(id: params[:channel_id]).first()
erb :'channel/edit', :locals => {
:title => "Editing: #{channel.name}",
:channel => channel
erb :'channel/edit', locals: {
title: "Editing: #{channel.name}",
channel: channel
}
end
post '/:channel_id/edit' do
@ -77,9 +80,9 @@ class StageManager
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]
attr_to_edit = params[:attr]
if attrToEdit == 'directory_path'
if attr_to_edit == 'directory_path'
File.rename(channel.directory_path, params[:value])
channel.videos.each do |v|
video_path = v.directory_path.sub(channel.directory_path, params[:value])
@ -87,10 +90,10 @@ class StageManager
end
end
channel[attrToEdit.to_sym] = params[:value]
channel.save()
channel[attr_to_edit.to_sym] = params[:value]
channel.save_changes()
return "success"
return 'success'
end
end

View File

@ -1,15 +1,18 @@
# frozen_string_literal: true
class StageManager
# Controller to handle top-level pages
class IndexController
get '/' do
channels = Channel.reverse(:updated_at).limit(10).all()
videos = Video.reverse(:updated_at).limit(10).all()
active_projects = Video.where(starred: true).reverse(:updated_at).limit($conf.get('stgm.max_stars'))
erb :index, :locals => {
:title => 'Dashboard',
:channels => channels,
:videos => videos,
:active_projects => active_projects
erb :index, locals: {
title: 'Dashboard',
channels: channels,
videos: videos,
active_projects: active_projects
}
end

View File

@ -1,6 +1,9 @@
# frozen_string_literal: true
require 'fileutils'
class StageManager
# Controller to handle top-level video routes
class VideoController
get '/' do
@ -8,24 +11,21 @@ class StageManager
end
get '/list' do
videos = Video.reverse(:updated_at).all()
erb :'video/list', :locals => {
:title => 'List of videos',
:videos => videos
erb :'video/list', locals: {
title: 'List of videos',
videos: videos
}
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
selected_channel = params[:channel].to_i() if params.key?(:channel)
channels = Channel.all()
erb :'video/create', :locals => {
:title => 'Create new video',
:channels => channels,
:selected_channel => selected_channel
erb :'video/create', locals: {
title: 'Create new video',
channels: channels,
selected_channel: selected_channel
}
end
post '/create' do
@ -48,34 +48,34 @@ class StageManager
# create supporting directory structure
Dir.mkdir(video_path)
video.ensureDirectoryStructure()
video.ensure_directory_structure()
redirect "/video/#{video.id}"
end
get '/:video_id' do
video = Video.where(id: params[:video_id]).first()
erb :'video/view', :locals => {
:title => video.name,
:video => video
erb :'video/view', locals: {
title: video.name,
video: video
}
end
get '/:video_id/script' do
video = Video.where(id: params[:video_id]).first()
erb :'video/script', :locals => {
:title => "Script: #{video.name}",
:video => video
erb :'video/script', locals: {
title: "Script: #{video.name}",
video: video
}
end
get '/:video_id/edit' do
video = Video.where(id: params[:video_id]).first()
channels = Channel.all()
erb :'video/edit', :locals => {
:title => "Editing: #{video.name}",
:video => video,
:channels => channels
erb :'video/edit', locals: {
title: "Editing: #{video.name}",
video: video,
channels: channels
}
end
post '/:video_id/edit' do
@ -110,20 +110,20 @@ class StageManager
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]
attr_to_edit = params[:attr]
# if we update the video's serial, we need to also update the directory path
if attrToEdit == 'serial'
if attr_to_edit == 'serial'
old_path = video.directory_path
new_path = video.directory_path.sub("##{video.serial}", "##{params[:value]}")
File.rename(old_path, new_path)
video[:directory_path] = new_path
end
video[attrToEdit.to_sym] = params[:value]
video.save()
video[attr_to_edit.to_sym] = params[:value]
video.save_changes()
return "success"
return 'success'
end
get '/:video_id/archive' do
@ -145,8 +145,9 @@ class StageManager
archived: true
)
redirect '/video/' + video.id.to_s()
redirect "/video/#{video.id}"
end
get '/:video_id/unarchive' do
# find the video
video = Video.where(id: params[:video_id]).first()
@ -166,14 +167,14 @@ class StageManager
archived: false
)
redirect '/video/' + video.id.to_s()
redirect "/video/#{video.id}"
end
get '/:video_id/edit/script' do
video = Video.where(id: params[:video_id]).first()
erb :'video/edit-script', :locals => {
:title => "Editing script: #{video.name}",
:video => video
erb :'video/edit-script', locals: {
title: "Editing script: #{video.name}",
video: video
}
end
post '/:video_id/edit/script' do