Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wave 4 #107

Open
wants to merge 3 commits into
base: mmr/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions task_list/app/assets/javascripts/people.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
4 changes: 0 additions & 4 deletions task_list/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@
text-align: left;
}

th, td {
padding-left: 50px;
}

a {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some of the styles below, you want to separate multi-word styles with the - rather than the _

text-decoration: underline;
font-size: 12px;
Expand Down
3 changes: 3 additions & 0 deletions task_list/app/assets/stylesheets/people.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the People controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
19 changes: 19 additions & 0 deletions task_list/app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class PeopleController < ApplicationController

def index
@people = Person.all
@title = "Peeps"
end

def show
id = params[:id]
@people = Person.find(id)
@title = "Peep Info"
end

def show_tasks
id = params[:id]
@tasks = Person.find(id).tasks
@title = "#{Person.find(id).name}'s Tasks"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are unnecessarily retrieving the person's information twice here. Each time you use find you are querying the database again and as a dev you want to try to query the DB as little as possible. You should be retrieving the person using your Person.find(id) first, then retrieving the tasks and the name from that variable. This will ensure only a single database query.

end
end
2 changes: 2 additions & 0 deletions task_list/app/helpers/people_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module PeopleHelper
end
8 changes: 8 additions & 0 deletions task_list/app/models/person.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Person < ActiveRecord::Base
has_many :tasks

def not_complete

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might recommend renaming this method to be num_not_complete or something that more clearly indicates that this method returns the number of incomplete tasks as opposed to the incomplete tasks themselves.

complete = self.tasks.where({:completed_at => nil})
return complete.length
end
end
2 changes: 1 addition & 1 deletion task_list/app/models/task.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Task < ActiveRecord::Base

belongs_to :person
end
23 changes: 23 additions & 0 deletions task_list/app/views/people/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<table>
<thead>
<tr>
<th>
Person
</th>
<th>
# of Incomplete Tasks
</th>
</tr>
</thead>
<tbody>
<% @people.each do |person| %>
<tr>
<td><%= link_to person.name, "/people/#{person.id}" %>
</td>
<td>
<%= person.not_complete %>
<% end %>
</td>
</tr>
</tbody>
</table>
28 changes: 28 additions & 0 deletions task_list/app/views/people/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<table>
<thead>
<tr>
<th>
Person
</th>
<th>
What's Special About Them?
</th>
<th>
Tasks
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<%= @people.name %>
</td>
<td>
<%= @people.interests %>
</td>
<td>
<%= button_to "See Tasks", { action: "show_tasks", id: @people.id }, method: :get %>
</td>
</tr>
</tbody>
</table>
5 changes: 5 additions & 0 deletions task_list/app/views/people/show_tasks.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% @tasks.each do |task| %>
<p>
<%= task.name %>
</p>
<% end %>
3 changes: 2 additions & 1 deletion task_list/app/views/tasks/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<%= f.text_field :name %>
<%= f.label :description %>
<%= f.text_field :description %>
<%= f.collection_select(:person_id, Person.all, :id, :name, prompt: "Who's going to do this?") %>
</fieldset>
<%= f.submit class: "submit"%>
<%= f.submit class: "submit"%>
<% end %>
6 changes: 6 additions & 0 deletions task_list/app/views/tasks/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<th>
Task
</th>
<th>
Who's Responsible?
</th>
<th>
Done?
</th>
Expand All @@ -17,6 +20,9 @@
<% @tasks.each do |task| %>
<tr>
<td><%= link_to task.name, "/tasks/#{task.id}" %></td>
<td>
<%= task.person.name %>
</td>
<td>
<% if task.completed_at == nil %>
<%= button_to "Complete?", { action: "toggle_complete", id: task.id }, method: :patch, class: "complete_button" %>
Expand Down
6 changes: 6 additions & 0 deletions task_list/app/views/tasks/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<th>
Complete Date
</th>
<th>
Who Did It?
</th>
<th>
Edit?
</th>
Expand All @@ -29,6 +32,9 @@
<%= @task.completed_at %>
<% end %>
</td>
<td>
<%= @task.person.name %>
</td>
<td>
<%= button_to "Edit", { action: "edit", id: @task.id }, method: :get %>
</td>
Expand Down
6 changes: 5 additions & 1 deletion task_list/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
post 'tasks/' => 'tasks#create'
delete 'tasks/:id' => 'tasks#destroy'
get 'tasks/:id/edit' => 'tasks#edit', as: 'edit_task'
patch 'tasks/:id' => 'tasks#update'
patch 'tasks/:id' => 'tasks#toggle_complete'
patch 'tasks/:id' => 'tasks#update'

get 'people/' => 'people#index'
get 'people/:id' => 'people#show'
get 'people/:id/tasks' => 'people#show_tasks'

# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
Expand Down
10 changes: 10 additions & 0 deletions task_list/db/migrate/20151116202008_create_people.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreatePeople < ActiveRecord::Migration
def change
create_table :people do |t|
t.string :name
t.string :interests

t.timestamps null: false
end
end
end
10 changes: 10 additions & 0 deletions task_list/db/migrate/20151116212829_modify_tasks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class ModifyTasks < ActiveRecord::Migration
def change
change_table :tasks do |t|
remove_column :tasks, :completed
add_column :tasks, :person_id, :integer
end

add_index :tasks, :person_id
end
end
13 changes: 11 additions & 2 deletions task_list/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20151110221757) do
ActiveRecord::Schema.define(version: 20151116212829) do

