Skip to content

Commit

Permalink
Add links to annotations and fix empty comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Aug 2, 2024
1 parent 13782cf commit 7f2a9bd
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 22 deletions.
6 changes: 6 additions & 0 deletions app/assets/stylesheets/annotations_overview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@

.annotation-overview-item {
border-width: 1.5px;
cursor: pointer;
transition: box-shadow 120ms cubic-bezier(0.33, 1, 0.68, 1);

&:hover {
box-shadow: rgba(0, 0, 0, 0.23) 1px 2px 8px -2px;
}
}
10 changes: 9 additions & 1 deletion app/controllers/annotations_overview_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ class AnnotationsOverviewController < ApplicationController
layout "application_no_sidebar_with_background"

def show
@user_annotations = Annotation.where(user_id: current_user.id)
@user_annotations = Annotation.where(user_id: current_user.id).map do |annotation|
{
category: annotation.category,
text: annotation.comment_optional,
link: helpers.video_link_timed(annotation.medium_id, annotation.timestamp),
color: annotation.color,
updated_at: annotation.updated_at
}
end
render "annotations/annotations_overview"
end
end
5 changes: 5 additions & 0 deletions app/helpers/media_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,9 @@ def external_link_description_not_empty(medium)
# link url itself.
medium.external_link_description.presence || medium.external_reference_link
end

def video_link_timed(medium_id, timestamp)
play_path = Rails.application.routes.url_helpers.play_medium_path(medium_id)
"#{play_path}?time=#{timestamp.total_seconds}"
end
end
38 changes: 20 additions & 18 deletions app/views/annotations/annotations_overview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@
<h2>Your annotations</h2>
<p>
This list comprises all annotations you have created across various lectures.
Click on an annotation to view it.
</p>

<% @user_annotations.each do |annotation| %>
<div class="annotation-overview-item card mb-3"
style="border-color: <%= annotation.color %>"">
<a href="<%= annotation[:link] %>"
style="text-decoration: none;">

<div class="card-header">
<%= annotation.category.capitalize %>
</div>

<div class="card-body">
<p class="card-text">
<%= truncate(annotation.comment, length: 100) %>
</p>
<div class="annotation-overview-item card mb-3"
style='border-color: <%= annotation[:color] %>'>
<div class="card-header">
<%= annotation[:category].capitalize %>
</div>

<p class="card-text">
<small class="text-body-secondary">
Last updated <%= time_ago_in_words(annotation.updated_at) %> ago
</small>
</p>
<div class="card-body">
<p class="card-text">
<%= truncate(annotation[:text], length: 100) %>
<br>
<small class="text-body-secondary">
Last updated <%= time_ago_in_words(annotation[:updated_at]) %> ago
</small>
</p>
</div>
</div>

</div>
<% end %>
</a>
<% end %>

</div>
7 changes: 4 additions & 3 deletions app/views/commontator/comments/_body.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
<!--- Show timestamps in comments that have a linked annotation --->
<% annotation = comment.annotation %>
<% unless annotation.nil? %>
<% medium = annotation.medium %>
<% medium_id = annotation.medium.id %>
<% timestamp = annotation.timestamp %>
<br>
Timestamp:
<a href= '<%= Rails.application.routes.url_helpers.play_medium_path(medium) %>?time=<%= timestamp.total_seconds %>'>
<%= timestamp.hms_colon_string %> </a>
<a href="<%= video_link_timed(medium_id, timestamp) %>">
<%= timestamp.hms_colon_string %>
</a>
<% end %>

0 comments on commit 7f2a9bd

Please sign in to comment.