testmycode/tmc-server

View on GitHub
app/views/points/show.html.erb

Summary

Maintainability
Test Coverage
<div class="points-container">
  <div class="course-point-header">
    <% unless @bare_layout %>
      <h1>Points for <%= @sheetname %> of <%= @course.title %></h1>
    <% end %>

    <div class="alternative-options-links">
      <% if params[:sort_by].blank? %>
        <%= link_to('Sort by points', organization_course_point_path(@organization, @course, @sheetname, sort_by: 'points', show_attempted: params[:show_attempted]),  class: "btn btn-primary")%>
      <% else %>
        <%= link_to('Sort by default order', organization_course_point_path(@organization, @course, @sheetname, show_attempted: params[:show_attempted]), class: "btn btn-primary") %>
      <% end %>

      <% if can? :refresh_gdocs_spreadsheet, @course %>
        <% link_to 'Refresh Google Docs worksheet', refresh_gdocs_organization_course_point_path(@organization, @course, @sheetname), class: "btn btn-primary" %>
      <% end %>
    </div>
  </div>

  <% @user_fields_length = @user_fields ? @user_fields.length : 0 %>
  <% @exercises_length = @exercises? @exercises.length : 0 %>

  <%= content_tag('div', :class => if @bare_layout then nil elsif @user_fields_length + @exercises_length >= 6 then 'scrollable' end) do %>
    <table class="points">
      <thead>
        <% if tailoring.show_exercise_names_in_points_table %>
          <tr>
            <th></th>
            <th></th>
            <% if @user_fields %>
              <% @user_fields.each do |field| %>
                <th><%= field.label %></th>
              <% end %>
            <% end %>
            <% if can?(:teach, @course) %>
              <th>Email</th>
            <% end %>
            <% @exercises.each do |exercise| %>
              <% points = exercise.available_points.order! %>
              <% if points.size > 0 %>
                <th class="point-cell" colspan="<%= points.size %>"><%= tailoring.exercise_name_for_points_table(exercise) %></th>
              <% end %>
            <% end %>
          </tr>
        <% end %>
        <tr>
          <th colspan="<%= 2 + (@user_fields ? @user_fields.length : 0) + (can?(:teach, @course) ? 1 : 0) %>"></th>

          <% @exercises.each do |exercise| %>
            <% exercise.available_points.sort.each do |point| %>
              <th class="point-cell"><%= point.name %></th>
            <% end %>
          <% end %>
        </tr>
      </thead>

      <tbody>
        <% @users.each_with_index do |user, index| %>
          <% if !user.administrator? || current_user.administrator? %>
            <% row_class = if user.administrator? then "admin" else "student" end %>
            <% user_points = @users_to_points[user.login] %>
            <tr class="<%= row_class %>">
              <td><%= index + 1 %></td>
              <td>
                <% if current_user.id == user.id || can?(:teach, @course) %>
                  <%= link_to 'Profile', participant_path(user) %>
                <% else %>
                  &nbsp;
                <% end %>
              </td>
              <% if @user_fields %>
                <% @user_fields.each do |field| %>
                <% value = user.user_field_values.find { |o| o.field_name == field.name }%>
                <td><%= value.value if value %></td>
                <% end %>
              <% end %>
              <% if can?(:teach, @course) %>
                <td><%= user.email %></td>
              <% end %>
              <% @exercises.each do |exercise| %>
                <% exercise.available_points.sort.each do |p| %>
                  <td class="point-cell">
                    <% if user_points.include?(p.name) %>
                      <%= raw("&#x2714;") %>
                    <% elsif !params[:show_attempted].nil? && exercise.attempted_by?(user) %>
                      <%= raw("&#x2718;") %>
                    <% end %>
                  </td>
                <% end %>
              <% end %>
            </tr>
          <% end %>
        <% end %>
      </tbody>
    </table>
  <% end %>
</div>