From efe0b86708fcf84674018d5f690071072354586a Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 14 Jun 2009 14:02:14 -0400 Subject: [PATCH] Integration - report helper functions - Added getDueDate helper function. - Added getFullDescription (description + annotations) helper function. --- src/custom.cpp | 128 +++++++++++++++++++++++-------------------------- src/main.h | 3 ++ src/report.cpp | 120 +++++++++++++++++++--------------------------- 3 files changed, 113 insertions(+), 138 deletions(-) diff --git a/src/custom.cpp b/src/custom.cpp index 9c3df54a0..8e3ec4431 100644 --- a/src/custom.cpp +++ b/src/custom.cpp @@ -97,7 +97,7 @@ std::string handleCustomReport (const std::string& report) table.setTableWidth (context.getWidth ()); table.setDateFormat (context.config.get ("dateformat", "m/d/Y")); - for (unsigned int i = 0; i < tasks.size (); ++i) + foreach (task, tasks) table.addRow (); int columnCount = 0; @@ -111,8 +111,9 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::right); - for (unsigned int row = 0; row < tasks.size(); ++row) - table.addCell (row, columnCount, tasks[row].id); + int row = 0; + foreach (task, tasks) + table.addCell (++row, columnCount, task->id); } else if (*col == "uuid") @@ -121,8 +122,9 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::left); - for (unsigned int row = 0; row < tasks.size(); ++row) - table.addCell (row, columnCount, tasks[row].get ("uuid")); + int row = 0; + foreach (task, tasks) + table.addCell (++row, columnCount, task->get ("uuid")); } else if (*col == "project") @@ -131,8 +133,9 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::left); - for (unsigned int row = 0; row < tasks.size(); ++row) - table.addCell (row, columnCount, tasks[row].get ("project")); + int row = 0; + foreach (task, tasks) + table.addCell (++row, columnCount, task->get ("project")); } else if (*col == "priority") @@ -141,8 +144,9 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::left); - for (unsigned int row = 0; row < tasks.size(); ++row) - table.addCell (row, columnCount, tasks[row].get ("priority")); + int row = 0; + foreach (task, tasks) + table.addCell (++row, columnCount, task->get ("priority")); } else if (*col == "entry") @@ -151,15 +155,16 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::right); + int row = 0; 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 ()) { Date dt (::atoi (entered.c_str ())); 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.setColumnJustification (columnCount, Table::right); + int row = 0; 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 ()) { Date dt (::atoi (started.c_str ())); 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.setColumnJustification (columnCount, Table::right); + int row = 0; 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 ()) { Date dt (::atoi (started.c_str ())); 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.setColumnJustification (columnCount, Table::right); + int row = 0; std::string due; - for (unsigned int row = 0; row < tasks.size(); ++row) - { - 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); - } - } + foreach (task, tasks) + table.addCell (++row, columnCount, getDueDate (*task)); dueColumn = columnCount; } @@ -229,17 +229,18 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::right); + int row = 0; std::string created; std::string age; 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 ()) { Date dt (::atoi (created.c_str ())); 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.setColumnJustification (columnCount, Table::right); + int row = 0; std::string created; std::string age; 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 ()) { Date dt (::atoi (created.c_str ())); 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.setColumnJustification (columnCount, Table::left); - for (unsigned int row = 0; row < tasks.size(); ++row) - if (tasks[row].get ("start") != "") - table.addCell (row, columnCount, "*"); + int row = 0; + foreach (task, tasks) + if (task->get ("start") != "") + table.addCell (++row, columnCount, "*"); } else if (*col == "tags") @@ -282,13 +285,14 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::left); + int row = 0; std::vector all; 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); - 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.setColumnJustification (columnCount, Table::left); - for (unsigned int row = 0; row < tasks.size(); ++row) - table.addCell (row, columnCount, tasks[row].get ("description")); + int row = 0; + foreach (task, tasks) + table.addCell (++row, columnCount, task->get ("description")); } else if (*col == "description") @@ -308,23 +313,9 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::flexible); table.setColumnJustification (columnCount, Table::left); - std::string description; - std::string when; - for (unsigned int row = 0; row < tasks.size(); ++row) - { - description = tasks[row].get ("description"); - - std::vector 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); - } + int row = 0; + foreach (task, tasks) + table.addCell (++row, columnCount, getFullDescription (*task)); } else if (*col == "recur") @@ -333,8 +324,9 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::right); - for (unsigned int row = 0; row < tasks.size (); ++row) - table.addCell (row, columnCount, tasks[row].get ("recur")); + int row = 0; + foreach (task, tasks) + table.addCell (++row, columnCount, task->get ("recur")); } else if (*col == "recurrence_indicator") @@ -343,9 +335,10 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::right); - for (unsigned int row = 0; row < tasks.size (); ++row) - table.addCell (row, columnCount, - tasks[row].get ("recur") != "" ? "R" : ""); + int row = 0; + foreach (task, tasks) + table.addCell (++row, columnCount, + task->get ("recur") != "" ? "R" : ""); } else if (*col == "tag_indicator") @@ -354,9 +347,10 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::right); - for (unsigned int row = 0; row < tasks.size (); ++row) - table.addCell (row, columnCount, - tasks[row].getTagCount () ? "+" : ""); + int row = 0; + foreach (task, tasks) + table.addCell (++row, columnCount, + task->getTagCount () ? "+" : ""); } // Common to all columns. diff --git a/src/main.h b/src/main.h index b99e9e8f7..2cfd93dd0 100644 --- a/src/main.h +++ b/src/main.h @@ -90,6 +90,9 @@ std::string handleReportCalendar (); std::string handleReportStats (); std::string handleReportTimesheet (); +std::string getFullDescription (Task&); +std::string getDueDate (Task&); + // custom.cpp std::string handleCustomReport (const std::string&); diff --git a/src/report.cpp b/src/report.cpp index 12030abf5..92fb55bfe 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -308,11 +308,8 @@ std::string handleInfo () table.addCell (row, 0, "ID"); table.addCell (row, 1, task->id); - std::string status = task->getStatus () == Task::pending ? "Pending" - : task->getStatus () == Task::completed ? "Completed" - : task->getStatus () == Task::deleted ? "Deleted" - : task->getStatus () == Task::recurring ? "Recurring" - : ""; + std::string status = Task::statusToText (task->getStatus ()); + if (task->has ("parent")) status += " (Recurring)"; @@ -320,20 +317,9 @@ std::string handleInfo () table.addCell (row, 0, "Status"); table.addCell (row, 1, status); - std::string description = task->get ("description"); - std::string when; - std::vector 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 (); table.addCell (row, 0, "Description"); - table.addCell (row, 1, description); + table.addCell (row, 1, getFullDescription (*task)); if (task->has ("project")) { @@ -388,29 +374,25 @@ std::string handleInfo () // due (colored) bool imminent = false; bool overdue = false; - std::string due = task->get ("due"); - if (due != "") + if (task->has ("due")) { row = table.addRow (); table.addCell (row, 0, "Due"); - Date dt (::atoi (due.c_str ())); - due = dt.toString (context.config.get ("dateformat", "m/d/Y")); + Date dt (::atoi (task->get ("due").c_str ())); + std::string due = getDueDate (*task); table.addCell (row, 1, due); - if (due.length ()) - { - overdue = (dt < now) ? true : false; - Date nextweek = now + 7 * 86400; - imminent = dt < nextweek ? true : false; + overdue = (dt < now) ? 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 (overdue) - table.setCellFg (row, 1, Text::colorCode (context.config.get ("color.overdue", "red"))); - else if (imminent) - table.setCellFg (row, 1, Text::colorCode (context.config.get ("color.due", "yellow"))); - } + if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) + { + if (overdue) + table.setCellFg (row, 1, Text::colorCode (context.config.get ("color.overdue", "red"))); + else if (imminent) + table.setCellFg (row, 1, Text::colorCode (context.config.get ("color.due", "yellow"))); } } @@ -1262,25 +1244,8 @@ std::string handleReportTimesheet () { int row = completed.addRow (); completed.addCell (row, 1, task->get ("project")); - - 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")); - completed.addCell (row, 2, due); - } - - std::string description = task->get ("description"); - std::vector 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); + completed.addCell (row, 2, getDueDate (*task)); + completed.addCell (row, 3, getFullDescription (*task)); if (context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) { @@ -1332,25 +1297,8 @@ std::string handleReportTimesheet () { int row = started.addRow (); started.addCell (row, 1, task->get ("project")); - - 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")); - started.addCell (row, 2, due); - } - - std::string description = task->get ("description"); - std::vector 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); + started.addCell (row, 2, getDueDate (*task)); + started.addCell (row, 3, getFullDescription (*task)); 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 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; +} + +///////////////////////////////////////////////////////////////////////////////