mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-31 05:47:18 +02:00
Feature
- Missing data now tolerated for UDAs. - Info command includes all column data, even for unrecognized types.
This commit is contained in:
parent
8177b74a52
commit
c8027a17c1
4 changed files with 163 additions and 75 deletions
|
@ -62,38 +62,42 @@ ColumnUDA::~ColumnUDA ()
|
||||||
//
|
//
|
||||||
void ColumnUDA::measure (Task& task, int& minimum, int& maximum)
|
void ColumnUDA::measure (Task& task, int& minimum, int& maximum)
|
||||||
{
|
{
|
||||||
|
minimum = maximum = 0;
|
||||||
|
|
||||||
if (_style == "default")
|
if (_style == "default")
|
||||||
{
|
{
|
||||||
std::string value = task.get (_name);
|
std::string value = task.get (_name);
|
||||||
|
if (value != "")
|
||||||
|
{
|
||||||
|
if (_type == "date")
|
||||||
|
{
|
||||||
|
// Determine the output date format, which uses a hierarchy of definitions.
|
||||||
|
// rc.report.<report>.dateformat
|
||||||
|
// rc.dateformat.report
|
||||||
|
// rc.dateformat.
|
||||||
|
Date date ((time_t) strtol (value.c_str (), NULL, 10));
|
||||||
|
std::string format = context.config.get ("report." + _report + ".dateformat");
|
||||||
|
if (format == "")
|
||||||
|
format = context.config.get ("dateformat.report");
|
||||||
|
if (format == "")
|
||||||
|
format = context.config.get ("dateformat");
|
||||||
|
|
||||||
if (_type == "date")
|
minimum = maximum = date.toString (format).length ();
|
||||||
{
|
}
|
||||||
// Determine the output date format, which uses a hierarchy of definitions.
|
else if (_type == "duration")
|
||||||
// rc.report.<report>.dateformat
|
{
|
||||||
// rc.dateformat.report
|
minimum = maximum = Duration (value).formatCompact ().length ();
|
||||||
// rc.dateformat.
|
}
|
||||||
Date date ((time_t) strtol (value.c_str (), NULL, 10));
|
else if (_type == "string")
|
||||||
std::string format = context.config.get ("report." + _report + ".dateformat");
|
{
|
||||||
if (format == "")
|
std::string stripped = Color::strip (value);
|
||||||
format = context.config.get ("dateformat.report");
|
maximum = longestLine (stripped);
|
||||||
if (format == "")
|
minimum = longestWord (stripped);
|
||||||
format = context.config.get ("dateformat");
|
}
|
||||||
|
else if (_type == "numeric")
|
||||||
minimum = maximum = date.toString (format).length ();
|
{
|
||||||
}
|
minimum = maximum = value.length ();
|
||||||
else if (_type == "duration")
|
}
|
||||||
{
|
|
||||||
minimum = maximum = Duration (value).formatCompact ().length ();
|
|
||||||
}
|
|
||||||
else if (_type == "string")
|
|
||||||
{
|
|
||||||
std::string stripped = Color::strip (value);
|
|
||||||
maximum = longestLine (stripped);
|
|
||||||
minimum = longestWord (stripped);
|
|
||||||
}
|
|
||||||
else if (_type == "numeric")
|
|
||||||
{
|
|
||||||
minimum = maximum = value.length ();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -110,45 +114,47 @@ void ColumnUDA::render (
|
||||||
if (_style == "default")
|
if (_style == "default")
|
||||||
{
|
{
|
||||||
std::string value = task.get (_name);
|
std::string value = task.get (_name);
|
||||||
|
if (value != "")
|
||||||
|
{
|
||||||
|
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." + _report + ".dateformat");
|
||||||
|
if (format == "")
|
||||||
|
format = context.config.get ("dateformat.report");
|
||||||
|
if (format == "")
|
||||||
|
format = context.config.get ("dateformat");
|
||||||
|
|
||||||
if (_type == "date")
|
lines.push_back (
|
||||||
{
|
color.colorize (
|
||||||
// Determine the output date format, which uses a hierarchy of definitions.
|
leftJustify (
|
||||||
// rc.report.<report>.dateformat
|
Date ((time_t) strtol (value.c_str (), NULL, 10))
|
||||||
// rc.dateformat.report
|
.toString (format), width)));
|
||||||
// rc.dateformat.
|
}
|
||||||
std::string format = context.config.get ("report." + _report + ".dateformat");
|
else if (_type == "duration")
|
||||||
if (format == "")
|
{
|
||||||
format = context.config.get ("dateformat.report");
|
lines.push_back (
|
||||||
if (format == "")
|
color.colorize (
|
||||||
format = context.config.get ("dateformat");
|
rightJustify (
|
||||||
|
Duration (value).formatCompact (),
|
||||||
|
width)));
|
||||||
|
}
|
||||||
|
else if (_type == "string")
|
||||||
|
{
|
||||||
|
std::vector <std::string> raw;
|
||||||
|
wrapText (raw, value, width, _hyphenate);
|
||||||
|
|
||||||
lines.push_back (
|
std::vector <std::string>::iterator i;
|
||||||
color.colorize (
|
for (i = raw.begin (); i != raw.end (); ++i)
|
||||||
leftJustify (
|
lines.push_back (color.colorize (leftJustify (*i, width)));
|
||||||
Date ((time_t) strtol (value.c_str (), NULL, 10))
|
}
|
||||||
.toString (format), width)));
|
else if (_type == "numeric")
|
||||||
}
|
{
|
||||||
else if (_type == "duration")
|
lines.push_back (color.colorize (rightJustify (value, width)));
|
||||||
{
|
}
|
||||||
lines.push_back (
|
|
||||||
color.colorize (
|
|
||||||
rightJustify (
|
|
||||||
Duration (value).formatCompact (),
|
|
||||||
width)));
|
|
||||||
}
|
|
||||||
else if (_type == "string")
|
|
||||||
{
|
|
||||||
std::vector <std::string> raw;
|
|
||||||
wrapText (raw, value, width, _hyphenate);
|
|
||||||
|
|
||||||
std::vector <std::string>::iterator i;
|
|
||||||
for (i = raw.begin (); i != raw.end (); ++i)
|
|
||||||
lines.push_back (color.colorize (leftJustify (*i, width)));
|
|
||||||
}
|
|
||||||
else if (_type == "numeric")
|
|
||||||
{
|
|
||||||
lines.push_back (color.colorize (rightJustify (value, width)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,9 +323,11 @@ int CmdInfo::execute (std::string& output)
|
||||||
// Show any UDAs
|
// Show any UDAs
|
||||||
std::vector <std::string> all = task->all ();
|
std::vector <std::string> all = task->all ();
|
||||||
std::vector <std::string>::iterator att;
|
std::vector <std::string>::iterator att;
|
||||||
|
std::string type;
|
||||||
for (att = all.begin (); att != all.end (); ++att)
|
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];
|
Column* col = context.columns[*att];
|
||||||
if (col)
|
if (col)
|
||||||
|
@ -335,14 +337,25 @@ int CmdInfo::execute (std::string& output)
|
||||||
{
|
{
|
||||||
row = view.addRow ();
|
row = view.addRow ();
|
||||||
view.set (row, 0, col->label ());
|
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);
|
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
69
test/uda_date.t
Executable 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;
|
||||||
|
|
|
@ -49,8 +49,8 @@ if (open my $fh, '>', 'uda.rc')
|
||||||
qx{../src/task rc:uda.rc add with extra:1day};
|
qx{../src/task rc:uda.rc add with extra:1day};
|
||||||
qx{../src/task rc:uda.rc add without};
|
qx{../src/task rc:uda.rc add without};
|
||||||
my $output = qx{../src/task rc:uda.rc uda};
|
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');
|
like ($output, qr/2\s+-\s+without/, 'UDA duration blank');
|
||||||
|
|
||||||
# Add bad data.
|
# Add bad data.
|
||||||
$output = qx{../src/task rc:uda.rc add bad extra:unrecognized_duration};
|
$output = qx{../src/task rc:uda.rc add bad extra:unrecognized_duration};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue