Adding weekly/daily history commands

This commit is contained in:
Lukas Barth 2017-02-08 19:18:40 +01:00 committed by Paul Beckingham
parent 9e3c8b3956
commit 615336f3a8
4 changed files with 224 additions and 0 deletions

View file

@ -519,9 +519,215 @@ public:
static constexpr bool graphical = false;
};
////////////////////////////////////////////////////////////////////////////i
class DailyHistoryStrategy
{
public:
static Datetime getRelevantDate (const Datetime & dt)
{
return dt.startOfDay ();
}
static void setupTableDates (Table & view)
{
view.add (STRING_CMD_HISTORY_YEAR);
view.add (STRING_CMD_HISTORY_MONTH);
view.add (STRING_CMD_HISTORY_DAY);
}
static void insertRowDate (
Table& view,
int row,
time_t rowTime,
time_t lastTime)
{
Datetime dt (rowTime);
int m, d, y;
dt.toYMD (y, m, d);
Datetime last_dt (lastTime);
int last_m, last_d, last_y;
last_dt.toYMD (last_y, last_m, last_d);
if ((y != last_y) || (lastTime == 0))
{
view.set (row, 0, y);
}
if ((m != last_m) || (lastTime == 0))
{
view.set (row, 1, Datetime::monthName (m));
}
view.set (row, 2, d);
}
static constexpr const char* keyword = "history.daily";
static constexpr const char* usage = "task <filter> history.daily";
static constexpr const char* description = STRING_CMD_HISTORY_USAGE_D;
static constexpr unsigned int dateFieldCount = 3;
static constexpr bool graphical = false;
};
////////////////////////////////////////////////////////////////////////////i
class DailyGHistoryStrategy
{
public:
static Datetime getRelevantDate (const Datetime & dt)
{
return dt.startOfDay ();
}
static void setupTableDates (Table & view)
{
view.add (STRING_CMD_HISTORY_YEAR);
view.add (STRING_CMD_HISTORY_MONTH);
view.add (STRING_CMD_HISTORY_DAY);
}
static void insertRowDate (
Table& view,
int row,
time_t rowTime,
time_t lastTime)
{
Datetime dt (rowTime);
int m, d, y;
dt.toYMD (y, m, d);
Datetime last_dt (lastTime);
int last_m, last_d, last_y;
last_dt.toYMD (last_y, last_m, last_d);
if ((y != last_y) || (lastTime == 0))
{
view.set (row, 0, y);
}
if ((m != last_m) || (lastTime == 0))
{
view.set (row, 1, Datetime::monthName (m));
}
view.set (row, 2, d);
}
static constexpr const char* keyword = "ghistory.daily";
static constexpr const char* usage = "task <filter> ghistory.daily";
static constexpr const char* description = STRING_CMD_GHISTORY_USAGE_D;
static constexpr unsigned int dateFieldCount = 3;
static constexpr bool graphical = true;
};
////////////////////////////////////////////////////////////////////////////i
class WeeklyHistoryStrategy
{
public:
static Datetime getRelevantDate (const Datetime & dt)
{
return dt.startOfWeek ();
}
static void setupTableDates (Table & view)
{
view.add (STRING_CMD_HISTORY_YEAR);
view.add (STRING_CMD_HISTORY_MONTH);
view.add (STRING_CMD_HISTORY_DAY);
}
static void insertRowDate (
Table& view,
int row,
time_t rowTime,
time_t lastTime)
{
Datetime dt (rowTime);
int m, d, y;
dt.toYMD (y, m, d);
Datetime last_dt (lastTime);
int last_m, last_d, last_y;
last_dt.toYMD (last_y, last_m, last_d);
if ((y != last_y) || (lastTime == 0))
{
view.set (row, 0, y);
}
if ((m != last_m) || (lastTime == 0))
{
view.set (row, 1, Datetime::monthName (m));
}
view.set (row, 2, d);
}
static constexpr const char* keyword = "history.weekly";
static constexpr const char* usage = "task <filter> history.weekly";
static constexpr const char* description = STRING_CMD_HISTORY_USAGE_W;
static constexpr unsigned int dateFieldCount = 3;
static constexpr bool graphical = false;
};
////////////////////////////////////////////////////////////////////////////i
class WeeklyGHistoryStrategy
{
public:
static Datetime getRelevantDate (const Datetime & dt)
{
return dt.startOfWeek ();
}
static void setupTableDates (Table & view)
{
view.add (STRING_CMD_HISTORY_YEAR);
view.add (STRING_CMD_HISTORY_MONTH);
view.add (STRING_CMD_HISTORY_DAY);
}
static void insertRowDate (
Table& view,
int row,
time_t rowTime,
time_t lastTime)
{
Datetime dt (rowTime);
int m, d, y;
dt.toYMD (y, m, d);
Datetime last_dt (lastTime);
int last_m, last_d, last_y;
last_dt.toYMD (last_y, last_m, last_d);
if ((y != last_y) || (lastTime == 0))
{
view.set (row, 0, y);
}
if ((m != last_m) || (lastTime == 0))
{
view.set (row, 1, Datetime::monthName (m));
}
view.set (row, 2, d);
}
static constexpr const char* keyword = "ghistory.weekly";
static constexpr const char* usage = "task <filter> ghistory.weekly";
static constexpr const char* description = STRING_CMD_GHISTORY_USAGE_W;
static constexpr unsigned int dateFieldCount = 3;
static constexpr bool graphical = true;
};
// Explicit instantiations, avoiding cpp-inclusion or implementation in header
template class CmdHistoryBase<DailyHistoryStrategy>;
template class CmdHistoryBase<WeeklyHistoryStrategy>;
template class CmdHistoryBase<MonthlyHistoryStrategy>;
template class CmdHistoryBase<AnnualHistoryStrategy>;
template class CmdHistoryBase<DailyGHistoryStrategy>;
template class CmdHistoryBase<WeeklyGHistoryStrategy>;
template class CmdHistoryBase<MonthlyGHistoryStrategy>;
template class CmdHistoryBase<AnnualGHistoryStrategy>;

