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

Th/master #111

Open
wants to merge 6 commits into
base: th/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
Binary file added task-list/.DS_Store
Binary file not shown.
Binary file added task-list/app/.DS_Store
Binary file not shown.
Binary file added task-list/app/assets/.DS_Store
Binary file not shown.
Binary file added task-list/app/assets/images/.DS_Store
Binary file not shown.
Binary file added task-list/app/assets/images/note 2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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/
Binary file added task-list/app/assets/stylesheets/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion task-list/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
height: 600px;
background-image: url('/assets/gradient-background.jpg');
background-size: 1500px 2000px;
width: 900px;
width: 1000px;
margin-left:auto;
margin-right:auto;
background-repeat: no-repeat;
Expand Down
16 changes: 16 additions & 0 deletions task-list/app/assets/stylesheets/people.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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/

table {
width: 900px;
margin-left:auto;
margin-right:auto;

}

td, th {
border: 1px solid transparent; /* No more visible border */

Choose a reason for hiding this comment

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

Watch your formatting here

height: 30px;
transition: all 0.3s; /* Simple transition for hover effect */
}
12 changes: 10 additions & 2 deletions task-list/app/assets/stylesheets/tasks.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ a{


#name {
text-align: center;
margin-left: 32%;
}

#description {
Expand Down Expand Up @@ -75,10 +75,18 @@ footer {

}

.comp_date {
font-weight: bold;
font-size: 15px;

}

#task_person_id {

Choose a reason for hiding this comment

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

CSS styles that contain multiple words should be separated by the - not the _

margin-left: 39%;
}

