mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Database: Exclusions are back to being strings again
This commit is contained in:
parent
1aa72f99b6
commit
b29f458a7b
3 changed files with 18 additions and 14 deletions
|
@ -57,6 +57,11 @@ void Database::initialize (const std::string& location)
|
||||||
{
|
{
|
||||||
Datafile df;
|
Datafile df;
|
||||||
df.initialize (file);
|
df.initialize (file);
|
||||||
|
|
||||||
|
// New files need the set of current exclusions.
|
||||||
|
if (! File (file).exists ())
|
||||||
|
df.setExclusions (_exclusion);
|
||||||
|
|
||||||
_files.push_back (df);
|
_files.push_back (df);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +120,7 @@ void Database::clearExclusions ()
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Database::addExclusion (const Exclusion& exclusion)
|
void Database::addExclusion (const std::string& exclusion)
|
||||||
{
|
{
|
||||||
_exclusions.push_back (exclusion);
|
_exclusions.push_back (exclusion);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
|
|
||||||
#include <Datafile.h>
|
#include <Datafile.h>
|
||||||
#include <Interval.h>
|
#include <Interval.h>
|
||||||
#include <Exclusion.h>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -45,7 +44,7 @@ public:
|
||||||
std::vector <Interval> getAllIntervals ();
|
std::vector <Interval> getAllIntervals ();
|
||||||
|
|
||||||
void clearExclusions ();
|
void clearExclusions ();
|
||||||
void addExclusion (const Exclusion&);
|
void addExclusion (const std::string&);
|
||||||
void addInterval (const Interval&);
|
void addInterval (const Interval&);
|
||||||
void modifyInterval (const Interval&);
|
void modifyInterval (const Interval&);
|
||||||
|
|
||||||
|
@ -57,7 +56,7 @@ private:
|
||||||
private:
|
private:
|
||||||
std::string _location {"~/.timewarrior/data"};
|
std::string _location {"~/.timewarrior/data"};
|
||||||
std::vector <Datafile> _files {};
|
std::vector <Datafile> _files {};
|
||||||
std::vector <Exclusion> _exclusions {};
|
std::vector <std::string> _exclusions {};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
16
src/init.cpp
16
src/init.cpp
|
@ -161,14 +161,17 @@ void initializeDataAndRules (
|
||||||
if (shinyNewDatabase)
|
if (shinyNewDatabase)
|
||||||
rules.set ("temp.shiny", 1);
|
rules.set ("temp.shiny", 1);
|
||||||
|
|
||||||
|
// Provide the exclusions from configuration to the database. These are used
|
||||||
|
// to seed new Diatafile objects.
|
||||||
|
initializeDatabaseExclusions (database, rules);
|
||||||
|
|
||||||
// Initialize the database (no data read), but files are enumerated.
|
// Initialize the database (no data read), but files are enumerated.
|
||||||
database.initialize (data._data);
|
database.initialize (data._data);
|
||||||
|
|
||||||
// Provide the exclusions from configuration to the database.
|
|
||||||
initializeDatabaseExclusions (database, rules);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// The exclusions are read from configuration as strings, and passed to the
|
||||||
|
// database object as strings.
|
||||||
void initializeDatabaseExclusions (Database& database, const Rules& rules)
|
void initializeDatabaseExclusions (Database& database, const Rules& rules)
|
||||||
{
|
{
|
||||||
database.clearExclusions ();
|
database.clearExclusions ();
|
||||||
|
@ -176,13 +179,10 @@ void initializeDatabaseExclusions (Database& database, const Rules& rules)
|
||||||
for (auto& name : rules.all ("exclusions."))
|
for (auto& name : rules.all ("exclusions."))
|
||||||
{
|
{
|
||||||
name = lowerCase (name);
|
name = lowerCase (name);
|
||||||
Exclusion e;
|
|
||||||
if (name.substr (0, 16) == "exclusions.days.")
|
if (name.substr (0, 16) == "exclusions.days.")
|
||||||
e.initialize ("exc day " + rules.get (name) + " " + name.substr (16));
|
database.addExclusion ("exc day " + rules.get (name) + " " + name.substr (16));
|
||||||
else
|
else
|
||||||
e.initialize ("exc " + name.substr (11) + " " + rules.get (name));
|
database.addExclusion ("exc " + name.substr (11) + " " + rules.get (name));
|
||||||
|
|
||||||
database.addExclusion (e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue