Skip to content

Commit

Permalink
added priorities to db, model, views
Browse files Browse the repository at this point in the history
  • Loading branch information
te0d committed Nov 13, 2012
1 parent 6bf1b3a commit d180a69
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TasksController < ApplicationController
# GET /tasks
# GET /tasks.json
def index
@tasks = current_user.tasks
@tasks = current_user.tasks.order("priority DESC")
@tasks_by_day = Array.new

# tasks_by_day is used by the index page to display
Expand Down
4 changes: 3 additions & 1 deletion app/models/task.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class Task < ActiveRecord::Base
has_many :hours, :dependent => :destroy
belongs_to :user
attr_accessible :desc, :name, :public
attr_accessible :desc, :name, :public, :priority

validates :priority, :numericality => {:only_integer => true, :greater_than_or_equal_to => 0, :less_than_or_equal_to => 3}

def total_hours
self.hours.sum("ammt").to_f.round(2)
Expand Down
4 changes: 4 additions & 0 deletions app/views/tasks/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :priority %>
<%= f.select :priority, [['High', 3], ['Medium', 2], ['Low', 1], ['Zero', 0]] %>
</div>
<div class="field">
<%= f.label :desc %><br />
<%= f.text_area :desc, :rows => 5 %>
Expand Down
15 changes: 14 additions & 1 deletion app/views/tasks/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@

<table>
<tr>
<th></th>
<th>Name</th>
<th>Desc</th>
<th>Hours</th>
</tr>

<% @tasks.each do |task| %>
<tr>
<td>
<% case task.priority %>
<% when 3 %>
★★★
<% when 2 %>
★★☆
<% when 1 %>
★☆☆
<% when 0 %>
☆☆☆
<% end %>
</td>
<td><%= link_to task.name, task %></td>
<td><%= task.desc %></td>
<td><%= task.total_hours %></td>
Expand All @@ -19,7 +32,7 @@

<br />

<%= link_to 'New Task', new_task_path %>
<%= button_to 'New Task', new_task_path, :method => 'get' %>
</div>
<div id="right_col">
<%= render "stats"%>
Expand Down
13 changes: 12 additions & 1 deletion app/views/tasks/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<p id="notice"><%= notice %></p>
<div id="left_col">
<h2><%= @task.name %></h2>
<h2><%= @task.name %> (
<% case @task.priority %>
<% when 3 %>
★★★
<% when 2 %>
★★☆
<% when 1 %>
★☆☆
<% when 0 %>
☆☆☆
<% end %>
)</h2>

<p><%= @task.desc %></p>

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20121113223447_add_priority_to_tasks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPriorityToTasks < ActiveRecord::Migration
def change
add_column :tasks, :priority, :integer, :default => 2
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20121110171015) do
ActiveRecord::Schema.define(:version => 20121113223447) do

create_table "hours", :force => true do |t|
t.decimal "ammt"
Expand All @@ -31,6 +31,7 @@
t.datetime "updated_at", :null => false
t.integer "user_id"
t.boolean "public", :default => false
t.integer "priority", :default => 2
end

create_table "users", :force => true do |t|
Expand Down

0 comments on commit d180a69

Please sign in to comment.