Commands - projects, _projects

- Migraged handleProjects and handleCompletionProjects to CmdProjects.
This commit is contained in:
Paul Beckingham
2011-05-28 16:18:53 -04:00
parent a7bc09d487
commit 920e1c6c86
9 changed files with 229 additions and 130 deletions

View File

@@ -215,122 +215,6 @@ int handleLog (std::string& outs)
return rc;
}
////////////////////////////////////////////////////////////////////////////////
int handleProjects (std::string& outs)
{
int rc = 0;
std::stringstream out;
std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking"));
int quantity;
if (context.config.getBoolean ("list.all.projects"))
quantity = context.tdb.load (tasks, context.filter);
else
quantity = context.tdb.loadPending (tasks, context.filter);
context.tdb.commit ();
context.tdb.unlock ();
// Scan all the tasks for their project name, building a map using project
// names as keys.
std::map <std::string, int> unique;
std::map <std::string, int> high;
std::map <std::string, int> medium;
std::map <std::string, int> low;
std::map <std::string, int> none;
bool no_project = false;
std::string project;
std::string priority;
foreach (t, tasks)
{
project = t->get ("project");
priority = t->get ("priority");
unique[project] += 1;
if (project == "")
no_project = true;
if (priority == "H") high[project] += 1;
else if (priority == "M") medium[project] += 1;
else if (priority == "L") low[project] += 1;
else none[project] += 1;
}
if (unique.size ())
{
// Render a list of project names from the map.
ViewText view;
view.width (context.getWidth ());
view.add (Column::factory ("string", "Project"));
view.add (Column::factory ("string.right", "Tasks"));
view.add (Column::factory ("string.right", "Pri:None"));
view.add (Column::factory ("string.right", "Pri:L"));
view.add (Column::factory ("string.right", "Pri:M"));
view.add (Column::factory ("string.right", "Pri:H"));
foreach (i, unique)
{
int row = view.addRow ();
view.set (row, 0, (i->first == "" ? "(none)" : i->first));
view.set (row, 1, i->second);
view.set (row, 2, none[i->first]);
view.set (row, 3, low[i->first]);
view.set (row, 4, medium[i->first]);
view.set (row, 5, high[i->first]);
}
int number_projects = unique.size ();
if (no_project)
--number_projects;
out << optionalBlankLine ()
<< view.render ()
<< optionalBlankLine ()
<< number_projects
<< (number_projects == 1 ? " project" : " projects")
<< " (" << quantity << (quantity == 1 ? " task" : " tasks") << ")\n";
}
else
{
out << "No projects.\n";
rc = 1;
}
outs = out.str ();
return rc;
}
////////////////////////////////////////////////////////////////////////////////
int handleCompletionProjects (std::string& outs)
{
std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter;
if (context.config.getBoolean ("complete.all.projects"))
context.tdb.load (tasks, filter);
else
context.tdb.loadPending (tasks, filter);
context.tdb.commit ();
context.tdb.unlock ();
// Scan all the tasks for their project name, building a map using project
// names as keys.
std::map <std::string, int> unique;
foreach (t, tasks)
unique[t->get ("project")] = 0;
std::stringstream out;
foreach (project, unique)
if (project->first.length ())
out << project->first << "\n";
outs = out.str ();
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int handleCompletionConfig (std::string& outs)
{