Skip to content

Commit

Permalink
Fix code working with nil values
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Jun 26, 2024
1 parent 31334ce commit b00c53e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ export class SavedAnnotationList extends DodonaElement {
<a href="${sa.url}">${sa.title}</a>
</td>
<td class="ellipsis-overflow" title="${sa.annotation_text}">${sa.annotation_text}</td>
<td><d-filter-button param="course_id" value="${sa.course.id}">${sa.course.name}</td></td>
<td><d-filter-button param="exercise_id" value="${sa.exercise.id}">${sa.exercise.name}</td></td>
<td>
${sa.course ? html`<d-filter-button param="course_id" value="${sa.course.id}">${sa.course.name}</d-filter-button>` : ""}
</td>
<td>
${sa.exercise ? html`<d-filter-button param="exercise_id" value="${sa.exercise.id}">${sa.exercise.name}</d-filter-button>` : ""}
</td>
</tr>
`)}
</tbody>
Expand Down
4 changes: 2 additions & 2 deletions app/models/saved_annotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class SavedAnnotation < ApplicationRecord
has_many :submissions, through: :annotations

scope :by_user, ->(user_id) { where user_id: user_id }
scope :by_course, ->(course_id) { where course_id: course_id }
scope :by_exercise, ->(exercise_id) { where exercise_id: exercise_id }
scope :by_course, ->(course_id) { where(course_id: course_id).or(where(course_id: nil)) }
scope :by_exercise, ->(exercise_id) { where(exercise_id: exercise_id).or(where(exercise_id: nil)) }
scope :by_filter, ->(filter) { where 'title LIKE ? or annotation_text LIKE ?', "%#{filter}%", "%#{filter}%" }

scope :order_by_annotations_count, ->(direction) { reorder(annotations_count: direction) }
Expand Down
20 changes: 12 additions & 8 deletions app/views/saved_annotations/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ json.array! @saved_annotations do |saved_annotation|
json.url user_url(saved_annotation.user)
json.id saved_annotation.user.id
end
json.exercise do
json.name saved_annotation.exercise.name
json.url activity_url(saved_annotation.exercise)
json.id saved_annotation.exercise.id
if saved_annotation.exercise.present?
json.exercise do
json.name saved_annotation.exercise.name
json.url activity_url(saved_annotation.exercise)
json.id saved_annotation.exercise.id
end
end
json.course do
json.name saved_annotation.course.name
json.url course_url(saved_annotation.course)
json.id saved_annotation.course.id
if saved_annotation.course.present?
json.course do
json.name saved_annotation.course.name
json.url course_url(saved_annotation.course)
json.id saved_annotation.course.id
end
end
end
19 changes: 13 additions & 6 deletions app/views/saved_annotations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@
<div class="card-supporting-text">
<p><strong><%= @saved_annotation.title %></strong></p>
<blockquote><%= markdown @saved_annotation.annotation_text %></blockquote>
<%= t ".usage_info_html",
exercise_path: course_activity_path(@saved_annotation.course ,@saved_annotation.exercise),
exercise_name: @saved_annotation.exercise.name,
course_path: course_path(@saved_annotation.course),
course_name: @saved_annotation.course.name
%><br/>
<%= t ".usage_info" %>
<% if @saved_annotation.exercise.present? %>
<%= t ".exercise_info_html",
exercise_path: activity_scoped_path(activity: @saved_annotation.exercise, course: @saved_annotation.course),
exercise_name: @saved_annotation.exercise.name
%>
<% end %>
<% if @saved_annotation.course.present? %>
<%= t ".course_info_html",
course_path: course_path(@saved_annotation.course),
course_name: @saved_annotation.course.name
%>
<% end %><br/>
<%= t ".count_info_html", count: @saved_annotation.annotations_count %>
</div>
<div class="card-supporting-text card-border">
Expand Down
4 changes: 3 additions & 1 deletion config/locales/views/saved_annotations/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ en:
title: Saved comments
show:
linked_submissions: Linked submissions
usage_info_html: This comment can be reused on all submissions for the exercise <a href="%{exercise_path}">%{exercise_name}</a> in the course <a href="%{course_path}">%{course_name}</a>.
usage_info: This comment can be reused on all submissions
exercise_info_html: for the exercise <a href="%{exercise_path}">%{exercise_name}</a>
course_info_html: in the course <a href="%{course_path}">%{course_name}</a>
count_info_html: This comment is used %{count} times.
edit:
title: Edit saved comment
Expand Down
4 changes: 3 additions & 1 deletion config/locales/views/saved_annotations/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ nl:
title: Opgeslagen opmerkingen
show:
linked_submissions: Gekoppelde oplossingen
usage_info_html: Deze opmerking kan worden hergebruikt op alle ingediende oplossingen voor de oefening <a href="%{exercise_path}">%{exercise_name}</a> in de cursus <a href="%{course_path}">%{course_name}</a>.
usage_info: Deze opmerking kan worden hergebruikt op alle ingediende oplossingen
exercise_info_html: voor de oefening <a href="%{exercise_path}">%{exercise_name}</a>
course_info_html: in de cursus <a href="%{course_path}">%{course_name}</a>
count_info_html: Deze opmerking wordt <strong>%{count}</strong> keer gebruikt.
edit:
title: Bewerk opgeslagen opmerking
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AllowNullForSavedAnnotationExerciseAndCourse < ActiveRecord::Migration[7.1]
def change
change_column_null :saved_annotations, :exercise_id, true
change_column_null :saved_annotations, :course_id, true
end
end

0 comments on commit b00c53e

Please sign in to comment.