View file

@ -52,12 +52,20 @@ private:
};
// Forward-declare strategies implemented in CmdHistory.cpp
class DailyHistoryStrategy;
class DailyGHistoryStrategy;
class WeeklyHistoryStrategy;
class WeeklyGHistoryStrategy;
class MonthlyHistoryStrategy;
class MonthlyGHistoryStrategy;
class AnnualHistoryStrategy;
class AnnualGHistoryStrategy;
// typedef the templates to nice names to be used outside this class
typedef CmdHistoryBase<DailyHistoryStrategy> CmdHistoryDaily;
typedef CmdHistoryBase<DailyGHistoryStrategy> CmdGHistoryDaily;
typedef CmdHistoryBase<WeeklyHistoryStrategy> CmdHistoryWeekly;
typedef CmdHistoryBase<WeeklyGHistoryStrategy> CmdGHistoryWeekly;
typedef CmdHistoryBase<MonthlyHistoryStrategy> CmdHistoryMonthly;
typedef CmdHistoryBase<MonthlyGHistoryStrategy> CmdGHistoryMonthly;
typedef CmdHistoryBase<AnnualHistoryStrategy> CmdHistoryAnnual;

View file

@ -134,9 +134,13 @@ void Command::factory (std::map <std::string, Command*>& all)
#endif
c = new CmdExport (); all[c->keyword ()] = c;
c = new CmdGet (); all[c->keyword ()] = c;
c = new CmdGHistoryDaily (); all[c->keyword ()] = c;
c = new CmdGHistoryWeekly (); all[c->keyword ()] = c;
c = new CmdGHistoryMonthly (); all[c->keyword ()] = c;
c = new CmdGHistoryAnnual (); all[c->keyword ()] = c;
c = new CmdHelp (); all[c->keyword ()] = c;
c = new CmdHistoryDaily (); all[c->keyword ()] = c;
c = new CmdHistoryWeekly (); all[c->keyword ()] = c;
c = new CmdHistoryMonthly (); all[c->keyword ()] = c;
c = new CmdHistoryAnnual (); all[c->keyword ()] = c;
c = new CmdIDs (); all[c->keyword ()] = c;

View file

@ -267,9 +267,12 @@
#define STRING_CMD_TAGS_SINGLE "1 tag"
#define STRING_CMD_TAGS_PLURAL "{1} tags"
#define STRING_CMD_TAGS_NO_TAGS "No tags."
#define STRING_CMD_HISTORY_USAGE_D "Shows a report of task history, by day"
#define STRING_CMD_HISTORY_USAGE_W "Shows a report of task history, by week"
#define STRING_CMD_HISTORY_USAGE_M "Shows a report of task history, by month"
#define STRING_CMD_HISTORY_YEAR "Year"
#define STRING_CMD_HISTORY_MONTH "Month"
#define STRING_CMD_HISTORY_DAY "Day"
#define STRING_CMD_HISTORY_ADDED "Added"
#define STRING_CMD_HISTORY_COMP "Completed"
#define STRING_CMD_HISTORY_DEL "Deleted"
@ -278,10 +281,13 @@
#define STRING_CMD_HISTORY_AVERAGE "Average"
#define STRING_CMD_HISTORY_LEGEND "Legend: {1}, {2}, {3}"
#define STRING_CMD_HISTORY_LEGEND_A "Legend: + Added, X Completed, - Deleted"
#define STRING_CMD_GHISTORY_USAGE_D "Shows a graphical report of task history, by day"
#define STRING_CMD_GHISTORY_USAGE_W "Shows a graphical report of task history, by week"
#define STRING_CMD_GHISTORY_USAGE_M "Shows a graphical report of task history, by month"
#define STRING_CMD_GHISTORY_USAGE_A "Shows a graphical report of task history, by year"
#define STRING_CMD_GHISTORY_YEAR "Year"
#define STRING_CMD_GHISTORY_MONTH "Month"
#define STRING_CMD_GHISTORY_DAY "Day"
#define STRING_CMD_GHISTORY_NUMBER "Number Added/Completed/Deleted"
#define STRING_CMD_UNIQUE_USAGE "Generates lists of unique attribute values"
#define STRING_CMD_UNIQUE_MISSING "An attribute must be specified. See 'task _columns'."