<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<%
  css_bundle :learning_outcomes
  js_bundle :react_outcome_alignment
  provide :page_title, @outcome.short_description
%>
<% provide :right_side do %>
  <a class="btn button-sidebar-wide" href="<%= context_url(@context, :context_outcomes_url) %>">
    <i class="icon-arrow-left"></i>
    <%= t "#buttons.back_to_outcomes", "Back to Outcomes" %>
  </a>
<% end %>

<h2><%= t "#titles.aligned_items", "Aligned Items" %></h2>
<%= t(:no_aligned_items, "No aligned items") if @alignments.empty? %>
<ul id="alignments" class="<%= 'orderable' if @context.is_a?(Course) %>">
<% @alignments.each do |alignment| %>
  <%= render :partial => "outcome_alignment", :object => alignment %>
<% end %>
</ul>
<h2 style="margin-top: 20px;"><%= t("#titles.outcome_artifacts", "Outcome Artifacts") %></h2>
<%= t(:no_artifacts, "No artifacts") if @results.empty? %>
<div id="outcome_results">
  <ul id="outcome_results_list">
  <% @results.each do |result| %>
    <%#
      There are a few old LearningOutcomeResults that have a nil artifact, and
      many that have a Submission as an artifact.  We want to get rid of these
      because they come from bad data, and step 1 toward that goal is to stop
      creating them and hide them in the UI.

      The LORs with a nil artifact are very old and I believe came from a very
      early incarnation of outcomes.  The LORs with a Submission as an artifact
      came from a combination of two code problems.  The first was old code
      that allowed an assignment that was aligned with an outcome but did not
      have a rubric to create LORs directly based on it's submission.  The
      second was a bug that prevented the assignment <-> outcome link from
      being destroyed when a rubric with an outcome was removed from an
      assignment.
    %>
    <% if result.artifact_type.present? && result.artifact_type != 'Submission' %>
      <%= render :partial => "outcome_result", :object => result %>
    <% end %>
  <% end %>
  </ul>
  <%= will_paginate(@results) %>
</div>
<div style="display: none;">
  <div id="outcome_results_total_pages"><%= @results.total_pages %></div>
  <a href="<%= context_url(@context, :context_outcome_results_url, @outcome.id) %>" style="display: none;" class="outcome_results_url">&nbsp;</a>
  <ul>
  <%= render :partial => "outcome_result" %>
  <%= render :partial => "outcome_alignment" %>
  </ul>
</div>
