mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-09-08 15:20:36 +02:00
Extract project sorting function
This commit is contained in:
parent
7cb341ee05
commit
6a8beed7f5
4 changed files with 59 additions and 61 deletions
|
@ -112,29 +112,7 @@ int CmdProjects::execute (std::string& output)
|
|||
|
||||
// create sorted list of table entries
|
||||
std::list <std::pair<std::string, int>> sorted_view;
|
||||
for (auto& project : unique)
|
||||
{
|
||||
const std::vector <std::string> parents = extractParents (project.first);
|
||||
if (parents.size ()) {
|
||||
// if parents exist: store iterator position of last parent
|
||||
std::list<std::pair<std::string, int>>::iterator parent_pos;
|
||||
for (auto& parent : parents)
|
||||
{
|
||||
parent_pos = std::find_if (sorted_view.begin (), sorted_view.end (),
|
||||
[&parent](const std::pair<std::string, int>& element) { return element.first == parent; }
|
||||
);
|
||||
// if parent does not exist yet: insert into sorted view
|
||||
if (parent_pos == sorted_view.end()) {
|
||||
sorted_view.insert (parent_pos, std::make_pair(parent, 1));
|
||||
}
|
||||
}
|
||||
// insert new element below latest parent
|
||||
sorted_view.insert (++parent_pos, project);
|
||||
} else {
|
||||
// if has no parents: simply push to end of list
|
||||
sorted_view.push_back (project);
|
||||
}
|
||||
}
|
||||
sort_projects (sorted_view, unique);
|
||||
|
||||
// construct view from sorted list
|
||||
for (auto& item: sorted_view) {
|
||||
|
|
|
@ -148,53 +148,24 @@ int CmdSummary::execute (std::string& output)
|
|||
}
|
||||
|
||||
// sort projects into sorted list
|
||||
std::list<std::string> sortedProjects;
|
||||
for (auto& i : allProjects)
|
||||
{
|
||||
if (showAllProjects || countPending[i.first] > 0)
|
||||
{
|
||||
const std::vector <std::string> parents = extractParents (i.first);
|
||||
if (parents.size ())
|
||||
{
|
||||
// if parents exist: store iterator position of last parent
|
||||
std::list<std::string>::iterator parent_pos;
|
||||
for (auto& parent : parents)
|
||||
{
|
||||
parent_pos = std::find (sortedProjects.begin (), sortedProjects.end (), parent);
|
||||
// if parent does not exist yet: insert into sorted view
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::list<std::pair<std::string, int>> sortedProjects;
|
||||
sort_projects (sortedProjects, allProjects);
|
||||
|
||||
int barWidth = 30;
|
||||
// construct view from sorted list
|
||||
for (auto& i : sortedProjects)
|
||||
{
|
||||
int row = view.addRow ();
|
||||
view.set (row, 0, (i == ""
|
||||
view.set (row, 0, (i.first == ""
|
||||
? "(none)"
|
||||
: indentProject (i, " ", '.')));
|
||||
: indentProject (i.first, " ", '.')));
|
||||
|
||||
view.set (row, 1, countPending[i]);
|
||||
if (counter[i])
|
||||
view.set (row, 2, Duration ((int) (sumEntry[i] / (double)counter[i])).formatVague ());
|
||||
view.set (row, 1, countPending[i.first]);
|
||||
if (counter[i.first])
|
||||
view.set (row, 2, Duration ((int) (sumEntry[i.first] / (double)counter[i.first])).formatVague ());
|
||||
|
||||
int c = countCompleted[i];
|
||||
int p = countPending[i];
|
||||
int c = countCompleted[i.first];
|
||||
int p = countPending[i.first];
|
||||
int completedBar = 0;
|
||||
if (c + p)
|
||||
completedBar = (c * barWidth) / (c + p);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue