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

Hrw/master #112

Open
wants to merge 7 commits into
base: hrw/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
12 changes: 12 additions & 0 deletions seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: "" },
Expand Down
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: 4 additions & 0 deletions task-list/app/assets/stylesheets/mysite.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ li {
#completed {
text-decoration: line-through;
}

#people_list {

Choose a reason for hiding this comment

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

In CSS - we separate multiple-named styles with the - rather than _

text-align: center;
}
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/
17 changes: 17 additions & 0 deletions task-list/app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion task-list/app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
15 changes: 15 additions & 0 deletions task-list/app/models/person.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Person < ActiveRecord::Base
has_many :tasks

def incomplete_tasks
t = self.tasks

Choose a reason for hiding this comment

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

I would recommend a more meaningful variable name instead of t

t = t.where(completed: nil)
return t
end

def complete_tasks
t = self.tasks
t = t.where.not(completed: nil)
return t
end
end
1 change: 1 addition & 0 deletions task-list/app/models/task.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class Task < ActiveRecord::Base
belongs_to :person
end
9 changes: 9 additions & 0 deletions task-list/app/views/people/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1> Here are each of the people you can assign to a task </h1>
<ul id=people_list>
<% @people.each do |p| %>
<li>
Task left to do: <%=p.incomplete_tasks.count%>
<br><a href=people/<%=p.id%>><%= p.name %></a>
</li>
<%end%>
</ul>
3 changes: 3 additions & 0 deletions task-list/app/views/people/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1><%[email protected]%> </h1>

<li><a href=<%[email protected]%>/tasks>Click here to see all of <%[email protected]%>'s tasks </a>
22 changes: 22 additions & 0 deletions task-list/app/views/people/tasks.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<h1> <%[email protected]%>'s' Incomplete Tasks: </h1>
<ul id=person_task_list>
<% @remaining_tasks.each do |t| %>
<li>
Task: <%=t.name%>

Choose a reason for hiding this comment

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

For readability, it is best practice to add a space after the = and before the last % so:
<%= t.name %>

<br>Description: <%=t.description%>
</li>
<%end%>
</ul>

<br>

<h1> <%[email protected]%>'s' Completed Tasks: </h1>
<ul id=person_task_list>
<% @finished_tasks.each do |t| %>
<li>
Task: <%=t.name%>
<br>Description: <%=t.description%>
<br>Completed: <%=t.completed%>
</li>
<%end%>
</ul>
11 changes: 8 additions & 3 deletions task-list/app/views/tasks/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
<h2> This is all the stuff you still gotta do:</h2>
<ul>
<% @current_tasks.each do |task| %>
<li><a href=tasks/<%=task.id%>><%= task.name %></a>: <%= task.description%>
<%= task.completed%>
<li>Task: <a href=tasks/<%=task.id%>><%= task.name %></a>
<br>Description: <%= task.description%>,
<br>Assigned to: <%= task.person.name%>
<br> <%= 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%>

Expand All @@ -17,7 +19,10 @@
<h2> Here's all the stuff you already finished!</h2>
<ul id= completed>
<% @completed_tasks.each do |task| %>
<li><a href=tasks/<%=task.id%>><%= task.name %></a>: <%= task.description%>, Completed at: <%= task.completed%>
<li>Task: <a href=tasks/<%=task.id%>><%= task.name %></a>
<br>Description: <%= task.description%>,
<br>Assigned to: <%= task.person.name%>
<br> 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?" } %>
</li>
<%end%>
Expand Down
6 changes: 6 additions & 0 deletions task-list/app/views/tasks/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<br>
<%= f.label :description %>
<%= f.text_field :description %>
<br>
<%= f.label :person_id, "Person" %>

<%= f.collection_select(:person_id, Person.all, :id, :name,
prompt: "Select Person for Task:") %>


</fieldset>
<%= f.submit %>
Expand Down
5 changes: 3 additions & 2 deletions task-list/app/views/tasks/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<h1> <%[email protected]%> </h1>
<h5><%[email protected]%></h5>
<h1> Task: <%[email protected]%> </h1>
<h5>Description: <%[email protected]%></h5>
<h5>Assigned to: <%= @task.person.name%></h5>
<h5><%[email protected]%></h5>

<li><a href=<%[email protected]%>/edit>UPDATE!</a>
8 changes: 8 additions & 0 deletions task-list/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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".

Expand Down
9 changes: 9 additions & 0 deletions task-list/db/migrate/20151116195108_create_people.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions task-list/db/migrate/20151116195337_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|
add_column :tasks, :person_id, :integer

end
#first parameter is table name, second is column name
add_index :tasks, :person_id
end
end
11 changes: 10 additions & 1 deletion task-list/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@
#
# 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"
t.string "description"
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
34 changes: 24 additions & 10 deletions task-list/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down