Enhancement - next report

- Implemented next report.
This commit is contained in:
Paul Beckingham 2009-06-14 14:53:22 -04:00
parent f470acadaa
commit 9004b65956
3 changed files with 65 additions and 89 deletions

View file

@ -199,13 +199,11 @@ std::string Context::dispatch ()
*/ */
// Command that display IDs and therefore need TDB::gc first. // Command that display IDs and therefore need TDB::gc first.
/* else if (cmd.command == "next") { if (!inShadow) gcMod = tdb.gc (); out = handleReportNext (); }
else if (command == "next") { if (!inShadow) gcMod = tdb.gc (); out = handleReportNext (); } else if (cmd.validCustom (cmd.command)) { if (!inShadow) gcMod = tdb.gc (); out = handleCustomReport (cmd.command); }
*/
else if (cmd.validCustom (cmd.command)) { if (!inShadow) gcMod = tdb.gc (); out = handleCustomReport (cmd.command); }
// If the command is not recognized, display usage. // If the command is not recognized, display usage.
else { out = shortUsage (); } else { out = shortUsage (); }
// Only update the shadow file if such an update was not suppressed (shadow), // Only update the shadow file if such an update was not suppressed (shadow),
// TODO // TODO

View file

@ -41,7 +41,7 @@ void validSortColumns (const std::vector <std::string>&, const std::vector <std:
bool validTag (const std::string&); bool validTag (const std::string&);
// task.cpp // task.cpp
void gatherNextTasks (/*const TDB&,*/ Task&, std::vector <Task>&, std::vector <int>&); void gatherNextTasks (std::vector <Task>&, std::vector <int>&);
void onChangeCallback (); void onChangeCallback ();
// recur.cpp // recur.cpp
@ -89,7 +89,6 @@ std::string handleReportGHistory ();
std::string handleReportCalendar (); std::string handleReportCalendar ();
std::string handleReportStats (); std::string handleReportStats ();
std::string handleReportTimesheet (); std::string handleReportTimesheet ();
std::string getFullDescription (Task&); std::string getFullDescription (Task&);
std::string getDueDate (Task&); std::string getDueDate (Task&);

View file

@ -51,7 +51,6 @@ extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string shortUsage () std::string shortUsage ()
{ {
std::stringstream out;
Table table; Table table;
table.addColumn (" "); table.addColumn (" ");
@ -202,6 +201,7 @@ std::string shortUsage ()
table.addCell (row, 2, description); table.addCell (row, 2, description);
} }
std::stringstream out;
out << table.render () out << table.render ()
<< std::endl << std::endl
<< "See http://taskwarrior.org/wiki/taskwarrior/Download for the latest " << "See http://taskwarrior.org/wiki/taskwarrior/Download for the latest "
@ -267,8 +267,6 @@ std::string longUsage ()
// Display all information for the given task. // Display all information for the given task.
std::string handleInfo () std::string handleInfo ()
{ {
std::stringstream out;
// Get all the tasks. // Get all the tasks.
std::vector <Task> tasks; std::vector <Task> tasks;
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.get ("locking", true));
@ -280,6 +278,7 @@ std::string handleInfo ()
context.filter.applySequence (tasks, context.sequence); context.filter.applySequence (tasks, context.sequence);
// Find the task. // Find the task.
std::stringstream out;
foreach (task, tasks) foreach (task, tasks)
{ {
Table table; Table table;
@ -648,22 +647,16 @@ std::string handleReportSummary ()
// //
std::string handleReportNext () std::string handleReportNext ()
{ {
std::stringstream out; // Get all the tasks.
/* std::vector <Task> tasks;
// Load all pending. context.tdb.lock (context.config.get ("locking", true));
std::vector <T> pending; context.tdb.loadPending (tasks, context.filter);
tdb.allPendingT (pending); context.tdb.unlock ();
handleRecurrence (tdb, pending); // TODO handleRecurrence (tdb, tasks);
filter (pending, task);
// Restrict to matching subset. // Restrict to matching subset.
std::vector <int> matching; std::vector <int> matching;
gatherNextTasks (tdb, task, pending, matching); gatherNextTasks (tasks, matching);
// Get the pending tasks.
std::vector <T> tasks;
tdb.pendingT (tasks);
filter (tasks, task);
initializeColorRules (); initializeColorRules ();
@ -712,13 +705,12 @@ std::string handleReportNext ()
// Iterate over each task, and apply selection criteria. // Iterate over each task, and apply selection criteria.
foreach (i, matching) foreach (i, matching)
{ {
T refTask (pending[*i]);
Date now; Date now;
// Now format the matching task. // Now format the matching task.
bool imminent = false; bool imminent = false;
bool overdue = false; bool overdue = false;
std::string due = refTask.getAttribute ("due"); std::string due = tasks[*i].get ("due");
if (due.length ()) if (due.length ())
{ {
switch (getDueState (due)) switch (getDueState (due))
@ -734,44 +726,32 @@ std::string handleReportNext ()
} }
std::string active; std::string active;
if (refTask.has ("start")) if (tasks[*i].has ("start"))
active = "*"; active = "*";
std::string age; std::string age;
std::string created = refTask.getAttribute ("entry"); std::string created = tasks[*i].get ("entry");
if (created.length ()) if (created.length ())
{ {
Date dt (::atoi (created.c_str ())); Date dt (::atoi (created.c_str ()));
age = formatSeconds ((time_t) (now - dt)); age = formatSeconds ((time_t) (now - dt));
} }
// All criteria match, so add refTask to the output table. // All criteria match, so add tasks[*i] to the output table.
int row = table.addRow (); int row = table.addRow ();
table.addCell (row, 0, refTask.getId ()); table.addCell (row, 0, tasks[*i].id);
table.addCell (row, 1, refTask.getAttribute ("project")); table.addCell (row, 1, tasks[*i].get ("project"));
table.addCell (row, 2, refTask.getAttribute ("priority")); table.addCell (row, 2, tasks[*i].get ("priority"));
table.addCell (row, 3, due); table.addCell (row, 3, due);
table.addCell (row, 4, active); table.addCell (row, 4, active);
table.addCell (row, 5, age); table.addCell (row, 5, age);
table.addCell (row, 6, getFullDescription (tasks[*i]));
std::string description = refTask.getDescription ();
std::string when;
std::map <time_t, std::string> annotations;
refTask.getAnnotations (annotations);
foreach (anno, annotations)
{
Date dt (anno->first);
when = dt.toString (context.config.get ("dateformat", "m/d/Y"));
description += "\n" + when + " " + anno->second;
}
table.addCell (row, 6, description);
if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false))
{ {
Text::color fg = Text::colorCode (refTask.getAttribute ("fg")); Text::color fg = Text::colorCode (tasks[*i].get ("fg"));
Text::color bg = Text::colorCode (refTask.getAttribute ("bg")); Text::color bg = Text::colorCode (tasks[*i].get ("bg"));
autoColorize (refTask, fg, bg); autoColorize (tasks[*i], fg, bg);
table.setRowFg (row, fg); table.setRowFg (row, fg);
table.setRowBg (row, bg); table.setRowBg (row, bg);
@ -785,6 +765,7 @@ std::string handleReportNext ()
} }
} }
std::stringstream out;
if (table.rowCount ()) if (table.rowCount ())
out << optionalBlankLine () out << optionalBlankLine ()
<< table.render () << table.render ()
@ -795,7 +776,7 @@ std::string handleReportNext ()
else else
out << "No matches." out << "No matches."
<< std::endl; << std::endl;
*/
return out.str (); return out.str ();
} }
@ -1519,7 +1500,7 @@ std::string handleReportCalendar ()
{ {
if (it->has ("due")) if (it->has ("due"))
{ {
Date d (::atoi (it->getAttribute ("due").c_str ())); Date d (::atoi (it->get ("due").c_str ()));
if (d < oldest) oldest = d; if (d < oldest) oldest = d;
if (d > newest) newest = d; if (d > newest) newest = d;
@ -1801,9 +1782,7 @@ std::string handleReportStats ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void gatherNextTasks ( void gatherNextTasks (
// const TDB& tdb, std::vector <Task>& tasks,
Task& task,
std::vector <Task>& pending,
std::vector <int>& all) std::vector <int>& all)
{ {
// For counting tasks by project. // For counting tasks by project.
@ -1816,16 +1795,16 @@ void gatherNextTasks (
int limit = context.config.get ("next", 3); int limit = context.config.get ("next", 3);
// due:< 1wk, pri:* // due:< 1wk, pri:*
for (unsigned int i = 0; i < pending.size (); ++i) for (unsigned int i = 0; i < tasks.size (); ++i)
{ {
if (pending[i].getStatus () == Task::pending) if (tasks[i].getStatus () == Task::pending)
{ {
if (pending[i].has ("due")) if (tasks[i].has ("due"))
{ {
Date d (::atoi (pending[i].get ("due").c_str ())); Date d (::atoi (tasks[i].get ("due").c_str ()));
if (d < now + (7 * 24 * 60 * 60)) // if due:< 1wk if (d < now + (7 * 24 * 60 * 60)) // if due:< 1wk
{ {
std::string project = pending[i].get ("project"); std::string project = tasks[i].get ("project");
if (countByProject[project] < limit && matching.find (i) == matching.end ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];
@ -1837,16 +1816,16 @@ void gatherNextTasks (
} }
// due:*, pri:H // due:*, pri:H
for (unsigned int i = 0; i < pending.size (); ++i) for (unsigned int i = 0; i < tasks.size (); ++i)
{ {
if (pending[i].getStatus () == Task::pending) if (tasks[i].getStatus () == Task::pending)
{ {
if (pending[i].has ("due")) if (tasks[i].has ("due"))
{ {
std::string priority = pending[i].get ("priority"); std::string priority = tasks[i].get ("priority");
if (priority == "H") if (priority == "H")
{ {
std::string project = pending[i].get ("project"); std::string project = tasks[i].get ("project");
if (countByProject[project] < limit && matching.find (i) == matching.end ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];
@ -1858,14 +1837,14 @@ void gatherNextTasks (
} }
// pri:H // pri:H
for (unsigned int i = 0; i < pending.size (); ++i) for (unsigned int i = 0; i < tasks.size (); ++i)
{ {
if (pending[i].getStatus () == Task::pending) if (tasks[i].getStatus () == Task::pending)
{ {
std::string priority = pending[i].get ("priority"); std::string priority = tasks[i].get ("priority");
if (priority == "H") if (priority == "H")
{ {
std::string project = pending[i].get ("project"); std::string project = tasks[i].get ("project");
if (countByProject[project] < limit && matching.find (i) == matching.end ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];
@ -1876,16 +1855,16 @@ void gatherNextTasks (
} }
// due:*, pri:M // due:*, pri:M
for (unsigned int i = 0; i < pending.size (); ++i) for (unsigned int i = 0; i < tasks.size (); ++i)
{ {
if (pending[i].getStatus () == Task::pending) if (tasks[i].getStatus () == Task::pending)
{ {
if (pending[i].has ("due")) if (tasks[i].has ("due"))
{ {
std::string priority = pending[i].get ("priority"); std::string priority = tasks[i].get ("priority");
if (priority == "M") if (priority == "M")
{ {
std::string project = pending[i].get ("project"); std::string project = tasks[i].get ("project");
if (countByProject[project] < limit && matching.find (i) == matching.end ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];
@ -1897,14 +1876,14 @@ void gatherNextTasks (
} }
// pri:M // pri:M
for (unsigned int i = 0; i < pending.size (); ++i) for (unsigned int i = 0; i < tasks.size (); ++i)
{ {
if (pending[i].getStatus () == Task::pending) if (tasks[i].getStatus () == Task::pending)
{ {
std::string priority = pending[i].get ("priority"); std::string priority = tasks[i].get ("priority");
if (priority == "M") if (priority == "M")
{ {
std::string project = pending[i].get ("project"); std::string project = tasks[i].get ("project");
if (countByProject[project] < limit && matching.find (i) == matching.end ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];
@ -1915,16 +1894,16 @@ void gatherNextTasks (
} }
// due:*, pri:L // due:*, pri:L
for (unsigned int i = 0; i < pending.size (); ++i) for (unsigned int i = 0; i < tasks.size (); ++i)
{ {
if (pending[i].getStatus () == Task::pending) if (tasks[i].getStatus () == Task::pending)
{ {
if (pending[i].has ("due")) if (tasks[i].has ("due"))
{ {
std::string priority = pending[i].get ("priority"); std::string priority = tasks[i].get ("priority");
if (priority == "L") if (priority == "L")
{ {
std::string project = pending[i].get ("project"); std::string project = tasks[i].get ("project");
if (countByProject[project] < limit && matching.find (i) == matching.end ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];
@ -1936,14 +1915,14 @@ void gatherNextTasks (
} }
// pri:L // pri:L
for (unsigned int i = 0; i < pending.size (); ++i) for (unsigned int i = 0; i < tasks.size (); ++i)
{ {
if (pending[i].getStatus () == Task::pending) if (tasks[i].getStatus () == Task::pending)
{ {
std::string priority = pending[i].get ("priority"); std::string priority = tasks[i].get ("priority");
if (priority == "L") if (priority == "L")
{ {
std::string project = pending[i].get ("project"); std::string project = tasks[i].get ("project");
if (countByProject[project] < limit && matching.find (i) == matching.end ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];
@ -1954,16 +1933,16 @@ void gatherNextTasks (
} }
// due:, pri: // due:, pri:
for (unsigned int i = 0; i < pending.size (); ++i) for (unsigned int i = 0; i < tasks.size (); ++i)
{ {
if (pending[i].getStatus () == Task::pending) if (tasks[i].getStatus () == Task::pending)
{ {
if (pending[i].has ("due")) if (tasks[i].has ("due"))
{ {
std::string priority = pending[i].get ("priority"); std::string priority = tasks[i].get ("priority");
if (priority == "") if (priority == "")
{ {
std::string project = pending[i].get ("project"); std::string project = tasks[i].get ("project");
if (countByProject[project] < limit && matching.find (i) == matching.end ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];