2005-01-09 11:59:57 +00:00
class TodoController < ApplicationController
2005-08-08 01:54:05 +00:00
2005-12-04 11:43:09 +00:00
model :user
model :project
model :context
2005-01-09 11:59:57 +00:00
helper :todo
2005-08-08 01:54:05 +00:00
2006-06-10 05:52:20 +00:00
prepend_before_filter :login_required
2005-01-09 11:59:57 +00:00
layout " standard "
2005-08-08 01:54:05 +00:00
2005-05-28 14:08:44 +00:00
def index
list
render_action " list "
end
2005-03-27 17:45:49 +00:00
2005-05-28 14:08:44 +00:00
# Main method for listing tasks
# Set page title, and fill variables with contexts and done and not-done tasks
# Number of completed actions to show is determined by a setting in settings.yml
#
2005-06-11 12:24:19 +00:00
def list
2005-08-08 01:54:05 +00:00
self . init
2005-12-07 19:06:24 +00:00
@on_page = " home "
2005-06-11 12:24:19 +00:00
@page_title = " TRACKS::List tasks "
2006-04-11 12:40:10 +00:00
2006-04-11 17:19:30 +00:00
# If you've set no_completed to zero, the completed items box
# isn't shown on the home page
max_completed = @user . preferences [ " no_completed " ] . to_i - 1
@done = ( max_completed > 0 ) ? @done [ 0 .. max_completed ] : nil
2005-08-08 01:54:05 +00:00
2006-07-17 03:40:35 +00:00
@contexts_to_show = @contexts . reject { | x | x . hide? }
2006-02-26 12:02:11 +00:00
if @contexts . empty?
flash [ 'warning' ] = 'You must add at least one context before adding next actions.'
end
2005-12-04 11:43:09 +00:00
2005-06-11 12:24:19 +00:00
# Set count badge to number of not-done, not hidden context items
2006-06-10 05:52:20 +00:00
@count = @todos . reject { | x | x . done? || x . context . hide? } . size
respond_to do | wants |
wants . html
wants . xml { render :action = > 'list.rxml' , :layout = > false }
end
2005-06-11 12:24:19 +00:00
end
2005-01-09 11:59:57 +00:00
2006-07-17 03:40:35 +00:00
# Is this used? Seems like it should be deleted. -lukemelia, 2006-07-16
2006-01-04 19:49:15 +00:00
def update_element
end
2005-05-28 14:08:44 +00:00
# Called by a form button
# Parameters from form fields are passed to create new action
# in the selected context.
def add_item
2005-08-08 01:54:05 +00:00
self . init
2006-01-04 19:49:15 +00:00
@item = @user . todos . build
2006-05-13 13:32:39 +00:00
@item . attributes = params [ " todo " ]
2006-01-04 19:49:15 +00:00
@on_page = " home "
2006-07-17 03:40:35 +00:00
perform_add_item ( 'list' )
2005-05-28 14:08:44 +00:00
end
Added the beginnings of a tickler to Tracks. It's fairly rudimentary at the moment, but it's designed to set the foundations for more kinds of deferred tasks.The current system works, but isn't very DRY: it will need refactoring for speed.
It has these features:
* The todos table and model has been altered (run rake migrate to update) to create two sub-classes of the todo model: Immediate and Deferred. Fairly obviously, Immediate actions are those shown immediately, and Deferred are those shown when certain conditions are fulfilled. At the moment, this is when the 'show_from' date arrives.
* Deferred actions are created on a separate page: /todo/tickler. You can view the show_from date here and delete or edit the actions. Deferred actions don't show on the home page (their handling on project and context pages is still to be fixed).
* A periodically called method (every 10 minutes) checks whether any of the deferred actions is due to be show, and if so, a warning message is shown on the home page to tell you how many deferred actions are to be shown. You need to refresh the page to see them (again, this is to be fixed).
* When deferred actions become due, their type is changed from "Deferred" to "Immediate". The handling of their staleness is still to be fixed.
There's a way to go before it's really smooth, but it's a start.
At least partially fixes #270 and #78, but will be improved with time too.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@232 a4c988fc-2ded-0310-b66e-134b36920a42
2006-05-02 17:11:46 +00:00
# Adding deferred actions from form on todo/tickler
#
def add_deferred_item
self . init
2006-07-17 03:40:35 +00:00
@item = Deferred . create ( params [ " todo " ] )
@item . user_id = @user . id
@on_page = " tickler "
Added the beginnings of a tickler to Tracks. It's fairly rudimentary at the moment, but it's designed to set the foundations for more kinds of deferred tasks.The current system works, but isn't very DRY: it will need refactoring for speed.
It has these features:
* The todos table and model has been altered (run rake migrate to update) to create two sub-classes of the todo model: Immediate and Deferred. Fairly obviously, Immediate actions are those shown immediately, and Deferred are those shown when certain conditions are fulfilled. At the moment, this is when the 'show_from' date arrives.
* Deferred actions are created on a separate page: /todo/tickler. You can view the show_from date here and delete or edit the actions. Deferred actions don't show on the home page (their handling on project and context pages is still to be fixed).
* A periodically called method (every 10 minutes) checks whether any of the deferred actions is due to be show, and if so, a warning message is shown on the home page to tell you how many deferred actions are to be shown. You need to refresh the page to see them (again, this is to be fixed).
* When deferred actions become due, their type is changed from "Deferred" to "Immediate". The handling of their staleness is still to be fixed.
There's a way to go before it's really smooth, but it's a start.
At least partially fixes #270 and #78, but will be improved with time too.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@232 a4c988fc-2ded-0310-b66e-134b36920a42
2006-05-02 17:11:46 +00:00
2006-07-17 03:40:35 +00:00
perform_add_item ( 'tickler' )
Added the beginnings of a tickler to Tracks. It's fairly rudimentary at the moment, but it's designed to set the foundations for more kinds of deferred tasks.The current system works, but isn't very DRY: it will need refactoring for speed.
It has these features:
* The todos table and model has been altered (run rake migrate to update) to create two sub-classes of the todo model: Immediate and Deferred. Fairly obviously, Immediate actions are those shown immediately, and Deferred are those shown when certain conditions are fulfilled. At the moment, this is when the 'show_from' date arrives.
* Deferred actions are created on a separate page: /todo/tickler. You can view the show_from date here and delete or edit the actions. Deferred actions don't show on the home page (their handling on project and context pages is still to be fixed).
* A periodically called method (every 10 minutes) checks whether any of the deferred actions is due to be show, and if so, a warning message is shown on the home page to tell you how many deferred actions are to be shown. You need to refresh the page to see them (again, this is to be fixed).
* When deferred actions become due, their type is changed from "Deferred" to "Immediate". The handling of their staleness is still to be fixed.
There's a way to go before it's really smooth, but it's a start.
At least partially fixes #270 and #78, but will be improved with time too.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@232 a4c988fc-2ded-0310-b66e-134b36920a42
2006-05-02 17:11:46 +00:00
end
2006-07-17 03:40:35 +00:00
2005-12-04 11:43:09 +00:00
def edit_action
self . init
2006-07-17 03:40:35 +00:00
@item = check_user_return_item
render :layout = > false
2005-12-04 11:43:09 +00:00
end
2006-06-10 06:00:32 +00:00
def show
self . init
item = check_user_return_item
respond_to do | wants |
wants . xml { render :xml = > item . to_xml ( :root = > 'todo' , :except = > :user_id ) }
end
end
2005-12-04 11:43:09 +00:00
# Toggles the 'done' status of the action
#
def toggle_check
self . init
2006-01-10 06:15:48 +00:00
@item = check_user_return_item
@item . toggle! ( 'done' )
@item . completed = Time . now ( ) # For some reason, the before_save in todo.rb stopped working
@saved = @item . save
@on_page = " home "
if @saved
@down_count = @todos . collect { | x | ( ! x . done? and ! x . context . hide? ) ? x : nil } . compact . size . to_s
end
return if request . xhr?
if @saved
flash [ 'notice' ] = " The action <strong>' #{ @item . description } '</strong> was marked as <strong> #{ @item . done? ? 'complete' : 'incomplete' } </strong> "
else
flash [ 'notice' ] = " The action <strong>' #{ @item . description } '</strong> was NOT marked as <strong> #{ @item . done? ? 'complete' : 'incomplete' } due to an error on the server.</strong> "
2005-12-04 11:43:09 +00:00
end
2006-01-10 06:15:48 +00:00
redirect_to :action = > " list "
2005-12-04 11:43:09 +00:00
end
2005-05-28 14:08:44 +00:00
# Edit the details of an action
2005-08-08 01:54:05 +00:00
#
2005-05-28 14:08:44 +00:00
def update_action
2005-08-08 01:54:05 +00:00
self . init
2006-05-13 13:32:39 +00:00
if params [ " on_project_page " ] == true
2005-12-07 19:06:24 +00:00
@on_page = " project "
end
2006-04-11 12:40:10 +00:00
@item = check_user_return_item
@original_item_context_id = @item . context_id
2006-05-13 13:32:39 +00:00
@item . attributes = params [ " item " ]
2005-08-08 01:54:05 +00:00
2006-04-11 12:40:10 +00:00
if @item . due?
2006-05-13 13:32:39 +00:00
@item . due = Date . strptime ( params [ " item " ] [ " due " ] , @user . preferences [ " date_format " ] )
2005-05-28 14:08:44 +00:00
else
2006-04-11 12:40:10 +00:00
@item . due = " "
2005-05-28 14:08:44 +00:00
end
2005-08-08 01:54:05 +00:00
2006-04-11 12:40:10 +00:00
@saved = @item . save
2005-01-09 11:59:57 +00:00
end
2006-07-03 00:22:28 +00:00
2006-07-17 03:40:35 +00:00
def deferred_update_action
#self.init
@tickle = check_user_return_item
@original_item_context_id = @tickle . context_id
@tickle . attributes = params [ " item " ]
if @tickle . due?
@tickle . due = Date . strptime ( params [ " item " ] [ " due " ] , @user . preferences [ " date_format " ] )
else
@tickle . due = " "
end
@saved = @tickle . save
end
2006-07-03 00:22:28 +00:00
def update_context
self . init
@item = check_user_return_item
context = Context . find ( params [ 'context_id' ] ) ;
if @user == context . user
@original_item_context_id = @item . context_id
@item . context_id = context . id
@item . context = context
@saved = @item . save
render :action = > 'update_action'
else
render :update do | page |
page . replace_html " info " , content_tag ( " div " , " Error updating the context of the dragged item. Item and context user mis-match: #{ @item . user . name } and #{ @context . user . name } ! - refresh the page to see them. " , " class " = > " warning " )
end
end
end
2006-07-03 00:59:31 +00:00
def update_project
self . init
@item = check_user_return_item
project = Project . find ( params [ 'project_id' ] ) ;
if @user == project . user
@original_item_context_id = @item . context_id
@item . project_id = project . id
@item . project = project
@saved = @item . save
render :action = > 'update_action'
else
render :update do | page |
page . replace_html " info " , content_tag ( " div " , " Error updating the project of the dragged item. Item and project user mis-match: #{ @item . user . name } and #{ @project . user . name } ! - refresh the page to see them. " , " class " = > " warning " )
end
end
end
Added the beginnings of a tickler to Tracks. It's fairly rudimentary at the moment, but it's designed to set the foundations for more kinds of deferred tasks.The current system works, but isn't very DRY: it will need refactoring for speed.
It has these features:
* The todos table and model has been altered (run rake migrate to update) to create two sub-classes of the todo model: Immediate and Deferred. Fairly obviously, Immediate actions are those shown immediately, and Deferred are those shown when certain conditions are fulfilled. At the moment, this is when the 'show_from' date arrives.
* Deferred actions are created on a separate page: /todo/tickler. You can view the show_from date here and delete or edit the actions. Deferred actions don't show on the home page (their handling on project and context pages is still to be fixed).
* A periodically called method (every 10 minutes) checks whether any of the deferred actions is due to be show, and if so, a warning message is shown on the home page to tell you how many deferred actions are to be shown. You need to refresh the page to see them (again, this is to be fixed).
* When deferred actions become due, their type is changed from "Deferred" to "Immediate". The handling of their staleness is still to be fixed.
There's a way to go before it's really smooth, but it's a start.
At least partially fixes #270 and #78, but will be improved with time too.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@232 a4c988fc-2ded-0310-b66e-134b36920a42
2006-05-02 17:11:46 +00:00
2006-01-04 19:49:15 +00:00
# Delete a next action
2005-05-28 14:08:44 +00:00
#
def destroy_action
2006-01-04 19:49:15 +00:00
self . init
@item = check_user_return_item
@saved = @item . destroy
2006-01-10 06:15:48 +00:00
@on_page = " home "
if @saved
2006-05-29 11:02:28 +00:00
self . init
@down_count = @todos . reject { | x | x . done? or x . context . hide? } . size . to_s
2006-01-10 06:15:48 +00:00
end
2006-01-04 19:49:15 +00:00
return if request . xhr?
# fallback for standard requests
if @saved
2006-01-08 13:21:24 +00:00
flash [ " notice " ] = 'Successfully deleted next action'
2006-01-04 19:49:15 +00:00
redirect_to :action = > 'list'
2005-06-11 12:24:19 +00:00
else
2006-01-04 19:49:15 +00:00
render :action = > 'list'
2005-06-11 12:24:19 +00:00
end
2006-01-04 19:49:15 +00:00
rescue
if request . xhr? # be sure to include an error.rjs
render :action = > 'error'
else
flash [ " warning " ] = 'An error occurred on the server.'
render :action = > 'list'
end
2005-05-28 14:08:44 +00:00
end
2005-08-08 01:54:05 +00:00
2005-12-04 11:43:09 +00:00
# List the completed tasks, sorted by completion date
2006-03-31 13:24:22 +00:00
# @done_today: in the last 24 hours
# @done_this_week: in the last week
# @done_this_month: in the last 4 weeks (<=28 days)
2005-12-04 11:43:09 +00:00
def completed
2005-08-08 01:54:05 +00:00
self . init
2005-12-04 11:43:09 +00:00
@page_title = " TRACKS::Completed tasks "
2006-03-31 13:24:22 +00:00
unless @done . nil?
@done_today = @done . collect { | x | x . completed > = 1 . day . ago ? x : nil } . compact
@done_this_week = @done . collect { | x | 1 . week . ago < = x . completed ? x : nil } . compact
@done_this_month = @done . collect { | x | 4 . week . ago < = x . completed ? x : nil } . compact
end
2005-08-08 01:54:05 +00:00
end
2006-03-31 13:24:22 +00:00
# Archived completed items, older than 28 days
2005-12-04 11:43:09 +00:00
#
def completed_archive
self . init
@page_title = " TRACKS::Archived completed tasks "
2006-03-31 13:24:22 +00:00
@done_archive = @done . collect { | x | 28 . day . ago > x . completed ? x : nil } . compact
2005-12-04 11:43:09 +00:00
end
2006-02-26 11:36:25 +00:00
def feeds
self . init
@page_title = " TRACKS::Feeds "
end
Added the beginnings of a tickler to Tracks. It's fairly rudimentary at the moment, but it's designed to set the foundations for more kinds of deferred tasks.The current system works, but isn't very DRY: it will need refactoring for speed.
It has these features:
* The todos table and model has been altered (run rake migrate to update) to create two sub-classes of the todo model: Immediate and Deferred. Fairly obviously, Immediate actions are those shown immediately, and Deferred are those shown when certain conditions are fulfilled. At the moment, this is when the 'show_from' date arrives.
* Deferred actions are created on a separate page: /todo/tickler. You can view the show_from date here and delete or edit the actions. Deferred actions don't show on the home page (their handling on project and context pages is still to be fixed).
* A periodically called method (every 10 minutes) checks whether any of the deferred actions is due to be show, and if so, a warning message is shown on the home page to tell you how many deferred actions are to be shown. You need to refresh the page to see them (again, this is to be fixed).
* When deferred actions become due, their type is changed from "Deferred" to "Immediate". The handling of their staleness is still to be fixed.
There's a way to go before it's really smooth, but it's a start.
At least partially fixes #270 and #78, but will be improved with time too.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@232 a4c988fc-2ded-0310-b66e-134b36920a42
2006-05-02 17:11:46 +00:00
def tickler
self . init
@page_title = " TRACKS::Tickler "
@tickles = @user . todos . find ( :all , :conditions = > [ 'type = ?' , " Deferred " ] , :order = > " show_from ASC " )
@count = @tickles . size
2006-07-17 03:40:35 +00:00
@on_page = " tickler "
Added the beginnings of a tickler to Tracks. It's fairly rudimentary at the moment, but it's designed to set the foundations for more kinds of deferred tasks.The current system works, but isn't very DRY: it will need refactoring for speed.
It has these features:
* The todos table and model has been altered (run rake migrate to update) to create two sub-classes of the todo model: Immediate and Deferred. Fairly obviously, Immediate actions are those shown immediately, and Deferred are those shown when certain conditions are fulfilled. At the moment, this is when the 'show_from' date arrives.
* Deferred actions are created on a separate page: /todo/tickler. You can view the show_from date here and delete or edit the actions. Deferred actions don't show on the home page (their handling on project and context pages is still to be fixed).
* A periodically called method (every 10 minutes) checks whether any of the deferred actions is due to be show, and if so, a warning message is shown on the home page to tell you how many deferred actions are to be shown. You need to refresh the page to see them (again, this is to be fixed).
* When deferred actions become due, their type is changed from "Deferred" to "Immediate". The handling of their staleness is still to be fixed.
There's a way to go before it's really smooth, but it's a start.
At least partially fixes #270 and #78, but will be improved with time too.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@232 a4c988fc-2ded-0310-b66e-134b36920a42
2006-05-02 17:11:46 +00:00
end
2005-12-04 11:43:09 +00:00
Added the beginnings of a tickler to Tracks. It's fairly rudimentary at the moment, but it's designed to set the foundations for more kinds of deferred tasks.The current system works, but isn't very DRY: it will need refactoring for speed.
It has these features:
* The todos table and model has been altered (run rake migrate to update) to create two sub-classes of the todo model: Immediate and Deferred. Fairly obviously, Immediate actions are those shown immediately, and Deferred are those shown when certain conditions are fulfilled. At the moment, this is when the 'show_from' date arrives.
* Deferred actions are created on a separate page: /todo/tickler. You can view the show_from date here and delete or edit the actions. Deferred actions don't show on the home page (their handling on project and context pages is still to be fixed).
* A periodically called method (every 10 minutes) checks whether any of the deferred actions is due to be show, and if so, a warning message is shown on the home page to tell you how many deferred actions are to be shown. You need to refresh the page to see them (again, this is to be fixed).
* When deferred actions become due, their type is changed from "Deferred" to "Immediate". The handling of their staleness is still to be fixed.
There's a way to go before it's really smooth, but it's a start.
At least partially fixes #270 and #78, but will be improved with time too.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@232 a4c988fc-2ded-0310-b66e-134b36920a42
2006-05-02 17:11:46 +00:00
# Called by periodically_call_remote
# Check for any due tickler items, change them to type Immediate and show
# on the page
#
def check_tickler
self . init
now = Date . today ( )
@due_tickles = @user . todos . find ( :all , :conditions = > [ 'type = ? AND (show_from < ? OR show_from = ?)' , " Deferred " , now , now ] , :order = > " show_from ASC " )
unless @due_tickles . empty?
# Change the due tickles to type "Immediate"
@due_tickles . each do | t |
t [ :type ] = " Immediate "
t . show_from = nil
t . save
end
end
end
2006-07-03 00:22:28 +00:00
2005-08-08 01:54:05 +00:00
protected
def check_user_return_item
2006-05-13 13:32:39 +00:00
item = Todo . find ( params [ 'id' ] )
2006-04-08 17:46:41 +00:00
if @user == item . user
2005-08-08 01:54:05 +00:00
return item
else
2006-04-08 17:46:41 +00:00
flash [ " warning " ] = " Item and session user mis-match: #{ item . user . name } and #{ @user . name } ! "
2005-08-08 01:54:05 +00:00
render_text " "
end
end
def init
@projects = @user . projects
@contexts = @user . contexts
2006-07-17 03:40:35 +00:00
init_todos
end
def init_todos
Added the beginnings of a tickler to Tracks. It's fairly rudimentary at the moment, but it's designed to set the foundations for more kinds of deferred tasks.The current system works, but isn't very DRY: it will need refactoring for speed.
It has these features:
* The todos table and model has been altered (run rake migrate to update) to create two sub-classes of the todo model: Immediate and Deferred. Fairly obviously, Immediate actions are those shown immediately, and Deferred are those shown when certain conditions are fulfilled. At the moment, this is when the 'show_from' date arrives.
* Deferred actions are created on a separate page: /todo/tickler. You can view the show_from date here and delete or edit the actions. Deferred actions don't show on the home page (their handling on project and context pages is still to be fixed).
* A periodically called method (every 10 minutes) checks whether any of the deferred actions is due to be show, and if so, a warning message is shown on the home page to tell you how many deferred actions are to be shown. You need to refresh the page to see them (again, this is to be fixed).
* When deferred actions become due, their type is changed from "Deferred" to "Immediate". The handling of their staleness is still to be fixed.
There's a way to go before it's really smooth, but it's a start.
At least partially fixes #270 and #78, but will be improved with time too.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@232 a4c988fc-2ded-0310-b66e-134b36920a42
2006-05-02 17:11:46 +00:00
@todos = Todo . find ( :all , :conditions = > [ 'user_id = ? and type = ?' , @user . id , " Immediate " ] )
2006-06-29 17:38:13 +00:00
@done = Todo . find ( :all , :conditions = > [ 'user_id = ? and done = ?' , @user . id , true ] , :order = > 'completed DESC' )
2005-08-08 01:54:05 +00:00
end
2005-12-04 11:43:09 +00:00
2006-07-17 03:40:35 +00:00
def perform_add_item ( redirect_action )
if @item . due?
@item . due = Date . strptime ( params [ " todo " ] [ " due " ] , @user . preferences [ " date_format " ] )
else
@item . due = " "
end
@saved = @item . save
if @saved
init_todos
@up_count = @todos . reject { | x | x . done? or x . context . hide? } . size . to_s
end
respond_to do | wants |
wants . html { redirect_to :action = > redirect_action }
wants . js
wants . xml { render :xml = > @item . to_xml ( :root = > 'todo' , :except = > :user_id ) }
end
# if you're seeing the message 'An error occurred on the server.' and you want to debug, comment out the rescue section and check the Ajax response for an exception message
rescue
respond_to do | wants |
wants . html { render :action = > redirect_action } # TODO: would prefer something like: flash["warning"] = 'An error occurred on the server.' render :action => 'list'
wants . js { render :action = > 'error' }
wants . xml { render :text = > 'An error occurred on the server.' + $! }
end
end
2005-01-09 11:59:57 +00:00
end