- Extended DOM support:
    <id|uuid>.<date>.year
    <id|uuid>.<date>.month
    <id|uuid>.<date>.day
    <id|uuid>.<date>.week
    <id|uuid>.<date>.weekday
    <id|uuid>.<date>.julian
    <id|uuid>.<date>.hour
    <id|uuid>.<date>.minute
    <id|uuid>.<date>.second
    <id|uuid>.tags.<literal>
    <id|uuid>.annotations.<N>.entry
    <id|uuid>.annotations.<N>.entry.year
    <id|uuid>.annotations.<N>.entry.month
    <id|uuid>.annotations.<N>.entry.day
    <id|uuid>.annotations.<N>.entry.week
    <id|uuid>.annotations.<N>.entry.weekday
    <id|uuid>.annotations.<N>.entry.julian
    <id|uuid>.annotations.<N>.entry.hour
    <id|uuid>.annotations.<N>.entry.minute
    <id|uuid>.annotations.<N>.entry.second
    <id|uuid>.annotations.<N>.description
This commit is contained in:
Paul Beckingham 2014-06-06 19:43:20 -04:00
parent 4c3a59a333
commit f969bcbe59
2 changed files with 150 additions and 50 deletions

View file

@ -26,8 +26,11 @@
#include <cmake.h> #include <cmake.h>
#include <sstream> #include <sstream>
#include <map>
#include <stdlib.h>
#include <Context.h> #include <Context.h>
#include <Nibbler.h> #include <Nibbler.h>
#include <Date.h>
#include <text.h> #include <text.h>
#include <i18n.h> #include <i18n.h>
#include <DOM.h> #include <DOM.h>
@ -194,20 +197,26 @@ bool DOM::get (const std::string& name, std::string& value)
// <date>.year // <date>.year
// <date>.month // <date>.month
// <date>.day // <date>.day
// <date>.week
// <date>.weekday
// <date>.julian
// <date>.hour // <date>.hour
// <date>.minute // <date>.minute
// <date>.second // <date>.second
// //
// <tag>.<literal> Includes virtual tags // tags.<literal> Includes virtual tags
// //
// <annotation>.<N>.entry // annotations.<N>.entry
// <annotation>.<N>.entry.year // annotations.<N>.entry.year
// <annotation>.<N>.entry.month // annotations.<N>.entry.month
// <annotation>.<N>.entry.day // annotations.<N>.entry.day
// <annotation>.<N>.entry.hour // annotations.<N>.entry.week
// <annotation>.<N>.entry.minute // annotations.<N>.entry.weekday
// <annotation>.<N>.entry.second // annotations.<N>.entry.julian
// <annotation>.<N>.description // annotations.<N>.entry.hour
// annotations.<N>.entry.minute
// annotations.<N>.entry.second
// annotations.<N>.description
// //
bool DOM::get (const std::string& name, const Task& task, std::string& value) bool DOM::get (const std::string& name, const Task& task, std::string& value)
{ {
@ -247,23 +256,19 @@ bool DOM::get (const std::string& name, const Task& task, std::string& value)
std::string uuid; std::string uuid;
bool proceed = false; bool proceed = false;
if (n.getInt (id)) if (n.getInt (id) && n.depleted ())
{ {
if (n.skip ('.')) if (id == task.id)
{ ref = task;
if (id == task.id)
ref = task;
else
context.tdb2.get (id, ref);
proceed = true;
}
else else
n.restore (); context.tdb2.get (id, ref);
proceed = true;
} }
else if (n.getUUID (uuid)) else
{ {
if (n.skip ('.')) n.restore ();
if (n.getUUID (uuid) && n.depleted ())
{ {
if (uuid == task.get ("uuid")) if (uuid == task.get ("uuid"))
ref = task; ref = task;
@ -297,33 +302,104 @@ bool DOM::get (const std::string& name, const Task& task, std::string& value)
} }
else if (elements.size () == 3) else if (elements.size () == 3)
{ {
// <date>.year // tags.<tag>
// <date>.month if (canonical == "tags")
// <date>.day
// <date>.hour
// <date>.minute
// <date>.second
// <tag>.<literal>
if (elements[1] == "tag")
{ {
value = ref.hasTag (elements[2]) ? elements[2] : ""; value = ref.hasTag (elements[2]) ? elements[2] : "";
return true; return true;
} }
Column* column = context.columns[canonical];
if (column && column->type () == "date")
{
// <date>.year
// <date>.month
// <date>.day
// <date>.week
// <date>.weekday
// <date>.julian
// <date>.hour
// <date>.minute
// <date>.second
Date date (ref.get_date (canonical));
if (elements[2] == "year") { value = format (date.year ()); return true; }
else if (elements[2] == "month") { value = format (date.month ()); return true; }
else if (elements[2] == "day") { value = format (date.day ()); return true; }
else if (elements[2] == "week") { value = format (date.week ()); return true; }
else if (elements[2] == "weekday") { value = format (date.dayOfWeek ()); return true; }
else if (elements[2] == "julian") { value = format (date.dayOfYear ()); return true; }
else if (elements[2] == "hour") { value = format (date.hour ()); return true; }
else if (elements[2] == "minute") { value = format (date.minute ()); return true; }
else if (elements[2] == "second") { value = format (date.second ()); return true; }
}
} }
else if (elements.size () == 3) }
else if (elements[1] == "annotations")
{
if (elements.size () == 4)
{ {
// <annotation>.<N>.entry std::map <std::string, std::string> annos;
// <annotation>.<N>.description ref.getAnnotations (annos);
int a = strtol (elements[2].c_str (), NULL, 10);
int count = 0;
// Count off the 'a'th annotation.
std::map <std::string, std::string>::iterator i;
for (i = annos.begin (); i != annos.end (); ++i)
{
if (++count == a)
{
if (elements[3] == "entry")
{
// annotation_1234567890
// 0 ^11
value = i->first.substr (11);
return true;
}
else if (elements[3] == "description")
{
value = i->second;
return true;
}
}
}
} }
else if (elements.size () == 4) else if (elements.size () == 5)
{ {
// <annotation>.<N>.entry.year std::map <std::string, std::string> annos;
// <annotation>.<N>.entry.month ref.getAnnotations (annos);
// <annotation>.<N>.entry.day
// <annotation>.<N>.entry.hour int a = strtol (elements[2].c_str (), NULL, 10);
// <annotation>.<N>.entry.minute int count = 0;
// <annotation>.<N>.entry.second
// Count off the 'a'th annotation.
std::map <std::string, std::string>::iterator i;
for (i = annos.begin (); i != annos.end (); ++i)
{
if (++count == a)
{
// <annotations>.<N>.entry.year
// <annotations>.<N>.entry.month
// <annotations>.<N>.entry.day
// <annotations>.<N>.entry.week
// <annotations>.<N>.entry.weekday
// <annotations>.<N>.entry.julian
// <annotations>.<N>.entry.hour
// <annotations>.<N>.entry.minute
// <annotations>.<N>.entry.second
Date date (i->first.substr (11));
if (elements[4] == "year") { value = format (date.year ()); return true; }
else if (elements[4] == "month") { value = format (date.month ()); return true; }
else if (elements[4] == "day") { value = format (date.day ()); return true; }
else if (elements[4] == "week") { value = format (date.week ()); return true; }
else if (elements[4] == "weekday") { value = format (date.dayOfWeek ()); return true; }
else if (elements[4] == "julian") { value = format (date.dayOfYear ()); return true; }
else if (elements[4] == "hour") { value = format (date.hour ()); return true; }
else if (elements[4] == "minute") { value = format (date.minute ()); return true; }
else if (elements[4] == "second") { value = format (date.second ()); return true; }
}
}
} }
} }
} }

