- Missing data now tolerated for UDAs.
- Info command includes all column data, even for unrecognized types.
This commit is contained in:
Paul Beckingham 2012-03-05 22:49:41 -05:00
parent 8177b74a52
commit c8027a17c1
4 changed files with 163 additions and 75 deletions

View file

@ -62,38 +62,42 @@ ColumnUDA::~ColumnUDA ()
//
void ColumnUDA::measure (Task& task, int& minimum, int& maximum)
{
minimum = maximum = 0;
if (_style == "default")
{
std::string value = task.get (_name);
if (value != "")
{
if (_type == "date")
{
// Determine the output date format, which uses a hierarchy of definitions.
// rc.report.<report>.dateformat
// rc.dateformat.report
// rc.dateformat.
Date date ((time_t) strtol (value.c_str (), NULL, 10));
std::string format = context.config.get ("report." + _report + ".dateformat");
if (format == "")
format = context.config.get ("dateformat.report");
if (format == "")
format = context.config.get ("dateformat");
if (_type == "date")
{
// Determine the output date format, which uses a hierarchy of definitions.
// rc.report.<report>.dateformat
// rc.dateformat.report
// rc.dateformat.
Date date ((time_t) strtol (value.c_str (), NULL, 10));
std::string format = context.config.get ("report." + _report + ".dateformat");
if (format == "")
format = context.config.get ("dateformat.report");
if (format == "")
format = context.config.get ("dateformat");
minimum = maximum = date.toString (format).length ();
}
else if (_type == "duration")
{
minimum = maximum = Duration (value).formatCompact ().length ();
}
else if (_type == "string")
{
std::string stripped = Color::strip (value);
maximum = longestLine (stripped);
minimum = longestWord (stripped);
}
else if (_type == "numeric")
{
minimum = maximum = value.length ();
minimum = maximum = date.toString (format).length ();
}
else if (_type == "duration")
{
minimum = maximum = Duration (value).formatCompact ().length ();
}
else if (_type == "string")
{
std::string stripped = Color::strip (value);
maximum = longestLine (stripped);
minimum = longestWord (stripped);
}
else if (_type == "numeric")
{
minimum = maximum = value.length ();
}
}
}
else
@ -110,45 +114,47 @@ void ColumnUDA::render (
if (_style == "default")
{
std::string value = task.get (_name);
if (value != "")
{
if (_type == "date")
{
// Determine the output date format, which uses a hierarchy of definitions.
// rc.report.<report>.dateformat
// rc.dateformat.report
// rc.dateformat.
std::string format = context.config.get ("report." + _report + ".dateformat");
if (format == "")
format = context.config.get ("dateformat.report");
if (format == "")
format = context.config.get ("dateformat");
if (_type == "date")
{
// Determine the output date format, which uses a hierarchy of definitions.
// rc.report.<report>.dateformat
// rc.dateformat.report
// rc.dateformat.
std::string format = context.config.get ("report." + _report + ".dateformat");
if (format == "")
format = context.config.get ("dateformat.report");
if (format == "")
format = context.config.get ("dateformat");
lines.push_back (
color.colorize (
leftJustify (
Date ((time_t) strtol (value.c_str (), NULL, 10))
.toString (format), width)));
}
else if (_type == "duration")
{
lines.push_back (
color.colorize (
rightJustify (
Duration (value).formatCompact (),
width)));
}
else if (_type == "string")
{
std::vector <std::string> raw;
wrapText (raw, value, width, _hyphenate);
lines.push_back (
color.colorize (
leftJustify (
Date ((time_t) strtol (value.c_str (), NULL, 10))
.toString (format), width)));
}
else if (_type == "duration")
{
lines.push_back (
color.colorize (
rightJustify (
Duration (value).formatCompact (),
width)));
}
else if (_type == "string")
{
std::vector <std::string> raw;
wrapText (raw, value, width, _hyphenate);
std::vector <std::string>::iterator i;
for (i = raw.begin (); i != raw.end (); ++i)
lines.push_back (color.colorize (leftJustify (*i, width)));
}
else if (_type == "numeric")
{
lines.push_back (color.colorize (rightJustify (value, width)));
std::vector <std::string>::iterator i;
for (i = raw.begin (); i != raw.end (); ++i)
lines.push_back (color.colorize (leftJustify (*i, width)));
}
else if (_type == "numeric")
{
lines.push_back (color.colorize (rightJustify (value, width)));
}
}
}
}

View file

@ -323,9 +323,11 @@ int CmdInfo::execute (std::string& output)
// Show any UDAs
std::vector <std::string> all = task->all ();
std::vector <std::string>::iterator att;
std::string type;
for (att = all.begin (); att != all.end (); ++att)
{
if (context.config.get ("uda." + *att + ".type") != "")
type = context.config.get ("uda." + *att + ".type");
if (type != "")
{
Column* col = context.columns[*att];
if (col)
@ -335,14 +337,25 @@ int CmdInfo::execute (std::string& output)
{
row = view.addRow ();
view.set (row, 0, col->label ());
if (type == "date")
{
// Determine the output date format, which uses a hierarchy of definitions.
// rc.report.<report>.dateformat
// rc.dateformat.report
// rc.dateformat.
std::string format = context.config.get ("report.info.dateformat");
if (format == "")
format = context.config.get ("dateformat.report");
if (format == "")
format = context.config.get ("dateformat");
value = Date (value).toString (format);
}
else if (type == "duration")
value = Duration (value).formatCompact ();
view.set (row, 1, value);
/*
std::vector <std::string> lines;
Color color;
col->render (lines, *task, 0, color);
join (value, " ", lines);
view.set (row, 1, value);
*/
}
}
}