Bug - timesheet

- Converted the timesheet report to use raw word arguments instead of
  filters.
- Uses new TDB2:all_tasks method.
- Cleaned up unit tests.
This commit is contained in:
Paul Beckingham 2011-09-05 10:47:38 -04:00
parent 195c7d5142
commit 297ec6dd1f
2 changed files with 29 additions and 43 deletions

View file

@ -52,13 +52,9 @@ int CmdTimesheet::execute (std::string& output)
// Scan the pending tasks. // Scan the pending tasks.
handleRecurrence (); handleRecurrence ();
std::vector <Task> filtered; std::vector <Task> all = context.tdb2.all_tasks ();
filter (filtered);
context.tdb2.commit (); context.tdb2.commit ();
// Just do this once.
int width = context.getWidth ();
// What day of the week does the user consider the first? // What day of the week does the user consider the first?
int weekStart = Date::dayOfWeek (context.config.get ("weekstart")); int weekStart = Date::dayOfWeek (context.config.get ("weekstart"));
if (weekStart != 0 && weekStart != 1) if (weekStart != 0 && weekStart != 1)
@ -76,9 +72,9 @@ int CmdTimesheet::execute (std::string& output)
// Determine how many reports to run. // Determine how many reports to run.
int quantity = 1; int quantity = 1;
A3 modifications = context.a3.extract_modifications (); std::vector <std::string> words = context.a3.extract_words ();
if (modifications.size () == 1) if (words.size () == 1)
quantity = strtol (modifications[0]._raw.c_str (), NULL, 10);; quantity = strtol (words[0].c_str (), NULL, 10);;
std::stringstream out; std::stringstream out;
for (int week = 0; week < quantity; ++week) for (int week = 0; week < quantity; ++week)
@ -97,14 +93,14 @@ int CmdTimesheet::execute (std::string& output)
// Render the completed table. // Render the completed table.
ViewText completed; ViewText completed;
completed.width (width); completed.width (context.getWidth ());
completed.add (Column::factory ("string", " ")); completed.add (Column::factory ("string", " "));
completed.add (Column::factory ("string", "Project")); completed.add (Column::factory ("string", "Project"));
completed.add (Column::factory ("string.right", "Due")); completed.add (Column::factory ("string.right", "Due"));
completed.add (Column::factory ("string", "Description")); completed.add (Column::factory ("string", "Description"));
std::vector <Task>::iterator task; std::vector <Task>::iterator task;
for (task = filtered.begin (); task != filtered.end (); ++task) for (task = all.begin (); task != all.end (); ++task)
{ {
// If task completed within range. // If task completed within range.
if (task->getStatus () == Task::completed) if (task->getStatus () == Task::completed)
@ -135,13 +131,13 @@ int CmdTimesheet::execute (std::string& output)
// Now render the started table. // Now render the started table.
ViewText started; ViewText started;
started.width (width); started.width (context.getWidth ());
started.add (Column::factory ("string", " ")); started.add (Column::factory ("string", " "));
started.add (Column::factory ("string", "Project")); started.add (Column::factory ("string", "Project"));
started.add (Column::factory ("string.right", "Due")); started.add (Column::factory ("string.right", "Due"));
started.add (Column::factory ("string", "Description")); started.add (Column::factory ("string", "Description"));
for (task = filtered.begin (); task != filtered.end (); ++task) for (task = all.begin (); task != all.end (); ++task)
{ {
// If task started within range, but not completed withing range. // If task started within range, but not completed withing range.
if (task->getStatus () == Task::pending && if (task->getStatus () == Task::pending &&

View file

@ -28,7 +28,7 @@
use strict; use strict;
use warnings; use warnings;
use Test::More tests => 11; use Test::More tests => 6;
# Create the rc file. # Create the rc file.
if (open my $fh, '>', 'time.rc') if (open my $fh, '>', 'time.rc')
@ -51,22 +51,22 @@ if (open my $fh, '>', 'time.rc')
# C1 completed, last week # C1 completed, last week
# C2 completed, 2wks ago # C2 completed, 2wks ago
my $now = time (); my $now = time ();
my $seven = $now - 7 * 86_400; my $six = $now - 6 * 86_400;
my $fourteen = $now - 14 * 86_400; my $twelve = $now - 12 * 86_400;
if (open my $fh, '>', 'pending.data') if (open my $fh, '>', 'pending.data')
{ {
print $fh <<EOF; print $fh <<EOF;
[status:"pending" description:"P0" entry:"$fourteen"] [uuid:"00000000-0000-0000-0000-000000000000 " status:"pending" description:"P0" entry:"$twelve"]
[status:"pending" description:"PS0" entry:"$fourteen" start:"$now"] [uuid:"11111111-1111-1111-1111-111111111111 " status:"pending" description:"PS0" entry:"$twelve" start:"$now"]
[status:"pending" description:"PS1" entry:"$fourteen" start:"$seven"] [uuid:"22222222-2222-2222-2222-222222222222 " status:"pending" description:"PS1" entry:"$twelve" start:"$six"]
[status:"pending" description:"PS2" entry:"$fourteen" start:"$fourteen"] [uuid:"33333333-3333-3333-3333-333333333333 " status:"pending" description:"PS2" entry:"$twelve" start:"$twelve"]
[status:"deleted" description:"D0" entry:"$fourteen" end:"$now"] [uuid:"44444444-4444-4444-4444-444444444444 " status:"deleted" description:"D0" entry:"$twelve" end:"$now"]
[status:"deleted" description:"D1" entry:"$fourteen" end:"$seven"] [uuid:"55555555-5555-5555-5555-555555555555 " status:"deleted" description:"D1" entry:"$twelve" end:"$six"]
[status:"deleted" description:"D2" entry:"$fourteen" end:"$fourteen"] [uuid:"66666666-6666-6666-6666-666666666666 " status:"deleted" description:"D2" entry:"$twelve" end:"$twelve"]
[status:"completed" description:"C0" entry:"$fourteen" end:"$now"] [uuid:"77777777-7777-7777-7777-777777777777 " status:"completed" description:"C0" entry:"$twelve" end:"$now"]
[status:"completed" description:"C1" entry:"$fourteen" end:"$seven"] [uuid:"88888888-8888-8888-8888-888888888888 " status:"completed" description:"C1" entry:"$twelve" end:"$six"]
[status:"completed" description:"C2" entry:"$fourteen" end:"$fourteen"] [uuid:"99999999-9999-9999-9999-999999999999 " status:"completed" description:"C2" entry:"$twelve" end:"$twelve"]
EOF EOF
close $fh; close $fh;
ok (-r 'pending.data', 'Created pending.data'); ok (-r 'pending.data', 'Created pending.data');
@ -82,23 +82,13 @@ $output = qx{../src/task rc:time.rc timesheet 3};
like ($output, qr/Completed.+C0.+Started.+PS0.+Completed.+C1.+Started.+PS1.+Completed.+C2.+Started.+PS2/ms, 'three weeks of started and completed'); like ($output, qr/Completed.+C0.+Started.+PS0.+Completed.+C1.+Started.+PS1.+Completed.+C2.+Started.+PS2/ms, 'three weeks of started and completed');
# Cleanup. # Cleanup.
unlink 'pending.data'; unlink qw(pending.data completed.data undo.data backlog.data synch.key time.rc);
ok (!-r 'pending.data', 'Removed pending.data'); ok (! -r 'pending.data' &&
! -r 'completed.data' &&
unlink 'completed.data'; ! -r 'undo.data' &&
ok (!-r 'completed.data', 'Removed completed.data'); ! -r 'backlog.data' &&
! -r 'synch_key.data' &&
unlink 'undo.data'; ! -r 'time.rc', 'Cleanup');
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'backlog.data';
ok (!-r 'backlog.data', 'Removed backlog.data');
unlink 'synch.key';
ok (!-r 'synch.key', 'Removed synch.key');
unlink 'time.rc';
ok (!-r 'time.rc', 'Removed time.rc');
exit 0; exit 0;