This is a bit of a messy commit ;-)

* Moved the forms (for edit and add_item) into a partial, which saves some time. It's not as clean as I would like.
* Added some caching back in.
* Error message display still isn't working, so I've taken those code stubs out for now.



git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@15 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
bsag 2005-01-29 15:07:47 +00:00
parent ed4481f3b6
commit 36b36e8dac
13 changed files with 103 additions and 122 deletions

View file

@ -14,6 +14,7 @@ class TodoController < ApplicationController
@page_title = "List tasks"
@projects = Project.find_all
@places = Context.find_all( "hide=0", "id ASC")
@hidden_places = Context.find_all( "hide=1")
@done = Todo.find_all( "done=1", "completed DESC", 5 )
@count = Todo.count( "done=0" )
end
@ -32,33 +33,23 @@ class TodoController < ApplicationController
#
def add_item
@item = Todo.new
@item.attributes = @params["new_item"]
@item.attributes = @params["item"]
# Convert the date format entered (as set in config/settings.yml)
# to the mysql format YYYY-MM-DD
if @params["new_item"]["due"] != ""
if @params["item"]["due"] != ""
date_fmt = app_configurations["formats"]["date"]
formatted_date = DateTime.strptime(@params["new_item"]["due"], "#{date_fmt}")
formatted_date = DateTime.strptime(@params["item"]["due"], "#{date_fmt}")
@item.due = formatted_date.strftime("%Y-%m-%d")
else
@item.due = "0000-00-00"
end
# This doesn't seem to be working. No error, but the error
# message isn't printed either.
unless @item.errors.empty?
error_msg = ''
@item.errors.each_full do |message|
error_msg << message
end
return error_msg
end
if @item.save
flash["confirmation"] = "Next action was successfully added"
redirect_to( :action => "list" )
else
flash["warning"] = "Couldn't add the action because of an error: #{error_msg}"
flash["warning"] = "Couldn't add the action because of an error"
redirect_to( :action => "list" )
end
end

View file

@ -1,6 +1,7 @@
<% @item = not_done %>
<tr>
<td valign="top"><%= check_box( "item", "done", "onclick" => "document.location.href='/todo/toggle_check/#{@item.id}'" ) %></td>
<td valign="top">
<%= check_box( "item", "done", "onclick" => "document.location.href='/todo/toggle_check/#{@item.id}'" ) %></td>
<td valign="top" width="30"><%= link_to( $edit_img, { :action => "edit", :id => @item.id }, :title => "Edit item" ) + " " + link_to($delete_img, { :controller => "todo", :action => "destroy", :id => @item.id }, :title => "Delete item", :confirm => "Are you sure you want to delete this entry: #{@item.description}" ) + " " %></td>
<td valign="top"><%= due_date( @item.due ) %>
<%= @item.description %>

View file

@ -6,6 +6,7 @@
</style>
<script type="text/javascript" src="/javascripts/toggle_notes.js"></script>
<script type="text/javascript" language="JavaScript" src="/javascripts/xmlhttp.js"></script>
<title><%= @page_title %></title>
</head>

View file

@ -1,24 +1,24 @@
<% @item = done %>
<% @done_item = done %>
<tr>
<% if @item.completed %>
<% if @done_item.completed %>
<td valign="top"><%= $done_img %></td>
<td valign="top"><span class="grey"><%= format_date( @item.completed ) %></span></td>
<td valign="top"><%= " " + @item.description + " "%>
<td valign="top"><span class="grey"><%= format_date( @done_item.completed ) %></span></td>
<td valign="top"><%= " " + @done_item.description + " "%>
<% if @item.project_id %>
<%= "(" + @item.context['name'].capitalize + ", " + @item.project['name'] + ")" %>
<% if @done_item.project_id %>
<%= "(" + @done_item.context['name'].capitalize + ", " + @done_item.project['name'] + ")" %>
<% else %>
<%= "(" + @item.context['name'].capitalize + ")" %>
<%= "(" + @done_item.context['name'].capitalize + ")" %>
<% end %>
<% if @item.due %>
<%= " - was due on " + format_date( @item.due ) %>
<% if @done_item.due %>
<%= " - was due on " + format_date( @done_item.due ) %>
<% end %>
<% if @item.notes? %>
<%= "<a href=\"javascript:toggle('" + @item.id.to_s + "')\" title=\"Show notes\">" + $notes_img + "</a>" %>
<% m_notes = markdown( @item.notes ) %>
<%= "<div class=\"notes\" id=\"" + @item.id.to_s + "\">" + m_notes + "</div>" %>
<% if @done_item.notes? %>
<%= "<a href=\"javascript:toggle('" + @done_item.id.to_s + "')\" title=\"Show notes\">" + $notes_img + "</a>" %>
<% m_notes = markdown( @done_item.notes ) %>
<%= "<div class=\"notes\" id=\"" + @done_item.id.to_s + "\">" + m_notes + "</div>" %>
<% end %>
</td>
<% end %>

