mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Enhancement - recurring tasks
- Implemented handleRecurringTasks. - Implemented TDB::nextId.
This commit is contained in:
parent
840c61cbbf
commit
4d43b77441
4 changed files with 44 additions and 39 deletions
|
@ -196,6 +196,7 @@ int TDB::loadPending (std::vector <Task>& tasks, Filter& filter)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
mId = 1;
|
||||||
char line[T_LINE_MAX];
|
char line[T_LINE_MAX];
|
||||||
foreach (location, mLocations)
|
foreach (location, mLocations)
|
||||||
{
|
{
|
||||||
|
@ -425,6 +426,12 @@ int TDB::gc ()
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int TDB::nextId ()
|
||||||
|
{
|
||||||
|
return mId++;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
FILE* TDB::openAndLock (const std::string& file)
|
FILE* TDB::openAndLock (const std::string& file)
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,6 +58,7 @@ public:
|
||||||
int commit (); // Write out all tasks
|
int commit (); // Write out all tasks
|
||||||
void upgrade (); // Convert both files to FF4
|
void upgrade (); // Convert both files to FF4
|
||||||
int gc (); // Clean up pending
|
int gc (); // Clean up pending
|
||||||
|
int nextId ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FILE* openAndLock (const std::string&);
|
FILE* openAndLock (const std::string&);
|
||||||
|
|
|
@ -87,6 +87,7 @@ std::string handleCustomReport (const std::string& report)
|
||||||
// TODO Include filter from custom report.
|
// TODO Include filter from custom report.
|
||||||
context.tdb.load (tasks, context.filter);
|
context.tdb.load (tasks, context.filter);
|
||||||
handleRecurrence (tasks);
|
handleRecurrence (tasks);
|
||||||
|
context.tdb.commit ();
|
||||||
context.tdb.unlock ();
|
context.tdb.unlock ();
|
||||||
|
|
||||||
// Filter sequence.
|
// Filter sequence.
|
||||||
|
|
|
@ -55,13 +55,12 @@ extern Context context;
|
||||||
// child tasks need to be generated to fill gaps.
|
// child tasks need to be generated to fill gaps.
|
||||||
void handleRecurrence (std::vector <Task>& tasks)
|
void handleRecurrence (std::vector <Task>& tasks)
|
||||||
{
|
{
|
||||||
/*
|
std::vector <Task> modified;
|
||||||
std::vector <T> modified;
|
|
||||||
|
|
||||||
// Look at all tasks and find any recurring ones.
|
// Look at all tasks and find any recurring ones.
|
||||||
foreach (t, tasks)
|
foreach (t, tasks)
|
||||||
{
|
{
|
||||||
if (t->getStatus () == T::recurring)
|
if (t->getStatus () == Task::recurring)
|
||||||
{
|
{
|
||||||
// Generate a list of due dates for this recurring task, regardless of
|
// Generate a list of due dates for this recurring task, regardless of
|
||||||
// the mask.
|
// the mask.
|
||||||
|
@ -69,22 +68,23 @@ void handleRecurrence (std::vector <Task>& tasks)
|
||||||
if (!generateDueDates (*t, due))
|
if (!generateDueDates (*t, due))
|
||||||
{
|
{
|
||||||
std::cout << "Task "
|
std::cout << "Task "
|
||||||
<< t->getUUID ()
|
<< t->get ("uuid")
|
||||||
<< " ("
|
<< " ("
|
||||||
<< trim (t->getDescription ())
|
<< trim (t->get ("description"))
|
||||||
<< ") is past its 'until' date, and has be deleted" << std::endl;
|
<< ") is past its 'until' date, and has been deleted"
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
// Determine the end date.
|
// Determine the end date.
|
||||||
char endTime[16];
|
char endTime[16];
|
||||||
sprintf (endTime, "%u", (unsigned int) time (NULL));
|
sprintf (endTime, "%u", (unsigned int) time (NULL));
|
||||||
t->setAttribute ("end", endTime);
|
t->set ("end", endTime);
|
||||||
t->setStatus (T::deleted);
|
t->setStatus (Task::deleted);
|
||||||
tdb.modifyT (*t);
|
context.tdb.update (*t);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the mask from the parent task.
|
// Get the mask from the parent task.
|
||||||
std::string mask = t->getAttribute ("mask");
|
std::string mask = t->get ("mask");
|
||||||
|
|
||||||
// Iterate over the due dates, and check each against the mask.
|
// Iterate over the due dates, and check each against the mask.
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
@ -96,25 +96,25 @@ void handleRecurrence (std::vector <Task>& tasks)
|
||||||
mask += '-';
|
mask += '-';
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|
||||||
T rec (*t); // Clone the parent.
|
Task rec (*t); // Clone the parent.
|
||||||
rec.setId (tdb.nextId ()); // Assign a unique id.
|
rec.id = context.tdb.nextId (); // Assign a unique id.
|
||||||
rec.setUUID (uuid ()); // New UUID.
|
rec.set ("uuid", uuid ()); // New UUID.
|
||||||
rec.setStatus (T::pending); // Shiny.
|
rec.setStatus (Task::pending); // Shiny.
|
||||||
rec.setAttribute ("parent", t->getUUID ()); // Remember mom.
|
rec.set ("parent", t->get ("uuid")); // Remember mom.
|
||||||
|
|
||||||
char dueDate[16];
|
char dueDate[16];
|
||||||
sprintf (dueDate, "%u", (unsigned int) d->toEpoch ());
|
sprintf (dueDate, "%u", (unsigned int) d->toEpoch ());
|
||||||
rec.setAttribute ("due", dueDate); // Store generated due date.
|
rec.set ("due", dueDate); // Store generated due date.
|
||||||
|
|
||||||
char indexMask[12];
|
char indexMask[12];
|
||||||
sprintf (indexMask, "%u", (unsigned int) i);
|
sprintf (indexMask, "%u", (unsigned int) i);
|
||||||
rec.setAttribute ("imask", indexMask); // Store index into mask.
|
rec.set ("imask", indexMask); // Store index into mask.
|
||||||
|
|
||||||
// Add the new task to the vector, for immediate use.
|
// Add the new task to the vector, for immediate use.
|
||||||
modified.push_back (rec);
|
modified.push_back (rec);
|
||||||
|
|
||||||
// Add the new task to the DB.
|
// Add the new task to the DB.
|
||||||
tdb.addT (rec);
|
context.tdb.add (rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
|
@ -123,8 +123,8 @@ void handleRecurrence (std::vector <Task>& tasks)
|
||||||
// Only modify the parent if necessary.
|
// Only modify the parent if necessary.
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
{
|
||||||
t->setAttribute ("mask", mask);
|
t->set ("mask", mask);
|
||||||
tdb.modifyT (*t);
|
context.tdb.update (*t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -132,7 +132,6 @@ void handleRecurrence (std::vector <Task>& tasks)
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks = modified;
|
tasks = modified;
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -327,30 +326,28 @@ Date getNextRecurrence (Date& current, std::string& period)
|
||||||
// When the status of a recurring child task changes, the parent task must
|
// When the status of a recurring child task changes, the parent task must
|
||||||
// update it's mask.
|
// update it's mask.
|
||||||
void updateRecurrenceMask (
|
void updateRecurrenceMask (
|
||||||
// TDB& tdb,
|
|
||||||
std::vector <Task>& all,
|
std::vector <Task>& all,
|
||||||
Task& task)
|
Task& task)
|
||||||
{
|
{
|
||||||
/*
|
std::string parent = task.get ("parent");
|
||||||
std::string parent = task.getAttribute ("parent");
|
|
||||||
if (parent != "")
|
if (parent != "")
|
||||||
{
|
{
|
||||||
std::vector <T>::iterator it;
|
std::vector <Task>::iterator it;
|
||||||
for (it = all.begin (); it != all.end (); ++it)
|
for (it = all.begin (); it != all.end (); ++it)
|
||||||
{
|
{
|
||||||
if (it->getUUID () == parent)
|
if (it->get ("uuid") == parent)
|
||||||
{
|
{
|
||||||
unsigned int index = atoi (task.getAttribute ("imask").c_str ());
|
unsigned int index = ::atoi (task.get ("imask").c_str ());
|
||||||
std::string mask = it->getAttribute ("mask");
|
std::string mask = it->get ("mask");
|
||||||
if (mask.length () > index)
|
if (mask.length () > index)
|
||||||
{
|
{
|
||||||
mask[index] = (task.getStatus () == T::pending) ? '-'
|
mask[index] = (task.getStatus () == Task::pending) ? '-'
|
||||||
: (task.getStatus () == T::completed) ? '+'
|
: (task.getStatus () == Task::completed) ? '+'
|
||||||
: (task.getStatus () == T::deleted) ? 'X'
|
: (task.getStatus () == Task::deleted) ? 'X'
|
||||||
: '?';
|
: '?';
|
||||||
|
|
||||||
it->setAttribute ("mask", mask);
|
it->set ("mask", mask);
|
||||||
tdb.modifyT (*it);
|
context.tdb.update (*it);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -358,9 +355,9 @@ void updateRecurrenceMask (
|
||||||
for (unsigned int i = 0; i < index; ++i)
|
for (unsigned int i = 0; i < index; ++i)
|
||||||
mask += "?";
|
mask += "?";
|
||||||
|
|
||||||
mask += (task.getStatus () == T::pending) ? '-'
|
mask += (task.getStatus () == Task::pending) ? '-'
|
||||||
: (task.getStatus () == T::completed) ? '+'
|
: (task.getStatus () == Task::completed) ? '+'
|
||||||
: (task.getStatus () == T::deleted) ? 'X'
|
: (task.getStatus () == Task::deleted) ? 'X'
|
||||||
: '?';
|
: '?';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,7 +365,6 @@ void updateRecurrenceMask (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue