Make summary output configurable via rules

- add config `reports.summary.ids` to toggle display of IDs
- add config `reports.summary.annotations` to toggle display of annotations
- add hints `:no-ids` and `:no-annotations` to override positive configs

Closes #474

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
Thomas Lauf 2021-12-19 15:32:49 +01:00
parent b40f28ca4a
commit 1a6d5cacca
9 changed files with 70 additions and 8 deletions

View file

@ -1,3 +1,4 @@
- #474 Make display of ids and annotations in summary report configurable
- #408 Update documentation of hint `:all`
(thanks to quazgar)
- #437 Minor AtomicFile cleanup

View file

@ -17,11 +17,25 @@ Accepts date ranges and tags for filtering, or shortcut hints:
The ':ids' hint adds an 'ID' column to the summary report output for interval modification.
The ':annotations' hint adds an 'Annotation' column to the summary report output.
The annotation column is limited to 15 characters.
Longer values in this column are truncated to 12 characters and shown with an ellipsis attached.
== CONFIGURATION
**reports.summary.annotations**::
Determines whether the annotation column is shown in the summary.
Can be overridden by the ':annotations' and ':no-annotations' hint, respectively.
Default value is 'no'
**reports.summary.holidays**::
Determines whether relevant holidays are shown beneath the report.
Default value is 'yes'.
**reports.summary.ids**::
Determines whether the id column is shown in the summary.
Can be overridden by the ':ids' and ':no-ids' hint, respectively.
Default value is 'no'
**tags.**__<tag>__**.color**::
Assigns a specific foreground and background color to a tag.
Examples of valid colors include 'white', 'gray8', 'black on yellow', and 'rgb345'.

View file

@ -833,3 +833,44 @@ Interval CLI::getFilter (const Range& default_range) const
return filter;
}
////////////////////////////////////////////////////////////////////////////////
bool CLI::findHint (const std::string& hint) const
{
for (auto& arg : _args)
{
if (arg.hasTag ("HINT") &&
arg.getToken () == ":" + hint)
{
return true;
}
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool CLI::getComplementaryHint (const std::string& base, const bool default_value) const
{
if (findHint (base))
{
return true;
}
else if (findHint ("no-" + base))
{
return false;
}
return default_value;
}
////////////////////////////////////////////////////////////////////////////////
bool CLI::getHint (const std::string &base, const bool default_value) const
{
if (findHint (base))
{
return true;
}
return default_value;
}

View file

@ -67,6 +67,8 @@ public:
bool canonicalize (std::string&, const std::string&, const std::string&) const;
std::string getBinary () const;
std::string getCommand () const;
bool getComplementaryHint (const std::string&, bool) const;
bool getHint(const std::string&, bool) const;
std::set <int> getIds () const;
std::vector<std::string> getTags () const;
std::string getAnnotation() const;
@ -84,6 +86,8 @@ private:
void identifyFilter ();
bool exactMatch (const std::string&, const std::string&) const;
bool findHint (const std::string &hint) const;
public:
std::multimap <std::string, std::string> _entities {};
std::vector <A2> _original_args {};

View file

@ -152,12 +152,12 @@ int renderChart (
configuration.with_label_week = rules.getBoolean ("reports." + type + ".week");
configuration.with_label_weekday = rules.getBoolean ("reports." + type + ".weekday");
configuration.with_label_day = rules.getBoolean ("reports." + type + ".day");
configuration.with_ids = findHint (cli, ":ids");
configuration.with_ids = cli.getHint ("ids", false);
configuration.with_summary = rules.getBoolean ("reports." + type + ".summary");
configuration.with_holidays = rules.getBoolean ("reports." + type + ".holidays");
configuration.with_totals = rules.getBoolean ("reports." + type + ".totals");
configuration.with_internal_axis = rules.get ("reports." + type + ".axis") == "internal";
configuration.show_intervals = findHint (cli, ":blank");
configuration.show_intervals = cli.getHint ("blank", false);
configuration.determine_hour_range = rules.get ("reports." + type + ".hours") == "auto";
configuration.minutes_per_char = minutes_per_char;
configuration.spacing = rules.getInteger ("reports." + type + ".spacing", 1);

View file

@ -50,7 +50,7 @@ int CmdGaps (
}
// Is the :blank hint being used?
bool blank = findHint (cli, ":blank");
bool blank = cli.getHint ("blank", false);
std::vector <Range> untracked;
if (blank)

View file

@ -85,8 +85,8 @@ int CmdSummary (
// Map tags to colors.
Color colorID (rules.getBoolean ("color") ? rules.get ("theme.colors.ids") : "");
auto show_ids = findHint (cli, ":ids");
auto show_annotations = findHint (cli, ":annotations");
const auto show_ids = cli.getComplementaryHint ("ids", rules.getBoolean ("reports.summary.ids"));
const auto show_annotations = cli.getComplementaryHint ("annotations", rules.getBoolean ("reports.summary.annotations"));
Table table;
table.width (1024);

View file

@ -95,7 +95,9 @@ void initializeEntities (CLI& cli)
cli.entity ("hint", ":debug");
cli.entity ("hint", ":fill");
cli.entity ("hint", ":ids");
cli.entity ("hint", ":no-ids");
cli.entity ("hint", ":annotations");
cli.entity ("hint", ":no-annotations");
cli.entity ("hint", ":lastmonth");
cli.entity ("hint", ":lastquarter");
cli.entity ("hint", ":lastweek");
@ -166,7 +168,7 @@ void initializeDataJournalAndRules (
bool shinyNewDatabase = false;
if (! dbLocation.exists () &&
(findHint (cli, ":yes") ||
(cli.getHint ("yes", false) ||
confirm ("Create new database in " + dbLocation._data + "?")))
{
dbLocation.create (0700);

View file

@ -226,12 +226,12 @@ bool validate (
Interval& interval)
{
// All validation performed here.
if (findHint (cli, ":fill"))
if (cli.getHint ("fill", false))
{
autoFill (rules, database, interval);
}
return autoAdjust (findHint (cli, ":adjust"), rules, database, interval);
return autoAdjust (cli.getHint ("adjust", false), rules, database, interval);
}
////////////////////////////////////////////////////////////////////////////////