testmycode/tmc-server

View on GitHub
app/views/participants/index.html.erb

Summary

Maintainability
Test Coverage
<h1>List of participants</h1>

<%= form_tag(participants_path, :method => :get, :class => "filter-form") do %>
  <div style="float: left">
    <%= render :partial => 'participants/filter_controls' %>
  </div>

  <div style="float: left; margin-left: 6em;">
    <%= render :partial => 'participants/column_controls' %>
  </div>

  <div style="clear: both; margin-bottom: 3em;">
    <%= submit_tag 'Apply filter', class: 'btn' %>
  </div>
<% end %>

<p><%= link_to 'List of e-mails as plain-text', emails_path(@raw_filter_params.merge(:format => 'txt')) %>.</p>

<table class="participants">
  <thead>
    <tr>
      <% for field_name in @ordinary_fields %>
        <% if @visible_columns.include?(field_name) %>
          <th><%= field_name.humanize %></th>
        <% end %>
      <% end %>

      <% for field in @extra_fields %>
        <% if @visible_columns.include?(field.name) %>
          <th><%= field.name.humanize %></th>
        <% end %>
      <% end %>

      <% if @group_completion %>
        <% group_completion_cols = @group_completion.keys.natsort %>
        <% for group in group_completion_cols %>
          <th><%= if group.blank? then '<root>' else group end %></th>
        <% end %>
      <% end %>

    </tr>
  </thead>
  <tbody>
    <% for user in @participants %>
      <tr>

        <% for field_name in @ordinary_fields.select {|f| @visible_columns.include?(f) } %>
          <% case field_name %>
          <% when 'username' %>
            <td><%= link_to user.login, participant_path(user) %></td>
          <% else %>
            <td><%= user.send(field_name) %></td>
          <% end %>
        <% end %>

        <% for field in @extra_fields.select {|f| @visible_columns.include?(f.name) } %>
          <td><%= extra_field_value(user.field_value_record(field)) %></td>
        <% end %>

        <% if @group_completion %>
          <% for group in group_completion_cols %>
            <%
               points = @group_completion[group][:points_by_user][user.id] || 0
               total = @group_completion[group][:available_points]
               percentage = sprintf("%.0f%%", ((points.to_f / total) * 100).ceil)
            %>
            <td><%= percentage %></td>
          <% end %>
        <% end %>

      </tr>
    <% end %>
  </tbody>
</table>
<div class="alternative-options-links">
  [
  <%= link_to "json", "#{participants_path request.params.merge(:format => :json, :api_version => ApiVersion::API_VERSION)}" %>
  |
  <%= link_to "csv", "#{participants_path request.params.merge(:format => :csv, :api_version => ApiVersion::API_VERSION)}" %>
  ]
</div>

<%= use_datatables('table.participants', :bPaginate => false) %>