Did some refactoring of the todo/list page, which should make it a little quicker to load.

Changed the toggle_check method to use the built-in toggle() method, and moved setting of completion date to the before_save method of todo.rb


git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@10 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
bsag 2005-01-23 11:50:07 +00:00
parent d7b1c6e167
commit f7b77f6fd9
7 changed files with 55 additions and 87 deletions

View file

@ -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"

View file

@ -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

View file

@ -1,26 +1,5 @@
module TodoHelper
def display_done(ary,context)
result_string = ""
result_string << "<ul>"
ary.each do |@item|
result_string << "<li>" + @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 + "</li>"
end
result_string << "</ul>"
return result_string
end
def count_items(items, context)
# Count the number of items in the selected context
#

View file

@ -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

View file

@ -10,7 +10,7 @@
<% end %>
<td align="right" width="20"><%= @project.id.to_s %></td>
<td width="390"><%= link_to ( "#{@project.name}", :action => "show", :id => @project.id ) %></td>
<td width="40"><%= 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." ) + " " %></td>
<td width="40"><%= 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." ) + " " %></td>
</tr>
<% row += 1 %>
<% end %>

View file

@ -0,0 +1,22 @@
<% @item = not_done %>
<li>
<div class="box">
<%= check_box( "item", "done", "onclick" => "document.location.href='/todo/toggle_check/#{@item.id}'" ) %>
</div>
<div class="description">
<%= 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 %>
</div>
<div class="tools">
<%= link_to( $edit_img, { :action => "edit", :id => @item.id }, :title => "Edit item" ) + " " + link_to($delete_img, { :action => "destroy", :id => @item.id }, :title => "Delete item", :confirm => "Are you sure you want to delete this entry: #{@item.description}" ) + " " %>
<% if @item.notes? %>
<%= "<a href=\"javascript:toggle('" + @item.id.to_s + "')\" title=\"Show notes\">" + $notes_img + "</a>" %></div>
<% m_notes = markdown( @item.notes ) %>
<%= "<div class=\"notes\" id=\"" + @item.id.to_s + "\">" + m_notes + "</div>" %>
<% else %>
</div>
<% end %>
</li>

View file

@ -1,48 +1,14 @@
<div id="display_box">
<% 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 ) %>
<div class="contexts">
<h2><%= link_to( "#{@item.context['name'].capitalize}", :controller => "context", :action => "show", :id => @item.context_id ) %></h2>
<ul>
<% heading = true %>
<% end %>
<li>
<div class="box">
<%= check_box( "item", "done", "onclick" => "document.location.href='/todo/toggle_check/#{@item.id}'" ) %>
</div>
<div class="description">
<%= 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 %>
</div>
<div class="tools">
<%= link_to( $edit_img, { :action => "edit", :id => @item.id }, :title => "Edit item" ) + " " + link_to($delete_img, { :action => "destroy", :id => @item.id }, :title => "Delete item", :confirm => "Are you sure you want to delete this entry: #{@item.description}" ) + " " %>
<% if @item.notes? %>
<%= "<a href=\"javascript:toggle('" + @item.id.to_s + "')\" title=\"Show notes\">" + $notes_img + "</a>" %></div>
<% m_notes = markdown( @item.notes ) %>
<%= "<div class=\"notes\" id=\"" + @item.id.to_s + "\">" + m_notes + "</div>" %>
<% else %>
</div>
<% end %>
</li>
<% end %>
<% @not_done = Todo.find_all( "done=0 AND context_id=#{@place.id}", "created ASC" ) %>
<% if !@not_done.empty? %>
<div class="contexts">
<h2><%= link_to( "#{@place.name.capitalize}", :controller => "context", :action => "show", :id => @place.id ) %></h2>
<ul>
<%= render_collection_of_partials "not_done", @not_done %>
</ul>
</div><!-- End contexts -->
<% end %>
<% if heading == true %>
</ul>
</div>
<% end %>
<% end %>
<div class="contexts">
@ -53,14 +19,14 @@
</div>
</div><!- End of display_box -->
<div id="input_box">
<h2>Today's events are: </h2>
<div id="input_box">
<!-- <h2>Today's events are: </h2>
<ul>
<% ical = ICal::ICalReader.new("Personal") %>
<% ical.todaysEvents do |event| %>
<%= puts "<li>#{event.startTime} - #{event.summary}</li>" %>
<% end %>
</ul>
</ul> -->
<h2>Add next action</h2>
<form method="post" action="add_item">
@ -68,7 +34,7 @@
<%= text_field( "new_item", "description" ) %>
<br />
<label for="new_item_notes">Notes</label><br />
<%= text_area( "new_item", "notes", "cols" => 40, "rows" => 15 ) %>
<%= text_area( "new_item", "notes", "cols" => 35, "rows" => 15 ) %>
<br />
<label for="new_item_context_id">Context</label><br />
<select name="new_item[context_id]" id="new_item_context_id">