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

final wave of task list by Audrey #104

Open
wants to merge 17 commits into
base: ald/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
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/
77 changes: 69 additions & 8 deletions task-list/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
@import url('https://fonts.googleapis.com/css?family=Crimson Text|Open Sans|');


a {
text-decoration: none;
color: #000;
Expand All @@ -13,9 +16,7 @@ a:hover {
}

body {
margin: 0 auto;
text-align: center;
width: 500px;
font-family: Helvetica, Verdana, sans-serif;
font-size: 15px;
background-image: url('wood-background.jpg');
Expand All @@ -30,18 +31,25 @@ body {

}

.complete_button {
#complete_button {
-webkit-appearance: checkbox;
height:30px;
vertical-align: middle;
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
backface-visibility: hidden;
transition-property: transform;
}

.complete_button:hover {
#complete_button:hover {
-webkit-appearance: push button;
transform: scale(1.1);
}

div.container {
margin: 0 auto;
}

label {
float: left;
width: 40%;
Expand All @@ -67,7 +75,7 @@ fieldset input {
}

h1 {
padding-top: 30px;
padding-top: 50px;
padding-bottom: 10px;
}

Expand All @@ -77,17 +85,28 @@ h2 {
padding: 0;
}

.incomplete_button {
h3 {
font: 400 40px/1.5 Crimson Text, Helvetica, Verdana, sans-serif;
font-style: italic;
font-size: 0.5cm;
margin-top: 0;
margin-bottom: 10px;
}

#incomplete_button {
-webkit-appearance: checkbox;
height:30px;
color: #E6E3E1;
display: inline;
vertical-align: middle;
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
backface-visibility: hidden;
transition-property: transform;
text-align: center;
}

.incomplete_button:hover {
#incomplete_button:hover {
transform: scale(1.1);
}

Expand Down Expand Up @@ -119,7 +138,6 @@ li a {
color: #000;
width: 300px;
text-align: center;
padding-left: 20px;
}

li a:hover {
Expand All @@ -133,6 +151,10 @@ li a:hover {
padding: 20px;
}

#person_name {
padding-left: 40px;
}

section {
background-color: white;
width: 400px;
Expand All @@ -145,6 +167,22 @@ section {
margin: 20px;
}

#left.task_list {
display: inline-block;
float: left;
}

#second_to_left.task_list {
padding-left: 10px;
display: inline-block;
max-width: 180px;
text-align: left;
}

#right.task_list {
float: right;
}

ul {
max-width: 350px;
list-style-type: none;
Expand All @@ -154,6 +192,29 @@ ul {
align-self: center;
}

.welcome_links {
margin-left: 35px;
margin-right: 35px;
padding: 5px;
}

.welcome_links a {
font-weight: 200;
}

#welcome_link_holder {
margin: 0 auto;
}

#welcome_title {
padding-bottom: 0px;
margin-bottom: 5px;
}

#welcome_subtitle {
padding-bottom: 40px;
}

/*all css below is for buttons to navigate from index page- add, edit, delete */
.button_holder {
display: inline-block;
Expand Down
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/
19 changes: 19 additions & 0 deletions task-list/app/controllers/people_controller.rb
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
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 @@ -53,7 +53,7 @@ def update
private

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

end
8 changes: 8 additions & 0 deletions task-list/app/helpers/layout_helper.rb
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
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
10 changes: 10 additions & 0 deletions task-list/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 count_incomplete
Copy link

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 of self.tasks we should use Task.all. We would then be able to say Task.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.

t = self.tasks
incomplete = t.where(completed_date: nil)
incomplete.length
Copy link

Choose a reason for hiding this comment

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

Generally we should prefer to use count on ActiveRecord relations (the array-link objects that are returned by all and where), because they "compose" together better and allow ActiveRecord to use more efficient SQL code.

If you try it out in rails console vs. using length you should be able to see how the generated SQL code is different.

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
24 changes: 13 additions & 11 deletions task-list/app/views/layouts/application.html.erb
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>
15 changes: 15 additions & 0 deletions task-list/app/views/people/index.html.erb
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>
5 changes: 5 additions & 0 deletions task-list/app/views/people/show.html.erb
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>
8 changes: 8 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,8 @@
<section>
<h1> Tasks for <%= @person.name %> </h1>
<ul>
<% @tasks.each do |task|%>
<li><%= task.name %></li>
<% end %>
</ul>
</section>
4 changes: 4 additions & 0 deletions task-list/app/views/shared/_task_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<%= f.text_field :completed_date %><br />
</div>

<div>
<%= f.collection_select(:person_id, Person.all, :id, :name, prompt: "Person to do task:") %>
</div>

<div id="submit_button_holder">
<%= f.submit %>
</div>
Expand Down
41 changes: 25 additions & 16 deletions task-list/app/views/tasks/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Copy link

Choose a reason for hiding this comment

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

Because this li tag and the div tags within it are all within a loop, they will potentially be repeated in the output HTML. For that reason we should not use id attributes without making them unique by doing something like id="holder_<%= task.id %>", or by writing a view helper method to do the same thing.

In this case it looks like the id values could probably be considered classes, so we could change them to classes instead by moving them into the class attribute: <li class="task_list holder">.

<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>
1 change: 1 addition & 0 deletions task-list/app/views/tasks/remove.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
</ul>

<a href="/tasks/" class="bottom_of_page_link">Back to List</a>

</section>
2 changes: 1 addition & 1 deletion task-list/app/views/tasks/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<h1><%= @task.name %></h1>

<p><%= @task.description %></p>
<p><%= @task.person.name %></p>
<% if @task.completed_date != nil %>
<p>Completed!</p>
<% else %>
Expand All @@ -11,5 +12,4 @@

<%= link_to 'Edit', { action: :edit, id: @task.id }, method: :get %>


</section>
16 changes: 13 additions & 3 deletions task-list/app/views/welcome/index.html.erb
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>
5 changes: 5 additions & 0 deletions task-list/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
get 'tasks/:id/edit' => 'tasks#edit'
patch 'tasks/:id/complete' => 'tasks#complete'

get 'people/' => 'people#index'
get 'people/:id' => 'people#show'
get 'people/:id/tasks' => 'people#show_tasks'


resources :tasks, :path => 'tasks'

# The priority is based upon order of creation: first created -> highest priority.
Expand Down
Loading