- Missing data now tolerated for UDAs.
- Info command includes all column data, even for unrecognized types.
This commit is contained in:
Paul Beckingham 2012-03-05 22:49:41 -05:00
parent 8177b74a52
commit c8027a17c1
4 changed files with 163 additions and 75 deletions

View file

@ -62,10 +62,13 @@ ColumnUDA::~ColumnUDA ()
//
void ColumnUDA::measure (Task& task, int& minimum, int& maximum)
{
minimum = maximum = 0;
if (_style == "default")
{
std::string value = task.get (_name);
if (value != "")
{
if (_type == "date")
{
// Determine the output date format, which uses a hierarchy of definitions.
@ -96,6 +99,7 @@ void ColumnUDA::measure (Task& task, int& minimum, int& maximum)
minimum = maximum = value.length ();
}
}
}
else
throw format (STRING_COLUMN_BAD_FORMAT, _name, _style);
}
@ -110,7 +114,8 @@ void ColumnUDA::render (
if (_style == "default")
{
std::string value = task.get (_name);
if (value != "")
{
if (_type == "date")
{
// Determine the output date format, which uses a hierarchy of definitions.
@ -152,5 +157,6 @@ void ColumnUDA::render (
}
}
}
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -323,9 +323,11 @@ int CmdInfo::execute (std::string& output)
// Show any UDAs
std::vector <std::string> all = task->all ();
std::vector <std::string>::iterator att;
std::string type;
for (att = all.begin (); att != all.end (); ++att)
{
if (context.config.get ("uda." + *att + ".type") != "")
type = context.config.get ("uda." + *att + ".type");
if (type != "")
{
Column* col = context.columns[*att];
if (col)
@ -335,14 +337,25 @@ int CmdInfo::execute (std::string& output)
{
row = view.addRow ();
view.set (row, 0, col->label ());
if (type == "date")
{
// Determine the output date format, which uses a hierarchy of definitions.
// rc.report.<report>.dateformat
// rc.dateformat.report
// rc.dateformat.
std::string format = context.config.get ("report.info.dateformat");
if (format == "")
format = context.config.get ("dateformat.report");
if (format == "")
format = context.config.get ("dateformat");
value = Date (value).toString (format);
}
else if (type == "duration")
value = Duration (value).formatCompact ();
view.set (row, 1, value);
/*
std::vector <std::string> lines;
Color color;
col->render (lines, *task, 0, color);
join (value, " ", lines);
view.set (row, 1, value);
*/
}
}
}

69
test/uda_date.t Executable file
View file

@ -0,0 +1,69 @@
#! /usr/bin/perl
################################################################################
## taskwarrior - a command line task list manager.
##
## Copyright 2006-2012, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
use strict;
use warnings;
use Test::More tests => 5;
# Create the rc file.
if (open my $fh, '>', 'uda.rc')
{
print $fh "data.location=.\n",
"confirmation=off\n",
"uda.extra.type=date\n",
"uda.extra.label=Extra\n",
"report.uda.description=UDA Test\n",
"report.uda.columns=id,extra,description\n",
"report.uda.sort=extra,description\n",
"report.uda.labels=ID,Extra,Description\n";
close $fh;
ok (-r 'uda.rc', 'Created uda.rc');
}
# Add tasks with and without the UDA.
qx{../src/task rc:uda.rc add with extra:tomorrow};
qx{../src/task rc:uda.rc add without};
my $output = qx{../src/task rc:uda.rc uda};
like ($output, qr/1\s+[\d\/]+\s+with/, 'UDA date stored');
like ($output, qr/2\s+without/, 'UDA date blank');
# Add bad data.
$output = qx{../src/task rc:uda.rc add bad extra:unrecognized_date};
unlike ($output, qr/Created task \d+/, 'UDA date bad data not accepted');
# Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data synch.key uda.rc);
ok (! -r 'pending.data' &&
! -r 'completed.data' &&
! -r 'undo.data' &&
! -r 'backlog.data' &&
! -r 'synch.key' &&
! -r 'uda.rc', 'Cleanup');
exit 0;

View file

@ -49,7 +49,7 @@ if (open my $fh, '>', 'uda.rc')
qx{../src/task rc:uda.rc add with extra:1day};
qx{../src/task rc:uda.rc add without};
my $output = qx{../src/task rc:uda.rc uda};
like ($output, qr/1\s+\S+\s+with/, 'UDA duration stored');
like ($output, qr/1\s+1d\s+with/, 'UDA duration stored');
like ($output, qr/2\s+-\s+without/, 'UDA duration blank');
# Add bad data.