Commands - history.monthly, history.annual, ghistory.monthly, ghistory.annual

- Migrated all history reports into CmdHistory objects.
This commit is contained in:
Paul Beckingham 2011-05-28 17:34:30 -04:00
parent b9246e04b2
commit 82eebc93bf
9 changed files with 140 additions and 55 deletions

View file

@ -45,7 +45,6 @@ set (task_SRCS API.cpp API.h
dependency.cpp
export.cpp
feedback.cpp
history.cpp
i18n.h
import.cpp
interactive.cpp

View file

@ -134,10 +134,6 @@ void Cmd::load ()
commands.push_back ("export.csv");
commands.push_back ("export.ical");
commands.push_back ("export.yaml");
commands.push_back ("history.monthly");
commands.push_back ("history.annual");
commands.push_back ("ghistory.monthly");
commands.push_back ("ghistory.annual");
commands.push_back ("burndown.daily");
commands.push_back ("burndown.weekly");
commands.push_back ("burndown.monthly");
@ -221,10 +217,6 @@ bool Cmd::isReadOnlyCommand ()
command == "export.csv" ||
command == "export.ical" ||
command == "export.yaml" ||
command == "history.monthly" ||
command == "history.annual" ||
command == "ghistory.monthly" ||
command == "ghistory.annual" ||
command == "burndown.daily" ||
command == "burndown.weekly" ||
command == "burndown.monthly" ||

View file

@ -249,10 +249,6 @@ int Context::dispatch (std::string &out)
// TODO Chain-of-command pattern dispatch.
if (cmd.command == "colors") { rc = handleColor (out); }
else if (cmd.command == "config") { rc = handleConfig (out); }
else if (cmd.command == "history.monthly") { rc = handleReportHistoryMonthly (out); }
else if (cmd.command == "history.annual") { rc = handleReportHistoryAnnual (out); }
else if (cmd.command == "ghistory.monthly") { rc = handleReportGHistoryMonthly (out); }
else if (cmd.command == "ghistory.annual") { rc = handleReportGHistoryAnnual (out); }
else if (cmd.command == "burndown.daily") { rc = handleReportBurndownDaily (out); }
else if (cmd.command == "burndown.weekly") { rc = handleReportBurndownWeekly (out); }
else if (cmd.command == "burndown.monthly") { rc = handleReportBurndownMonthly (out); }

View file

@ -14,6 +14,7 @@ set (commands_SRCS Command.cpp Command.h
CmdEdit.cpp CmdEdit.h
CmdExec.cpp CmdExec.h
CmdHelp.cpp CmdHelp.h
CmdHistory.cpp CmdHistory.h
CmdIds.cpp CmdIds.h
CmdInfo.cpp CmdInfo.h
CmdInstall.cpp CmdInstall.h

View file

@ -151,22 +151,6 @@ int CmdHelp::execute (const std::string& command_line, std::string& output)
view.set (row, 1, "task timesheet [weeks]");
view.set (row, 2, "Shows a weekly report of tasks completed and started.");
row = view.addRow ();
view.set (row, 1, "task history");
view.set (row, 2, "Shows a report of task history, by month. Alias to history.monthly.");
row = view.addRow ();
view.set (row, 1, "task history.annual");
view.set (row, 2, "Shows a report of task history, by year.");
row = view.addRow ();
view.set (row, 1, "task ghistory");
view.set (row, 2, "Shows a graphical report of task history, by month. Alias to ghistory.monthly.");
row = view.addRow ();
view.set (row, 1, "task ghistory.annual");
view.set (row, 2, "Shows a graphical report of task history, by year.");
row = view.addRow ();
view.set (row, 1, "task burndown.daily");
view.set (row, 2, "Shows a graphical burndown chart, by day.");

View file

@ -28,14 +28,25 @@
#include <sstream>
#include <Context.h>
#include <ViewText.h>
#include <text.h>
#include <util.h>
#include <main.h>
#include <text.h>
#include <CmdHistory.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
int handleReportHistoryMonthly (std::string& outs)
CmdHistoryMonthly::CmdHistoryMonthly ()
{
_keyword = "history.monthly";
_usage = "task execute <external command>";
_usage = "task history.monthly [<filter>]";
_description = "Shows a report of task history, by month.";
_read_only = true;
_displays_id = false;
}
////////////////////////////////////////////////////////////////////////////////
int CmdHistoryMonthly::execute (const std::string& command_line, std::string& output)
{
int rc = 0;
std::map <time_t, int> groups; // Represents any month with data
@ -51,7 +62,8 @@ int handleReportHistoryMonthly (std::string& outs)
context.tdb.commit ();
context.tdb.unlock ();
foreach (task, tasks)
std::vector <Task>::iterator task;
for (task = tasks.begin (); task != tasks.end (); ++task)
{
Date entry (task->get ("entry"));
@ -98,7 +110,8 @@ int handleReportHistoryMonthly (std::string& outs)
int priorYear = 0;
int row = 0;
foreach (i, groups)
std::map <time_t, int>::iterator i;
for (i = groups.begin (); i != groups.end (); ++i)
{
row = view.addRow ();
@ -174,12 +187,22 @@ int handleReportHistoryMonthly (std::string& outs)
rc = 1;
}
outs = out.str ();
output = out.str ();
return rc;
}
////////////////////////////////////////////////////////////////////////////////
int handleReportHistoryAnnual (std::string& outs)
CmdHistoryAnnual::CmdHistoryAnnual ()
{
_keyword = "history.annual";
_usage = "task history.annual [<filter>]";
_description = "Shows a report of task history, by year.";
_read_only = true;
_displays_id = false;
}
////////////////////////////////////////////////////////////////////////////////
int CmdHistoryAnnual::execute (const std::string& command_line, std::string& output)
{
int rc = 0;
std::map <time_t, int> groups; // Represents any month with data
@ -195,7 +218,8 @@ int handleReportHistoryAnnual (std::string& outs)
context.tdb.commit ();
context.tdb.unlock ();
foreach (task, tasks)
std::vector <Task>::iterator task;
for (task = tasks.begin (); task != tasks.end (); ++task)
{
Date entry (task->get ("entry"));
@ -241,7 +265,8 @@ int handleReportHistoryAnnual (std::string& outs)
int priorYear = 0;
int row = 0;
foreach (i, groups)
std::map <time_t, int>::iterator i;
for (i = groups.begin (); i != groups.end (); ++i)
{
row = view.addRow ();
@ -315,12 +340,22 @@ int handleReportHistoryAnnual (std::string& outs)
rc = 1;
}
outs = out.str ();
output = out.str ();
return rc;
}
////////////////////////////////////////////////////////////////////////////////
int handleReportGHistoryMonthly (std::string& outs)
CmdGHistoryMonthly::CmdGHistoryMonthly ()
{
_keyword = "ghistory.monthly";
_usage = "task ghistory.monthly [<filter>]";
_description = "Shows a graphical report of task history, by month.";
_read_only = true;
_displays_id = false;
}
////////////////////////////////////////////////////////////////////////////////
int CmdGHistoryMonthly::execute (const std::string& command_line, std::string& output)
{
int rc = 0;
std::map <time_t, int> groups; // Represents any month with data
@ -336,7 +371,8 @@ int handleReportGHistoryMonthly (std::string& outs)
context.tdb.commit ();
context.tdb.unlock ();
foreach (task, tasks)
std::vector <Task>::iterator task;
for (task = tasks.begin (); task != tasks.end (); ++task)
{
Date entry (task->get ("entry"));
@ -383,7 +419,8 @@ int handleReportGHistoryMonthly (std::string& outs)
// Determine the longest line, and the longest "added" line.
int maxAddedLine = 0;
int maxRemovedLine = 0;
foreach (i, groups)
std::map <time_t, int>::iterator i;
for (i = groups.begin (); i != groups.end (); ++i)
{
if (completedGroup[i->first] + deletedGroup[i->first] > maxRemovedLine)
maxRemovedLine = completedGroup[i->first] + deletedGroup[i->first];
@ -403,7 +440,8 @@ int handleReportGHistoryMonthly (std::string& outs)
int priorYear = 0;
int row = 0;
foreach (i, groups)
std::map <time_t, int>::iterator i;
for (i = groups.begin (); i != groups.end (); ++i)
{
row = view.addRow ();
@ -498,12 +536,22 @@ int handleReportGHistoryMonthly (std::string& outs)
rc = 1;
}
outs = out.str ();
output = out.str ();
return rc;
}
////////////////////////////////////////////////////////////////////////////////
int handleReportGHistoryAnnual (std::string& outs)
CmdGHistoryAnnual::CmdGHistoryAnnual ()
{
_keyword = "ghistory.annual";
_usage = "task ghistory.annual [<filter>]";
_description = "Shows a graphical report of task history, by year.";
_read_only = true;
_displays_id = false;
}
////////////////////////////////////////////////////////////////////////////////
int CmdGHistoryAnnual::execute (const std::string& command_line, std::string& output)
{
int rc = 0;
std::map <time_t, int> groups; // Represents any month with data
@ -519,7 +567,8 @@ int handleReportGHistoryAnnual (std::string& outs)
context.tdb.commit ();
context.tdb.unlock ();
foreach (task, tasks)
std::vector <Task>::iterator task;
for (task = tasks.begin (); task != tasks.end (); ++task)
{
Date entry (task->get ("entry"));
@ -565,7 +614,8 @@ int handleReportGHistoryAnnual (std::string& outs)
// Determine the longest line, and the longest "added" line.
int maxAddedLine = 0;
int maxRemovedLine = 0;
foreach (i, groups)
std::map <time_t, int>::iterator i;
for (i = groups.begin (); i != groups.end (); ++i)
{
if (completedGroup[i->first] + deletedGroup[i->first] > maxRemovedLine)
maxRemovedLine = completedGroup[i->first] + deletedGroup[i->first];
@ -585,7 +635,8 @@ int handleReportGHistoryAnnual (std::string& outs)
int priorYear = 0;
int row = 0;
foreach (i, groups)
std::map <time_t, int>::iterator i;
for (i = groups.begin (); i != groups.end (); ++i)
{
row = view.addRow ();
@ -678,7 +729,7 @@ int handleReportGHistoryAnnual (std::string& outs)
rc = 1;
}
outs = out.str ();
output = out.str ();
return rc;
}

63
src/commands/CmdHistory.h Normal file
View file

@ -0,0 +1,63 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_CMDHISTORY
#define INCLUDED_CMDHISTORY
#define L10N // Localization complete.
#include <string>
#include <Command.h>
class CmdHistoryMonthly : public Command
{
public:
CmdHistoryMonthly ();
int execute (const std::string&, std::string&);
};
class CmdHistoryAnnual : public Command
{
public:
CmdHistoryAnnual ();
int execute (const std::string&, std::string&);
};
class CmdGHistoryMonthly : public Command
{
public:
CmdGHistoryMonthly ();
int execute (const std::string&, std::string&);
};
class CmdGHistoryAnnual : public Command
{
public:
CmdGHistoryAnnual ();
int execute (const std::string&, std::string&);
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -36,6 +36,7 @@
#include <CmdEdit.h>
#include <CmdExec.h>
#include <CmdHelp.h>
#include <CmdHistory.h>
#include <CmdIds.h>
#include <CmdInfo.h>
#include <CmdInstall.h>
@ -68,7 +69,11 @@ void Command::factory (std::map <std::string, Command*>& all)
c = new CmdDiagnostics (); all[c->keyword ()] = c;
c = new CmdEdit (); all[c->keyword ()] = c;
c = new CmdExec (); 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 CmdHistoryMonthly (); all[c->keyword ()] = c;
c = new CmdHistoryAnnual (); all[c->keyword ()] = c;
c = new CmdIds (); all[c->keyword ()] = c;
c = new CmdInfo (); all[c->keyword ()] = c;
c = new CmdInstall (); all[c->keyword ()] = c;

View file

@ -89,12 +89,6 @@ int handleReportBurndownDaily (std::string&);
int handleReportBurndownWeekly (std::string&);
int handleReportBurndownMonthly (std::string&);
// history.cpp
int handleReportHistoryMonthly (std::string&);
int handleReportHistoryAnnual (std::string&);
int handleReportGHistoryMonthly (std::string&);
int handleReportGHistoryAnnual (std::string&);
// rules.cpp
void initializeColorRules ();
void autoColorize (Task&, Color&);