From ec919a8677e79d04f0008439690c11e99e7d0425 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 14 Feb 2015 12:50:10 -0500 Subject: [PATCH] TW-1534 - TW-1534 Urgency coefficient for user project disables 'info' output(thanks to Martin). - Reimplemented 'information' command urgency details as a ViewText. - Fixed math bug in rightJustify. --- AUTHORS | 1 + ChangeLog | 2 + src/commands/CmdInfo.cpp | 168 ++++++++++++++++++++++----------------- src/commands/CmdInfo.h | 3 +- src/text.cpp | 6 +- 5 files changed, 107 insertions(+), 73 deletions(-) diff --git a/AUTHORS b/AUTHORS index fe6e9e21b..2cd0d30b1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -244,3 +244,4 @@ suggestions: Sujeevan Vijayakumaran Scott Carter Taisuke Hachimura + Martin diff --git a/ChangeLog b/ChangeLog index b373b2e17..2831d1e45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -27,6 +27,8 @@ - TW-1531 'task export' should handle recurrence (thanks to Tomas Babej). - TW-1532 Hooks does not execute any script on Cygwin (thanks to Taisuke Hachimura). +- TW-1534 Urgency coefficient for user project disables 'info' output(thanks to + Martin). - Fixed assorted color theme problems. - Changed assorted reports so they do not use '.age' format for dates that are in the future, because those are never shown with this format (thanks to diff --git a/src/commands/CmdInfo.cpp b/src/commands/CmdInfo.cpp index 7b8e98ee7..9097472df 100644 --- a/src/commands/CmdInfo.cpp +++ b/src/commands/CmdInfo.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -324,62 +323,7 @@ int CmdInfo::execute (std::string& output) // Task::urgency row = view.addRow (); view.set (row, 0, STRING_COLUMN_LABEL_URGENCY); - - std::string urgency = - trimLeft (format (task->urgency (), 4, 4)) + "\n" + - urgencyTerm ("project", task->urgency_project (), Task::urgencyProjectCoefficient) + - urgencyTerm ("priority", task->urgency_priority (), Task::urgencyPriorityCoefficient) + - urgencyTerm ("active", task->urgency_active (), Task::urgencyActiveCoefficient) + - urgencyTerm ("scheduled", task->urgency_scheduled (), Task::urgencyScheduledCoefficient) + - urgencyTerm ("waiting", task->urgency_waiting (), Task::urgencyWaitingCoefficient) + - urgencyTerm ("blocked", task->urgency_blocked (), Task::urgencyBlockedCoefficient) + - urgencyTerm ("blocking", task->urgency_blocking (), Task::urgencyBlockingCoefficient) + - urgencyTerm ("annotations", task->urgency_annotations (), Task::urgencyAnnotationsCoefficient) + - urgencyTerm ("tags", task->urgency_tags (), Task::urgencyTagsCoefficient) + - urgencyTerm ("next", task->urgency_next (), Task::urgencyNextCoefficient) + - urgencyTerm ("due", task->urgency_due (), Task::urgencyDueCoefficient) + - urgencyTerm ("age", task->urgency_age (), Task::urgencyAgeCoefficient); - - // Tag, Project- and UDA-specific coefficients. - std::map ::iterator var; - for (var = Task::coefficients.begin (); var != Task::coefficients.end (); ++var) - { - if (var->first.substr (0, 13) == "urgency.user.") - { - // urgency.user.project..coefficient - std::string::size_type end = std::string::npos; - if (var->first.substr (13, 8) == "project." && - (end = var->first.find (".coefficient")) != std::string::npos) - { - std::string project = var->first.substr (21, end - 21); - if (task->get ("project").find (project) == 0) - urgency += urgencyTerm ("PROJECT " + project, 1.0, var->second); - } - - // urgency.user.tag..coefficient - if (var->first.substr (13, 4) == "tag." && - (end = var->first.find (".coefficient")) != std::string::npos) - { - std::string name = var->first.substr (17, end - 17); - if (task->hasTag (name)) - urgency += urgencyTerm ("TAG " + name, 1.0, var->second); - } - } - - // urgency.uda..coefficient - else if (var->first.substr (0, 12) == "urgency.uda.") - { - std::string::size_type end = var->first.find (".coefficient"); - if (end != std::string::npos) - { - std::string name = var->first.substr (12, end - 12); - if (task->has (name)) - urgency += urgencyTerm ("UDA " + name, 1.0, var->second); - } - } - } - - view.set (row, 1, urgency); + view.set (row, 1, format (task->urgency (), 4, 4)); // Show any UDAs std::vector all = task->all (); @@ -413,6 +357,7 @@ int CmdInfo::execute (std::string& output) // Show any orphaned UDAs, which are identified by not being represented in // the context.columns map. for (att = all.begin (); att != all.end (); ++att) + { if (att->substr (0, 11) != "annotation_" && context.columns.find (*att) == context.columns.end ()) { @@ -420,8 +365,86 @@ int CmdInfo::execute (std::string& output) view.set (row, 0, "[" + *att); view.set (row, 1, task->get (*att) + "]"); } + } - // Create a second table, containing undo log change details. + // Create a second table, containing urgency details. + ViewText urgencyDetails; + if (context.color ()) + { + Color alternate (context.config.get ("color.alternate")); + urgencyDetails.colorOdd (alternate); + urgencyDetails.intraColorOdd (alternate); + + Color label (context.config.get ("color.label")); + urgencyDetails.colorHeader (label); + } + + urgencyDetails.width (context.getWidth ()); + urgencyDetails.add (Column::factory ("string", "")); // Attribute + urgencyDetails.add (Column::factory ("string", "")); // Value + urgencyDetails.add (Column::factory ("string", "")); // * + urgencyDetails.add (Column::factory ("string", "")); // Coefficient + urgencyDetails.add (Column::factory ("string", "")); // = + urgencyDetails.add (Column::factory ("string", "")); // Result + + urgencyTerm (urgencyDetails, "project", task->urgency_project (), Task::urgencyProjectCoefficient); + urgencyTerm (urgencyDetails, "priority", task->urgency_priority (), Task::urgencyPriorityCoefficient); + urgencyTerm (urgencyDetails, "active", task->urgency_active (), Task::urgencyActiveCoefficient); + urgencyTerm (urgencyDetails, "scheduled", task->urgency_scheduled (), Task::urgencyScheduledCoefficient); + urgencyTerm (urgencyDetails, "waiting", task->urgency_waiting (), Task::urgencyWaitingCoefficient); + urgencyTerm (urgencyDetails, "blocked", task->urgency_blocked (), Task::urgencyBlockedCoefficient); + urgencyTerm (urgencyDetails, "blocking", task->urgency_blocking (), Task::urgencyBlockingCoefficient); + urgencyTerm (urgencyDetails, "annotations", task->urgency_annotations (), Task::urgencyAnnotationsCoefficient); + urgencyTerm (urgencyDetails, "tags", task->urgency_tags (), Task::urgencyTagsCoefficient); + urgencyTerm (urgencyDetails, "next", task->urgency_next (), Task::urgencyNextCoefficient); + urgencyTerm (urgencyDetails, "due", task->urgency_due (), Task::urgencyDueCoefficient); + urgencyTerm (urgencyDetails, "age", task->urgency_age (), Task::urgencyAgeCoefficient); + + // Tag, Project- and UDA-specific coefficients. + std::map ::iterator var; + for (var = Task::coefficients.begin (); var != Task::coefficients.end (); ++var) + { + if (var->first.substr (0, 13) == "urgency.user.") + { + // urgency.user.project..coefficient + std::string::size_type end = std::string::npos; + if (var->first.substr (13, 8) == "project." && + (end = var->first.find (".coefficient")) != std::string::npos) + { + std::string project = var->first.substr (21, end - 21); + if (task->get ("project").find (project) == 0) + urgencyTerm (urgencyDetails, "PROJECT " + project, 1.0, var->second); + } + + // urgency.user.tag..coefficient + if (var->first.substr (13, 4) == "tag." && + (end = var->first.find (".coefficient")) != std::string::npos) + { + std::string name = var->first.substr (17, end - 17); + if (task->hasTag (name)) + urgencyTerm (urgencyDetails, "TAG " + name, 1.0, var->second); + } + } + + // urgency.uda..coefficient + else if (var->first.substr (0, 12) == "urgency.uda.") + { + std::string::size_type end = var->first.find (".coefficient"); + if (end != std::string::npos) + { + std::string name = var->first.substr (12, end - 12); + if (task->has (name)) + urgencyTerm (urgencyDetails, "UDA " + name, 1.0, var->second); + } + } + } + + row = urgencyDetails.addRow (); + urgencyDetails.set (row, 5, rightJustify ("------", 6)); + row = urgencyDetails.addRow (); + urgencyDetails.set (row, 5, rightJustify (format (task->urgency (), 4, 4), 6)); + + // Create a third table, containing undo log change details. ViewText journal; // If an alternating row color is specified, notify the table. @@ -479,6 +502,10 @@ int CmdInfo::execute (std::string& output) << view.render () << "\n"; + if (urgencyDetails.rows () > 0) + out << urgencyDetails.render () + << "\n"; + if (journal.rows () > 0) out << journal.render () << "\n"; @@ -489,24 +516,23 @@ int CmdInfo::execute (std::string& output) } //////////////////////////////////////////////////////////////////////////////// -std::string CmdInfo::urgencyTerm ( +void CmdInfo::urgencyTerm ( + ViewText& view, const std::string& label, float measure, float coefficient) const { float value = measure * coefficient; - if (fabsf (value) > epsilon) - return std::string ( - rightJustify (label, 20) + - " " + - leftJustify (format (measure, 5, 3), 6) + - " * " + - leftJustify (format (coefficient, 4, 2), 4) + - " = " + - leftJustify (format (value, 5, 3), 5) + - "\n"); - - return ""; + if (value != 0.0) + { + int row = view.addRow (); + view.set (row, 0, " " + label); + view.set (row, 1, rightJustify (format (measure, 5, 3), 6)); + view.set (row, 2, "+"); + view.set (row, 3, rightJustify (format (coefficient, 4, 2), 4)); + view.set (row, 4, "="); + view.set (row, 5, rightJustify (format (value, 5, 3), 6)); + } } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdInfo.h b/src/commands/CmdInfo.h index 6ba3df902..a6299d108 100644 --- a/src/commands/CmdInfo.h +++ b/src/commands/CmdInfo.h @@ -29,6 +29,7 @@ #include #include +#include class CmdInfo : public Command { @@ -37,7 +38,7 @@ public: int execute (std::string&); private: - std::string urgencyTerm (const std::string&, float, float) const; + void urgencyTerm (ViewText&, const std::string&, float, float) const; }; #endif diff --git a/src/text.cpp b/src/text.cpp index d0f752672..91f81ffdf 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -985,7 +985,11 @@ std::string rightJustify (const int input, const int width) //////////////////////////////////////////////////////////////////////////////// std::string rightJustify (const std::string& input, const int width) { - return std::string (width - utf8_text_width (input), ' ') + input; + unsigned int len = utf8_text_width (input); + return ((width > len) + ? std::string (width - len, ' ') + : "") + + input; } ////////////////////////////////////////////////////////////////////////////////