mfvico/gCamp

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

Summary

Maintainability
Test Coverage
<% if notice != nil %>
  <p class="alert alert-success" id="notice"><%= notice  %></p>
<% end %>
<div class="page-header">
  <div class="pull-right">
    <%= link_to_unless_current 'All', project_tasks_path(sort_by: "all")  %> |
    <%if params[:sort_by] == nil%>
      Incomplete
    <%else%>
      <%= link_to 'Incomplete', project_tasks_path %>
    <%end%>
    <% if current_user.memberships.where(project_id: @project.id).exists? || admin_check %>
      <%= link_to 'Create Task', new_project_task_path, class: "btn btn-info" %>
    <% end %>
  </div>
  <h1>Tasks</h1>
</div>

  <ol class="breadcrumb">
    <li><%= link_to "Projects", projects_path %></li>
    <li><%= link_to @project.name, project_path(@project) %></li>
    <li class="active">Tasks</li>
  </ol>

<table class="table">
  <thead>
    <tr>
      <th>Description</th>
      <th>Due Date</th>
      <th>Complete?</th>

      <th colspan="2"></th>

    </tr>
  </thead>

  <tbody>
    <% @tasks.each do |task| %>
      <% if task.due_date  %>
        <% due_week = (task.due_date - Date.today) %>

        <% if due_week <=7 %>
          <tr class="alert alert-warning">
        <% else %>
          <tr>
        <% end %>

      <% else %>
          <tr>
      <% end %>

      <td class="col-md-6"><%= link_to task.task, project_task_path(@project, task) %>
         <span class="badge"><%= task.comments.count %></span></td>
      <% if task.due_date == nil %>
        <td class="col-md-2"> none </td>
      <%else%>
        <td class="col-md-2"><%= task.due_date.strftime("%B %e %Y") %></td>
      <%end%>
      <%if task.complete == true%>
        <td class="col-md-1">Complete</td>
      <%else%>
        <td class="col-md-1">Incomplete</td>
      <%end%>
      <td class="col-md-3">
        <% if current_user.memberships.where(project_id: @project.id).exists? %>
        <div class="pull-right">
        <%= link_to 'Edit', edit_project_task_path(@project, task), class: "btn btn-warning btn-sm" %>
        <%= link_to project_task_path(@project, task), method: :delete, data: { confirm: 'Are you sure?' } do %>
          <span class="glyphicon glyphicon-remove"></span>
        <% end %></td>
      </div>
        <% end %>
    </tr>
  <% end %>

  </tbody>
</table>
<%= link_to "Download CSV", project_tasks_path(format: "csv") %>

<br>