diff --git a/src/commands/CmdHistory.cpp b/src/commands/CmdHistory.cpp index 319265f07..0b74d36ae 100644 --- a/src/commands/CmdHistory.cpp +++ b/src/commands/CmdHistory.cpp @@ -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 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 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 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 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; +template class CmdHistoryBase; template class CmdHistoryBase; template class CmdHistoryBase; +template class CmdHistoryBase; +template class CmdHistoryBase; template class CmdHistoryBase; template class CmdHistoryBase; diff --git a/src/commands/CmdHistory.h b/src/commands/CmdHistory.h index 10b7f5e11..8a3977f5e 100644 --- a/src/commands/CmdHistory.h +++ b/src/commands/CmdHistory.h @@ -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 CmdHistoryDaily; +typedef CmdHistoryBase CmdGHistoryDaily; +typedef CmdHistoryBase CmdHistoryWeekly; +typedef CmdHistoryBase CmdGHistoryWeekly; typedef CmdHistoryBase CmdHistoryMonthly; typedef CmdHistoryBase CmdGHistoryMonthly; typedef CmdHistoryBase CmdHistoryAnnual; diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index cb164bad7..e060f5ca9 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -134,9 +134,13 @@ void Command::factory (std::map & 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; diff --git a/src/l10n/eng-USA.h b/src/l10n/eng-USA.h index 325e625b9..617c2abd6 100644 --- a/src/l10n/eng-USA.h +++ b/src/l10n/eng-USA.h @@ -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'."