-
Notifications
You must be signed in to change notification settings - Fork 21
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
final wave of task list by Audrey #104
base: ald/master
Are you sure you want to change the base?
Changes from all commits
8a30319
4914bf7
247e749
fdde62b
5c234a8
0274a84
71cf329
b1fe316
815c121
1b86ea2
10451bb
502f6d2
c48f37a
f88fbcc
87a9e4a
223e0e1
e4c0408
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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/ |
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/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class PeopleController < ApplicationController | ||
|
||
def index | ||
@people = Person.all | ||
end | ||
|
||
|
||
def show | ||
id = params[:id] | ||
@person = Person.find(id) | ||
end | ||
|
||
def show_tasks | ||
id = params[:id] | ||
@person = Person.find(id) | ||
@tasks = @person.tasks | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module LayoutHelper | ||
|
||
def bootstrap_version | ||
# Choose the Bootstrap version you would like to use from the CDN | ||
"3.3.5" | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module PeopleHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Person < ActiveRecord::Base | ||
has_many :tasks | ||
|
||
def count_incomplete | ||
t = self.tasks | ||
incomplete = t.where(completed_date: nil) | ||
incomplete.length | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally we should prefer to use If you try it out in rails console vs. using |
||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
class Task < ActiveRecord::Base | ||
belongs_to :person | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>TaskList</title> | ||
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> | ||
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> | ||
<%= csrf_meta_tags %> | ||
</head> | ||
<body> | ||
|
||
<%= yield %> | ||
|
||
</body> | ||
<head> | ||
<title>TaskList with Bootstrap</title> | ||
<link href="//netdna.bootstrapcdn.com/bootstrap/<%= bootstrap_version %>/css/bootstrap.min.css" rel="stylesheet"> | ||
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> | ||
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> | ||
<%= csrf_meta_tags %> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<%= yield %> | ||
</div> | ||
<script src="//netdna.bootstrapcdn.com/bootstrap/<%= bootstrap_version %>/js/bootstrap.min.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<section> | ||
<h1>Employees</h1> | ||
<ul> | ||
<% @people.each do |person| %> | ||
<li> | ||
<div> | ||
<a href= "/people/<%= person.id %>"><%= person.name %></a> | ||
</div> | ||
<div> | ||
<p>Incomplete tasks: <%= person.count_incomplete %></p> | ||
</div> | ||
</li> | ||
<% end %> | ||
</ul> | ||
</section> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<section> | ||
<h1><%= @person.name %></h1> | ||
<p><%= @person.job_title %></p> | ||
<%= link_to 'Tasks', { action: :show_tasks, id: @person.id }, method: :get %> | ||
</section> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<section> | ||
<h1> Tasks for <%= @person.name %> </h1> | ||
<ul> | ||
<% @tasks.each do |task|%> | ||
<li><%= task.name %></li> | ||
<% end %> | ||
</ul> | ||
</section> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,28 +3,37 @@ | |
<ul> | ||
<% @tasks.each do |task| %> | ||
<% if task.completed_date == nil %> | ||
<% @completion_class = "incomplete_button" %> | ||
<% @completion_id = "incomplete_button" %> | ||
<% else %> | ||
<% @completion_class = "complete_button" %> | ||
<% @completion_id = "complete_button" %> | ||
<% end %> | ||
<li> | ||
<%= button_to "✓","/tasks/#{task.id}/complete", method: :patch, class: @completion_class %> | ||
<a href= "/tasks/<%= task.id %>"><%= task.name %></a> | ||
<li class="task_list", id="holder"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because this In this case it looks like the |
||
<div class="task_list", id="left"> | ||
<%= button_to "✓","/tasks/#{task.id}/complete", method: :patch, id: @completion_id %> | ||
</div> | ||
<div class="task_list", id="second_to_left"> | ||
<a href= "/tasks/<%= task.id %>"><%= task.name %></a> | ||
</div> | ||
<div class="task_list", id="right"> | ||
<% if !task.person.nil? %> | ||
<a href= "/people/<%= task.person.id %>"><%= task.person.name %></a> | ||
<% end %> | ||
<div> | ||
</li> | ||
<% end %> | ||
</ul> | ||
|
||
<section id="index_buttons"> | ||
<div class="button_holder"> | ||
<a href="/tasks/new" class="button plus"></a> | ||
</div> | ||
<section id="index_buttons"> | ||
<div class="button_holder"> | ||
<a href="/tasks/new" class="button plus"></a> | ||
</div> | ||
|
||
<div class="button_holder"> | ||
<a href="/tasks/pre_edit" class="button pencil"></a> | ||
</div> | ||
<div class="button_holder"> | ||
<a href="/tasks/pre_edit" class="button pencil"></a> | ||
</div> | ||
|
||
<div class="button_holder"> | ||
<a href="/tasks/remove" class="button cross"></a> | ||
</div> | ||
</section> | ||
<div class="button_holder"> | ||
<a href="/tasks/remove" class="button cross"></a> | ||
</div> | ||
</section> | ||
</section> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ | |
</ul> | ||
|
||
<a href="/tasks/" class="bottom_of_page_link">Back to List</a> | ||
|
||
</section> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
<section> | ||
<h1>Tasks</h1> | ||
<%= link_to "Let's jot it all down.", "/tasks/" %> | ||
|
||
<h1 id="welcome_title">Things to Do</h1> | ||
<h3 id="welcome_subtitle">for the staff of Maggy Magazine</h3> | ||
<div id="welcome_link_holder"> | ||
<div class="welcome_links"> | ||
<%= link_to "Tasks", "/tasks/" %> | ||
</div> | ||
<div class="welcome_links"> | ||
<%= link_to "Employees", "/people/" %> | ||
</div> | ||
<div class="welcome_links"> | ||
<%= link_to "Inspiration", "http://worstcats.tumblr.com/" %> | ||
</div> | ||
</div> | ||
<%= link_to (image_tag "pencil_shavings.jpg", :id => "pencil_shavings"), "/tasks/" %> | ||
</section> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty good use of a method on a model class!
For optimal usage, this should be located in the
Task
model as a class method, and instead ofself.tasks
we should useTask.all
. We would then be able to sayTask.count_incomplete
to get the total number of incomplete tasks for all people.However, ActiveRecord is smart enough to know that if we instead say
@person.tasks.count_incomplete
we're only looking for the number that are associated with@person
.