TW-1704: Task: Use Task::identifier to reference the task

To achieve consistent output, use a helper method to generate a proper
handle - ID for tasks with non-zero ID, UUID otherwise.
This commit is contained in:
Tomas Babej 2015-10-30 00:37:20 +01:00 committed by Paul Beckingham
parent 1236abc7d5
commit 2d25cf6f59
16 changed files with 50 additions and 57 deletions

View file

@ -1,5 +1,6 @@
2.5.1 () - 2.5.1 () -
- TW-1704 Use Task::identifier to reference the Task in the output
- The default configuration is now 256-color only. - The default configuration is now 256-color only.
- The 'columns' report now shows whether a column is modifiable or read only. - The 'columns' report now shows whether a column is modifiable or read only.

View file

@ -202,6 +202,20 @@ std::string Task::statusToText (Task::status s)
return "pending"; return "pending";
} }
////////////////////////////////////////////////////////////////////////////////
// Returns a proper handle to the task. Tasks should not be referenced by UUIDs
// as long as they have non-zero ID.
//
const std::string Task::identifier (bool shortened /* = false */) const
{
if (this->id != 0)
return format (this->id);
else if (shortened)
return this->get ("uuid").substr (0, 8);
else
return this->get ("uuid");
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Task::setAsNow (const std::string& att) void Task::setAsNow (const std::string& att)
{ {

View file

@ -92,6 +92,7 @@ public:
void setAsNow (const std::string&); void setAsNow (const std::string&);
bool has (const std::string&) const; bool has (const std::string&) const;
std::vector <std::string> all (); std::vector <std::string> all ();
const std::string identifier (bool shortened = false) const;
const std::string get (const std::string&) const; const std::string get (const std::string&) const;
const std::string& get_ref (const std::string&) const; const std::string& get_ref (const std::string&) const;
int get_int (const std::string&) const; int get_int (const std::string&) const;

View file

@ -79,7 +79,7 @@ int CmdAnnotate::execute (std::string&)
// Annotate the specified task. // Annotate the specified task.
std::string question = format (STRING_CMD_ANNO_CONFIRM, std::string question = format (STRING_CMD_ANNO_CONFIRM,
task.id, task.identifier (true),
task.get ("description")); task.get ("description"));
task.modify (Task::modAnnotate, true); task.modify (Task::modAnnotate, true);

View file

@ -79,7 +79,7 @@ int CmdAppend::execute (std::string&)
// Append to the specified task. // Append to the specified task.
std::string question = format (STRING_CMD_APPEND_CONFIRM, std::string question = format (STRING_CMD_APPEND_CONFIRM,
task.id, task.identifier (true),
task.get ("description")); task.get ("description"));
task.modify (Task::modAppend, true); task.modify (Task::modAppend, true);

View file

@ -80,14 +80,9 @@ int CmdDelete::execute (std::string&)
{ {
// Delete the specified task. // Delete the specified task.
std::string question; std::string question;
if (task.id) question = format (STRING_CMD_DELETE_CONFIRM,
question = format (STRING_CMD_DELETE_CONFIRM, task.identifier (true),
task.id, task.get ("description"));
task.get ("description"));
else
question = format (STRING_CMD_DELETE_CONFIRM,
task.get ("uuid"),
task.get ("description"));
task.modify (Task::modAnnotate); task.modify (Task::modAnnotate);
task.setStatus (Task::deleted); task.setStatus (Task::deleted);
@ -173,7 +168,7 @@ int CmdDelete::execute (std::string&)
else else
{ {
std::cout << format (STRING_CMD_DELETE_NOT_DEL, std::cout << format (STRING_CMD_DELETE_NOT_DEL,
task.id, task.identifier (true),
task.get ("description")) task.get ("description"))
<< "\n"; << "\n";
rc = 1; rc = 1;

View file

@ -127,7 +127,7 @@ int CmdDenotate::execute (std::string&)
if (before != task) if (before != task)
{ {
std::string question = format (STRING_CMD_DENO_CONFIRM, std::string question = format (STRING_CMD_DENO_CONFIRM,
task.id, task.identifier (true),
task.get ("description")); task.get ("description"));
if (permission (taskDifferences (before, task) + question, filtered.size ())) if (permission (taskDifferences (before, task) + question, filtered.size ()))

View file

@ -81,7 +81,7 @@ int CmdDone::execute (std::string&)
{ {
// Complete the specified task. // Complete the specified task.
std::string question = format (STRING_CMD_DONE_CONFIRM, std::string question = format (STRING_CMD_DONE_CONFIRM,
task.id, task.identifier (true),
task.get ("description")); task.get ("description"));
task.modify (Task::modAnnotate); task.modify (Task::modAnnotate);
@ -121,7 +121,7 @@ int CmdDone::execute (std::string&)
else else
{ {
std::cout << format (STRING_CMD_DONE_NOTPEND, std::cout << format (STRING_CMD_DONE_NOTPEND,
task.id, task.identifier (true),
task.get ("description")) task.get ("description"))
<< "\n"; << "\n";
rc = 1; rc = 1;

View file

@ -88,7 +88,7 @@ int CmdDuplicate::execute (std::string&)
dup.remove ("recur"); dup.remove ("recur");
dup.remove ("until"); dup.remove ("until");
dup.remove ("imask"); dup.remove ("imask");
std::cout << format (STRING_CMD_DUPLICATE_NON_REC, task.id) std::cout << format (STRING_CMD_DUPLICATE_NON_REC, task.identifier ())
<< "\n"; << "\n";
} }
@ -96,7 +96,7 @@ int CmdDuplicate::execute (std::string&)
else if (dup.getStatus () == Task::recurring) else if (dup.getStatus () == Task::recurring)
{ {
dup.remove ("mask"); dup.remove ("mask");
std::cout << format (STRING_CMD_DUPLICATE_REC, task.id) std::cout << format (STRING_CMD_DUPLICATE_REC, task.identifier ())
<< "\n"; << "\n";
} }
@ -106,7 +106,7 @@ int CmdDuplicate::execute (std::string&)
dup.modify (Task::modAnnotate); dup.modify (Task::modAnnotate);
if (permission (format (STRING_CMD_DUPLICATE_CONFIRM, if (permission (format (STRING_CMD_DUPLICATE_CONFIRM,
task.id, task.identifier (true),
task.get ("description")), task.get ("description")),
filtered.size ())) filtered.size ()))
{ {

View file

@ -82,14 +82,9 @@ int CmdModify::execute (std::string&)
checkConsistency(before, task); checkConsistency(before, task);
std::string question; std::string question;
if (task.id != 0) question = format (STRING_CMD_MODIFY_CONFIRM,
question = format (STRING_CMD_MODIFY_CONFIRM, task.identifier (true),
task.id, task.get ("description"));
task.get ("description"));
else
question = format (STRING_CMD_MODIFY_CONFIRM,
task.get ("uuid"),
task.get ("description"));
if (permission (taskDifferences (before, task) + question, filtered.size ())) if (permission (taskDifferences (before, task) + question, filtered.size ()))
{ {

View file

@ -79,7 +79,7 @@ int CmdPrepend::execute (std::string&)
// Prepend to the specified task. // Prepend to the specified task.
std::string question = format (STRING_CMD_PREPEND_CONFIRM, std::string question = format (STRING_CMD_PREPEND_CONFIRM,
task.id, task.identifier (true),
task.get ("description")); task.get ("description"));
task.modify (Task::modPrepend, true); task.modify (Task::modPrepend, true);

View file

@ -80,7 +80,7 @@ int CmdStart::execute (std::string&)
// Start the specified task. // Start the specified task.
std::string question = format (STRING_CMD_START_CONFIRM, std::string question = format (STRING_CMD_START_CONFIRM,
task.id, task.identifier (true),
task.get ("description")); task.get ("description"));
task.modify (Task::modAnnotate); task.modify (Task::modAnnotate);
task.setAsNow ("start"); task.setAsNow ("start");

View file

@ -78,7 +78,7 @@ int CmdStop::execute (std::string&)
// Stop the specified task. // Stop the specified task.
std::string question = format (STRING_CMD_STOP_CONFIRM, std::string question = format (STRING_CMD_STOP_CONFIRM,
task.id, task.identifier (true),
task.get ("description")); task.get ("description"));
task.modify (Task::modAnnotate); task.modify (Task::modAnnotate);
@ -108,7 +108,7 @@ int CmdStop::execute (std::string&)
else else
{ {
std::cout << format (STRING_CMD_STOP_ALREADY, std::cout << format (STRING_CMD_STOP_ALREADY,
task.id, task.identifier (true),
task.get ("description")) task.get ("description"))
<< "\n"; << "\n";
rc = 1; rc = 1;

View file

@ -70,19 +70,10 @@ int CmdUrgency::execute (std::string& output)
std::stringstream out; std::stringstream out;
for (auto& task : filtered) for (auto& task : filtered)
{ {
if (task.id) out << format (STRING_CMD_URGENCY_RESULT,
{ task.identifier (),
out << format (STRING_CMD_URGENCY_RESULT, trim (format (task.urgency (), 6, 3)))
task.id, trim (format (task.urgency (), 6, 3))) << "\n";
<< "\n";
}
else
{
out << format (STRING_CMD_URGENCY_RESULT,
task.get ("uuid"),
trim (format (task.urgency (), 6, 3)))
<< "\n";
}
} }
output = out.str (); output = out.str ();

View file

@ -145,7 +145,7 @@ void dependencyChainOnComplete (Task& task)
// Nag about broken chain. // Nag about broken chain.
if (context.config.getBoolean ("dependency.reminder")) if (context.config.getBoolean ("dependency.reminder"))
{ {
std::cout << format (STRING_DEPEND_BLOCKED, task.id) std::cout << format (STRING_DEPEND_BLOCKED, task.identifier ())
<< "\n"; << "\n";
for (auto& b : blocking) for (auto& b : blocking)
@ -200,7 +200,7 @@ void dependencyChainOnStart (Task& task)
// broken chain. // broken chain.
if (blocking.size ()) if (blocking.size ())
{ {
std::cout << format (STRING_DEPEND_BLOCKED, task.id) std::cout << format (STRING_DEPEND_BLOCKED, task.identifier ())
<< "\n"; << "\n";
for (auto& b : blocking) for (auto& b : blocking)

View file

@ -309,12 +309,10 @@ void feedback_affected (const std::string& effect, const Task& task)
{ {
if (context.verbose ("affected")) if (context.verbose ("affected"))
{ {
if (task.id) std::cout << format (effect,
std::cout << format (effect, task.id, task.get ("description")) task.identifier (true),
<< "\n"; task.get ("description"))
else << "\n";
std::cout << format (effect, task.get ("uuid"), task.get ("description"))
<< "\n";
} }
} }
@ -373,12 +371,8 @@ void feedback_special_tags (const Task& task, const std::string& tag)
if (msg.length ()) if (msg.length ())
{ {
if (task.id) std::cout << format (msg, task.identifier ())
std::cout << format (msg, task.id) << "\n";
<< "\n";
else
std::cout << format (msg, task.get ("uuid"))
<< "\n";
} }
} }
} }
@ -506,7 +500,9 @@ std::string onExpiration (Task& task)
std::stringstream msg; std::stringstream msg;
if (context.verbose ("affected")) if (context.verbose ("affected"))
msg << format (STRING_FEEDBACK_EXPIRED, task.id, task.get ("description")); msg << format (STRING_FEEDBACK_EXPIRED,
task.identifier (true),
task.get ("description"));
return msg.str (); return msg.str ();
} }