View file

@ -0,0 +1,40 @@
<%= hidden_field( "item", "id" ) %>
<label for="item_description">Next action</label><br />
<%= text_field( "item", "description" ) %>
<br />
<label for="item_notes">Notes</label><br />
<%= text_area( "item", "notes", "cols" => 35, "rows" => 15 ) %>
<br />
<label for="item_context_id">Context</label><br />
<select name="item[context_id]" id="item_context_id">
<% for @place in @places %>
<% if @item %>
<% if @place.id == @item.context_id %>
<option value="<%= @place.id %>" selected="selected"><%= @place.name.capitalize %></option>
<% else %>
<option value="<%= @place.id %>"><%= @place.name.capitalize %></option>
<% end %>
<% else %>
<option value="<%= @place.id %>"><%= @place.name.capitalize %></option>
<% end %>
<% end %>
</select>
<br />
<label for="new_item_project_id">Project</label><br />
<select name="item[project_id]" id="item_project_id">
<% if @belongs == nil %>
<option value="" selected="selected">None</option>
<% end %>
<% for @project in @projects %>
<% if @project.id == @belongs %>
<option value="<%= @project.id %>" selected="selected"><%= @project.name %></option>
<% else %>
<option value="<%= @project.id %>"><%= @project.name %></option>
<% end %>
<% end %>
</select>
<br />
<label for="item_due">Due</label><br />
<%= text_field( "item", "due", {"size" => 10, "maxlength" => 10} ) %>
<br />

View file

@ -1,16 +1,18 @@
<% @item = not_done %>
<% @notdone_item = not_done %>
<tr>
<td valign="top"><%= check_box( "item", "done", "onclick" => "document.location.href='/todo/toggle_check/#{@item.id}'" ) %></td>
<td valign="top" width="30"><%= 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}" ) + " " %></td>
<td valign="top"><%= 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']}" ) %>
<!-- <%= '<tr id="' + @notdone_item.id.to_s + '">' %> -->
<td valign="top">
<%= check_box( "item", "done", "onclick" => "document.location.href='/todo/toggle_check/#{@notdone_item.id}'" ) %></td>
<td valign="top" width="30"><%= link_to( $edit_img, { :action => "edit", :id => @notdone_item.id }, :title => "Edit item" ) + " " + link_to($delete_img, { :action => "destroy", :id => @notdone_item.id }, :title => "Delete item", :confirm => "Are you sure you want to delete this entry: #{@notdone_item.description}" ) + " " %></td>
<td valign="top"><%= due_date( @notdone_item.due ) %>
<%= @notdone_item.description %>
<% if @notdone_item.project_id %>
<%= link_to( "[P]", { :controller => "project", :action => "show", :id => @notdone_item.project_id }, :title => "View project: #{@notdone_item.project['name']}" ) %>
<% end %>
<% if @item.notes? %>
<%= "<a href=\"javascript:toggle('" + @item.id.to_s + "')\" title=\"Show notes\">" + $notes_img + "</a>" %>
<% m_notes = markdown( @item.notes ) %>
<%= "<div class=\"notes\" id=\"" + @item.id.to_s + "\">" + m_notes + "</div>" %>
<% if @notdone_item.notes? %>
<%= "<a href=\"javascript:toggle('" + @notdone_item.id.to_s + "')\" title=\"Show notes\">" + $notes_img + "</a>" %>
<% m_notes = markdown( @notdone_item.notes ) %>
<%= "<div class=\"notes\" id=\"" + @notdone_item.id.to_s + "\">" + m_notes + "</div>" %>
<% end %>
</td>
</tr>

View file

@ -1,44 +1,8 @@
<div id="display_box">
<h2>Update task</h2>
<form action="/todo/update" method="post">
<%= hidden_field( "item", "id" ) %>
<p><label for="item_description">Description</label><br />
<%= text_field( "item", "description" ) %></p>
<p><label for="item_notes">Notes</label><br />
<%= text_area( "item", "notes" ) %></p>
<p><label for="item_context_id">Context</label><br />
<select name="item[context_id]" id="item_context_id">
<% for @place in @places %>
<% if @place.id == @item.context_id %>
<option value="<%= @place.id %>" selected="selected"><%= @place.name.capitalize %></option>
<% else %>
<option value="<%= @place.id %>"><%= @place.name.capitalize %></option>
<% end %>
<% end %>
</select></p>
<p><label for="new_item_project_id">Project</label><br />
<select name="item[project_id]" id="item_project_id">
<% if @belongs == nil %>
<option value="" selected="selected">None</option>
<% end %>
<% for @project in @projects %>
<% if @project.id == @belongs %>
<option value="<%= @project.id %>" selected="selected"><%= @project.name %></option>
<% else %>
<option value="<%= @project.id %>"><%= @project.name %></option>
<% end %>
<% end %>
</select></p>
<p><label for="item_due">Due (YYYY-MM-DD)</label><br />
<%= text_field( "item", "due" ) %></p>
<p><input type="submit" value="Update" /></p>
<%= render_partial "todo/item", "@item" %>
<input type="submit" value="Update" />
</form>
<%= link_to 'Cancel', :action => 'list' %>

