- Added feature #471, which makes greater use of projects by reporting
  changes to the completion percentage when it changes.
- Added unit tests.
This commit is contained in:
Paul Beckingham 2010-08-20 23:53:57 -04:00
parent d460e604ff
commit 5c235ce1ef
6 changed files with 193 additions and 6 deletions

View file

@ -51,6 +51,8 @@
#include <ncurses.h>
#endif
static void countTasks (const std::vector <Task>&, const std::string&, const std::string&, int&, int&);
extern Context context;
////////////////////////////////////////////////////////////////////////////////
@ -2828,3 +2830,83 @@ std::string getDueDate (Task& task, const std::string& format)
}
///////////////////////////////////////////////////////////////////////////////
std::string onProjectChange (Task& task, bool scope /* = true */)
{
std::stringstream msg;
std::string project = task.get ("project");
if (project != "")
{
if (scope)
msg << "The scope of project '"
<< project
<< "' has changed. ";
// Count pending and done tasks, for this project.
int count_pending = 0;
int count_done = 0;
std::vector <Task> all;
Filter filter;
context.tdb.load (all, filter);
countTasks (all, project, task.get ("uuid"), count_pending, count_done);
countTasks (context.tdb.getAllNew (), project, "nope", count_pending, count_done);
countTasks (context.tdb.getAllModified (), project, "nope", count_pending, count_done);
msg << "Project '"
<< project
<< "' is "
<< (count_done * 100 / (count_done + count_pending))
<< "% complete ("
<< count_pending
<< " of "
<< (count_pending + count_done)
<< " tasks remaining).\n";
}
return msg.str ();
}
///////////////////////////////////////////////////////////////////////////////
std::string onProjectChange (Task& task1, Task& task2)
{
std::string messages = onProjectChange (task1);
messages += onProjectChange (task2);
return messages;
}
///////////////////////////////////////////////////////////////////////////////
static void countTasks (
const std::vector <Task>& all,
const std::string& project,
const std::string& skip,
int& count_pending,
int& count_done)
{
std::vector <Task>::const_iterator it;
for (it = all.begin (); it != all.end (); ++it)
{
if (it->get ("project") == project &&
it->get ("uuid") != skip)
{
switch (it->getStatus ())
{
case Task::pending:
case Task::waiting:
++count_pending;
break;
case Task::completed:
++count_done;
break;
default:
break;
}
}
}
}
///////////////////////////////////////////////////////////////////////////////