indocomsoft/cvwo-assignment-2017

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

Summary

Maintainability
Test Coverage
<%= render "header" %>
<div class="toolbar">
  <%= form_tag(categories_path, method: :get, class: 'search-form form-group') do %>
    <%= link_to '<i class="fa fa-plus"></i>'.html_safe, new_category_path, class: 'btn btn-primary', data: { toggle: 'tooltip', placement: 'bottom' }, title: 'New Category' %>
    <%= link_to '<i class="fa fa-list"></i>'.html_safe, tasks_path, class: 'btn btn-info', data: { toggle: 'tooltip', placement: 'bottom'}, title: 'List Tasks' %>
    <%= text_field_tag :search, params[:search], class: 'form-control', placeholder: "Search tasks" %>
    <%= button_tag(type: 'submit', class: 'btn btn-default') do %>
      <i class="fa fa-search"></i>
    <% end %>
  <% end %>
</div>
<table class="table table-sm table-hover table-bordered">
<thead class="thead-dark">
    <tr>
      <th scope="col">Category</th>
      <th scope="col">Tasks</th>
      <th scope="col"></th>
    </tr>
  </thead>
  <tbody>
    <% @categories.each do |c| %>
    <% if c.colour.nil? %>
      <% bgcolour = "#FFFFFF"; fgcolour = "#000000" %>
    <% else %>
      <% bgcolour = c.colour; fgcolour = choose_fgcolour(c.colour); %>
    <% end %>
    <tr>
      <th scope="row" style="background-color:<%= bgcolour %>; color: <%= fgcolour %>"><%= c.name %></th>
      <td class="name">
        <ol>
        <% c.tasks.all.each do |t| %>
          <li><%= link_to t.name, edit_task_path(id: t.id) %></li>
        <% end %>
        </ol>
      </td>
      <td>
        <span class="dropdown">
          <button type="button" class="btn btn-secondary btn-sm" data-toggle="dropdown">
            <i class="fa fa-ellipsis-v"></i>
          </button>
          <div class="dropdown-menu dropdown-menu-right">
            <%= link_to '<i class="fa fa-edit"></i> Edit Category'.html_safe, edit_category_path(c), class: 'dropdown-item' %>
            <%= link_to '<i class="fa fa-trash"></i> Delete Category'.html_safe, category_path(c), method: :delete, data: { confirm: 'Are you sure?' }, class: 'dropdown-item bg-danger text-white' %>
          </div>
        </span>
      </td>
    </tr>
    <% end %>
  </tbody>
</table>
<%= render "footer" %>