YaleSTC/shifts

View on GitHub
app/views/data_objects/_data_objects_table.html.erb

Summary

Maintainability
Test Coverage
<%# This can be refactored with the data_object.data_entries virtual attribute %>
<% grouped_objects.each do |type, objects| %>
  <div>
    <h2><%= link_to_if current_user.is_admin_of?(current_department), type.name.pluralize, type %></h2>
    <table class="tablesorter data_objects_table">
      <thead>
        <tr>
          <th>Name</th>
          <th>Description</th>
          <th>When Updated</th>
          <% type.data_fields.each do |df| %>
            <th><%= df.name %></th>
          <% end %>
        </tr>
      </thead>
      <tbody>
      <% objects.each do |obj| %>
        <% entry = obj.data_entries.last.data_fields_with_contents unless obj.data_entries.empty? %>
      <tr>
      <td><%= link_to obj.name, obj %></td>
          <td><%= obj.description %></td>
          <%unless obj.data_entries == [] %>
            <td><%= obj.data_entries.last.updated_at.strftime("%m-%d-%Y %-I:%M %p") %></td>
          <%else %>
            <td></td>
          <%end %>
          <% type.data_fields.each do |df| %>
            <td>
              <%= entry[df.id.to_s] if entry %>
            </td>
          <% end %>
        </tr>
      <% end %>
      </tbody>
    </table>
  </div>
<% end %>