table {
width: 600px;
width: 900px;
margin-left:auto;
margin-right:auto;

Expand Down
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[:id]
@person = Person.find(id)
end

def show_tasks
@person = Person.find(params[:id])
@tasks = Person.find(params[:id]).tasks

Choose a reason for hiding this comment

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

Since you already did the Person.find(params[:id]) on the line above, you don't want to do it again here. That will query the database twice. You should instead use the @person variable to retrieve the tasks.

end

end
4 changes: 2 additions & 2 deletions task-list/app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def set_completed

def update
task = Task.find(params[:id])
task.update(name: task_params[:task][:name], description: task_params[:task][:description])
task.update(task_params[:task])
redirect_to '/tasks/'
end

Expand All @@ -52,7 +52,7 @@ def edit
private

def task_params
params.permit(task:[:name, :description])
params.permit(task:[:name, :description, :person_id])
end


Expand Down
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 uncompleted

Choose a reason for hiding this comment

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

Since this method returns the count, it might make sense to change the name of the method to something like uncompleted_count since it returns the length rather than the tasks themselves

completed = self.tasks.where({:completed_at => nil})

Choose a reason for hiding this comment

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

It might make sense to rename this variable since these are the pieces that are not completed

return completed.length
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
Binary file added task-list/app/views/.DS_Store
Binary file not shown.
22 changes: 22 additions & 0 deletions task-list/app/views/people/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<table>
<col width="80%">

Choose a reason for hiding this comment

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

It might make more sense to have a class associated with these columns that will then set the width

<col width="20%">
<tr>
<th> Name </th>
<th> # uncompleted tasks</th>
</tr>
<% @people.each do |person| %>
<tr>
<td>
<%if !person.name.nil? %>
<%= link_to "#{person.name}", {controller: "people", action: "show_tasks", id: person.id} %>
<% end %>
</td>
<td>
<%= person.uncompleted %>
</td>
</tr>
<% end %>
</table>

\
4 changes: 4 additions & 0 deletions task-list/app/views/people/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h1> User Information </h1>
<h2> name: <%= @person.name %> </h2>
<h3>Favorite Color: <%= @person.favorite_color %></h3>

Choose a reason for hiding this comment

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

The formatting here looks inconsistent from the h1,h2 to this h3

<p> <%= link_to "Check out #{@person.name} tasks", "/people/#{@person.id}/tasks" %></p>
14 changes: 14 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,14 @@
<%= link_to "Uncompleted Tasks", {action: "index", controller: "people"} %>
<h1>This is The task list of <%= @person.name %> </h1>
<ul>
<% @tasks.each do |task| %>
<li> Task: <%= task.name %> description: <%= task.description %> </li>
<ul>
<% if !task.completed_at.nil? %>
<li class="comp_date">completed_at: <%= task.completed_at %></li>
<% else %>
<li class="comp_date">This task is not yet completed</li>
<% end %>
</ul>
<% end %>
</ul>
2 changes: 2 additions & 0 deletions task-list/app/views/tasks/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<%= form_for @task, url: {action: "#{@action}"} do |f| %>
<fieldset>
<legend> <%= @title %> </legend>

<p id="name"><%= f.label :name %>:
<%= f.text_field :name %> </p>

<p id="description"> <%= f.label :description %>
<%= f.text_field :description %></p>
<%= f.collection_select(:person_id, Person.all, :id, :name, prompt: "Who this task belongs to?") %>
<%= f.submit class: "submit"%>
</fieldset>

Expand Down
8 changes: 7 additions & 1 deletion task-list/app/views/tasks/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@
<col width="10%">
<tr>
<th id="task_name">Task</th>
<th id="person_name">Person</th>
<th></th>
</tr>
<% @tasks.each do |task| %>
<tr>
<td >
<%= link_to "Task: #{task.name}", "/tasks/#{task.id}" %>
</td>
<td>
<% if !task.person.nil? %>
<%= link_to "#{task.person.name}", "/people/#{task.person.id}" %>
<% end %>
</td>
<td>
<% if !task.completed_at.nil? %>
<%= task.completed_at %>
<%= task.completed_at.strftime("%d/%m/%Y %H:%M") %>
<<% else %>
<%= button_to "Completed", {action: 'set_completed', id: task.id}, method: :patch %>
<% end %>
Expand Down
6 changes: 6 additions & 0 deletions task-list/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
patch 'tasks/:id' => 'tasks#update', as: :task
patch 'tasks/:id/set_completed' => 'tasks#set_completed'

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
11 changes: 11 additions & 0 deletions task-list/db/migrate/20151116194615_create_people.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreatePeople < ActiveRecord::Migration
def change
create_table :people do |t|
t.string :name
t.string :city
t.string :favorite_color

t.timestamps null: false
end
end
end
9 changes: 9 additions & 0 deletions task-list/db/migrate/20151116200801_add_person_id.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddPersonId < ActiveRecord::Migration
def change
change_table :tasks do |t|
add_column :tasks, :person_id, :integer
end

add_index :tasks, :person_id
end
end
13 changes: 12 additions & 1 deletion task-list/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,25 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20151110223044) do
ActiveRecord::Schema.define(version: 20151116200801) do

create_table "people", force: :cascade do |t|
t.string "name"
t.string "city"
t.string "favorite_color"
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.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 @@ -2,17 +2,30 @@ def random_time
Time.at(rand * Time.now.to_i)
end

seed_person = [
{name: "Tammy", city: "Seattle", favorite_color: "purple"},
{name: "Daniella", city: "Tel Aviv", favorite_color: "deep blue"},
{name: "Itai", city: "Tel Aviv", favorite_color: "green"},
{name: "Jackie", city: "Ramat Gan", favorite_color: "metal"},
{name: "Michelle", city: "Hod Hasharon", favorite_color: "baby-pink"}
]

seed_person.each do |seed|
Person.create(seed)
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: 3},
{ name: "Go to Lunch", description: "", completed_at:random_time, person_id: 2 },
{ name: "Go to Second Lunch", description: "", person_id: 5 },
{ name: "Play Video Games", description: "", completed_at:random_time, person_id: 4 },
{ name: "High Five Somebody You Don't Know", description: "", completed_at:random_time, person_id: 2 },
{ name: "Plant Flowers", description: "", completed_at:random_time, person_id: 4 },
{ name: "Call Mom", description: "", person_id: 1 },
{ name: "She worries, you know.", description: "", person_id: 3 },
{ name: "Nap.", description: "", completed_at:random_time, person_id: 4 }
]

tasks.each do |task|
Expand Down