From 59776e6dc9dd95024dac6f8834b1ef5a67eb143e Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Tue, 29 Nov 2011 19:16:49 +0800 Subject: bug 706021: updates to the user-activitty report --- extensions/BMO/lib/Reports.pm | 71 +++++++++++++++++----- .../en/default/pages/user_activity.html.tmpl | 30 ++++++--- 2 files changed, 78 insertions(+), 23 deletions(-) diff --git a/extensions/BMO/lib/Reports.pm b/extensions/BMO/lib/Reports.pm index f291e72e7..7dcbc0ae6 100644 --- a/extensions/BMO/lib/Reports.pm +++ b/extensions/BMO/lib/Reports.pm @@ -43,6 +43,15 @@ sub user_activity_report { my $from = trim($input->{'from'}); my $to = trim($input->{'to'}); + if ($from eq '') { + my $dt = DateTime->now()->subtract('weeks' => 8); + $from = $dt->ymd('-'); + } + if ($to eq '') { + my $dt = DateTime->now(); + $to = $dt->ymd('-'); + } + if ($input->{'action'} eq 'run') { if ($input->{'who'} eq '') { ThrowUserError('user_activity_missing_username'); @@ -50,7 +59,7 @@ sub user_activity_report { Bugzilla::User::match_field({ 'who' => {'type' => 'multi'} }); ThrowUserError('user_activity_missing_from_date') unless $from; - my $from_time = str2time($from) + my $from_time = _parse_date($from) or ThrowUserError('user_activity_invalid_date', { date => $from }); my $from_dt = DateTime->from_epoch(epoch => $from_time) ->set_time_zone('local') @@ -58,7 +67,7 @@ sub user_activity_report { $from = $from_dt->ymd(); ThrowUserError('user_activity_missing_to_date') unless $to; - my $to_time = str2time($to) + my $to_time = _parse_date($to) or ThrowUserError('user_activity_invalid_date', { date => $to }); my $to_dt = DateTime->from_epoch(epoch => $to_time) ->set_time_zone('local') @@ -178,11 +187,11 @@ sub user_activity_report { UNION ALL SELECT - 'attachments.filename' AS name, + 'attachments.description' AS name, attachments.bug_id, attachments.attach_id, ".$dbh->sql_date_format('attachments.creation_ts', '%Y.%m.%d %H:%i:%s')." AS ts, - '' AS removed, + '(new attachment)' AS removed, attachments.description AS added, profiles.login_name, NULL AS comment_id, @@ -264,6 +273,10 @@ sub user_activity_report { next if $change{'comment'}->count == 0; } + if ($attachid) { + $change{'attach'} = Bugzilla::Attachment->new($attachid); + } + push (@$changes, \%change); } } @@ -275,25 +288,53 @@ sub user_activity_report { $vars->{'incomplete_data'} = $incomplete_data; $vars->{'operations'} = \@operations; - - } else { - - if ($from eq '') { - my ($yy, $mm) = (localtime)[5, 4]; - $from = sprintf("%4d-%02d-01", $yy + 1900, $mm + 1); - } - if ($to eq '') { - my ($yy, $mm, $dd) = (localtime)[5, 4, 3]; - $to = sprintf("%4d-%02d-%02d", $yy + 1900, $mm + 1, $dd); - } } $vars->{'action'} = $input->{'action'}; $vars->{'who'} = join(',', @who); + $vars->{'who_count'} = scalar @who; $vars->{'from'} = $from; $vars->{'to'} = $to; } +sub _parse_date { + my ($str) = @_; + if ($str =~ /^(-|\+)?(\d+)([hHdDwWmMyY])$/) { + # relative date + my ($sign, $amount, $unit, $date) = ($1, $2, lc $3, time); + my ($sec, $min, $hour, $mday, $month, $year, $wday) = localtime($date); + $amount = -$amount if $sign && $sign eq '+'; + if ($unit eq 'w') { + # convert weeks to days + $amount = 7*$amount + $wday; + $unit = 'd'; + } + if ($unit eq 'd') { + $date -= $sec + 60*$min + 3600*$hour + 24*3600*$amount; + return $date; + } + elsif ($unit eq 'y') { + return str2time(sprintf("%4d-01-01 00:00:00", $year+1900-$amount)); + } + elsif ($unit eq 'm') { + $month -= $amount; + while ($month<0) { $year--; $month += 12; } + return str2time(sprintf("%4d-%02d-01 00:00:00", $year+1900, $month+1)); + } + elsif ($unit eq 'h') { + # Special case 0h for 'beginning of this hour' + if ($amount == 0) { + $date -= $sec + 60*$min; + } else { + $date -= 3600*$amount; + } + return $date; + } + return undef; + } + return str2time($str); +} + sub triage_reports { my ($vars, $filter) = @_; my $dbh = Bugzilla->dbh; diff --git a/extensions/BMO/template/en/default/pages/user_activity.html.tmpl b/extensions/BMO/template/en/default/pages/user_activity.html.tmpl index bd48d00fd..b42a9d797 100644 --- a/extensions/BMO/template/en/default/pages/user_activity.html.tmpl +++ b/extensions/BMO/template/en/default/pages/user_activity.html.tmpl @@ -18,8 +18,14 @@ # Byron Jones #%] +[% IF who %] +[% who_title = ' (' _ who _ ')' %] +[% ELSE %] +[% who_title = '' %] +[% END %] + [% INCLUDE global/header.html.tmpl - title = "User Activity Report" + title = "User Activity Report" _ who_title yui = [ 'autocomplete', 'calendar' ] javascript_urls = [ "js/util.js", "js/field.js" ] %] @@ -108,7 +114,9 @@
- + [% IF who_count > 1 %] + + [% END %] @@ -118,11 +126,13 @@ [% FOREACH operation = operations %] + [% IF who_count > 1 %] + + [% END %] - " IF loop.index > 0 %]
WhoWhoWhen [% terms.Bug %] What
+ [% operation.who FILTER email FILTER html %] + - [% operation.who FILTER email FILTER html %] - - [% operation.when FILTER time %] + [% operation.when FILTER time FILTER no_break %] [% operation.bug FILTER bug_link(operation.bug) FILTER none %] @@ -131,8 +141,12 @@ [% "
[% IF change.attachid %] - Attachment #[% change.attachid FILTER html %] - [% ELSIF change.comment.defined && change.fieldname == 'longdesc' %] + Attachment #[% change.attachid FILTER html %] + [% END %] + [%IF change.comment.defined && change.fieldname == 'longdesc' %] [% "Comment $change.comment.count" FILTER bug_link(operation.bug, comment_num => change.comment.count) FILTER none %] [% ELSE %] [%+ field_descs.${change.fieldname} FILTER html %] -- cgit v1.2.3-24-g4f1b