diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb
index 6b1d59c0..3c8d0918 100644
--- a/tracks/app/controllers/todo_controller.rb
+++ b/tracks/app/controllers/todo_controller.rb
@@ -1,14 +1,13 @@
class TodoController < ApplicationController
helper :todo
- model :context
- model :project
+ model :context, :project
scaffold :todo
before_filter :login_required
caches_action :list, :completed
layout "standard"
-
+
# Main method for listing tasks
# Set page title, and fill variables with contexts and done and not-done tasks
#
@@ -16,7 +15,6 @@ class TodoController < ApplicationController
@page_title = "List tasks"
@places = Context.find_all
@projects = Project.find_all
- @not_done = Todo.find_all( "done=0", "completed DESC" )
@done = Todo.find_all( "done=1", "completed DESC", 5 )
end
@@ -104,10 +102,7 @@ class TodoController < ApplicationController
def toggle_check
item = Todo.find(@params['id'])
- case item.done
- when 0: item.done = 1; item.completed = Time.now()
- when 1: item.done = 0; item.completed = nil
- end
+ item.toggle('done')
if item.save
flash["confirmation"] = "Next action marked as completed"
diff --git a/tracks/app/helpers/application_helper.rb b/tracks/app/helpers/application_helper.rb
index e36d7a81..09b7ec69 100644
--- a/tracks/app/helpers/application_helper.rb
+++ b/tracks/app/helpers/application_helper.rb
@@ -1,6 +1,5 @@
# The methods added to this helper will be available to all templates in the application.
module ApplicationHelper
- #require_dependency 'date'
def format_date(date)
# Convert a date object to the format specified
@@ -10,24 +9,27 @@ module ApplicationHelper
formatted_date = date.strftime("#{date_fmt}")
end
+
+ # Uses RedCloth to transform text using either Textile or Markdown
+ # Need to require redcloth above
+ # RedCloth 3.0 or greater is needed to use Markdown, otherwise it only handles Textile
+ #
def markdown(text)
- # Uses RedCloth to transform text using either Textile or Markdown
- # Need to require redcloth above
- # RedCloth 3.0 or greater is needed to use Markdown, otherwise it only handles Textile
- #
RedCloth.new(text).to_html
end
+
+ # Wraps object in HTML tags, tag
+ #
def tag_object(object, tag)
- # Wraps object in HTML tags, tag
- #
tagged = "<#{tag}>#{object}#{tag}>"
end
+
+ # Check due date in comparison to today's date
+ # Flag up date appropriately with a 'traffic light' colour code
+ #
def due_date(due)
- # Check due date in comparison to today's date
- # Flag up date appropriately with a 'traffic light' colour code
- #
if due == nil
return ""
end
diff --git a/tracks/app/helpers/todo_helper.rb b/tracks/app/helpers/todo_helper.rb
index e2c62222..bd33f44f 100644
--- a/tracks/app/helpers/todo_helper.rb
+++ b/tracks/app/helpers/todo_helper.rb
@@ -1,26 +1,5 @@
module TodoHelper
-
-
- def display_done(ary,context)
- result_string = ""
- result_string << "
"
- ary.each do |@item|
- result_string << "- " + @item.description + " "
-
- # Item should have a completion date if it is done
- # This is just a sanity check
- #
- if @item.completed != nil
- result_string << "[completed: " + format_date(@item.completed) + "]" + " "
- end
-
- result_string << "in " + @item.context['name'].capitalize + "
"
- end
- result_string << "
"
- return result_string
- end
-
-
+
def count_items(items, context)
# Count the number of items in the selected context
#
diff --git a/tracks/app/models/todo.rb b/tracks/app/models/todo.rb
index 09e57c5e..2ce2f6f8 100644
--- a/tracks/app/models/todo.rb
+++ b/tracks/app/models/todo.rb
@@ -19,6 +19,10 @@ class Todo < ActiveRecord::Base
if self.created == nil
self.created = Time.now()
end
+
+ if self.done == 1
+ self.completed = Time.now()
+ end
end
diff --git a/tracks/app/views/project/list.rhtml b/tracks/app/views/project/list.rhtml
index cb21dadd..18b4a76b 100644
--- a/tracks/app/views/project/list.rhtml
+++ b/tracks/app/views/project/list.rhtml
@@ -10,7 +10,7 @@
<% end %>
<%= @project.id.to_s %> |
<%= link_to ( "#{@project.name}", :action => "show", :id => @project.id ) %> |
- <%= link_to( $edit_img, { :action => "edit", :id => @project.id }, :title => "Edit item" ) + " " + link_to($delete_img, { :action => "destroy", :id => @project.id }, :title => "Delete item", :confirm => "Are you sure you want to delete this context: #{@project.name}. Any todos in this context will be deleted." ) + " " %> |
+ <%= link_to( $edit_img, { :action => "edit", :id => @project.id }, :title => "Edit item" ) + " " + link_to($delete_img, { :action => "destroy", :id => @project.id }, :title => "Delete item", :confirm => "Are you sure you want to delete the project: #{@project.name}. Any todos in this project will be deleted." ) + " " %> |
<% row += 1 %>
<% end %>
diff --git a/tracks/app/views/todo/_not_done.rhtml b/tracks/app/views/todo/_not_done.rhtml
new file mode 100644
index 00000000..211ecdf6
--- /dev/null
+++ b/tracks/app/views/todo/_not_done.rhtml
@@ -0,0 +1,22 @@
+<% @item = not_done %>
+
+
+ <%= check_box( "item", "done", "onclick" => "document.location.href='/todo/toggle_check/#{@item.id}'" ) %>
+
+
+ <%= due_date( @item.due ) %>
+ <%= @item.description %>
+ <% if @item.project_id %>
+ <%= link_to( "[P]", { :controller => "project", :action => "show", :id => @item.project_id }, :title => "View project: #{@item.project['name']}" ) %>
+ <% end %>
+
+
+ <% m_notes = markdown( @item.notes ) %>
+ <%= "" + m_notes + "
" %>
+ <% else %>
+
+ <% end %>
+
\ No newline at end of file
diff --git a/tracks/app/views/todo/list.rhtml b/tracks/app/views/todo/list.rhtml
index 45a50142..993be37e 100644
--- a/tracks/app/views/todo/list.rhtml
+++ b/tracks/app/views/todo/list.rhtml
@@ -1,48 +1,14 @@
<% for @place in @places %>
- <% heading = false %>
-
- <% for @item in @not_done %>
- <% if @place.name == @item.context['name'] %>
-
- <% if ( Todo.find_all( "context_id=#{@item.context['id']}" ) && heading == false ) %>
-
-
<%= link_to( "#{@item.context['name'].capitalize}", :controller => "context", :action => "show", :id => @item.context_id ) %>
-
- <% heading = true %>
- <% end %>
-
- -
-
- <%= check_box( "item", "done", "onclick" => "document.location.href='/todo/toggle_check/#{@item.id}'" ) %>
-
-
-
- <%= due_date( @item.due ) %>
- <%= @item.description %>
- <% if @item.project_id %>
- <%= link_to( "[P]", { :controller => "project", :action => "show", :id => @item.project_id }, :title => "View project: #{@item.project['name']}" ) %>
- <% end %>
-
-
-
- <% m_notes = markdown( @item.notes ) %>
- <%= "" + m_notes + "
" %>
- <% else %>
-
- <% end %>
-
- <% end %>
+ <% @not_done = Todo.find_all( "done=0 AND context_id=#{@place.id}", "created ASC" ) %>
+ <% if !@not_done.empty? %>
+
+
<%= link_to( "#{@place.name.capitalize}", :controller => "context", :action => "show", :id => @place.id ) %>
+
+ <%= render_collection_of_partials "not_done", @not_done %>
+
+
<% end %>
-
- <% if heading == true %>
-
-
- <% end %>
<% end %>
@@ -53,14 +19,14 @@
-