Helper Command

- Added _query helper command for script writers, which accepts a filter like
  any other report, but returns raw JSON.
This commit is contained in:
Paul Beckingham 2010-12-26 10:00:41 -05:00
parent 126a3d88b5
commit 7f32435ce9
8 changed files with 72 additions and 0 deletions

View file

@ -552,6 +552,46 @@ int handleUrgency (std::string& outs)
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int handleQuery (std::string& outs)
{
int rc = 0;
if (context.hooks.trigger ("pre-query-command"))
{
// Get all the tasks.
std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking"));
handleRecurrence ();
context.tdb.load (tasks, context.filter);
context.tdb.commit ();
context.tdb.unlock ();
// Filter sequence.
if (context.sequence.size ())
context.filter.applySequence (tasks, context.sequence);
// Note: "limit:" feature not supported.
// Compose output.
outs = "{";
std::vector <Task>::iterator t;
for (t = tasks.begin (); t != tasks.end (); ++t)
{
if (t != tasks.begin ())
outs += ",\n";
outs += t->composeJSON ();
}
outs += "}\n";
context.hooks.trigger ("post-query-command");
}
return rc;
}
////////////////////////////////////////////////////////////////////////////////
int handleCompletionIDs (std::string& outs)
{