- Added UDA and Orphan support to the 'edit' command.  It will show the
  data, but not yet recognize changes to that data.
This commit is contained in:
Paul Beckingham 2012-07-15 19:34:55 -04:00
parent 360ab3138a
commit 9028ca4945
5 changed files with 96 additions and 0 deletions

View file

@ -113,6 +113,21 @@ std::string CmdEdit::formatDate (
return value;
}
////////////////////////////////////////////////////////////////////////////////
std::string CmdEdit::formatDuration (
Task& task,
const std::string& attribute)
{
std::string value = task.get (attribute);
if (value.length ())
{
Duration dur (strtol (value.c_str (), NULL, 10));
value = dur.formatPrecise ();
}
return value;
}
////////////////////////////////////////////////////////////////////////////////
std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
{
@ -210,6 +225,55 @@ std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
before << " Dependencies: " << allDeps.str () << "\n";
// UDAs
std::vector <std::string> udas;
std::map <std::string, Column*>::iterator col;
for (col = context.columns.begin (); col != context.columns.end (); ++col)
if (context.config.get ("uda." + col->first + ".type") != "")
udas.push_back (col->first);
if (udas.size ())
{
before << "# " << STRING_EDIT_UDA_SEP << "\n";
std::sort (udas.begin (), udas.end ());
std::vector <std::string>::iterator uda;
for (uda = udas.begin (); uda != udas.end (); ++uda)
{
int pad = 13 - uda->length ();
std::string padding = "";
if (pad > 0)
padding = std::string (pad, ' ');
std::string type = context.config.get ("uda." + *uda + ".type");
if (type == "string" || type == "numeric")
before << " UDA " << *uda << ": " << padding << task.get (*uda) << "\n";
else if (type == "date")
before << " UDA " << *uda << ": " << padding << formatDate (task, *uda, dateformat) << "\n";
else if (type == "duration")
before << " UDA " << *uda << ": " << padding << formatDuration (task, *uda) << "\n";
}
}
// UDA orphans
std::vector <std::string> orphans;
task.getUDAOrphans (orphans);
if (orphans.size ())
{
before << "# " << STRING_EDIT_UDA_ORPHAN_SEP << "\n";
std::sort (orphans.begin (), orphans.end ());
std::vector <std::string>::iterator orphan;
for (orphan = orphans.begin (); orphan != orphans.end (); ++orphan)
{
int pad = 6 - orphan->length ();
std::string padding = "";
if (pad > 0)
padding = std::string (pad, ' ');
before << " UDA Orphan " << *orphan << ": " << padding << task.get (*orphan) << "\n";
}
}
before << "# " << STRING_EDIT_END << "\n";
return before.str ();
}
@ -616,6 +680,10 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
for (id = ids.begin (); id != ids.end(); id++)
task.addDependency (*id);
}
// TODO UDAs
// TODO UDA orphans
}
////////////////////////////////////////////////////////////////////////////////