Added channel and video edit pages; added link back to channel from video view page
This commit is contained in:
parent
ef1813f16e
commit
5ed1771b18
@ -38,4 +38,36 @@ namespace '/channel' do
|
||||
}
|
||||
end
|
||||
|
||||
get '/:channel_id/edit' do
|
||||
channel = Channel.where(id: params[:channel_id]).first()
|
||||
erb :'channel/edit', :locals => {
|
||||
:title => "Editing: #{channel.name}",
|
||||
:channel => channel
|
||||
}
|
||||
end
|
||||
post '/:channel_id/edit' do
|
||||
# get channel model and save old directory path
|
||||
channel = Channel.where(id: params[:channel_id]).first()
|
||||
old_path = channel.directory_path
|
||||
|
||||
# edit channel model
|
||||
channel.update(
|
||||
name: params[:channel_name],
|
||||
directory_path: params[:channel_dir],
|
||||
description: params[:channel_description]
|
||||
)
|
||||
|
||||
# edit associate videos' directory paths
|
||||
channel.videos.each do |v|
|
||||
video_path = v.directory_path.sub(old_path, channel.directory_path)
|
||||
v.update(directory_path: video_path)
|
||||
end
|
||||
|
||||
# rename channel directory
|
||||
File.rename(old_path, channel.directory_path)
|
||||
|
||||
# redirect user
|
||||
redirect "/channel/#{channel.id}"
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -48,4 +48,41 @@ namespace '/video' do
|
||||
}
|
||||
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
|
||||
}
|
||||
end
|
||||
post '/:video_id/edit' do
|
||||
channel = Channel.where(id: params[:video_channel]).first()
|
||||
video_serial = params[:video_serial].to_s.rjust(4, '0')
|
||||
video_path = File.join(
|
||||
channel.directory_path,
|
||||
"##{video_serial} - #{params[:video_name]}"
|
||||
)
|
||||
|
||||
# find video and temporarily save the old video path
|
||||
video = Video.where(id: params[:video_id]).first()
|
||||
old_path = video.directory_path
|
||||
|
||||
# edit video attributes
|
||||
video.update(
|
||||
name: params[:video_name],
|
||||
serial: params[:video_serial],
|
||||
channel_id: params[:video_channel],
|
||||
directory_path: video_path,
|
||||
description: params[:video_description]
|
||||
)
|
||||
|
||||
# rename the video project directory
|
||||
File.rename(old_path, video_path)
|
||||
|
||||
# redirect the user
|
||||
redirect "/video/#{video.id}"
|
||||
end
|
||||
|
||||
end
|
||||
|
34
views/channel/edit.erb
Normal file
34
views/channel/edit.erb
Normal file
@ -0,0 +1,34 @@
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<h1>Editing: <%= channel.name %></h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<form action="/channel/<%= channel.id %>/edit" method="POST" class="u-full-width">
|
||||
<div class="row">
|
||||
<div class="columns twelve">
|
||||
<label for="channel_name">Channel name:</label>
|
||||
<input class="u-full-width" type="text" placeholder="My new channel" id="channel_name" name="channel_name" required value="<%= channel.name %>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="columns twelve">
|
||||
<label for="channel_dir">Channel directory:</label>
|
||||
<input class="u-full-width" type="text" id="channel_dir" name="channel_dir" required value="<%= channel.directory_path %>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<label for="channel_description">Channel description:</label>
|
||||
<textarea class="u-full-width" type="text" placeholder="Description of the channel" id="channel_description" name="channel_description"><%= channel.description %></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input class="button-primary u-full-width" type="submit" value="Submit">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
43
views/video/edit.erb
Normal file
43
views/video/edit.erb
Normal file
@ -0,0 +1,43 @@
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<h1>Editing: <%= video.name %></h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<form action="/video/<%= video.id %>/edit" method="POST" class="u-full-width">
|
||||
<div class="row">
|
||||
<div class="columns twelve">
|
||||
<label for="video_name">Video name:</label>
|
||||
<input class="u-full-width" type="text" placeholder="My new video" id="video_name" name="video_name" required value="<%= video.name %>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="columns three">
|
||||
<label for="video_serial">Video serial:</label>
|
||||
<input class="u-full-width" type="number" placeholder="0001" id="video_serial" name="video_serial" required value="<%= video.serial %>">
|
||||
</div>
|
||||
|
||||
<div class="columns nine">
|
||||
<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 %>"<% if c.id == video.channel_id %> selected<% end %>><%= c.name %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<label for="video_description">Video description:</label>
|
||||
<textarea class="u-full-width" type="text" placeholder="Description of the video" id="video_description" name="video_description"><%= video.description %></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input class="button-primary u-full-width" type="submit" value="Submit">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
@ -15,7 +15,7 @@
|
||||
<a href="/video/<%= video.id %>/delete">Delete <i class="fa-solid fa-trash"></i></a></span>
|
||||
</div>
|
||||
<div class="video-channel">
|
||||
<p>Channel: <span><%= video.channel.name %></span></p>
|
||||
<p>Channel: <a href="/channel/<%= video.channel.id %>"><span><%= video.channel.name %></span></a></p>
|
||||
</div>
|
||||
<div class="video-serial">
|
||||
<p>Serial: <span><%= serialize(video.serial) %></span></p>
|
||||
|
Loading…
Reference in New Issue
Block a user