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}" 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 << "" - 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 %> +
    +
    + <%= 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? %> + <%= "" + $notes_img + "" %>
    + <% 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 ) %>

    -
    - <% 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 ) %>

    + +
    <% end %> - - <% if heading == true %> - -
    - <% end %> <% end %>
    @@ -53,14 +19,14 @@
    -
    -

    Today's events are:

    +
    +

    Add next action

    @@ -68,7 +34,7 @@ <%= text_field( "new_item", "description" ) %>

    - <%= text_area( "new_item", "notes", "cols" => 40, "rows" => 15 ) %> + <%= text_area( "new_item", "notes", "cols" => 35, "rows" => 15 ) %>