Commands - add
- Migrated handleAdd to CmdAdd.
This commit is contained in:
@@ -51,102 +51,6 @@
|
||||
|
||||
extern Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int handleAdd (std::string& outs)
|
||||
{
|
||||
int rc = 0;
|
||||
std::stringstream out;
|
||||
|
||||
context.task.set ("uuid", uuid ());
|
||||
context.task.setEntry ();
|
||||
|
||||
// Recurring tasks get a special status.
|
||||
if (context.task.has ("due") &&
|
||||
context.task.has ("recur"))
|
||||
{
|
||||
context.task.setStatus (Task::recurring);
|
||||
context.task.set ("mask", "");
|
||||
}
|
||||
|
||||
// Tasks with a wait: date get a special status.
|
||||
else if (context.task.has ("wait"))
|
||||
context.task.setStatus (Task::waiting);
|
||||
|
||||
// By default, tasks are pending.
|
||||
else
|
||||
context.task.setStatus (Task::pending);
|
||||
|
||||
// Override with default.project, if not specified.
|
||||
if (context.task.get ("project") == "")
|
||||
context.task.set ("project", context.config.get ("default.project"));
|
||||
|
||||
// Override with default.priority, if not specified.
|
||||
if (context.task.get ("priority") == "")
|
||||
{
|
||||
std::string defaultPriority = context.config.get ("default.priority");
|
||||
if (Att::validNameValue ("priority", "", defaultPriority))
|
||||
context.task.set ("priority", defaultPriority);
|
||||
}
|
||||
|
||||
// Override with default.due, if not specified.
|
||||
if (context.task.get ("due") == "")
|
||||
{
|
||||
std::string defaultDue = context.config.get ("default.due");
|
||||
if (defaultDue != "" &&
|
||||
Att::validNameValue ("due", "", defaultDue))
|
||||
context.task.set ("due", defaultDue);
|
||||
}
|
||||
|
||||
// Include tags.
|
||||
foreach (tag, context.tagAdditions)
|
||||
context.task.addTag (*tag);
|
||||
|
||||
// Must load pending to resolve dependencies, and to provide a new ID.
|
||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||
|
||||
std::vector <Task> all;
|
||||
Filter none;
|
||||
context.tdb.loadPending (all, none);
|
||||
|
||||
// Resolve dependencies.
|
||||
if (context.task.has ("depends"))
|
||||
{
|
||||
// Convert ID to UUID.
|
||||
std::vector <std::string> deps;
|
||||
split (deps, context.task.get ("depends"), ',');
|
||||
|
||||
// Eliminate the ID-based set.
|
||||
context.task.set ("depends", "");
|
||||
|
||||
std::vector <std::string>::iterator i;
|
||||
for (i = deps.begin (); i != deps.end (); i++)
|
||||
{
|
||||
int id = atoi (i->c_str ());
|
||||
if (id < 0)
|
||||
context.task.removeDependency (-id);
|
||||
else
|
||||
context.task.addDependency (id);
|
||||
}
|
||||
}
|
||||
|
||||
// Only valid tasks can be added.
|
||||
context.task.validate ();
|
||||
|
||||
context.tdb.add (context.task);
|
||||
|
||||
#ifdef FEATURE_NEW_ID
|
||||
out << "Created task " << context.tdb.nextId () << ".\n";
|
||||
#endif
|
||||
|
||||
context.footnote (onProjectChange (context.task));
|
||||
|
||||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
|
||||
outs = out.str ();
|
||||
return rc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int handleLog (std::string& outs)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user