Added ability for UDAs to have a default value.

This commit is contained in:
Thomas
2013-05-07 13:46:10 -04:00
committed by Paul Beckingham
parent a1132f0028
commit 56eab7da0d
7 changed files with 123 additions and 2 deletions

View File

@@ -1260,6 +1260,43 @@ void Task::validate (bool applyDefault /* = true */)
context.columns["due"]->validate (defaultDue))
set ("due", Date (defaultDue).toEpoch ());
}
// If a UDA has a default value in the configuration,
// override with uda.(uda).default, if not specified
if (applyDefault)
{ // Gather a list of all UDAs with a .default value
std::vector <std::string> names;
context.config.all (names);
std::vector <std::string> udas;
std::vector <std::string>::iterator name;
for (name = names.begin (); name != names.end (); ++name)
{
if (name->substr (0, 4) == "uda." &&
name->find (".default") != std::string::npos)
{
std::string::size_type period = name->find ('.', 4);
if (period != std::string::npos)
udas.push_back (name->substr (4, period - 4));
}
}
if (udas.size ())
{ // For each of those, setup the default value on the task now,
// of course only if we don't have one on the command line already
std::vector <std::string>::iterator uda;
for (uda = udas.begin (); uda != udas.end (); ++uda)
{
std::string type = context.config.get ("uda." + *uda + ".type");
std::string defVal = context.config.get ("uda." + *uda + ".default");
// If the default is empty, and we already have a value, skip it
if (defVal != "" && get (*uda) == "")
set(*uda,defVal);
}
}
}
// 2) To provide suitable warnings about odd states

View File

@@ -77,13 +77,15 @@ int CmdUDAs::execute (std::string& output)
{
std::sort (udas.begin (), udas.end ());
// Render a list of UDA name, type and label.
// Render a list of UDA name, type, label, allowed values,
// possible default value, and finally the usage count.
ViewText view;
view.width (context.getWidth ());
view.add (Column::factory ("string", STRING_COLUMN_LABEL_UDA));
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_DEFAULT));
view.add (Column::factory ("string", STRING_COLUMN_LABEL_UDACOUNT));
std::vector <std::string>::iterator uda;
@@ -92,6 +94,7 @@ int CmdUDAs::execute (std::string& output)
std::string type = context.config.get ("uda." + *uda + ".type");
std::string label = context.config.get ("uda." + *uda + ".label");
std::string values = context.config.get ("uda." + *uda + ".values");
std::string defval = context.config.get ("uda." + *uda + ".default");
if (label == "")
label = *uda;
@@ -107,7 +110,8 @@ int CmdUDAs::execute (std::string& output)
view.set (row, 1, type);
view.set (row, 2, label);
view.set (row, 3, values);
view.set (row, 4, count);
view.set (row, 4, defval);
view.set (row, 5, count);
}
out << optionalBlankLine ()

View File

@@ -176,6 +176,7 @@
#define STRING_COLUMN_LABEL_UDA "Name"
#define STRING_COLUMN_LABEL_TYPE "Type"
#define STRING_COLUMN_LABEL_LABEL "Label"
#define STRING_COLUMN_LABEL_DEFAULT "Default"
#define STRING_COLUMN_LABEL_VALUES "Allowed Values"
#define STRING_COLUMN_LABEL_UDACOUNT "Usage Count"
#define STRING_COLUMN_LABEL_ORPHAN "Orphan UDA"

View File

@@ -178,6 +178,7 @@
#define STRING_COLUMN_LABEL_UDA "Nombre"
#define STRING_COLUMN_LABEL_TYPE "Tipo"
#define STRING_COLUMN_LABEL_LABEL "Etiqueta"
#define STRING_COLUMN_LABEL_DEFAULT "Defecto"
#define STRING_COLUMN_LABEL_VALUES "Valores permitidos"
#define STRING_COLUMN_LABEL_UDACOUNT "Recuento de uso"
#define STRING_COLUMN_LABEL_ORPHAN "UDA huérfano"

View File

@@ -176,6 +176,7 @@
#define STRING_COLUMN_LABEL_UDA "Name"
#define STRING_COLUMN_LABEL_TYPE "Type"
#define STRING_COLUMN_LABEL_LABEL "Label"
#define STRING_COLUMN_LABEL_DEFAULT "Default"
#define STRING_COLUMN_LABEL_VALUES "Allowed Values"
#define STRING_COLUMN_LABEL_UDACOUNT "Usage Count"
#define STRING_COLUMN_LABEL_ORPHAN "Orphan UDA"

View File

@@ -177,6 +177,7 @@
#define STRING_COLUMN_LABEL_UDA "Nome"
#define STRING_COLUMN_LABEL_TYPE "Tipo"
#define STRING_COLUMN_LABEL_LABEL "Etichetta"
#define STRING_COLUMN_LABEL_DEFAULT "Predefinito"
#define STRING_COLUMN_LABEL_VALUES "Valori consentiti"
#define STRING_COLUMN_LABEL_UDACOUNT "Conteggio Uso"
#define STRING_COLUMN_LABEL_ORPHAN "UDA Orfano"