mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-09-09 09:40:37 +02:00
Extend bug fix of #1917 to summary command
This commit is contained in:
parent
f5cd9cde05
commit
7cb341ee05
2 changed files with 38 additions and 39 deletions
|
@ -36,6 +36,7 @@
|
||||||
#include <format.h>
|
#include <format.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
#include <main.h>
|
#include <main.h>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CmdSummary::CmdSummary ()
|
CmdSummary::CmdSummary ()
|
||||||
|
@ -146,54 +147,54 @@ int CmdSummary::execute (std::string& output)
|
||||||
bg_color = Color (Context::getContext ().config.get ("color.summary.background"));
|
bg_color = Color (Context::getContext ().config.get ("color.summary.background"));
|
||||||
}
|
}
|
||||||
|
|
||||||
int barWidth = 30;
|
// sort projects into sorted list
|
||||||
std::vector <std::string> processed;
|
std::list<std::string> sortedProjects;
|
||||||
for (auto& i : allProjects)
|
for (auto& i : allProjects)
|
||||||
{
|
{
|
||||||
// store project name
|
if (showAllProjects || countPending[i.first] > 0)
|
||||||
std::string project_name = i.first;
|
|
||||||
// catch project names including '-'
|
|
||||||
if (project_name.find ('-') != std::string::npos)
|
|
||||||
{
|
{
|
||||||
// replace '-' with '=' which has a higher ASCII code
|
const std::vector <std::string> parents = extractParents (i.first);
|
||||||
// and will therefore be processed later
|
if (parents.size ())
|
||||||
std::string new_project = project_name;
|
|
||||||
std::replace(new_project.begin (), new_project.end (), '-', '=');
|
|
||||||
allProjects[new_project] = i.second;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// catch project names including '='
|
|
||||||
// (assuming the user did not create any such projects himself)
|
|
||||||
if (project_name.find ('=') != std::string::npos)
|
|
||||||
{
|
|
||||||
// revert '=' into '-' for correct displaying
|
|
||||||
std::replace(project_name.begin (), project_name.end (), '=', '-');
|
|
||||||
}
|
|
||||||
if (showAllProjects || countPending[project_name] > 0)
|
|
||||||
{
|
|
||||||
const std::vector <std::string> parents = extractParents (project_name);
|
|
||||||
for (auto& parent : parents)
|
|
||||||
{
|
{
|
||||||
if (std::find (processed.begin (), processed.end (), parent)
|
// if parents exist: store iterator position of last parent
|
||||||
== processed.end ())
|
std::list<std::string>::iterator parent_pos;
|
||||||
|
for (auto& parent : parents)
|
||||||
{
|
{
|
||||||
int row = view.addRow ();
|
parent_pos = std::find (sortedProjects.begin (), sortedProjects.end (), parent);
|
||||||
view.set (row, 0, indentProject (parent));
|
// if parent does not exist yet: insert into sorted view
|
||||||
processed.push_back (parent);
|
if (parent_pos == sortedProjects.end ())
|
||||||
|
{
|
||||||
|
sortedProjects.push_back (parent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// insert new element below latest parent
|
||||||
|
if (parent_pos == sortedProjects.end ()) {
|
||||||
|
sortedProjects.push_back (i.first);
|
||||||
|
} else {
|
||||||
|
sortedProjects.insert (++parent_pos, i.first);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if has no parents: simply push to end of list
|
||||||
|
sortedProjects.push_back (i.first);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int barWidth = 30;
|
||||||
|
// construct view from sorted list
|
||||||
|
for (auto& i : sortedProjects)
|
||||||
|
{
|
||||||
int row = view.addRow ();
|
int row = view.addRow ();
|
||||||
view.set (row, 0, (project_name == ""
|
view.set (row, 0, (i == ""
|
||||||
? "(none)"
|
? "(none)"
|
||||||
: indentProject (project_name, " ", '.')));
|
: indentProject (i, " ", '.')));
|
||||||
|
|
||||||
view.set (row, 1, countPending[project_name]);
|
view.set (row, 1, countPending[i]);
|
||||||
if (counter[project_name])
|
if (counter[i])
|
||||||
view.set (row, 2, Duration ((int) (sumEntry[project_name] / (double)counter[project_name])).formatVague ());
|
view.set (row, 2, Duration ((int) (sumEntry[i] / (double)counter[i])).formatVague ());
|
||||||
|
|
||||||
int c = countCompleted[project_name];
|
int c = countCompleted[i];
|
||||||
int p = countPending[project_name];
|
int p = countPending[i];
|
||||||
int completedBar = 0;
|
int completedBar = 0;
|
||||||
if (c + p)
|
if (c + p)
|
||||||
completedBar = (c * barWidth) / (c + p);
|
completedBar = (c * barWidth) / (c + p);
|
||||||
|
@ -216,8 +217,6 @@ int CmdSummary::execute (std::string& output)
|
||||||
if (c + p)
|
if (c + p)
|
||||||
snprintf (percent, 12, "%d%%", 100 * c / (c + p));
|
snprintf (percent, 12, "%d%%", 100 * c / (c + p));
|
||||||
view.set (row, 3, percent);
|
view.set (row, 3, percent);
|
||||||
processed.push_back (project_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
|
|
|
@ -74,9 +74,9 @@ class TestBug1904(TestCase):
|
||||||
|
|
||||||
def validate_order(self, out):
|
def validate_order(self, out):
|
||||||
order = (
|
order = (
|
||||||
|
"a-b",
|
||||||
"a",
|
"a",
|
||||||
" b",
|
" b",
|
||||||
"a-b",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
lines = out.splitlines(True)
|
lines = out.splitlines(True)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue