Added ability to comment on license records; updated item list view to link to the item display pages

This commit is contained in:
Gregory Ballantine 2022-12-09 11:42:12 -05:00
parent 36f7fb82a6
commit db6bfe8e7a
7 changed files with 62 additions and 2 deletions

View File

@ -0,0 +1,20 @@
Sequel.migration do
up do
create_table(:license_comments) do
primary_key :id
String :body, null: false
DateTime :created_at
DateTime :updated_at
end
alter_table(:license_comments) do
add_foreign_key :license_id, :items
end
end
down do
drop_table(:license_comments)
end
end

View File

@ -1,5 +1,5 @@
class License < Sequel::Model
one_to_many :license_comments
end

View File

@ -0,0 +1,5 @@
class LicenseComment < Sequel::Model
many_to_one :licenses
end

View File

@ -92,3 +92,12 @@ get '/license/:license_id' do
:license => license
}
end
post '/license/:license_id/comment' do
license = License.first(id: params[:license_id])
comment = LicenseComment.create(body: params[:comment_body])
license.add_license_comment(comment)
redirect "/license/#{license.id}"
end

View File

@ -24,6 +24,7 @@ DB = Sequel.connect(adapter: conf.get('database.adapter'), database: conf.get('d
require_relative 'lib/models/item.rb'
require_relative 'lib/models/item_comment.rb'
require_relative 'lib/models/license.rb'
require_relative 'lib/models/license_comment.rb'
# Load helper functions
require_relative 'lib/helpers.rb'

View File

@ -11,7 +11,7 @@
<% if items.length > 0 %>
<ul>
<% items.each do |item| %>
<li><%= item.name %></li>
<li><a href="/item/<%= item.id %>"><%= item.name %></a></li>
<% end %>
</ul>
<% else %>

View File

@ -34,3 +34,28 @@
</table>
</div>
</div>
<div class="row">
<div class="twelve columns">
<% if license.license_comments.length > 0 %>
<ul class="u-full-width">
<% license.license_comments.each do |comment| %>
<li><%= comment.body %></li>
<% end %>
</ul>
<% else %>
<p>There are no comments to display at this time.</p>
<% end %>
</div>
</div>
<div class="row">
<div class="twelve columns">
<form action="/license/<%= license.id %>/comment" method="POST" class="u-full-width">
<label for="comment_body">Add a comment:</label>
<textarea name="comment_body" id="comment_body" class="u-full-width" cols="30" rows="10"></textarea>
<input class="button button-primary" type="submit" value="Submit">
</form>
</div>
</div>