Chapter 17

The Tasks Module: Extending the Dashboard

Well that’s it! You know everything about extending and working with different engines. Let’s wrap up this module by adding a list of tasks to the dashboard view.

Before we begin, let’s create our chapter branch:

git checkout -b Chapter-17

17.1. Tasks in the Dashboard

17.1.1. Add the override

Let’s create the Deface override to insert our Tasks in the dashboard (you probably don’t need a reminder that you should be doing this from the Tasks engine):

touch app/overrides/add_tasks_list_to_dashboard.rb
Listing 0.1: Contents of tasks lists override app/overrides/add_tasks_list_to_dashboard.rb
Deface::Override.new(:virtual_path => "blast/dashboard/index",
                     :name => "add_tasks_list_to_dashboard",
                     :insert_after => "[data-blast-hook='dashboard']",
                     :partial => "overrides/dashboard_tasks_list",
                     :namespaced => true)

17.1.2. Add the override view

And now let’s create the view that displays the last 3 tasks created:

touch app/views/blast/tasks/overrides/_dashboard_tasks_list.html.erb
Listing 0.2: Contents of tasks lists override view app/views/blast/tasks/overrides/_dashboard_tasks_list.html.erb
<div class="col-md-6">
  <div class="panel panel-primary">
    <div class="panel-heading">
      Last 3 Tasks
    </div>
    <table class="table">
      <thead>
        <th>ID</th>
        <th>Title</th>
        <th>Content</th>
        <th>Created On</th>
      </thead>
      <tbody>
        <%- current_user.tasks.limit(3).each do |task| %>
          <tr>
          <td><%= task.id %></td>
          <td><%= task.title %></td>
          <td><%= task.content %></td>
          <td><%= task.created_at.strftime("%d %b. %Y") %></td>
          </tr>
        <% end %>
      </tbody>
    </table>
    <div class="panel-body text-center">
      <%= link_to '...', tasks_path %>
    </div>
  </div>
</div>

17.1.3. And for some pretty pictures

Let’s see if everything worked:

https://s3.amazonaws.com/devblast-modr-book/images/figures/04_17/dashboard_override
Figure 1: Seems to be working... nice!

17.2. Pushing Our Changes

Once again,

  1. Check the changes:
    git status
    
  2. Stage them:
    git add .
    
  3. Commit them:
    git commit -m "Extending the Dashboard"
    
  4. Push to your GitHub repo if you’ve configured it:
    git push origin Chapter-17
    

17.3. Wrap Up

In this chapter we extended the Dashboard to display the last 3 tasks.

17.3.1. Next Step

Just like with the Contacts module, we have an exercise for you.