Integration - report helper functions

- Added getDueDate helper function.
- Added getFullDescription (description + annotations) helper function.
This commit is contained in:
Paul Beckingham 2009-06-14 14:02:14 -04:00
parent 8529daaf28
commit efe0b86708
3 changed files with 113 additions and 138 deletions

View file

@ -97,7 +97,7 @@ std::string handleCustomReport (const std::string& report)
table.setTableWidth (context.getWidth ()); table.setTableWidth (context.getWidth ());
table.setDateFormat (context.config.get ("dateformat", "m/d/Y")); table.setDateFormat (context.config.get ("dateformat", "m/d/Y"));
for (unsigned int i = 0; i < tasks.size (); ++i) foreach (task, tasks)
table.addRow (); table.addRow ();
int columnCount = 0; int columnCount = 0;
@ -111,8 +111,9 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
for (unsigned int row = 0; row < tasks.size(); ++row) int row = 0;
table.addCell (row, columnCount, tasks[row].id); foreach (task, tasks)
table.addCell (++row, columnCount, task->id);
} }
else if (*col == "uuid") else if (*col == "uuid")
@ -121,8 +122,9 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::left); table.setColumnJustification (columnCount, Table::left);
for (unsigned int row = 0; row < tasks.size(); ++row) int row = 0;
table.addCell (row, columnCount, tasks[row].get ("uuid")); foreach (task, tasks)
table.addCell (++row, columnCount, task->get ("uuid"));
} }
else if (*col == "project") else if (*col == "project")
@ -131,8 +133,9 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::left); table.setColumnJustification (columnCount, Table::left);
for (unsigned int row = 0; row < tasks.size(); ++row) int row = 0;
table.addCell (row, columnCount, tasks[row].get ("project")); foreach (task, tasks)
table.addCell (++row, columnCount, task->get ("project"));
} }
else if (*col == "priority") else if (*col == "priority")
@ -141,8 +144,9 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::left); table.setColumnJustification (columnCount, Table::left);
for (unsigned int row = 0; row < tasks.size(); ++row) int row = 0;
table.addCell (row, columnCount, tasks[row].get ("priority")); foreach (task, tasks)
table.addCell (++row, columnCount, task->get ("priority"));
} }
else if (*col == "entry") else if (*col == "entry")
@ -151,15 +155,16 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
int row = 0;
std::string entered; std::string entered;
for (unsigned int row = 0; row < tasks.size(); ++row) foreach (task, tasks)
{ {
entered = tasks[row].get ("entry"); entered = task->get ("entry");
if (entered.length ()) if (entered.length ())
{ {
Date dt (::atoi (entered.c_str ())); Date dt (::atoi (entered.c_str ()));
entered = dt.toString (context.config.get ("dateformat", "m/d/Y")); entered = dt.toString (context.config.get ("dateformat", "m/d/Y"));
table.addCell (row, columnCount, entered); table.addCell (++row, columnCount, entered);
} }
} }
} }
@ -170,15 +175,16 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
int row = 0;
std::string started; std::string started;
for (unsigned int row = 0; row < tasks.size(); ++row) foreach (task, tasks)
{ {
started = tasks[row].get ("start"); started = task->get ("start");
if (started.length ()) if (started.length ())
{ {
Date dt (::atoi (started.c_str ())); Date dt (::atoi (started.c_str ()));
started = dt.toString (context.config.get ("dateformat", "m/d/Y")); started = dt.toString (context.config.get ("dateformat", "m/d/Y"));
table.addCell (row, columnCount, started); table.addCell (++row, columnCount, started);
} }
} }
} }
@ -189,15 +195,16 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
int row = 0;
std::string started; std::string started;
for (unsigned int row = 0; row < tasks.size(); ++row) foreach (task, tasks)
{ {
started = tasks[row].get ("end"); started = task->get ("end");
if (started.length ()) if (started.length ())
{ {
Date dt (::atoi (started.c_str ())); Date dt (::atoi (started.c_str ()));
started = dt.toString (context.config.get ("dateformat", "m/d/Y")); started = dt.toString (context.config.get ("dateformat", "m/d/Y"));
table.addCell (row, columnCount, started); table.addCell (++row, columnCount, started);
} }
} }
} }
@ -208,17 +215,10 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
int row = 0;
std::string due; std::string due;
for (unsigned int row = 0; row < tasks.size(); ++row) foreach (task, tasks)
{ table.addCell (++row, columnCount, getDueDate (*task));
due = tasks[row].get ("due");
if (due.length ())
{
Date dt (::atoi (due.c_str ()));
due = dt.toString (context.config.get ("dateformat", "m/d/Y"));
table.addCell (row, columnCount, due);
}
}
dueColumn = columnCount; dueColumn = columnCount;
} }
@ -229,17 +229,18 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
int row = 0;
std::string created; std::string created;
std::string age; std::string age;
Date now; Date now;
for (unsigned int row = 0; row < tasks.size(); ++row) foreach (task, tasks)
{ {
created = tasks[row].get ("entry"); created = task->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));
table.addCell (row, columnCount, age); table.addCell (++row, columnCount, age);
} }
} }
} }
@ -250,17 +251,18 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
int row = 0;
std::string created; std::string created;
std::string age; std::string age;
Date now; Date now;
for (unsigned int row = 0; row < tasks.size(); ++row) foreach (task, tasks)
{ {
created = tasks[row].get ("entry"); created = task->get ("entry");
if (created.length ()) if (created.length ())
{ {
Date dt (::atoi (created.c_str ())); Date dt (::atoi (created.c_str ()));
age = formatSecondsCompact ((time_t) (now - dt)); age = formatSecondsCompact ((time_t) (now - dt));
table.addCell (row, columnCount, age); table.addCell (++row, columnCount, age);
} }
} }
} }
@ -271,9 +273,10 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::left); table.setColumnJustification (columnCount, Table::left);
for (unsigned int row = 0; row < tasks.size(); ++row) int row = 0;
if (tasks[row].get ("start") != "") foreach (task, tasks)
table.addCell (row, columnCount, "*"); if (task->get ("start") != "")
table.addCell (++row, columnCount, "*");
} }
else if (*col == "tags") else if (*col == "tags")
@ -282,13 +285,14 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::left); table.setColumnJustification (columnCount, Table::left);
int row = 0;
std::vector <std::string> all; std::vector <std::string> all;
std::string tags; std::string tags;
for (unsigned int row = 0; row < tasks.size(); ++row) foreach (task, tasks)
{ {
tasks[row].getTags (all); task->getTags (all);
join (tags, " ", all); join (tags, " ", all);
table.addCell (row, columnCount, tags); table.addCell (++row, columnCount, tags);
} }
} }
@ -298,8 +302,9 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::flexible); table.setColumnWidth (columnCount, Table::flexible);
table.setColumnJustification (columnCount, Table::left); table.setColumnJustification (columnCount, Table::left);
for (unsigned int row = 0; row < tasks.size(); ++row) int row = 0;
table.addCell (row, columnCount, tasks[row].get ("description")); foreach (task, tasks)
table.addCell (++row, columnCount, task->get ("description"));
} }
else if (*col == "description") else if (*col == "description")
@ -308,23 +313,9 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::flexible); table.setColumnWidth (columnCount, Table::flexible);
table.setColumnJustification (columnCount, Table::left); table.setColumnJustification (columnCount, Table::left);
std::string description; int row = 0;
std::string when; foreach (task, tasks)
for (unsigned int row = 0; row < tasks.size(); ++row) table.addCell (++row, columnCount, getFullDescription (*task));
{
description = tasks[row].get ("description");
std::vector <Att> annotations;
tasks[row].getAnnotations (annotations);
foreach (anno, annotations)
{
Date dt (::atoi (anno->name ().substr (11, std::string::npos).c_str ()));
when = dt.toString (context.config.get ("dateformat", "m/d/Y"));
description += "\n" + when + " " + anno->value ();
}
table.addCell (row, columnCount, description);
}
} }
else if (*col == "recur") else if (*col == "recur")
@ -333,8 +324,9 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
for (unsigned int row = 0; row < tasks.size (); ++row) int row = 0;
table.addCell (row, columnCount, tasks[row].get ("recur")); foreach (task, tasks)
table.addCell (++row, columnCount, task->get ("recur"));
} }
else if (*col == "recurrence_indicator") else if (*col == "recurrence_indicator")
@ -343,9 +335,10 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
for (unsigned int row = 0; row < tasks.size (); ++row) int row = 0;
table.addCell (row, columnCount, foreach (task, tasks)
tasks[row].get ("recur") != "" ? "R" : ""); table.addCell (++row, columnCount,
task->get ("recur") != "" ? "R" : "");
} }
else if (*col == "tag_indicator") else if (*col == "tag_indicator")
@ -354,9 +347,10 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
for (unsigned int row = 0; row < tasks.size (); ++row) int row = 0;
table.addCell (row, columnCount, foreach (task, tasks)
tasks[row].getTagCount () ? "+" : ""); table.addCell (++row, columnCount,
task->getTagCount () ? "+" : "");
} }
// Common to all columns. // Common to all columns.

