From aff828c51b25958ea66b089ef3176e433e489312 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 8 Jun 2009 01:24:33 -0400 Subject: [PATCH] Integration - "tags" report - The "tags" report is now working under 1.8.0. --- src/Context.cpp | 2 +- src/command.cpp | 24 +++++++++++++----------- src/task.cpp | 1 - src/task.h | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index 2663fd197..472f7993a 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -163,8 +163,8 @@ void Context::dispatch () if (command == "export") { out = handleExport (tdb, task); } */ if (cmd.command == "projects") { out = handleProjects (); } + else if (cmd.command == "tags") { out = handleTags (); } /* - else if (command == "tags") { out = handleTags (tdb, task); } else if (command == "info") { out = handleInfo (tdb, task); } else if (command == "stats") { out = handleReportStats (tdb, task); } else if (command == "history") { out = handleReportHistory (tdb, task); } diff --git a/src/command.cpp b/src/command.cpp index 099e21199..5f03d0e0c 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -101,6 +101,7 @@ std::string handleProjects () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); int quantity = context.tdb.load (tasks, context.filter); + context.tdb.unlock (); // Scan all the tasks for their project name, building a map using project // names as keys. @@ -144,31 +145,31 @@ std::string handleProjects () out << "No projects." << std::endl; - context.tdb.unlock (); return out.str (); } //////////////////////////////////////////////////////////////////////////////// -std::string handleTags (TDB& tdb, T& task) +std::string handleTags () { std::stringstream out; - // Get all the tasks. - std::vector tasks; - tdb.pendingT (tasks); + context.filter.push_back (Att ("status", "pending")); + + std::vector tasks; + context.tdb.lock (context.config.get ("locking", true)); + int quantity = context.tdb.load (tasks, context.filter); + context.tdb.unlock (); // Scan all the tasks for their project name, building a map using project // names as keys. std::map unique; - for (unsigned int i = 0; i < tasks.size (); ++i) + foreach (t, tasks) { - T task (tasks[i]); - std::vector tags; - task.getTags (tags); + t->getTags (tags); - for (unsigned int t = 0; t < tags.size (); ++t) - unique[tags[t]] = ""; + foreach (tag, tags) + unique[*tag] = ""; } // Render a list of tag names from the map. @@ -180,6 +181,7 @@ std::string handleTags (TDB& tdb, T& task) out << optionalBlankLine () << unique.size () << (unique.size () == 1 ? " tag" : " tags") + << " (" << quantity << (quantity == 1 ? " task" : " tasks") << ")" << std::endl; else out << "No tags." diff --git a/src/task.cpp b/src/task.cpp index c67434893..a723bded6 100644 --- a/src/task.cpp +++ b/src/task.cpp @@ -453,7 +453,6 @@ std::string runTaskCommand ( // Read-only commands with no side effects. if (command == "export") { out = handleExport (tdb, task); } - else if (command == "tags") { out = handleTags (tdb, task); } else if (command == "info") { out = handleInfo (tdb, task); } else if (command == "stats") { out = handleReportStats (tdb, task); } else if (command == "history") { out = handleReportHistory (tdb, task); } diff --git a/src/task.h b/src/task.h index acca78aad..51e1e39ca 100644 --- a/src/task.h +++ b/src/task.h @@ -69,7 +69,7 @@ std::string handleExport (TDB&, T&); std::string handleDone (TDB&, T&); std::string handleModify (TDB&, T&); std::string handleProjects (); -std::string handleTags (TDB&, T&); +std::string handleTags (); std::string handleUndelete (TDB&, T&); std::string handleVersion (); std::string handleDelete (TDB&, T&);