View file

@ -27,7 +27,7 @@
use strict; use strict;
use warnings; use warnings;
use Test::More tests => 12; use Test::More tests => 20;
# Ensure environment has no influence. # Ensure environment has no influence.
delete $ENV{'TASKDATA'}; delete $ENV{'TASKDATA'};
@ -73,11 +73,35 @@ like ($output, qr/^$/, "DOM 4.description --> ''");
$output = qx{../src/task rc:$rc _get 3.tags 2>&1}; $output = qx{../src/task rc:$rc _get 3.tags 2>&1};
like ($output, qr/^tag1,tag2$/, "$ut: <id>.<tags>"); like ($output, qr/^tag1,tag2$/, "$ut: <id>.<tags>");
$output = qx{../src/task rc:$rc _get 3.tag.tag1 2>&1}; $output = qx{../src/task rc:$rc _get 3.tags.tag1 2>&1};
like ($output, qr/^tag1,tag2$/, "$ut: <id>.tag.tag1"); like ($output, qr/^tag1$/, "$ut: <id>.tags.tag1");
$output = qx{../src/task rc:$rc _get 3.tag.OVERDUE 2>&1}; $output = qx{../src/task rc:$rc _get 3.tags.OVERDUE 2>&1};
like ($output, qr/^OVERDUE$/, "$ut: <id>.tag.<tag>"); like ($output, qr/^OVERDUE$/, "$ut: <id>.tags.<tag>");
$output = qx{../src/task rc:$rc _get 3.due.year 2>&1};
like ($output, qr/^\d{4}$/, "$ut: <id>.due.year");
$output = qx{../src/task rc:$rc _get 3.due.month 2>&1};
like ($output, qr/^\d{1,2}$/, "$ut: <id>.due.month");
$output = qx{../src/task rc:$rc _get 3.due.day 2>&1};
like ($output, qr/^\d{1,2}$/, "$ut: <id>.due.day");
$output = qx{../src/task rc:$rc _get 3.due.week 2>&1};
like ($output, qr/^\d{1,2}$/, "$ut: <id>.due.week");
$output = qx{../src/task rc:$rc _get 3.due.weekday 2>&1};
like ($output, qr/^\d{1}$/, "$ut: <id>.due.weekday");
$output = qx{../src/task rc:$rc _get 3.due.hour 2>&1};
like ($output, qr/^\d{1,2}$/, "$ut: <id>.due.hour");
$output = qx{../src/task rc:$rc _get 3.due.minute 2>&1};
like ($output, qr/^\d{1,2}$/, "$ut: <id>.due.minute");
$output = qx{../src/task rc:$rc _get 3.due.second 2>&1};
like ($output, qr/^\d{1,2}$/, "$ut: <id>.due.second");
$output = qx{../src/task rc:$rc _get 3.due.year 2>&1}; $output = qx{../src/task rc:$rc _get 3.due.year 2>&1};
like ($output, qr/^\d{4}$/, "$ut: <id>.due.year"); like ($output, qr/^\d{4}$/, "$ut: <id>.due.year");
@ -85,11 +109,11 @@ like ($output, qr/^\d{4}$/, "$ut: <id>.due.year");
qx{../src/task rc:$rc 3 annotate note 2>&1}; qx{../src/task rc:$rc 3 annotate note 2>&1};
ok ($? == 0, "$ut: add annotation"); ok ($? == 0, "$ut: add annotation");
$output = qx{../src/task rc:$rc _get 3.annotation.1.entry 2>&1}; $output = qx{../src/task rc:$rc _get 3.annotations.1.entry 2>&1};
like ($output, qr/^\d+$/, "$ut: <id>.annotation.1.entry"); like ($output, qr/^\d+$/, "$ut: <id>.annotations.1.entry");
$output = qx{../src/task rc:$rc _get 3.annotation.1.description 2>&1}; $output = qx{../src/task rc:$rc _get 3.annotations.1.description 2>&1};
like ($output, qr/^note$/, "$ut: <id>.annotation.1.description"); like ($output, qr/^note$/, "$ut: <id>.annotations.1.description");
# Cleanup. # Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data), $rc; unlink qw(pending.data completed.data undo.data backlog.data), $rc;