diff --git a/seeds.rb b/seeds.rb
index de6ef27a7..b7413e642 100644
--- a/seeds.rb
+++ b/seeds.rb
@@ -2,6 +2,18 @@ def random_time
Time.at(rand * Time.now.to_i)
end
+seed_people = [
+ {name: "Shia"},
+ {name: "Hailey"},
+ {name: "David"},
+ {name: "Alex"},
+ {name: "Graham"},
+ {name: "Daniel"},
+
+]
+seed_people.each do |seed|
+ Person.create(seed)
+
tasks = [
{ name: "The First Task", description: "", completed_at: random_time },
{ name: "Go to Brunch", description: "" },
diff --git a/task-list/app/assets/javascripts/people.coffee b/task-list/app/assets/javascripts/people.coffee
new file mode 100644
index 000000000..24f83d18b
--- /dev/null
+++ b/task-list/app/assets/javascripts/people.coffee
@@ -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/
diff --git a/task-list/app/assets/stylesheets/mysite.css b/task-list/app/assets/stylesheets/mysite.css
index fa54356f5..f676ef43a 100644
--- a/task-list/app/assets/stylesheets/mysite.css
+++ b/task-list/app/assets/stylesheets/mysite.css
@@ -49,3 +49,7 @@ li {
#completed {
text-decoration: line-through;
}
+
+#people_list {
+ text-align: center;
+}
diff --git a/task-list/app/assets/stylesheets/people.scss b/task-list/app/assets/stylesheets/people.scss
new file mode 100644
index 000000000..521746256
--- /dev/null
+++ b/task-list/app/assets/stylesheets/people.scss
@@ -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/
diff --git a/task-list/app/controllers/people_controller.rb b/task-list/app/controllers/people_controller.rb
new file mode 100644
index 000000000..ac00d7f7c
--- /dev/null
+++ b/task-list/app/controllers/people_controller.rb
@@ -0,0 +1,17 @@
+class PeopleController < ApplicationController
+ def index
+ @people = Person.all
+ end
+
+ def show
+ id = params[:person_id]
+ @person = Person.find(id)
+ end
+
+ def tasks
+ id = params[:person_id]
+ @person = Person.find(id)
+ @finished_tasks= @person.complete_tasks
+ @remaining_tasks= @person.incomplete_tasks
+ end
+end
diff --git a/task-list/app/controllers/tasks_controller.rb b/task-list/app/controllers/tasks_controller.rb
index f8adfabc2..f2261ce9d 100644
--- a/task-list/app/controllers/tasks_controller.rb
+++ b/task-list/app/controllers/tasks_controller.rb
@@ -61,6 +61,6 @@ def toggle_completed
def task_params
#this makes strong params
- params.permit(task:[:name, :description])
+ params.permit(task:[:name, :description, :person_id])
end
end
diff --git a/task-list/app/helpers/people_helper.rb b/task-list/app/helpers/people_helper.rb
new file mode 100644
index 000000000..b682fbf12
--- /dev/null
+++ b/task-list/app/helpers/people_helper.rb
@@ -0,0 +1,2 @@
+module PeopleHelper
+end
diff --git a/task-list/app/models/person.rb b/task-list/app/models/person.rb
new file mode 100644
index 000000000..a4d879945
--- /dev/null
+++ b/task-list/app/models/person.rb
@@ -0,0 +1,15 @@
+class Person < ActiveRecord::Base
+ has_many :tasks
+
+ def incomplete_tasks
+ t = self.tasks
+ t = t.where(completed: nil)
+ return t
+ end
+
+ def complete_tasks
+ t = self.tasks
+ t = t.where.not(completed: nil)
+ return t
+ end
+end
diff --git a/task-list/app/models/task.rb b/task-list/app/models/task.rb
index 935f76e12..c3c534741 100644
--- a/task-list/app/models/task.rb
+++ b/task-list/app/models/task.rb
@@ -1,2 +1,3 @@
class Task < ActiveRecord::Base
+ belongs_to :person
end
diff --git a/task-list/app/views/people/index.html.erb b/task-list/app/views/people/index.html.erb
new file mode 100644
index 000000000..3e5d80b27
--- /dev/null
+++ b/task-list/app/views/people/index.html.erb
@@ -0,0 +1,9 @@
+
Here are each of the people you can assign to a task
+
+ <% @people.each do |p| %>
+ -
+ Task left to do: <%=p.incomplete_tasks.count%>
+
><%= p.name %>
+
+ <%end%>
+
diff --git a/task-list/app/views/people/show.html.erb b/task-list/app/views/people/show.html.erb
new file mode 100644
index 000000000..71d62295e
--- /dev/null
+++ b/task-list/app/views/people/show.html.erb
@@ -0,0 +1,3 @@
+<%=@person.name%>
+
+/tasks>Click here to see all of <%=@person.name%>'s tasks
diff --git a/task-list/app/views/people/tasks.html.erb b/task-list/app/views/people/tasks.html.erb
new file mode 100644
index 000000000..7d224dfbc
--- /dev/null
+++ b/task-list/app/views/people/tasks.html.erb
@@ -0,0 +1,22 @@
+ <%=@person.name%>'s' Incomplete Tasks:
+
+ <% @remaining_tasks.each do |t| %>
+ -
+ Task: <%=t.name%>
+
Description: <%=t.description%>
+
+ <%end%>
+
+
+
+
+ <%=@person.name%>'s' Completed Tasks:
+
+ <% @finished_tasks.each do |t| %>
+ -
+ Task: <%=t.name%>
+
Description: <%=t.description%>
+
Completed: <%=t.completed%>
+
+ <%end%>
+
diff --git a/task-list/app/views/tasks/index.html.erb b/task-list/app/views/tasks/index.html.erb
index 6b53d8925..fb69210ba 100644
--- a/task-list/app/views/tasks/index.html.erb
+++ b/task-list/app/views/tasks/index.html.erb
@@ -5,8 +5,10 @@
This is all the stuff you still gotta do:
<% @current_tasks.each do |task| %>
- - ><%= task.name %>: <%= task.description%>
- <%= task.completed%>
+
- Task: ><%= task.name %>
+
Description: <%= task.description%>,
+
Assigned to: <%= task.person.name%>
+
<%= task.completed%>
<%= button_to "Delete Task", { action: :destroy, id: task.id}, method: :delete, data: { confirm: "Are you sure that you want to delete this?" } %>
<%= button_to "Complete Task", {action: :toggle_completed, id: task.id}, method: :patch%>
@@ -17,7 +19,10 @@
Here's all the stuff you already finished!
<% @completed_tasks.each do |task| %>
- - ><%= task.name %>: <%= task.description%>, Completed at: <%= task.completed%>
+
- Task: ><%= task.name %>
+
Description: <%= task.description%>,
+
Assigned to: <%= task.person.name%>
+
Completed at: <%= task.completed%>
<%= button_to "Delete Task", { action: :destroy, id: task.id}, method: :delete, data: { confirm: "Are you sure that you want to delete this?" } %>
<%end%>
diff --git a/task-list/app/views/tasks/new.html.erb b/task-list/app/views/tasks/new.html.erb
index dcec5da70..a98486bd4 100644
--- a/task-list/app/views/tasks/new.html.erb
+++ b/task-list/app/views/tasks/new.html.erb
@@ -7,6 +7,12 @@
<%= f.label :description %>
<%= f.text_field :description %>
+
+ <%= f.label :person_id, "Person" %>
+
+ <%= f.collection_select(:person_id, Person.all, :id, :name,
+ prompt: "Select Person for Task:") %>
+
<%= f.submit %>
diff --git a/task-list/app/views/tasks/show.html.erb b/task-list/app/views/tasks/show.html.erb
index ce92cf627..a83cad8c0 100644
--- a/task-list/app/views/tasks/show.html.erb
+++ b/task-list/app/views/tasks/show.html.erb
@@ -1,5 +1,6 @@
- <%=@task.name%>
-<%=@task.description%>
+ Task: <%=@task.name%>
+Description: <%=@task.description%>
+Assigned to: <%= @task.person.name%>
<%=@task.completed%>
- /edit>UPDATE!
diff --git a/task-list/config/routes.rb b/task-list/config/routes.rb
index fa6953086..251ee2355 100644
--- a/task-list/config/routes.rb
+++ b/task-list/config/routes.rb
@@ -17,6 +17,14 @@
post 'tasks/' => 'tasks#create'
+ get 'people/' => 'people#index'
+
+ get 'people/:person_id' => 'people#show'
+
+ get 'people/:person_id/tasks' => 'people#tasks'
+
+
+
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
diff --git a/task-list/db/migrate/20151116195108_create_people.rb b/task-list/db/migrate/20151116195108_create_people.rb
new file mode 100644
index 000000000..727e50381
--- /dev/null
+++ b/task-list/db/migrate/20151116195108_create_people.rb
@@ -0,0 +1,9 @@
+class CreatePeople < ActiveRecord::Migration
+ def change
+ create_table :people do |t|
+ t.string :name
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/task-list/db/migrate/20151116195337_modify_tasks.rb b/task-list/db/migrate/20151116195337_modify_tasks.rb
new file mode 100644
index 000000000..b148ab14c
--- /dev/null
+++ b/task-list/db/migrate/20151116195337_modify_tasks.rb
@@ -0,0 +1,10 @@
+class ModifyTasks < ActiveRecord::Migration
+ def change
+ change_table :tasks do |t|
+ add_column :tasks, :person_id, :integer
+
+ end
+ #first parameter is table name, second is column name
+ add_index :tasks, :person_id
+ end
+end
diff --git a/task-list/db/schema.rb b/task-list/db/schema.rb
index 875a90816..372d880d9 100644
--- a/task-list/db/schema.rb
+++ b/task-list/db/schema.rb
@@ -11,7 +11,13 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20151110002600) do
+ActiveRecord::Schema.define(version: 20151116195337) do
+
+ create_table "people", force: :cascade do |t|
+ t.string "name"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
create_table "tasks", force: :cascade do |t|
t.string "name"
@@ -19,6 +25,9 @@
t.datetime "completed"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
+ t.integer "person_id"
end
+ add_index "tasks", ["person_id"], name: "index_tasks_on_person_id"
+
end
diff --git a/task-list/db/seeds.rb b/task-list/db/seeds.rb
index e07010ba6..81bdf84f0 100644
--- a/task-list/db/seeds.rb
+++ b/task-list/db/seeds.rb
@@ -9,17 +9,31 @@ def random_time
Time.at(rand * Time.now.to_i)
end
+seed_people = [
+ {name: "Shia"},
+ {name: "Hailey"},
+ {name: "David"},
+ {name: "Alex"},
+ {name: "Graham"},
+ {name: "Daniel"},
+
+]
+
+seed_people.each do |seed|
+ Person.create(seed)
+end
+
tasks = [
- { name: "The First Task", description: "", completed: random_time },
- { name: "Go to Brunch", description: "" },
- { name: "Go to Lunch", description: "", completed: random_time },
- { name: "Go to Second Lunch", description: "" },
- { name: "Play Video Games", description: "", completed: random_time },
- { name: "High Five Somebody You Don't Know", description: "", completed: random_time },
- { name: "Plant Flowers", description: "", completed: random_time },
- { name: "Call Mom", description: "" },
- { name: "She worries, you know.", description: "" },
- { name: "Nap.", description: "", completed: random_time }
+ { name: "The First Task", description: "", person_id: 2, completed: random_time },
+ { name: "Go to Brunch", description: "", person_id: 3 },
+ { name: "Go to Lunch", description: "", person_id: 4, completed: random_time },
+ { name: "Go to Second Lunch", description: "", person_id: 5 },
+ { name: "Play Video Games", description: "", person_id: 6, completed: random_time },
+ { name: "High Five Somebody You Don't Know", description: "", person_id: 3, completed: random_time },
+ { name: "Plant Flowers", description: "", person_id: 3, completed: random_time },
+ { name: "Call Mom", description: "", person_id: 3, },
+ { name: "She worries, you know.", description: "", person_id: 3, },
+ { name: "Nap.", description: "", person_id: 3, completed: random_time }
]
tasks.each do |task|