View file

@ -90,6 +90,9 @@ std::string handleReportCalendar ();
std::string handleReportStats (); std::string handleReportStats ();
std::string handleReportTimesheet (); std::string handleReportTimesheet ();
std::string getFullDescription (Task&);
std::string getDueDate (Task&);
// custom.cpp // custom.cpp
std::string handleCustomReport (const std::string&); std::string handleCustomReport (const std::string&);

View file

@ -308,11 +308,8 @@ std::string handleInfo ()
table.addCell (row, 0, "ID"); table.addCell (row, 0, "ID");
table.addCell (row, 1, task->id); table.addCell (row, 1, task->id);
std::string status = task->getStatus () == Task::pending ? "Pending" std::string status = Task::statusToText (task->getStatus ());
: task->getStatus () == Task::completed ? "Completed"
: task->getStatus () == Task::deleted ? "Deleted"
: task->getStatus () == Task::recurring ? "Recurring"
: "";
if (task->has ("parent")) if (task->has ("parent"))
status += " (Recurring)"; status += " (Recurring)";
@ -320,20 +317,9 @@ std::string handleInfo ()
table.addCell (row, 0, "Status"); table.addCell (row, 0, "Status");
table.addCell (row, 1, status); table.addCell (row, 1, status);
std::string description = task->get ("description");
std::string when;
std::vector <Att> annotations;
task->getAnnotations (annotations);
foreach (anno, annotations)
{
Date dt (::atoi (anno->name ().substr (11, std::string::npos).c_str ()));
when = dt.toString (context.config.get ("dateformat", "m/d/Y"));
description += "\n" + when + " " + anno->value ();
}
row = table.addRow (); row = table.addRow ();
table.addCell (row, 0, "Description"); table.addCell (row, 0, "Description");
table.addCell (row, 1, description); table.addCell (row, 1, getFullDescription (*task));
if (task->has ("project")) if (task->has ("project"))
{ {
@ -388,29 +374,25 @@ std::string handleInfo ()
// due (colored) // due (colored)
bool imminent = false; bool imminent = false;
bool overdue = false; bool overdue = false;
std::string due = task->get ("due"); if (task->has ("due"))
if (due != "")
{ {
row = table.addRow (); row = table.addRow ();
table.addCell (row, 0, "Due"); table.addCell (row, 0, "Due");
Date dt (::atoi (due.c_str ())); Date dt (::atoi (task->get ("due").c_str ()));
due = dt.toString (context.config.get ("dateformat", "m/d/Y")); std::string due = getDueDate (*task);
table.addCell (row, 1, due); table.addCell (row, 1, due);
if (due.length ()) overdue = (dt < now) ? true : false;
{ Date nextweek = now + 7 * 86400;
overdue = (dt < now) ? true : false; imminent = dt < nextweek ? true : false;
Date nextweek = now + 7 * 86400;
imminent = dt < nextweek ? true : false;
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))
{ {
if (overdue) if (overdue)
table.setCellFg (row, 1, Text::colorCode (context.config.get ("color.overdue", "red"))); table.setCellFg (row, 1, Text::colorCode (context.config.get ("color.overdue", "red")));
else if (imminent) else if (imminent)
table.setCellFg (row, 1, Text::colorCode (context.config.get ("color.due", "yellow"))); table.setCellFg (row, 1, Text::colorCode (context.config.get ("color.due", "yellow")));
}
} }
} }
@ -1262,25 +1244,8 @@ std::string handleReportTimesheet ()
{ {
int row = completed.addRow (); int row = completed.addRow ();
completed.addCell (row, 1, task->get ("project")); completed.addCell (row, 1, task->get ("project"));
completed.addCell (row, 2, getDueDate (*task));
std::string due = task->get ("due"); completed.addCell (row, 3, getFullDescription (*task));
if (due.length ())
{
Date d (::atoi (due.c_str ()));
due = d.toString (context.config.get ("dateformat", "m/d/Y"));
completed.addCell (row, 2, due);
}
std::string description = task->get ("description");
std::vector <Att> annotations;
tasks[row].getAnnotations (annotations);
foreach (anno, annotations)
{
Date dt (::atoi (anno->name ().substr (11, std::string::npos).c_str ()));
std::string when = dt.toString (context.config.get ("dateformat", "m/d/Y"));
description += "\n" + when + " " + anno->value ();
}
completed.addCell (row, 3, 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))
{ {
@ -1332,25 +1297,8 @@ std::string handleReportTimesheet ()
{ {
int row = started.addRow (); int row = started.addRow ();
started.addCell (row, 1, task->get ("project")); started.addCell (row, 1, task->get ("project"));
started.addCell (row, 2, getDueDate (*task));
std::string due = task->get ("due"); started.addCell (row, 3, getFullDescription (*task));
if (due.length ())
{
Date d (::atoi (due.c_str ()));
due = d.toString (context.config.get ("dateformat", "m/d/Y"));
started.addCell (row, 2, due);
}
std::string description = task->get ("description");
std::vector <Att> annotations;
tasks[row].getAnnotations (annotations);
foreach (anno, annotations)
{
Date dt (::atoi (anno->name ().substr (11, std::string::npos).c_str ()));
std::string when = dt.toString (context.config.get ("dateformat", "m/d/Y"));
description += "\n" + when + " " + anno->value ();
}
started.addCell (row, 3, 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))
{ {
@ -2030,3 +1978,33 @@ void gatherNextTasks (
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
std::string getFullDescription (Task& task)
{
std::string desc = task.get ("description");
std::vector <Att> annotations;
task.getAnnotations (annotations);
foreach (anno, annotations)
{
Date dt (::atoi (anno->name ().substr (11, std::string::npos).c_str ()));
std::string when = dt.toString (context.config.get ("dateformat", "m/d/Y"));
desc += "\n" + when + " " + anno->value ();
}
return desc;
}
///////////////////////////////////////////////////////////////////////////////
std::string getDueDate (Task& task)
{
std::string due = task.get ("due");
if (due.length ())
{
Date d (::atoi (due.c_str ()));
due = d.toString (context.config.get ("dateformat", "m/d/Y"));
}
return due;
}
///////////////////////////////////////////////////////////////////////////////