comparison lib/Benzin/Bugzilla/XmlWriter.pm @ 12:52b34ea50eff default tip

sync: work time projection doesn't seem to be working anyway
author cin
date Sun, 13 Sep 2015 19:37:16 +0300
parents 4eb9fdf4efa9
children
comparison
equal deleted inserted replaced
11:4eb9fdf4efa9 12:52b34ea50eff
7 'DateTime' => 'WriteTJ3DateTime', 7 'DateTime' => 'WriteTJ3DateTime',
8 -plain => 'WriteValue', 8 -plain => 'WriteValue',
9 -default => 'WriteValue' 9 -default => 'WriteValue'
10 ); 10 );
11 11
12 use IMPL::lang qw(coarsen coarsen_dt is);
12 use IMPL::Const qw(:prop); 13 use IMPL::Const qw(:prop);
13 use IMPL::declare { 14 use IMPL::declare {
14 require => { 15 require => {
15 XMLWriter => 'XML::Writer', 16 XMLWriter => 'XML::Writer',
16 Bug => 'Benzin::Bugzilla::Bug', 17 Bug => 'Benzin::Bugzilla::Bug',
17 BugComment => 'Benzin::Bugzilla::BugComment', 18 BugComment => 'Benzin::Bugzilla::BugComment',
19 Duration => 'DateTime::Duration',
18 }, 20 },
19 base => [ 21 base => [
20 'IMPL::Transform' => sub { %Transform } 22 'IMPL::Transform' => sub { %Transform }
21 ], 23 ],
22 props => [ 24 props => [
40 my $writer = $this->_writer; 42 my $writer = $this->_writer;
41 43
42 $writer->xmlDecl("UTF-8"); 44 $writer->xmlDecl("UTF-8");
43 $writer->startTag("bugzilla"); 45 $writer->startTag("bugzilla");
44 46
47 my %timesheets;
48
45 foreach my $bug (@$bugs) { 49 foreach my $bug (@$bugs) {
46 $writer->startTag("bug"); 50 $writer->startTag("bug");
47 $this->WriteBug($bug); 51 $this->WriteBug($bug);
52
53 if ( $this->timereports ) {
54 my $time = $bug->GetTimeReports( $this->timeresolution );
55
56 my $prevReportDate = $bug->{creation_time};
57
58 foreach my $item ( @{ $time->{report} || [] } ) {
59 $timesheets{ $item->{who} }{bugs}{ $bug->{id} }{work} +=
60 $item->{work_time};
61 $timesheets{ $item->{who} }{bugs}{ $bug->{id} }{remaining} =
62 $time->{remaining};
63
64 $timesheets{ $item->{who} }{start} = $prevReportDate
65 unless $timesheets{ $item->{who} }{start}
66 and $timesheets{ $item->{who} }{start} <= $prevReportDate;
67 $timesheets{ $item->{who} }{end} = $item->{when}
68 unless $timesheets{ $item->{who} }{end}
69 and $timesheets{ $item->{who} }{end} >= $item->{when};
70
71 $prevReportDate = $item->{when};
72 }
73
74 $this->WriteElement( 'time', $time );
75 }
76
77 $writer->endTag();
78 }
79
80 while ( my ( $who, $sheet ) = each %timesheets ) {
81
82 $writer->startTag(
83 'timesheet',
84 resource => $who,
85 start => $this->FormatTJ3DateTime( $sheet->{start} ),
86 end => $this->FormatTJ3DateTime( $sheet->{end} )
87 );
88
89 while ( my ( $bug, $info ) = each %{ $sheet->{bugs} } ) {
90 $writer->startTag( 'bug', id => $bug );
91 $this->WriteElement( 'work', $info->{work} );
92 $this->WriteElement( 'remaining', $info->{remaining} );
93 $writer->endTag();
94 }
95
48 $writer->endTag(); 96 $writer->endTag();
49 } 97 }
50 98
51 $writer->endTag(); 99 $writer->endTag();
52 100
59 107
60 foreach my $field ( @{ Bug->BUG_FIELDS } ) { 108 foreach my $field ( @{ Bug->BUG_FIELDS } ) {
61 next unless $value->{$field}; 109 next unless $value->{$field};
62 $this->WriteElement( $field, $value->{$field} ); 110 $this->WriteElement( $field, $value->{$field} );
63 } 111 }
64 $this->WriteElement( 'time',
65 $value->GetTimeReports( $this->timeresolution ) )
66 if $this->timereports;
67 } 112 }
68 113
69 sub WriteBugComment { 114 sub WriteBugComment {
70 my SELF $this = shift; 115 my SELF $this = shift;
71 my $value = shift; 116 my $value = shift;
111 $this->_writer->characters($value) if defined $value; 156 $this->_writer->characters($value) if defined $value;
112 } 157 }
113 158
114 sub WriteTJ3DateTime { 159 sub WriteTJ3DateTime {
115 my SELF $this = shift; 160 my SELF $this = shift;
116 my $value = shift; 161 my $value = shift;
117 162
118 $this->_writer->characters($value->strftime('%F-%T')) if defined $value; 163 $this->_writer->characters( $this->FormatTJ3DateTime($value) )
164 if defined $value;
165 }
166
167 sub FormatTJ3DateTime {
168 my SELF $this = shift;
169 my $value = shift;
170
171 my $duration =
172 is( $this->timeresolution, Duration )
173 ? $this->timeresolution
174 : Duration->new( %{ $this->timeresolution } );
175
176 return coarsen_dt( $value, $duration )->strftime('%F-%T');
119 } 177 }
120 178
121 1; 179 1;