Bug Fix - nag

- Implemented new nag algorithm, and debugged why it then broke.
This commit is contained in:
Paul Beckingham 2009-03-03 00:46:02 -05:00
parent 8157c729d6
commit 964d04322c
2 changed files with 19 additions and 17 deletions

View file

@ -334,20 +334,31 @@ void nag (TDB& tdb, T& task, Config& conf)
std::string nagMessage = conf.get ("nag", std::string ("")); std::string nagMessage = conf.get ("nag", std::string (""));
if (nagMessage != "") if (nagMessage != "")
{ {
// Load all pending. // Load all pending tasks.
std::vector <T> pending; std::vector <T> pending;
tdb.allPendingT (pending); tdb.allPendingT (pending);
// Counters. // Counters.
int overdue = 0; int overdue = 0;
int high = 0; int high = 0;
int medium = 0; int medium = 0;
int low = 0; int low = 0;
bool isOverdue = false;
char pri = ' ';
// Scan all pending tasks. // Scan all pending tasks.
foreach (t, pending) foreach (t, pending)
{ {
if (t->getId () != task.getId ()) if (t->getId () == task.getId ())
{
if (getDueState (t->getAttribute ("due")) == 2)
isOverdue = true;
std::string priority = t->getAttribute ("priority");
if (priority.length ())
pri = priority[0];
}
else if (t->getStatus () == T::pending)
{ {
if (getDueState (t->getAttribute ("due")) == 2) if (getDueState (t->getAttribute ("due")) == 2)
overdue++; overdue++;
@ -365,21 +376,15 @@ void nag (TDB& tdb, T& task, Config& conf)
} }
} }
// Scan the current task.
bool isOverdue = getDueState (task.getAttribute ("due")) == 2 ? true : false;
char pri = ' ';
std::string priority = task.getAttribute ("priority");
if (priority.length ())
pri = priority[0];
// General form is "if there are no more deserving tasks", suppress the nag. // General form is "if there are no more deserving tasks", suppress the nag.
/*
std::cout << "# task.isOverdue = " << (isOverdue ? "true" : "false") << std::endl; std::cout << "# task.isOverdue = " << (isOverdue ? "true" : "false") << std::endl;
std::cout << "# task.pri = " << pri << std::endl; std::cout << "# task.pri = " << pri << std::endl;
std::cout << "# task.overdue = " << overdue << std::endl; std::cout << "# task.overdue = " << overdue << std::endl;
std::cout << "# pending.high = " << high << std::endl; std::cout << "# pending.high = " << high << std::endl;
std::cout << "# pending.medium = " << medium << std::endl; std::cout << "# pending.medium = " << medium << std::endl;
std::cout << "# pending.low = " << low << std::endl; std::cout << "# pending.low = " << low << std::endl;
*/
if (isOverdue ) return; if (isOverdue ) return;
if (pri == 'H' && !overdue ) return; if (pri == 'H' && !overdue ) return;
@ -735,8 +740,6 @@ void updateShadowFile (TDB& tdb, Config& conf)
conf.set ("curses", oldCurses); conf.set ("curses", oldCurses);
conf.set ("color", oldColor); conf.set ("color", oldColor);
} }
else
throw std::string ("No specified shadow file '") + shadowFile + "'.";
// Optionally display a notification that the shadow file was updated. // Optionally display a notification that the shadow file was updated.
if (conf.get (std::string ("shadow.notify"), false)) if (conf.get (std::string ("shadow.notify"), false))

View file

@ -47,7 +47,6 @@ my $setup = "../task rc:nag.rc add due:yesterday one;"
. "../task rc:nag.rc add six;"; . "../task rc:nag.rc add six;";
qx{$setup}; qx{$setup};
my $output = qx{../task rc:nag.rc do 6};
like (qx{../task rc:nag.rc do 6}, qr/NAG/, 'do pri: -> nag'); like (qx{../task rc:nag.rc do 6}, qr/NAG/, 'do pri: -> nag');
like (qx{../task rc:nag.rc do 5}, qr/NAG/, 'do pri:L -> nag'); like (qx{../task rc:nag.rc do 5}, qr/NAG/, 'do pri:L -> nag');
like (qx{../task rc:nag.rc do 4}, qr/NAG/, 'do pri:M-> nag'); like (qx{../task rc:nag.rc do 4}, qr/NAG/, 'do pri:M-> nag');