diff --git a/src/Context.cpp b/src/Context.cpp index 13c3e8e60..91dc1f96a 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -174,8 +174,8 @@ std::string Context::dispatch () else if (cmd.command == "stats") { out = handleReportStats (); } else if (cmd.command == "info") { out = handleInfo (); } else if (cmd.command == "history") { out = handleReportHistory (); } -/* else if (cmd.command == "ghistory") { out = handleReportGHistory (); } +/* else if (cmd.command == "calendar") { out = handleReportCalendar (); } else if (cmd.command == "summary") { out = handleReportSummary (); } else if (cmd.command == "timesheet") { out = handleReportTimesheet (); } diff --git a/src/report.cpp b/src/report.cpp index ce0e7a6b8..bbd973f23 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -993,97 +993,55 @@ std::string handleReportHistory () //////////////////////////////////////////////////////////////////////////////// std::string handleReportGHistory () { - std::stringstream out; - -/* - int widthOfBar = width - 15; // 15 == strlen ("2008 September ") - - std::map groups; - std::map addedGroup; - std::map completedGroup; - std::map deletedGroup; + std::map groups; // Represents any month with data + std::map addedGroup; // Additions by month + std::map completedGroup; // Completions by month + std::map deletedGroup; // Deletions by month // Scan the pending tasks. - std::vector pending; - tdb.allPendingT (pending); - handleRecurrence (tdb, pending); - filter (pending, task); - for (unsigned int i = 0; i < pending.size (); ++i) + std::vector tasks; + context.tdb.lock (context.config.get ("locking", true)); + context.tdb.load (tasks, context.filter); + context.tdb.unlock (); + // TODO handleRecurrence (tdb, tasks); + + foreach (task, tasks) { - T task (pending[i]); - time_t epoch = monthlyEpoch (task.getAttribute ("entry")); - if (epoch) + time_t epoch = monthlyEpoch (task->get ("entry")); + groups[epoch] = 0; + + // Every task has an entry date. + if (addedGroup.find (epoch) != addedGroup.end ()) + addedGroup[epoch] = addedGroup[epoch] + 1; + else + addedGroup[epoch] = 1; + + // All deleted tasks have an end date. + if (task->getStatus () == Task::deleted) { + epoch = monthlyEpoch (task->get ("end")); groups[epoch] = 0; - if (addedGroup.find (epoch) != addedGroup.end ()) - addedGroup[epoch] = addedGroup[epoch] + 1; + if (deletedGroup.find (epoch) != deletedGroup.end ()) + deletedGroup[epoch] = deletedGroup[epoch] + 1; else - addedGroup[epoch] = 1; + deletedGroup[epoch] = 1; + } - if (task.getStatus () == T::deleted) - { - epoch = monthlyEpoch (task.getAttribute ("end")); - groups[epoch] = 0; + // All completed tasks have an end date. + else if (task->getStatus () == Task::completed) + { + epoch = monthlyEpoch (task->get ("end")); + groups[epoch] = 0; - if (deletedGroup.find (epoch) != deletedGroup.end ()) - deletedGroup[epoch] = deletedGroup[epoch] + 1; - else - deletedGroup[epoch] = 1; - } - else if (task.getStatus () == T::completed) - { - epoch = monthlyEpoch (task.getAttribute ("end")); - groups[epoch] = 0; - - if (completedGroup.find (epoch) != completedGroup.end ()) - completedGroup[epoch] = completedGroup[epoch] + 1; - else - completedGroup[epoch] = 1; - } + if (completedGroup.find (epoch) != completedGroup.end ()) + completedGroup[epoch] = completedGroup[epoch] + 1; + else + completedGroup[epoch] = 1; } } - // Scan the completed tasks. - std::vector completed; - tdb.allCompletedT (completed); - filter (completed, task); - for (unsigned int i = 0; i < completed.size (); ++i) - { - T task (completed[i]); - time_t epoch = monthlyEpoch (task.getAttribute ("entry")); - if (epoch) - { - groups[epoch] = 0; - - if (addedGroup.find (epoch) != addedGroup.end ()) - addedGroup[epoch] = addedGroup[epoch] + 1; - else - addedGroup[epoch] = 1; - - epoch = monthlyEpoch (task.getAttribute ("end")); - if (task.getStatus () == T::deleted) - { - epoch = monthlyEpoch (task.getAttribute ("end")); - groups[epoch] = 0; - - if (deletedGroup.find (epoch) != deletedGroup.end ()) - deletedGroup[epoch] = deletedGroup[epoch] + 1; - else - deletedGroup[epoch] = 1; - } - else if (task.getStatus () == T::completed) - { - epoch = monthlyEpoch (task.getAttribute ("end")); - groups[epoch] = 0; - - if (completedGroup.find (epoch) != completedGroup.end ()) - completedGroup[epoch] = completedGroup[epoch] + 1; - else - completedGroup[epoch] = 1; - } - } - } + int widthOfBar = context.getWidth () - 15; // 15 == strlen ("2008 September ") // Now build the table. Table table; @@ -1202,6 +1160,7 @@ std::string handleReportGHistory () } } + std::stringstream out; if (table.rowCount ()) { out << optionalBlankLine () @@ -1222,7 +1181,7 @@ std::string handleReportGHistory () } else out << "No tasks." << std::endl; -*/ + return out.str (); }