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

+ 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:

    + + +
    + +

    <%=@person.name%>'s' Completed Tasks:

    + 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: