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

Ash/master #99

Open
wants to merge 5 commits into
base: ash/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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 tasklist/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/
1 change: 1 addition & 0 deletions tasklist/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ li {
font-size: 20px;
font-weight: bold;
padding-bottom: 30px;
margin: auto;
}
3 changes: 3 additions & 0 deletions tasklist/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/
15 changes: 15 additions & 0 deletions tasklist/app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class PeopleController < ApplicationController
def index
@people = Person.all
end

def show
id = params[:id]
@person = Person.find(id)
end

def tasks
id = params[:id]
@person = Person.find(id)
end
end
2 changes: 1 addition & 1 deletion tasklist/app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ def destroy
private

def task_params
params.require(:task).permit(:name, :descript, :date_completed)
params.require(:task).permit(:name, :descript, :date_completed, :person_id)
end
end
2 changes: 2 additions & 0 deletions tasklist/app/helpers/people_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module PeopleHelper
end
10 changes: 10 additions & 0 deletions tasklist/app/models/person.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Person < ActiveRecord::Base
has_many :tasks


def incomplete_tasks
t = self.tasks
incomplete_tasks = t.where(date_completed: nil)
incomplete_tasks.count
end
end
1 change: 1 addition & 0 deletions tasklist/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
2 changes: 2 additions & 0 deletions tasklist/app/models/vendor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Vendor < ActiveRecord::Base
end
11 changes: 11 additions & 0 deletions tasklist/app/views/people/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h1> Tasking People </h1>

<ul>
<% @people.each do |person| %>
<li>
<%= link_to person.name, "/people/#{person.id}" %> <br>
incomplete tasks:
<%= person.incomplete_tasks %>
</li>
<% end %>
</ul>
5 changes: 5 additions & 0 deletions tasklist/app/views/people/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1> Info </h1>

<h2>
<%= link_to @person.name, "/people/#{@person.id}/tasks" %>
</h2>
15 changes: 15 additions & 0 deletions tasklist/app/views/people/tasks.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h1> Assigned Tasks </h1>

<h2> <%= @person.name %></h2>
<ul>
<% @person.tasks.each do |task| %>
<li>
<%= task.name %> <br>
<% if task.date_completed == nil %>

Choose a reason for hiding this comment

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

It is preferred to use the .nil? method as opposed to check for equivalence to nil

Status: Incomplete
<% else %>
Status: Complete
<% end %>
</li>
<% end %>
</ul>
7 changes: 3 additions & 4 deletions tasklist/app/views/tasks/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<html>
<body>
<%= form_for @task, url: {action: 'update'}, method: :patch do |f| %>
<fieldset>
<legend> Edit Task </legend>
Expand All @@ -9,11 +7,12 @@
<%= f.label :descript %>
<%= f.text_area :descript %>
<br>
<%= f.label :person_id, "Task For:" %>
<%= f.collection_select(:person_id, Person.all, :id, :name, prompt: "Select a Person") %>
<br>
<%= f.label :date_completed %>
<%= f.date_field :date_completed %>
<br>
</fieldset>
<%= f.submit %>
<% end %>
</body>
</html>
8 changes: 4 additions & 4 deletions tasklist/app/views/tasks/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<html>
<body>
<h1> What's Da Happs </h1>
<h2><a class = "new" href="/tasks/new">add a new task</a></h2>
<div>
<ul>
<% @tasks.each do |task| %>
<li>
<%= link_to task.name, "/tasks/#{task.id}" %> ✍ <br>
<% if !task.person.nil? %>
<%= link_to task.person.name, "/people/#{task.person_id}/tasks" %> ℹ︎

Choose a reason for hiding this comment

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

You still want to indent code that is inside of a conditional block even when it is in your view

<br>
<% end %>
<%= link_to 'DELETE TASK ⌧', { action: :destroy, id: task.id }, method: :delete, data: { confirm: 'Delete Task, For Real?' } %> <br>
<% if !task.date_completed.nil? %>
<div class ="status"> STATUS: COMPLETED </div>
Expand All @@ -17,5 +19,3 @@
<% end %>
</ul>
</div>
</body>
</html>
5 changes: 3 additions & 2 deletions tasklist/app/views/tasks/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<html>
<body>
<%= form_for @task do |f| %>
<fieldset>
<legend> Add a New Task </legend>
Expand All @@ -9,6 +7,9 @@
<%= f.label :descript %>
<%= f.text_field :descript %>
<br>
<%= f.label :person_id, "Task For:" %>
<%= f.collection_select(:person_id, Person.all, :id, :name, prompt: "Select a Person") %>
<br>
<%= f.label :date_completed %>
<%= f.date_field :date_completed %>
</fieldset>
Expand Down
4 changes: 0 additions & 4 deletions tasklist/app/views/tasks/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<html>
<body>
<h1><%= @task.name %></h1>
<h2><%= @task.descript %></h2>
<h2>COMPLETED ON:</h2>
<h2><%= @task.date_completed %> </h2>
<p><%= link_to "BACK TO TASK LIST", "/tasks/" %> </p>
<p><%= link_to "EDIT TASK", "/tasks/#{@task.id}/edit" %> </p>
</body>
</html>
3 changes: 3 additions & 0 deletions tasklist/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
delete '/tasks/:id' => 'tasks#destroy'
patch '/tasks/:id/completed' => 'tasks#completed'
get '/tasks/:id/edit' => 'tasks#edit', as: :task
get '/people' => 'people#index'
get '/people/:id' => 'people#show'
get '/people/: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
1 change: 1 addition & 0 deletions tasklist/db/migrate/20151110002236_create_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ def change
t.string :name
t.string :descript
t.datetime :date_completed
t.integer :person_id

t.timestamps null: false
end
Expand Down
9 changes: 9 additions & 0 deletions tasklist/db/migrate/20151116200652_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
7 changes: 7 additions & 0 deletions tasklist/db/migrate/20151116202727_modify.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Modify < ActiveRecord::Migration
def change
# change_table :tasks do |t|
# add_column :tasks, :person_id, :integer
# end
end
end
11 changes: 11 additions & 0 deletions tasklist/db/migrate/20151118005627_create_vendors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateVendors < ActiveRecord::Migration
def change
create_table :vendors do |t|
t.string :name
t.integer :no._of_employees
t.integer :market_id

t.timestamps null: false
end
end
end
9 changes: 8 additions & 1 deletion tasklist/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20151110002236) do
ActiveRecord::Schema.define(version: 20151116202727) 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 "descript"
t.datetime "date_completed"
t.integer "person_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
Expand Down
31 changes: 21 additions & 10 deletions tasklist/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,28 @@ def random_time
Time.at(rand * Time.now.to_i)
end

people = [
{name: "Annalee"},
{name: "Imari"},
{name: "Davin"},
{name: "Jaxson"}
]

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

tasks = [
{ name: "The First Task", descript: "do this first", date_completed: random_time },
{ name: "Go to Brunch", descript: "go to Cafe Presse" },
{ name: "Go to Lunch", descript: "eat", date_completed: random_time },
{ name: "Go to Second Lunch", descript: "eat more" },
{ name: "Play Video Games", descript: "Super Mario", date_completed: random_time },
{ name: "High Five Somebody You Don't Know", descript: "Everyone", date_completed: random_time },
{ name: "Plant Flowers", descript: "Magnolias!", date_completed: random_time },
{ name: "Call Mom", descript: "Hi MOM" },
{ name: "She worries, you know.", descript: "Yup" },
{ name: "Nap", descript: "ZZZZZZZZ", date_completed: random_time }
{ name: "The First Task", descript: "do this first", date_completed: random_time, person_id: 1 },
{ name: "Go to Brunch", descript: "go to Cafe Presse", person_id: 2 },
{ name: "Go to Lunch", descript: "eat", date_completed: random_time, person_id: 3 },
{ name: "Go to Second Lunch", descript: "eat more", person_id: 4 },
{ name: "Play Video Games", descript: "Super Mario", date_completed: random_time, person_id: 1 },
{ name: "High Five Somebody You Don't Know", descript: "Everyone", date_completed: random_time, person_id: 2 },
{ name: "Plant Flowers", descript: "Magnolias!", date_completed: random_time, person_id: 3 },
{ name: "Call Mom", descript: "Hi MOM", person_id: 4 },
{ name: "She worries, you know.", descript: "Yup", person_id: 1 },
{ name: "Nap", descript: "ZZZZZZZZ", date_completed: random_time, person_id: 2 }
]

tasks.each do |task|
Expand Down