TI-68: Let commands convert synthetic intervals before modifying them

- command 'lengthen'
- command 'move'
- command 'shorten'
- command 'tag'
- command 'untag'
This commit is contained in:
Thomas Lauf 2017-04-08 14:47:47 +02:00
parent 52853db6bd
commit 9b0f8e8c15
5 changed files with 108 additions and 2 deletions

View file

@ -59,7 +59,30 @@ int CmdLengthen (
Interval filter;
auto tracked = getTracked (database, rules, filter);
// Apply tags to ids.
bool dirty = true;
for (auto& id : ids)
{
if (id > static_cast <int> (tracked.size ()))
throw format ("ID '@{1}' does not correspond to any tracking.", id);
if (tracked[tracked.size() - id].synthetic && dirty)
{
auto latest = getLatestInterval(database);
auto exclusions = getAllExclusions (rules, filter.range);
Interval modified {latest};
// Update database.
database.deleteInterval (latest);
for (auto& interval : flatten (modified, exclusions))
database.addInterval (interval);
dirty = false;
}
}
// Lengthen intervals specified by ids
for (auto& id : ids)
{
if (id > static_cast <int> (tracked.size ()))

View file

@ -64,9 +64,23 @@ int CmdMove (
Interval filter;
auto tracked = getTracked (database, rules, filter);
if (id > static_cast <int> (tracked.size ()))
throw format ("ID '@{1}' does not correspond to any tracking.", id);
if (tracked[tracked.size() - id].synthetic)
{
auto latest = getLatestInterval(database);
auto exclusions = getAllExclusions (rules, filter.range);
Interval modified {latest};
// Update database.
database.deleteInterval (latest);
for (auto& interval : flatten (modified, exclusions))
database.addInterval (interval);
}
// Move start time.
Interval i = tracked[tracked.size () - id];
Datetime start (new_start);

View file

@ -59,7 +59,30 @@ int CmdShorten (
Interval filter;
auto tracked = getTracked (database, rules, filter);
// Apply tags to ids.
bool dirty = true;
for (auto& id : ids)
{
if (id > static_cast <int> (tracked.size ()))
throw format ("ID '@{1}' does not correspond to any tracking.", id);
if (tracked[tracked.size() - id].synthetic && dirty)
{
auto latest = getLatestInterval(database);
auto exclusions = getAllExclusions (rules, filter.range);
Interval modified {latest};
// Update database.
database.deleteInterval (latest);
for (auto& interval : flatten (modified, exclusions))
database.addInterval (interval);
dirty = false;
}
}
// Shorten intervals specified by ids
for (auto& id : ids)
{
if (id > static_cast <int> (tracked.size ()))

View file

@ -57,6 +57,29 @@ int CmdTag (
Interval filter;
auto tracked = getTracked (database, rules, filter);
bool dirty = true;
for (auto& id : ids)
{
if (id > static_cast <int> (tracked.size ()))
throw format ("ID '@{1}' does not correspond to any tracking.", id);
if (tracked[tracked.size() - id].synthetic && dirty)
{
auto latest = getLatestInterval(database);
auto exclusions = getAllExclusions (rules, filter.range);
Interval modified {latest};
// Update database.
database.deleteInterval (latest);
for (auto& interval : flatten (modified, exclusions))
database.addInterval (interval);
dirty = false;
}
}
// Apply tags to ids.
for (auto& id : ids)
{

View file

@ -57,6 +57,29 @@ int CmdUntag (
Interval filter;
auto tracked = getTracked (database, rules, filter);
bool dirty = true;
for (auto& id : ids)
{
if (id > static_cast <int> (tracked.size ()))
throw format ("ID '@{1}' does not correspond to any tracking.", id);
if (tracked[tracked.size() - id].synthetic && dirty)
{
auto latest = getLatestInterval(database);
auto exclusions = getAllExclusions (rules, filter.range);
Interval modified {latest};
// Update database.
database.deleteInterval (latest);
for (auto& interval : flatten (modified, exclusions))
database.addInterval (interval);
dirty = false;
}
}
// Apply tags to ids.
for (auto& id : ids)
{