- 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

@ -945,6 +945,28 @@ void Task::removeTag (const std::string& tag)
recalc_urgency = true;
}
////////////////////////////////////////////////////////////////////////////////
// A UDA is an attribute that has supporting config entries such as a data type:
// 'uda.<name>.type'
void Task::getUDAs (std::vector <std::string>& names) const
{
Task::const_iterator it;
for (it = this->begin (); it != this->end (); ++it)
if (context.config.get ("uda." + it->first + ".type") != "")
names.push_back (it->first);
}
////////////////////////////////////////////////////////////////////////////////
// A UDA Orphan is an attribute that is not represented in context.columns.
void Task::getUDAOrphans (std::vector <std::string>& names) const
{
Task::const_iterator it;
for (it = this->begin (); it != this->end (); ++it)
if (it->first.substr (0, 11) != "annotation_")
if (context.columns.find (it->first) == context.columns.end ())
names.push_back (it->first);
}
////////////////////////////////////////////////////////////////////////////////
void Task::substitute (
const std::string& from,

View file

@ -103,6 +103,9 @@ public:
void getDependencies (std::vector <int>&) const;
void getDependencies (std::vector <std::string>&) const;
void getUDAs (std::vector <std::string>&) const;
void getUDAOrphans (std::vector <std::string>&) const;
void substitute (const std::string&, const std::string&, bool);
void validate (bool applyDefault = true);

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
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -42,6 +42,7 @@ public:
private:
std::string findValue (const std::string&, const std::string&);
std::string formatDate (Task&, const std::string&, const std::string&);
std::string formatDuration (Task&, const std::string&);
std::string formatTask (Task, const std::string&);
void parseTask (Task&, const std::string&, const std::string&);
bool editFile (Task&);

View file

@ -618,6 +618,8 @@
#define STRING_EDIT_UNWRITABLE "Your data.location directory is not writable."
#define STRING_EDIT_TAG_SEP "Separate the tags with spaces, like this: tag1 tag2"
#define STRING_EDIT_DEP_SEP "Dependencies should be a comma-separated list of task IDs/UUIDs or ID ranges, with no spaces."
#define STRING_EDIT_UDA_SEP "User Defined Attributes"
#define STRING_EDIT_UDA_ORPHAN_SEP "User Defined Attribute Orphans"
#define STRING_EDIT_END "End"
#define STRING_EDIT_PROJECT_MOD "Project modified."