diff --git a/src/commands/CmdBurndown.cpp b/src/commands/CmdBurndown.cpp index 7d34da84d..b75d472c0 100644 --- a/src/commands/CmdBurndown.cpp +++ b/src/commands/CmdBurndown.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -392,8 +393,8 @@ void Chart::scan (std::vector & tasks) // | 21 22 23 24 25 26 27 28 29 30 31 01 02 03 04 05 06 | // | July August | // | | -// | Find rate 1.7/d Estimated completion 8/12/2010 | -// | Fix rate 1.3/d | +// | Add rate 1.7/d Estimated completion 8/12/2010 | +// | Don/Delete rate 1.3/d | // +---------------------------------------------------------------------+ std::string Chart::render () { @@ -522,14 +523,14 @@ std::string Chart::render () else strcpy (rate, "-"); - grid.replace (LOC (height - 2, max_label + 3), 11 + strlen (rate), std::string ("Find rate: ") + rate); + grid.replace (LOC (height - 2, max_label + 3), 11 + strlen (rate), std::string ("Add rate: ") + rate); if (fix_rate != 0.0) sprintf (rate, "%.1f/d", fix_rate); else strcpy (rate, "-"); - grid.replace (LOC (height - 1, max_label + 3), 11 + strlen (rate), std::string ("Fix rate: ") + rate); + grid.replace (LOC (height - 1, max_label + 3), 11 + strlen (rate), std::string ("Done/Delete rate: ") + rate); // Draw completion date. if (completion.length ()) @@ -982,43 +983,39 @@ int CmdBurndownMonthly::execute (std::string& output) { int rc = 0; -/* // Scan the pending tasks, applying any filter. std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); - context.tdb.load (tasks, context.filter); + Filter filter; + context.tdb.load (tasks, filter); context.tdb.commit (); context.tdb.unlock (); + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + // Create a chart, scan the tasks, then render. Chart chart ('M'); // Use any filter as a title. - if (context.filter.size ()) + if (context.args.size () > 2) { - std::string combined = "("; - - for (unsigned int i = 0; i < context.filter.size (); ++i) - { - if (i) - combined += " "; - - combined += context.filter[i].name (); - - if (context.filter[i].mod ().length ()) - combined += "." + context.filter[i].mod (); - - combined += ":" + context.filter[i].value (); - } - - combined += ")"; + std::string combined = "(" + + context.args.extract_read_only_filter ().combine () + + ")"; chart.description (combined); } - chart.scan (tasks); + chart.scan (filtered); output = chart.render (); -*/ return rc; } @@ -1037,43 +1034,39 @@ int CmdBurndownWeekly::execute (std::string& output) { int rc = 0; -/* // Scan the pending tasks, applying any filter. std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); - context.tdb.load (tasks, context.filter); + Filter filter; + context.tdb.load (tasks, filter); context.tdb.commit (); context.tdb.unlock (); + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + // Create a chart, scan the tasks, then render. Chart chart ('W'); // Use any filter as a title. - if (context.filter.size ()) + if (context.args.size () > 2) { - std::string combined = "("; - - for (unsigned int i = 0; i < context.filter.size (); ++i) - { - if (i) - combined += " "; - - combined += context.filter[i].name (); - - if (context.filter[i].mod ().length ()) - combined += "." + context.filter[i].mod (); - - combined += ":" + context.filter[i].value (); - } - - combined += ")"; + std::string combined = "(" + + context.args.extract_read_only_filter ().combine () + + ")"; chart.description (combined); } - chart.scan (tasks); + chart.scan (filtered); output = chart.render (); -*/ return rc; } @@ -1092,43 +1085,39 @@ int CmdBurndownDaily::execute (std::string& output) { int rc = 0; -/* // Scan the pending tasks, applying any filter. std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); - context.tdb.load (tasks, context.filter); + Filter filter; + context.tdb.load (tasks, filter); context.tdb.commit (); context.tdb.unlock (); + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + // Create a chart, scan the tasks, then render. Chart chart ('D'); // Use any filter as a title. - if (context.filter.size ()) + if (context.args.size () > 2) { - std::string combined = "("; - - for (unsigned int i = 0; i < context.filter.size (); ++i) - { - if (i) - combined += " "; - - combined += context.filter[i].name (); - - if (context.filter[i].mod ().length ()) - combined += "." + context.filter[i].mod (); - - combined += ":" + context.filter[i].value (); - } - - combined += ")"; + std::string combined = "(" + + context.args.extract_read_only_filter ().combine () + + ")"; chart.description (combined); } - chart.scan (tasks); + chart.scan (filtered); output = chart.render (); -*/ return rc; } diff --git a/src/commands/CmdHistory.cpp b/src/commands/CmdHistory.cpp index 6c4d1b29b..e0ec5c679 100644 --- a/src/commands/CmdHistory.cpp +++ b/src/commands/CmdHistory.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -48,7 +49,7 @@ CmdHistoryMonthly::CmdHistoryMonthly () int CmdHistoryMonthly::execute (std::string& output) { int rc = 0; -/* + std::map groups; // Represents any month with data std::map addedGroup; // Additions by month std::map completedGroup; // Completions by month @@ -58,12 +59,22 @@ int CmdHistoryMonthly::execute (std::string& output) std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); - context.tdb.load (tasks, context.filter); + Filter filter; + context.tdb.load (tasks, filter); context.tdb.commit (); context.tdb.unlock (); + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; std::vector ::iterator task; for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + + for (task = filtered.begin (); task != filtered.end (); ++task) { Date entry (task->get ("entry")); @@ -188,7 +199,6 @@ int CmdHistoryMonthly::execute (std::string& output) } output = out.str (); -*/ return rc; } @@ -206,7 +216,6 @@ CmdHistoryAnnual::CmdHistoryAnnual () int CmdHistoryAnnual::execute (std::string& output) { int rc = 0; -/* std::map groups; // Represents any month with data std::map addedGroup; // Additions by month std::map completedGroup; // Completions by month @@ -216,12 +225,22 @@ int CmdHistoryAnnual::execute (std::string& output) std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); - context.tdb.load (tasks, context.filter); + Filter filter; + context.tdb.load (tasks, filter); context.tdb.commit (); context.tdb.unlock (); + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; std::vector ::iterator task; for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + + for (task = filtered.begin (); task != filtered.end (); ++task) { Date entry (task->get ("entry")); @@ -343,7 +362,6 @@ int CmdHistoryAnnual::execute (std::string& output) } output = out.str (); -*/ return rc; } @@ -361,7 +379,6 @@ CmdGHistoryMonthly::CmdGHistoryMonthly () int CmdGHistoryMonthly::execute (std::string& output) { int rc = 0; -/* std::map groups; // Represents any month with data std::map addedGroup; // Additions by month std::map completedGroup; // Completions by month @@ -371,12 +388,22 @@ int CmdGHistoryMonthly::execute (std::string& output) std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); - context.tdb.load (tasks, context.filter); + Filter filter; + context.tdb.load (tasks, filter); context.tdb.commit (); context.tdb.unlock (); + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; std::vector ::iterator task; for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + + for (task = filtered.begin (); task != filtered.end (); ++task) { Date entry (task->get ("entry")); @@ -541,7 +568,6 @@ int CmdGHistoryMonthly::execute (std::string& output) } output = out.str (); -*/ return rc; } @@ -559,7 +585,6 @@ CmdGHistoryAnnual::CmdGHistoryAnnual () int CmdGHistoryAnnual::execute (std::string& output) { int rc = 0; -/* std::map groups; // Represents any month with data std::map addedGroup; // Additions by month std::map completedGroup; // Completions by month @@ -569,12 +594,22 @@ int CmdGHistoryAnnual::execute (std::string& output) std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); - context.tdb.load (tasks, context.filter); + Filter filter; + context.tdb.load (tasks, filter); context.tdb.commit (); context.tdb.unlock (); + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; std::vector ::iterator task; for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + + for (task = filtered.begin (); task != filtered.end (); ++task) { Date entry (task->get ("entry")); @@ -736,7 +771,6 @@ int CmdGHistoryAnnual::execute (std::string& output) } output = out.str (); -*/ return rc; } diff --git a/src/commands/CmdIDs.cpp b/src/commands/CmdIDs.cpp index cc1a03902..ee9f67dc4 100644 --- a/src/commands/CmdIDs.cpp +++ b/src/commands/CmdIDs.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -47,25 +48,33 @@ CmdIDs::CmdIDs () //////////////////////////////////////////////////////////////////////////////// int CmdIDs::execute (std::string& output) { -/* // Scan the pending tasks, applying any filter. std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); - context.tdb.load (tasks, context.filter); + Filter filter; + context.tdb.load (tasks, filter); context.tdb.commit (); context.tdb.unlock (); - // Find number of matching tasks. - std::vector ids; + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; std::vector ::iterator task; for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + + // Find number of matching tasks. + std::vector ids; + for (task = filtered.begin (); task != filtered.end (); ++task) if (task->id) ids.push_back (task->id); std::sort (ids.begin (), ids.end ()); output = compressIds (ids) + "\n"; -*/ return 0; } @@ -89,9 +98,18 @@ int CmdCompletionIds::execute (std::string& output) context.tdb.commit (); context.tdb.unlock (); - std::vector ids; + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; std::vector ::iterator task; for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + + std::vector ids; + for (task = filtered.begin (); task != filtered.end (); ++task) if (task->getStatus () != Task::deleted && task->getStatus () != Task::completed) ids.push_back (task->id); @@ -127,9 +145,18 @@ int CmdZshCompletionIds::execute (std::string& output) context.tdb.commit (); context.tdb.unlock (); - std::stringstream out; + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; std::vector ::iterator task; for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + + std::stringstream out; + for (task = filtered.begin (); task != filtered.end (); ++task) if (task->getStatus () != Task::deleted && task->getStatus () != Task::completed) out << task->id diff --git a/src/commands/CmdInfo.cpp b/src/commands/CmdInfo.cpp index 33adbef1a..799be917a 100644 --- a/src/commands/CmdInfo.cpp +++ b/src/commands/CmdInfo.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -51,17 +52,24 @@ int CmdInfo::execute (std::string& output) { int rc = 0; -/* // Get all the tasks. std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); - context.tdb.loadPending (tasks, context.filter); + Filter filter; + context.tdb.loadPending (tasks, filter); context.tdb.commit (); context.tdb.unlock (); - // Filter sequence. - context.filter.applySequence (tasks, context.sequence); + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); // Read the undo file. std::vector undo; @@ -74,8 +82,7 @@ int CmdInfo::execute (std::string& output) // Find the task. std::stringstream out; - std::vector ::iterator task; - for (task = tasks.begin (); task != tasks.end (); ++task) + for (task = filtered.begin (); task != filtered.end (); ++task) { ViewText view; view.width (context.getWidth ()); @@ -391,14 +398,13 @@ int CmdInfo::execute (std::string& output) << "\n"; } - if (! tasks.size ()) + if (! filtered.size ()) { out << "No matches.\n"; rc = 1; } output = out.str (); -*/ return rc; } diff --git a/src/commands/CmdQuery.cpp b/src/commands/CmdQuery.cpp index 1d8d1d4cf..562d7fea6 100644 --- a/src/commands/CmdQuery.cpp +++ b/src/commands/CmdQuery.cpp @@ -26,6 +26,7 @@ //////////////////////////////////////////////////////////////////////////////// #include +#include #include #include @@ -46,39 +47,44 @@ int CmdQuery::execute (std::string& output) { int rc = 0; -/* // Get all the tasks. std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); - context.tdb.load (tasks, context.filter); + Filter filter; + context.tdb.load (tasks, filter); context.tdb.commit (); context.tdb.unlock (); - // Filter sequence. - if (context.sequence.size ()) - context.filter.applySequence (tasks, context.sequence); + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); - if (tasks.size () == 0) + std::vector filtered; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + + if (filtered.size () == 0) { context.footnote ("No matches."); return 1; } // Note: "limit:" feature not supported. + // TODO Why not? // Compose output. - std::vector ::iterator t; - for (t = tasks.begin (); t != tasks.end (); ++t) + for (task = filtered.begin (); task != filtered.end (); ++task) { - if (t != tasks.begin ()) + if (task != filtered.begin ()) output += ",\n"; - output += t->composeJSON (true); + output += task->composeJSON (true); } output += "\n"; -*/ return rc; } diff --git a/src/commands/CmdStatistics.cpp b/src/commands/CmdStatistics.cpp index 000b9bb9b..6204dec61 100644 --- a/src/commands/CmdStatistics.cpp +++ b/src/commands/CmdStatistics.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -42,7 +43,7 @@ extern Context context; CmdStatistics::CmdStatistics () { _keyword = "stats"; - _usage = "task stats"; + _usage = "task stats []"; _description = "Shows task database statistics."; _read_only = true; _displays_id = false; @@ -52,7 +53,6 @@ CmdStatistics::CmdStatistics () int CmdStatistics::execute (std::string& output) { int rc = 0; -/* std::stringstream out; // Go get the file sizes. @@ -80,10 +80,21 @@ int CmdStatistics::execute (std::string& output) std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); - context.tdb.load (tasks, context.filter); + Filter filter; + context.tdb.load (tasks, filter); context.tdb.commit (); context.tdb.unlock (); + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + Date now; time_t earliest = time (NULL); time_t latest = 1; @@ -100,44 +111,43 @@ int CmdStatistics::execute (std::string& output) std::map allTags; std::map allProjects; - std::vector ::iterator it; - for (it = tasks.begin (); it != tasks.end (); ++it) + for (task = filtered.begin (); task != filtered.end (); ++task) { ++totalT; - if (it->getStatus () == Task::deleted) ++deletedT; - if (it->getStatus () == Task::pending) ++pendingT; - if (it->getStatus () == Task::completed) ++completedT; - if (it->getStatus () == Task::recurring) ++recurringT; - if (it->getStatus () == Task::waiting) ++waitingT; + if (task->getStatus () == Task::deleted) ++deletedT; + if (task->getStatus () == Task::pending) ++pendingT; + if (task->getStatus () == Task::completed) ++completedT; + if (task->getStatus () == Task::recurring) ++recurringT; + if (task->getStatus () == Task::waiting) ++waitingT; - time_t entry = strtol (it->get ("entry").c_str (), NULL, 10); + time_t entry = strtol (task->get ("entry").c_str (), NULL, 10); if (entry < earliest) earliest = entry; if (entry > latest) latest = entry; - if (it->getStatus () == Task::completed) + if (task->getStatus () == Task::completed) { - time_t end = strtol (it->get ("end").c_str (), NULL, 10); + time_t end = strtol (task->get ("end").c_str (), NULL, 10); daysPending += (end - entry) / 86400.0; } - if (it->getStatus () == Task::pending) + if (task->getStatus () == Task::pending) daysPending += (now.toEpoch () - entry) / 86400.0; - descLength += it->get ("description").length (); + descLength += task->get ("description").length (); std::vector annotations; - it->getAnnotations (annotations); + task->getAnnotations (annotations); annotationsT += annotations.size (); std::vector tags; - it->getTags (tags); + task->getTags (tags); if (tags.size ()) ++taggedT; std::vector ::iterator t; for (t = tags.begin (); t != tags.end (); ++t) allTags[*t] = 0; - std::string project = it->get ("project"); + std::string project = task->get ("project"); if (project != "") allProjects[project] = 0; } @@ -203,7 +213,7 @@ int CmdStatistics::execute (std::string& output) view.set (row, 1, value.str ()); } - if (tasks.size ()) + if (filtered.size ()) { Date e (earliest); row = view.addRow (); @@ -274,7 +284,6 @@ int CmdStatistics::execute (std::string& output) << optionalBlankLine (); output = out.str (); -*/ return rc; } diff --git a/src/commands/CmdSummary.cpp b/src/commands/CmdSummary.cpp index b7b4d7577..abf50c946 100644 --- a/src/commands/CmdSummary.cpp +++ b/src/commands/CmdSummary.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -54,19 +55,28 @@ int CmdSummary::execute (std::string& output) { int rc = 0; -/* // Scan the pending tasks. std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); - context.tdb.load (tasks, context.filter); + Filter filter; + context.tdb.load (tasks, filter); context.tdb.commit (); context.tdb.unlock (); - // Generate unique list of project names from all pending tasks. - std::map allProjects; + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; std::vector ::iterator task; for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + + // Generate unique list of project names from all pending tasks. + std::map allProjects; + for (task = filtered.begin (); task != filtered.end (); ++task) if (task->getStatus () == Task::pending) allProjects[task->get ("project")] = false; @@ -88,7 +98,7 @@ int CmdSummary::execute (std::string& output) } // Count the various tasks. - for (task = tasks.begin (); task != tasks.end (); ++task) + for (task = filtered.begin (); task != filtered.end (); ++task) { std::string project = task->get ("project"); ++counter[project]; @@ -176,7 +186,6 @@ int CmdSummary::execute (std::string& output) } output = out.str (); -*/ return rc; } diff --git a/src/commands/CmdTags.cpp b/src/commands/CmdTags.cpp index 37b022b71..bd8d86d28 100644 --- a/src/commands/CmdTags.cpp +++ b/src/commands/CmdTags.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -49,28 +50,37 @@ CmdTags::CmdTags () int CmdTags::execute (std::string& output) { int rc = 0; -/* std::stringstream out; std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); int quantity = 0; + Filter filter; if (context.config.getBoolean ("list.all.tags")) - quantity += context.tdb.load (tasks, context.filter); + quantity += context.tdb.load (tasks, filter); else - quantity += context.tdb.loadPending (tasks, context.filter); + quantity += context.tdb.loadPending (tasks, filter); context.tdb.commit (); context.tdb.unlock (); + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + // Scan all the tasks for their project name, building a map using project // names as keys. std::map unique; - std::vector ::iterator t; - for (t = tasks.begin (); t != tasks.end (); ++t) + for (task = filtered.begin (); task != filtered.end (); ++task) { std::vector tags; - t->getTags (tags); + task->getTags (tags); std::vector ::iterator tag; for (tag = tags.begin (); tag != tags.end (); ++tag) @@ -118,7 +128,6 @@ int CmdTags::execute (std::string& output) } output = out.str (); -*/ return rc; } @@ -135,7 +144,6 @@ CmdCompletionTags::CmdCompletionTags () //////////////////////////////////////////////////////////////////////////////// int CmdCompletionTags::execute (std::string& output) { -/* std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); @@ -148,11 +156,20 @@ int CmdCompletionTags::execute (std::string& output) context.tdb.commit (); context.tdb.unlock (); + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + // Scan all the tasks for their tags, building a map using tag // names as keys. std::map unique; - std::vector ::iterator task; - for (task = tasks.begin (); task != tasks.end (); ++task) + for (task = filtered.begin (); task != filtered.end (); ++task) { std::vector tags; task->getTags (tags); @@ -176,7 +193,6 @@ int CmdCompletionTags::execute (std::string& output) out << it->first << "\n"; output = out.str (); -*/ return 0; } diff --git a/src/commands/CmdTimesheet.cpp b/src/commands/CmdTimesheet.cpp index b5165d050..bd2194fef 100644 --- a/src/commands/CmdTimesheet.cpp +++ b/src/commands/CmdTimesheet.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -50,15 +51,25 @@ int CmdTimesheet::execute (std::string& output) { int rc = 0; -/* // Scan the pending tasks. std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); - context.tdb.load (tasks, context.filter); + Filter filter; + context.tdb.load (tasks, filter); context.tdb.commit (); context.tdb.unlock (); + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + // Just do this once. int width = context.getWidth (); @@ -79,8 +90,11 @@ int CmdTimesheet::execute (std::string& output) // Determine how many reports to run. int quantity = 1; +/* + TODO Need some command line parsing. if (context.sequence.size () == 1) quantity = context.sequence[0]; +*/ std::stringstream out; for (int week = 0; week < quantity; ++week) @@ -105,8 +119,7 @@ int CmdTimesheet::execute (std::string& output) completed.add (Column::factory ("string.right", "Due")); completed.add (Column::factory ("string", "Description")); - std::vector ::iterator task; - for (task = tasks.begin (); task != tasks.end (); ++task) + for (task = filtered.begin (); task != filtered.end (); ++task) { // If task completed within range. if (task->getStatus () == Task::completed) @@ -143,7 +156,7 @@ int CmdTimesheet::execute (std::string& output) started.add (Column::factory ("string.right", "Due")); started.add (Column::factory ("string", "Description")); - for (task = tasks.begin (); task != tasks.end (); ++task) + for (task = filtered.begin (); task != filtered.end (); ++task) { // If task started within range, but not completed withing range. if (task->getStatus () == Task::pending && @@ -180,7 +193,6 @@ int CmdTimesheet::execute (std::string& output) } output = out.str (); -*/ return rc; } diff --git a/src/commands/CmdUrgency.cpp b/src/commands/CmdUrgency.cpp index a7a41e9e8..eab8ca5cd 100644 --- a/src/commands/CmdUrgency.cpp +++ b/src/commands/CmdUrgency.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -46,18 +47,27 @@ CmdUrgency::CmdUrgency () //////////////////////////////////////////////////////////////////////////////// int CmdUrgency::execute (std::string& output) { -/* // Get all the tasks. std::vector tasks; context.tdb.lock (context.config.getBoolean ("locking")); handleRecurrence (); - context.tdb.loadPending (tasks, context.filter); + Filter filter; + context.tdb.loadPending (tasks, filter); context.tdb.commit (); context.tdb.unlock (); + // Filter. + Arguments f = context.args.extract_read_only_filter (); + Expression e (f); + + std::vector filtered; + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + if (e.eval (*task)) + filtered.push_back (*task); + // Filter sequence. - context.filter.applySequence (tasks, context.sequence); - if (tasks.size () == 0) + if (filtered.size () == 0) { context.footnote ("No tasks specified."); return 1; @@ -65,8 +75,7 @@ int CmdUrgency::execute (std::string& output) // Find the task(s). std::stringstream out; - std::vector ::iterator task; - for (task = tasks.begin (); task != tasks.end (); ++task) + for (task = filtered.begin (); task != filtered.end (); ++task) out << "task " << task->id << " urgency " @@ -74,7 +83,6 @@ int CmdUrgency::execute (std::string& output) << "\n"; output = out.str (); -*/ return 0; }