View file

@ -4,7 +4,7 @@
<% if !@not_done.empty? %>
<div class="contexts">
<h2><%= link_to( "#{@place.name.capitalize}", :controller => "context", :action => "show", :id => @place.id ) %></h2>
<table class="next_actions" cellspacing="2" cellpadding="0" border="0">
<table class="next_actions" id="incomplete" cellspacing="2" cellpadding="0" border="0">
<%= render_collection_of_partials "not_done", @not_done %>
</table>
</div><!-- End contexts -->
@ -13,46 +13,25 @@
<div class="contexts">
<h2>Last 5 completed actions</h2>
<table class="next_actions" cellspacing="5" cellpadding="0" border="0">
<table class="next_actions" id="complete" cellspacing="5" cellpadding="0" border="0">
<%= render_collection_of_partials "done", @done %>
</table>
</div>
<p>Hidden contexts:
<% for @hidden_place in @hidden_places %>
<a href="<%= url_for( :controller => "context", :action => "show", :id => "#{@hidden_place.id}" ) %>"><%= @hidden_place.name.capitalize %></a> |
<% end %>
</p>
</div><!- End of display_box -->
<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> -->
<h2>Add next action</h2>
<form method="post" action="add_item">
<label for="new_item_description">Next action</label><br />
<%= text_field( "new_item", "description" ) %>
<br />
<label for="new_item_notes">Notes</label><br />
<%= 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">
<%= options_from_collection_for_select(@places, "id", "name" ) %>
</select>
<br />
<label for="new_item_project_id">Project</label><br />
<select name="new_item[project_id]" id="new_item_project_id">
<option value="" selected>None</option>
<%= options_from_collection_for_select(@projects, "id", "name" ) %>
</select>
<br />
<label for="new_item_due">Due</label><br />
<%= text_field( "new_item", "due", {"size" => 10, "maxlength" => 10} ) %>
<br />
<input type="submit" value="Add item">
</form>
<div id="input_box">
<h2>Add next action</h2>
<form method="post" action="add_item">
<%= render_partial "todo/item", @item %>
<input type="submit" value="Add item">
</form>
</div>
<% if @flash["confirmation"] %><div class="confirmation"><%= @flash["confirmation"] %></div><% end %>

View file

@ -24,11 +24,11 @@ ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(di
# Require Rails gems.
require 'rubygems'
require_gem 'activerecord'
require_gem 'actionpack'
require_gem 'actionmailer'
require_gem 'rails'
require 'rubygems'
require_gem 'activerecord'
require_gem 'actionpack'
require_gem 'actionmailer'
require_gem 'rails'
# Environment-specific configuration.

View file

@ -2,4 +2,4 @@ Dependencies.mechanism = :load
ActionController::Base.consider_all_requests_local = true
BREAKPOINT_SERVER_PORT = 42531
ActionController::Base.fragment_cache_store = ActionController::Caching::Fragments::MemoryStore.new
ActionController::Base.fragment_cache_store = ActionController::Caching::Fragments::FileStore.new("localhost")

View file

@ -1,5 +1,5 @@
Dependencies.mechanism = :require
ActionController::Base.consider_all_requests_local = false
ActionController::Base.fragment_cache_store = ActionController::Caching::Fragments::MemoryStore.new
ActionController::Base.fragment_cache_store = ActionController::Caching::Fragments::FileStore.new("localhost")

View file

@ -12,6 +12,7 @@ Project wiki: <http://www.rousette.org.uk/projects/wiki/>
3. Added action caching.
4. Did a bit of refactoring to try to make page loading a bit more efficient.
5. Added a new row to the context table: 'hide'. This determines whether a particular context gets hidden on the main page. If the checkbox on the add new context form is checked, the context is hidden, and isn't listed on the front (todo/list) page. This is useful for contexts like 'wish list' or 'someday/maybe' that you don't want taking up your attention all the time.
6. Added a list of links to the hidden contexts at the bottom of the page.
## Version 1.01

View file

@ -17,6 +17,8 @@ p {
a, a:link, a:active, a:visited {
color: #cc3334;
text-decoration: none;
padding-left: 1px;
padding-right: 1px;
}
a:hover {