Skip to content

Commit

Permalink
Add list tasks by context to client.
Browse files Browse the repository at this point in the history
git-svn-id: http://toodledo.rubyforge.org/svn/trunk@76 7a1d1287-79c4-4140-ad4e-221ab6fece8c
  • Loading branch information
wsargent committed May 11, 2008
1 parent 58d109a commit 8287f93
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
48 changes: 46 additions & 2 deletions lib/toodledo/command_line/client.rb
Expand Up @@ -18,6 +18,7 @@
# READ
require 'toodledo/command_line/hotlist_command'
require 'toodledo/command_line/list_tasks_command'
require 'toodledo/command_line/list_tasks_by_context_command'
require 'toodledo/command_line/list_folders_command'
require 'toodledo/command_line/list_contexts_command'
require 'toodledo/command_line/list_goals_command'
Expand Down Expand Up @@ -76,10 +77,16 @@ def initialize(userconfig=CONFIG_F, opts={})
}
end

#
# Returns debugging status.
#
def debug?
return @debug
end

#
# Sets the debugging on or off.
#
def debug=(is_debug)
@debug = is_debug
if (@debug == true)
Expand All @@ -89,6 +96,9 @@ def debug=(is_debug)
end
end

#
# Returns the logger.
#
def logger
return @logger
end
Expand Down Expand Up @@ -293,6 +303,20 @@ def list_tasks(session, input)
end
end

#
# Prints all active tasks nested by context.
#
def list_tasks_by_context(session, line)
folder = parse_folder(line)

session.get_contexts().each do |context|
criteria = { :folder => folder, :context => context, :notcomp => true }
tasks = session.get_tasks(criteria)
print "#{context.name}" if (! tasks.empty?)
tasks.each { |task| print " " + @formatters[:task].format(task) }
end
end

#
# Lists the goals. Takes an optional argument of
# 'short', 'medium' or 'life'.
Expand Down Expand Up @@ -397,6 +421,9 @@ def add_task(session, line)
print "Task #{task_id} added."
end

#
# Adds context.
#
def add_context(session, input)

title = input.strip
Expand All @@ -406,6 +433,9 @@ def add_context(session, input)
print "Context #{context_id} added."
end

#
# Adds goal.
#
def add_goal(session, input)
input.strip!

Expand Down Expand Up @@ -522,7 +552,8 @@ def complete_task(session, line)
#
# delete 123
#
def delete_task(session, line)
def delete_task(session, line)
logger.debug("delete_task: #{line.inspect}")
task_id = line

if (task_id == nil)
Expand All @@ -538,7 +569,12 @@ def delete_task(session, line)
end
end

#
# Deletes context.
#
def delete_context(session, line)
logger.debug("delete_context #{line.inspect}")

id = line

id.strip!
Expand All @@ -550,6 +586,9 @@ def delete_context(session, line)
end
end

#
# Deletes goal.
#
def delete_goal(session, line)
id = line

Expand All @@ -562,6 +601,9 @@ def delete_goal(session, line)
end
end

#
# Deletes folder
#
def delete_folder(session, line)
id = line

Expand All @@ -573,8 +615,10 @@ def delete_folder(session, line)
print "Folder #{id} could not be deleted!"
end
end


#
# Prints out a single line.
#
def print(line = nil)
if (line == nil)
puts
Expand Down
26 changes: 26 additions & 0 deletions lib/toodledo/command_line/list_tasks_by_context_command.rb
@@ -0,0 +1,26 @@
module Toodledo
module CommandLine

#
# List Tasks By Context
#
class ListTasksByContextCommand < BaseCommand
def initialize(client)
super(client, 'nested', false)
self.short_desc = "List tasks by context"
self.description = "Lists the tasks grouped by context."
end

def execute(args)

Toodledo.begin(client.logger) do |session|
line = args.join(' ')
return client.list_tasks_by_context(session, line)
end

return 0
end
end

end
end
24 changes: 24 additions & 0 deletions test/client_test.rb
Expand Up @@ -149,6 +149,30 @@ def test_list_tasks_with_everything()
input = ''
@client.list_tasks(@session, input)
end

def test_list_tasks_by_context()
context = Context.new(345, 'test context')
folder = Folder.new(1234, 0, 0, 'test folder')

params = {
:priority => Priority::LOW,
:title => 'foo',
:folder => folder,
:goal => Goal::NO_GOAL,
:repeat => Repeat::NONE,
:context => context
}
task = Task.new(1234, params)
tasks = [ task ]
contexts = [ context ]
@session.should_receive(:get_contexts).and_return(contexts)
@session.should_receive(:get_tasks).and_return(tasks)
@client.should_receive(:print).with('test context')
@client.should_receive(:print).with(' <1234> -- !low *[test folder] @[test context] foo')

input = ''
@client.list_tasks_by_context(@session, input)
end

def test_list_contexts()
context = Context.new(1234, 'Context')
Expand Down

0 comments on commit 8287f93

Please sign in to comment.