From 1b329d34b355d6ea5d637e9e8d940f0beac07d67 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 4 Jul 2012 13:42:36 -0400 Subject: [PATCH] UDAs - The 'udas' command now accepts a filter, and reports UDA usage counts. - The 'udas' command also detects and lists orphaned UDAs and usage counts. --- ChangeLog | 2 +- src/commands/CmdUDAs.cpp | 51 +++++++++++++++++++++++++++++++++++++++- src/en-US.h | 4 ++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 49c49794c..c123a4dfb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,7 +10,7 @@ Features + Feature #516, which allows the duplication of completed tasks (thanks to Peter De Poorter, Ethan Schoonover). + Feature #921, which implements a 'udas' command that describes defined UDAs, - and a '_udas' for completion purposes. + and a '_udas' for completion purposes. Also detects UDA orphans. + Applied patch for feature #1005, which prevents the update-holidays.pl script from creating duplicate holidays (thanks to Jörg Plate). + Added the new 'indented' format for the 'project' attribute. diff --git a/src/commands/CmdUDAs.cpp b/src/commands/CmdUDAs.cpp index d26bb6946..63f29edc3 100644 --- a/src/commands/CmdUDAs.cpp +++ b/src/commands/CmdUDAs.cpp @@ -71,6 +71,10 @@ int CmdUDAs::execute (std::string& output) } } + // Load/filter all data. + std::vector 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 ::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 ::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 orphans; + std::vector ::iterator i; + for (i = filtered.begin (); i != filtered.end (); ++i) + { + std::map ::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 ::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; } diff --git a/src/en-US.h b/src/en-US.h index 71aada672..ac1e9b80a 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -187,6 +187,8 @@ #define STRING_COLUMN_LABEL_TYPE "Type" #define STRING_COLUMN_LABEL_LABEL "Label" #define STRING_COLUMN_LABEL_VALUES "Allowed Values" +#define STRING_COLUMN_LABEL_UDACOUNT "Usage Count" +#define STRING_COLUMN_LABEL_ORPHAN "Orphan UDA" // Column Examples #define STRING_COLUMN_EXAMPLES_TAGS "home @chore" @@ -315,6 +317,8 @@ #define STRING_CMD_UDAS_NO "No UDAs defined." #define STRING_CMD_UDAS_SUMMARY "{1} UDA defined" #define STRING_CMD_UDAS_SUMMARY2 "{1} UDAs defined" +#define STRING_CMD_UDAS_ORPHAN "{1} Orphan UDA" +#define STRING_CMD_UDAS_ORPHANS "{1} Orphan UDAs" #define STRING_CMD_DELETE_USAGE "Deletes the specified task" #define STRING_CMD_DELETE_CONFIRM "Permanently delete task {1} '{2}'?"