create_table "people", force: :cascade do |t|
t.string "name"
t.string "interests"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "tasks", force: :cascade do |t|
t.string "name"
t.string "description"
t.datetime "completed_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "completed"
t.integer "person_id"
end

add_index "tasks", ["person_id"], name: "index_tasks_on_person_id"

end
33 changes: 23 additions & 10 deletions task_list/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,35 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
person = [
{name: "Meighan", interests: "likes dogs"},
{name: "Daphne", interests: "likes cats"},
{name: "Lauren", interests: "likes dogs"},
{name: "Kari", interests: "likes dogs"},
{name: "Katherine", interests: "likes cats"},
{name: "Jenna", interests: "likes cats"},
{name: "Jessica", interests: "likes dogs"}
]

person.each do |seed|
Person.create(seed)
end

def random_time
Time.at(rand * Time.now.to_i)
end

tasks = [
{ name: "The First Task", description: "", completed_at: random_time },
{ name: "Go to Brunch", description: "" },
{ name: "Go to Lunch", description: "", completed_at: random_time },
{ name: "Go to Second Lunch", description: "" },
{ name: "Play Video Games", description: "", completed_at: random_time },
{ name: "High Five Somebody You Don't Know", description: "", completed_at: random_time },
{ name: "Plant Flowers", description: "", completed_at: random_time },
{ name: "Call Mom", description: "" },
{ name: "She worries, you know.", description: "" },
{ name: "Nap.", description: "", completed_at: random_time }
{ name: "The First Task", description: "", completed_at: random_time, person_id: 1 },
{ name: "Go to Brunch", description: "", person_id: 2 },
{ name: "Go to Lunch", description: "", completed_at: random_time, person_id: 3 },
{ name: "Go to Second Lunch", description: "", person_id: 4 },
{ name: "Play Video Games", description: "", completed_at: random_time, person_id: 5 },
{ name: "High Five Somebody You Don't Know", description: "", completed_at: random_time, person_id: 6 },
{ name: "Plant Flowers", description: "", completed_at: random_time, person_id: 7 },
{ name: "Call Mom", description: "", completed_at: random_time, person_id: 1},
{ name: "She worries, you know.", description: "", completed_at: random_time, person_id: 2 },
{ name: "Nap.", description: "", completed_at: random_time, person_id: 3 }
]

tasks.each do |task|
Expand Down