recent_event.mustache 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <%
  2. # Copyright (C) 2011 - present Instructure, Inc.
  3. #
  4. # This file is part of Canvas.
  5. #
  6. # Canvas is free software: you can redistribute it and/or modify it under
  7. # the terms of the GNU Affero General Public License as published by the Free
  8. # Software Foundation, version 3 of the License.
  9. #
  10. # Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. # A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. # details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License along
  16. # with this program. If not, see <http://www.gnu.org/licenses/>.
  17. %>
  18. <li style="<%= hidden if is_hidden %>" class="event">
  19. <%
  20. recent_event ||= nil
  21. show_context ||= false
  22. is_assignment = recent_event.is_a?(Assignment)
  23. is_calendar_event = recent_event.is_a?(CalendarEvent)
  24. if is_assignment
  25. if @current_user_submissions
  26. submission = @current_user_submissions.detect { |s| s.assignment_id == recent_event.id }
  27. elsif @current_user
  28. submission = @current_user.submissions.select([:id, :assignment_id, :grading_period_id, :score, :grade, :workflow_state, :updated_at]).where(:assignment_id => recent_event).first
  29. end
  30. if is_assignment
  31. recent_event = recent_event.overridden_for(@current_user)
  32. end
  33. end
  34. cache([ 'recent_event_render3',
  35. @current_user, # needs to be here to bust the cache when the user changes course nicknames
  36. submission || 'no_submission',
  37. recent_event || 'blank_event',
  38. (recent_event.due_at if is_assignment),
  39. Time.zone.today,
  40. Time.zone.name,
  41. recent_event.context.grants_right?(@current_user, :manage_grades),
  42. recent_event.context.grants_right?(@current_user, :participate_as_student)
  43. ].cache_key) do
  44. icon_explanation, icon_aria_label, icon_class = icon_data(:context => @context,
  45. :contexts => @contexts,
  46. :current_user => @current_user,
  47. :recent_event => recent_event,
  48. :submission => submission,
  49. :show_assignment_type_icon => true)
  50. if is_calendar_event
  51. context = recent_event.effective_context
  52. else
  53. context = recent_event.context
  54. end
  55. %>
  56. <a
  57. data-track-category="dashboard"
  58. data-track-label="recent event"
  59. href="<%= recent_event_url(recent_event) %>"
  60. >
  61. <i class="<%= icon_class %>" aria-label="<%= icon_aria_label %>"></i>
  62. <div class="event-details">
  63. <b class="event-details__title"><%= recent_event.title %></b>
  64. <% if show_context %>
  65. <p><%= context.nickname_for(@current_user, :short_name) %></p>
  66. <% end %>
  67. <p>
  68. <% if is_assignment %>
  69. <% if submission && readable_grade(submission) && !recent_event.muted? %>
  70. <%= readable_grade(submission) %>
  71. &bullet;
  72. <% elsif recent_event.points_possible %>
  73. <%= t({one: '1 point', other: '%{count} points'}, count: round_if_whole(recent_event.points_possible)) %>
  74. &bullet;
  75. <% end %>
  76. <%= due_at(recent_event, @current_user) %>
  77. <% else %>
  78. <%= datetime_string(recent_event.start_at) %>
  79. <% end %>
  80. </p>
  81. </div>
  82. </a>
  83. <% end %>
  84. </li>