mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
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:
parent
d7b1c6e167
commit
f7b77f6fd9
7 changed files with 55 additions and 87 deletions
|
|
@ -1,14 +1,13 @@
|
||||||
class TodoController < ApplicationController
|
class TodoController < ApplicationController
|
||||||
|
|
||||||
helper :todo
|
helper :todo
|
||||||
model :context
|
model :context, :project
|
||||||
model :project
|
|
||||||
|
|
||||||
scaffold :todo
|
scaffold :todo
|
||||||
before_filter :login_required
|
before_filter :login_required
|
||||||
caches_action :list, :completed
|
caches_action :list, :completed
|
||||||
layout "standard"
|
layout "standard"
|
||||||
|
|
||||||
# Main method for listing tasks
|
# Main method for listing tasks
|
||||||
# Set page title, and fill variables with contexts and done and not-done 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"
|
@page_title = "List tasks"
|
||||||
@places = Context.find_all
|
@places = Context.find_all
|
||||||
@projects = Project.find_all
|
@projects = Project.find_all
|
||||||
@not_done = Todo.find_all( "done=0", "completed DESC" )
|
|
||||||
@done = Todo.find_all( "done=1", "completed DESC", 5 )
|
@done = Todo.find_all( "done=1", "completed DESC", 5 )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -104,10 +102,7 @@ class TodoController < ApplicationController
|
||||||
def toggle_check
|
def toggle_check
|
||||||
item = Todo.find(@params['id'])
|
item = Todo.find(@params['id'])
|
||||||
|
|
||||||
case item.done
|
item.toggle('done')
|
||||||
when 0: item.done = 1; item.completed = Time.now()
|
|
||||||
when 1: item.done = 0; item.completed = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
if item.save
|
if item.save
|
||||||
flash["confirmation"] = "Next action marked as completed"
|
flash["confirmation"] = "Next action marked as completed"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
# The methods added to this helper will be available to all templates in the application.
|
# The methods added to this helper will be available to all templates in the application.
|
||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
#require_dependency 'date'
|
|
||||||
|
|
||||||
def format_date(date)
|
def format_date(date)
|
||||||
# Convert a date object to the format specified
|
# Convert a date object to the format specified
|
||||||
|
|
@ -10,24 +9,27 @@ module ApplicationHelper
|
||||||
formatted_date = date.strftime("#{date_fmt}")
|
formatted_date = date.strftime("#{date_fmt}")
|
||||||
end
|
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)
|
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
|
RedCloth.new(text).to_html
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# Wraps object in HTML tags, tag
|
||||||
|
#
|
||||||
def tag_object(object, tag)
|
def tag_object(object, tag)
|
||||||
# Wraps object in HTML tags, tag
|
|
||||||
#
|
|
||||||
tagged = "<#{tag}>#{object}</#{tag}>"
|
tagged = "<#{tag}>#{object}</#{tag}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# Check due date in comparison to today's date
|
||||||
|
# Flag up date appropriately with a 'traffic light' colour code
|
||||||
|
#
|
||||||
def due_date(due)
|
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
|
if due == nil
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,5 @@
|
||||||
module TodoHelper
|
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)
|
def count_items(items, context)
|
||||||
# Count the number of items in the selected context
|
# Count the number of items in the selected context
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,10 @@ class Todo < ActiveRecord::Base
|
||||||
if self.created == nil
|
if self.created == nil
|
||||||
self.created = Time.now()
|
self.created = Time.now()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.done == 1
|
||||||
|
self.completed = Time.now()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
<td align="right" width="20"><%= @project.id.to_s %></td>
|
<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="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>
|
</tr>
|
||||||
<% row += 1 %>
|
<% row += 1 %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
||||||
22
tracks/app/views/todo/_not_done.rhtml
Normal file
22
tracks/app/views/todo/_not_done.rhtml
Normal 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>
|
||||||
|
|
@ -1,48 +1,14 @@
|
||||||
<div id="display_box">
|
<div id="display_box">
|
||||||
<% for @place in @places %>
|
<% for @place in @places %>
|
||||||
<% heading = false %>
|
<% @not_done = Todo.find_all( "done=0 AND context_id=#{@place.id}", "created ASC" ) %>
|
||||||
|
<% if !@not_done.empty? %>
|
||||||
<% for @item in @not_done %>
|
<div class="contexts">
|
||||||
<% if @place.name == @item.context['name'] %>
|
<h2><%= link_to( "#{@place.name.capitalize}", :controller => "context", :action => "show", :id => @place.id ) %></h2>
|
||||||
|
<ul>
|
||||||
<% if ( Todo.find_all( "context_id=#{@item.context['id']}" ) && heading == false ) %>
|
<%= render_collection_of_partials "not_done", @not_done %>
|
||||||
<div class="contexts">
|
</ul>
|
||||||
<h2><%= link_to( "#{@item.context['name'].capitalize}", :controller => "context", :action => "show", :id => @item.context_id ) %></h2>
|
</div><!-- End contexts -->
|
||||||
<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 %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if heading == true %>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="contexts">
|
<div class="contexts">
|
||||||
|
|
@ -53,14 +19,14 @@
|
||||||
</div>
|
</div>
|
||||||
</div><!- End of display_box -->
|
</div><!- End of display_box -->
|
||||||
|
|
||||||
<div id="input_box">
|
<div id="input_box">
|
||||||
<h2>Today's events are: </h2>
|
<!-- <h2>Today's events are: </h2>
|
||||||
<ul>
|
<ul>
|
||||||
<% ical = ICal::ICalReader.new("Personal") %>
|
<% ical = ICal::ICalReader.new("Personal") %>
|
||||||
<% ical.todaysEvents do |event| %>
|
<% ical.todaysEvents do |event| %>
|
||||||
<%= puts "<li>#{event.startTime} - #{event.summary}</li>" %>
|
<%= puts "<li>#{event.startTime} - #{event.summary}</li>" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul> -->
|
||||||
|
|
||||||
<h2>Add next action</h2>
|
<h2>Add next action</h2>
|
||||||
<form method="post" action="add_item">
|
<form method="post" action="add_item">
|
||||||
|
|
@ -68,7 +34,7 @@
|
||||||
<%= text_field( "new_item", "description" ) %>
|
<%= text_field( "new_item", "description" ) %>
|
||||||
<br />
|
<br />
|
||||||
<label for="new_item_notes">Notes</label><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 />
|
<br />
|
||||||
<label for="new_item_context_id">Context</label><br />
|
<label for="new_item_context_id">Context</label><br />
|
||||||
<select name="new_item[context_id]" id="new_item_context_id">
|
<select name="new_item[context_id]" id="new_item_context_id">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue