- The 'udas' command now accepts a filter, and reports UDA usage counts.
- The 'udas' command also detects and lists orphaned UDAs and usage counts.
This commit is contained in:
Paul Beckingham 2012-07-04 13:42:36 -04:00
parent 19cfd5453d
commit 1b329d34b3
3 changed files with 55 additions and 2 deletions

View file

@ -71,6 +71,10 @@ int CmdUDAs::execute (std::string& output)
}
}
// Load/filter all data.
std::vector <Task> filtered;
filter (filtered);
if (udas.size ())
{
std::sort (udas.begin (), udas.end ());
@ -82,7 +86,7 @@ int CmdUDAs::execute (std::string& output)
view.add (Column::factory ("string", STRING_COLUMN_LABEL_TYPE));
view.add (Column::factory ("string", STRING_COLUMN_LABEL_LABEL));
view.add (Column::factory ("string", STRING_COLUMN_LABEL_VALUES));
view.add (Column::factory ("string", STRING_COLUMN_LABEL_UDACOUNT));
std::vector <std::string>::iterator uda;
for (uda = udas.begin (); uda != udas.end (); ++uda)
@ -93,11 +97,19 @@ int CmdUDAs::execute (std::string& output)
if (label == "")
label = *uda;
// Count UDA usage by UDA.
int count = 0;
std::vector <Task>::iterator i;
for (i = filtered.begin (); i != filtered.end (); ++i)
if (i->has (*uda))
++count;
int row = view.addRow ();
view.set (row, 0, *uda);
view.set (row, 1, type);
view.set (row, 2, label);
view.set (row, 3, values);
view.set (row, 4, count);
}
out << optionalBlankLine ()
@ -114,6 +126,43 @@ int CmdUDAs::execute (std::string& output)
rc = 1;
}
// Orphans are task attributes that are not represented in context.columns.
std::map <std::string, int> orphans;
std::vector <Task>::iterator i;
for (i = filtered.begin (); i != filtered.end (); ++i)
{
std::map <std::string, std::string>::iterator att;
for (att = i->begin (); att != i->end (); ++att)
if (att->first.substr (0, 11) != "annotation_" &&
context.columns.find (att->first) == context.columns.end ())
orphans[att->first]++;
}
if (orphans.size ())
{
// Display the orphans and their counts.
ViewText orphanView;
orphanView.width (context.getWidth ());
orphanView.add (Column::factory ("string", STRING_COLUMN_LABEL_ORPHAN));
orphanView.add (Column::factory ("string", STRING_COLUMN_LABEL_UDACOUNT));
std::map <std::string, int>::iterator o;
for (o = orphans.begin (); o != orphans.end (); ++o)
{
int row = orphanView.addRow ();
orphanView.set (row, 0, o->first);
orphanView.set (row, 1, o->second);
}
out << optionalBlankLine ()
<< orphanView.render ()
<< optionalBlankLine ()
<< (udas.size () == 1
? format (STRING_CMD_UDAS_ORPHAN, udas.size ())
: format (STRING_CMD_UDAS_ORPHANS, udas.size ()))
<< "\n";
}
output = out.str ();
return rc;
}