Enhancement - modify command

- Implemented modify command
This commit is contained in:
Paul Beckingham 2009-06-16 23:25:35 -04:00
parent 051720a279
commit b2c76f6123
2 changed files with 63 additions and 55 deletions

View file

@ -175,45 +175,44 @@ std::string Context::dispatch ()
std::string out; std::string out;
// TODO Just look at this thing. It cries out for a dispatch table. // TODO Just look at this thing. It cries out for a dispatch table.
if (cmd.command == "projects") { out = handleProjects (); } if (cmd.command == "projects") { out = handleProjects (); }
else if (cmd.command == "tags") { out = handleTags (); } else if (cmd.command == "tags") { out = handleTags (); }
else if (cmd.command == "colors") { out = handleColor (); } else if (cmd.command == "colors") { out = handleColor (); }
else if (cmd.command == "version") { out = handleVersion (); } else if (cmd.command == "version") { out = handleVersion (); }
else if (cmd.command == "help") { out = longUsage (); } else if (cmd.command == "help") { out = longUsage (); }
else if (cmd.command == "stats") { out = handleReportStats (); } else if (cmd.command == "stats") { out = handleReportStats (); }
else if (cmd.command == "info") { out = handleInfo (); } else if (cmd.command == "info") { out = handleInfo (); }
else if (cmd.command == "history") { out = handleReportHistory (); } else if (cmd.command == "history") { out = handleReportHistory (); }
else if (cmd.command == "ghistory") { out = handleReportGHistory (); } else if (cmd.command == "ghistory") { out = handleReportGHistory (); }
else if (cmd.command == "summary") { out = handleReportSummary (); } else if (cmd.command == "summary") { out = handleReportSummary (); }
else if (cmd.command == "calendar") { out = handleReportCalendar (); } else if (cmd.command == "calendar") { out = handleReportCalendar (); }
else if (cmd.command == "timesheet") { out = handleReportTimesheet (); } else if (cmd.command == "timesheet") { out = handleReportTimesheet (); }
else if (cmd.command == "add") { out = handleAdd (); } else if (cmd.command == "add") { out = handleAdd (); }
else if (cmd.command == "append") { out = handleAppend (); }
else if (cmd.command == "annotate") { out = handleAnnotate (); }
else if (cmd.command == "done") { out = handleDone (); }
else if (cmd.command == "undo") { out = handleUndo (); }
else if (cmd.command == "delete") { out = handleDelete (); }
else if (cmd.command == "undelete") { out = handleUndelete (); }
else if (cmd.command == "start") { out = handleStart (); }
else if (cmd.command == "stop") { out = handleStop (); }
else if (cmd.command == "export") { out = handleExport (); }
/* /*
else if (cmd.command == "" && task.getId ()) { out = handleModify (); } else if (cmd.command == "import") { out = handleImport (); }
*/ */
else if (cmd.command == "append") { out = handleAppend (); } else if (cmd.command == "duplicate") { out = handleDuplicate (); }
else if (cmd.command == "annotate") { out = handleAnnotate (); }
else if (cmd.command == "done") { out = handleDone (); }
else if (cmd.command == "undo") { out = handleUndo (); }
else if (cmd.command == "delete") { out = handleDelete (); }
else if (cmd.command == "undelete") { out = handleUndelete (); }
else if (cmd.command == "start") { out = handleStart (); }
else if (cmd.command == "stop") { out = handleStop (); }
else if (cmd.command == "export") { out = handleExport (); }
/* /*
else if (cmd.command == "import") { out = handleImport (); } else if (cmd.command == "edit") { out = handleEdit (); }
*/
else if (cmd.command == "duplicate") { out = handleDuplicate (); }
/*
else if (cmd.command == "edit") { out = handleEdit (); }
*/ */
else if (cmd.command == "" &&
sequence.size ()) { out = handleModify (); }
// Command that display IDs and therefore need TDB::gc first. // Command that display IDs and therefore need TDB::gc first.
else if (cmd.command == "next") { if (!inShadow) gcMod = tdb.gc (); out = handleReportNext (); } else if (cmd.command == "next") { if (!inShadow) gcMod = tdb.gc (); out = handleReportNext (); }
else if (cmd.validCustom (cmd.command)) { if (!inShadow) gcMod = tdb.gc (); out = handleCustomReport (cmd.command); } else if (cmd.validCustom (cmd.command)) { if (!inShadow) gcMod = tdb.gc (); out = handleCustomReport (cmd.command); }
// If the command is not recognized, display usage. // If the command is not recognized, display usage.
else { out = shortUsage (); } else { out = shortUsage (); }
// Only update the shadow file if such an update was not suppressed (shadow), // Only update the shadow file if such an update was not suppressed (shadow),
// TODO // TODO

View file

@ -761,57 +761,66 @@ std::string handleExport ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string handleModify () std::string handleModify ()
{ {
/*
int count = 0; int count = 0;
*/
std::stringstream out; std::stringstream out;
/*
std::vector <T> all;
tdb.allPendingT (all);
std::vector <T> filtered = all; std::vector <Task> tasks;
filterSequence (filtered, task); context.tdb.lock (context.config.get ("locking", true));
foreach (seq, filtered) context.tdb.loadPending (tasks, context.filter);
handleRecurrence (tasks);
// Filter sequence.
std::vector <Task> all = tasks;
context.filter.applySequence (tasks, context.sequence);
foreach (task, tasks)
{ {
// Perform some logical consistency checks. // Perform some logical consistency checks.
if (task.has ("recur") && if (context.task.has ("recur") &&
!task.has ("due") && !context.task.has ("due") &&
!seq->has ("due")) !task->has ("due"))
throw std::string ("You cannot specify a recurring task without a due date."); throw std::string ("You cannot specify a recurring task without a due date.");
if (task.has ("until") && if (context.task.has ("until") &&
!task.has ("recur") && !context.task.has ("recur") &&
!seq->has ("recur")) !task->has ("recur"))
throw std::string ("You cannot specify an until date for a non-recurring task."); throw std::string ("You cannot specify an until date for a non-recurring task.");
// Make all changes. // Make all changes.
foreach (other, all) foreach (other, all)
{ {
if (other->getId () == seq->getId () || // Self if (other->id == task->id || // Self
(seq->has ("parent") && (task->has ("parent") &&
seq->getAttribute ("parent") == other->getAttribute ("parent")) || // Sibling task->get ("parent") == other->get ("parent")) || // Sibling
other->getUUID () == seq->getAttribute ("parent")) // Parent other->get ("uuid") == task->get ("parent")) // Parent
{ {
// A non-zero value forces a file write. // A non-zero value forces a file write.
int changes = 0; int changes = 0;
// Apply other deltas. // Apply other deltas.
changes += deltaDescription (*other, task); changes += deltaDescription (*other);
changes += deltaTags (*other, task); context.task.remove ("description");
changes += deltaAttributes (*other, task);
changes += deltaSubstitutions (*other, task); changes += deltaTags (*other);
context.task.remove ("tags");
changes += deltaAttributes (*other);
changes += deltaSubstitutions (*other);
if (changes) if (changes)
tdb.modifyT (*other); context.tdb.update (*other);
++count; ++count;
} }
} }
} }
context.tdb.commit ();
context.tdb.unlock ();
if (context.config.get ("echo.command", true)) if (context.config.get ("echo.command", true))
out << "Modified " << count << " task" << (count == 1 ? "" : "s") << std::endl; out << "Modified " << count << " task" << (count == 1 ? "" : "s") << std::endl;
*/
return out.str (); return out.str ();
} }