From e4f138946bab0671594f8b56ec79d1d2d1292c7f Mon Sep 17 00:00:00 2001 From: "myk%mozilla.org" Date: Thu, 5 Feb 2004 18:14:11 +0000 Subject: [PATCH] Fix for bug 127995: shows the size of attachments in the show bug and attachment interfaces. Patch by Dave Swegen r=myk a=myk --- webtools/bugzilla/Attachment.pm | 7 +++--- webtools/bugzilla/Bugzilla/Attachment.pm | 7 +++--- webtools/bugzilla/Bugzilla/Template.pm | 24 +++++++++++++++++++ webtools/bugzilla/attachment.cgi | 12 ++++++---- webtools/bugzilla/checksetup.pl | 1 + webtools/bugzilla/t/004template.t | 1 + webtools/bugzilla/t/008filter.t | 3 ++- .../en/default/attachment/edit.html.tmpl | 1 + .../en/default/attachment/list.html.tmpl | 4 +++- .../attachment/show-multiple.html.tmpl | 3 ++- 10 files changed, 49 insertions(+), 14 deletions(-) diff --git a/webtools/bugzilla/Attachment.pm b/webtools/bugzilla/Attachment.pm index ea5cd531c0d9..84979d3eaf82 100644 --- a/webtools/bugzilla/Attachment.pm +++ b/webtools/bugzilla/Attachment.pm @@ -77,7 +77,8 @@ sub query # of hashes in which each hash represents a single attachment. &::SendSQL(" SELECT attach_id, DATE_FORMAT(creation_ts, '%Y.%m.%d %H:%i'), - mimetype, description, ispatch, isobsolete, isprivate, submitter_id + mimetype, description, ispatch, isobsolete, isprivate, + submitter_id, LENGTH(thedata) FROM attachments WHERE bug_id = $bugid ORDER BY attach_id "); my @attachments = (); @@ -85,8 +86,8 @@ sub query my %a; my $submitter_id; ($a{'attachid'}, $a{'date'}, $a{'contenttype'}, $a{'description'}, - $a{'ispatch'}, $a{'isobsolete'}, $a{'isprivate'}, $submitter_id) - = &::FetchSQLData(); + $a{'ispatch'}, $a{'isobsolete'}, $a{'isprivate'}, $submitter_id, + $a{'datasize'}) = &::FetchSQLData(); # Retrieve a list of flags for this attachment. $a{'flags'} = Bugzilla::Flag::match({ 'attach_id' => $a{'attachid'} }); diff --git a/webtools/bugzilla/Bugzilla/Attachment.pm b/webtools/bugzilla/Bugzilla/Attachment.pm index ea5cd531c0d9..84979d3eaf82 100644 --- a/webtools/bugzilla/Bugzilla/Attachment.pm +++ b/webtools/bugzilla/Bugzilla/Attachment.pm @@ -77,7 +77,8 @@ sub query # of hashes in which each hash represents a single attachment. &::SendSQL(" SELECT attach_id, DATE_FORMAT(creation_ts, '%Y.%m.%d %H:%i'), - mimetype, description, ispatch, isobsolete, isprivate, submitter_id + mimetype, description, ispatch, isobsolete, isprivate, + submitter_id, LENGTH(thedata) FROM attachments WHERE bug_id = $bugid ORDER BY attach_id "); my @attachments = (); @@ -85,8 +86,8 @@ sub query my %a; my $submitter_id; ($a{'attachid'}, $a{'date'}, $a{'contenttype'}, $a{'description'}, - $a{'ispatch'}, $a{'isobsolete'}, $a{'isprivate'}, $submitter_id) - = &::FetchSQLData(); + $a{'ispatch'}, $a{'isobsolete'}, $a{'isprivate'}, $submitter_id, + $a{'datasize'}) = &::FetchSQLData(); # Retrieve a list of flags for this attachment. $a{'flags'} = Bugzilla::Flag::match({ 'attach_id' => $a{'attachid'} }); diff --git a/webtools/bugzilla/Bugzilla/Template.pm b/webtools/bugzilla/Bugzilla/Template.pm index d370627d34f8..c123154bbebd 100644 --- a/webtools/bugzilla/Bugzilla/Template.pm +++ b/webtools/bugzilla/Bugzilla/Template.pm @@ -258,6 +258,30 @@ sub create { return $var; } , + # Format a filesize in bytes to a human readable value + unitconvert => sub + { + my ($data) = @_; + my $retval = ""; + my %units = ( + 'KB' => 1024, + 'MB' => 1024 * 1024, + 'GB' => 1024 * 1024 * 1024, + ); + + if ($data < 1024) { + return "$data bytes"; + } + else { + my $u; + foreach $u ('GB', 'MB', 'KB') { + if ($data >= $units{$u}) { + return sprintf("%.2f %s", $data/$units{$u}, $u); + } + } + } + }, + # Format a time for display (more info in Bugzilla::Util) time => \&Bugzilla::Util::format_time, diff --git a/webtools/bugzilla/attachment.cgi b/webtools/bugzilla/attachment.cgi index fd9983841f75..8df562120023 100755 --- a/webtools/bugzilla/attachment.cgi +++ b/webtools/bugzilla/attachment.cgi @@ -746,7 +746,8 @@ sub viewall $privacy = "AND isprivate < 1 "; } SendSQL("SELECT attach_id, DATE_FORMAT(creation_ts, '%Y.%m.%d %H:%i'), - mimetype, description, ispatch, isobsolete, isprivate + mimetype, description, ispatch, isobsolete, isprivate, + LENGTH(thedata) FROM attachments WHERE bug_id = $::FORM{'bugid'} $privacy ORDER BY attach_id"); my @attachments; # the attachments array @@ -754,8 +755,8 @@ sub viewall { my %a; # the attachment hash ($a{'attachid'}, $a{'date'}, $a{'contenttype'}, - $a{'description'}, $a{'ispatch'}, $a{'isobsolete'}, $a{'isprivate'}) - = FetchSQLData(); + $a{'description'}, $a{'ispatch'}, $a{'isobsolete'}, $a{'isprivate'}, + $a{'datasize'}) = FetchSQLData(); $a{'isviewable'} = isViewable($a{'contenttype'}); # Add the hash representing the attachment to the array of attachments. @@ -943,9 +944,9 @@ sub edit # Users cannot edit the content of the attachment itself. # Retrieve the attachment from the database. - SendSQL("SELECT description, mimetype, filename, bug_id, ispatch, isobsolete, isprivate + SendSQL("SELECT description, mimetype, filename, bug_id, ispatch, isobsolete, isprivate, LENGTH(thedata) FROM attachments WHERE attach_id = $::FORM{'id'}"); - my ($description, $contenttype, $filename, $bugid, $ispatch, $isobsolete, $isprivate) = FetchSQLData(); + my ($description, $contenttype, $filename, $bugid, $ispatch, $isobsolete, $isprivate, $datasize) = FetchSQLData(); my $isviewable = isViewable($contenttype); @@ -980,6 +981,7 @@ sub edit $vars->{'ispatch'} = $ispatch; $vars->{'isobsolete'} = $isobsolete; $vars->{'isprivate'} = $isprivate; + $vars->{'datasize'} = $datasize; $vars->{'isviewable'} = $isviewable; $vars->{'attachments'} = \@bugattachments; $vars->{'GetBugLink'} = \&GetBugLink; diff --git a/webtools/bugzilla/checksetup.pl b/webtools/bugzilla/checksetup.pl index 4385accfc3f3..9726986e0903 100755 --- a/webtools/bugzilla/checksetup.pl +++ b/webtools/bugzilla/checksetup.pl @@ -1111,6 +1111,7 @@ END quoteUrls => sub { return $_; }, bug_link => [ sub { return sub { return $_; } }, 1], csv => sub { return $_; }, + unitconvert => sub { return $_; }, time => sub { return $_; }, none => sub { return $_; } , }, diff --git a/webtools/bugzilla/t/004template.t b/webtools/bugzilla/t/004template.t index 3b41282cc5ae..6c753c0bd793 100644 --- a/webtools/bugzilla/t/004template.t +++ b/webtools/bugzilla/t/004template.t @@ -101,6 +101,7 @@ foreach my $include_path (@include_paths) { quoteUrls => sub { return $_ } , bug_link => [ sub { return sub { return $_; } }, 1] , csv => sub { return $_ } , + unitconvert => sub { return $_ }, time => sub { return $_ } , none => sub { return $_ } , }, diff --git a/webtools/bugzilla/t/008filter.t b/webtools/bugzilla/t/008filter.t index 8e0ca2d0432d..722802bb82ad 100644 --- a/webtools/bugzilla/t/008filter.t +++ b/webtools/bugzilla/t/008filter.t @@ -202,7 +202,8 @@ sub directive_ok { # Note: If a single directive prints two things, and only one is # filtered, we may not catch that case. return 1 if $directive =~ /FILTER\ (html|csv|js|url_quote|css_class_quote| - quoteUrls|time|uri|xml|lower|none)/x; + quoteUrls|time|uri|xml|lower| + unitconvert|none)/x; return 0; } diff --git a/webtools/bugzilla/template/en/default/attachment/edit.html.tmpl b/webtools/bugzilla/template/en/default/attachment/edit.html.tmpl index 6718421529bd..19cc06550429 100644 --- a/webtools/bugzilla/template/en/default/attachment/edit.html.tmpl +++ b/webtools/bugzilla/template/en/default/attachment/edit.html.tmpl @@ -211,6 +211,7 @@ Filename:

+ Size: [% datasize FILTER unitconvert %]
MIME Type:

diff --git a/webtools/bugzilla/template/en/default/attachment/list.html.tmpl b/webtools/bugzilla/template/en/default/attachment/list.html.tmpl index 407ef8dfb7eb..1ef6cab12c91 100644 --- a/webtools/bugzilla/template/en/default/attachment/list.html.tmpl +++ b/webtools/bugzilla/template/en/default/attachment/list.html.tmpl @@ -25,6 +25,7 @@ Attachment Type Created + Size [% IF show_attachment_flags %] Flags [% END %] @@ -47,6 +48,7 @@ [% attachment.date FILTER time %] + [% attachment.datasize FILTER unitconvert %] [% IF show_attachment_flags %] @@ -82,7 +84,7 @@ [% END %] - + Create a New Attachment (proposed patch, testcase, etc.) [% IF attachments.size %] diff --git a/webtools/bugzilla/template/en/default/attachment/show-multiple.html.tmpl b/webtools/bugzilla/template/en/default/attachment/show-multiple.html.tmpl index 3159b8e8726e..48f03dff133e 100644 --- a/webtools/bugzilla/template/en/default/attachment/show-multiple.html.tmpl +++ b/webtools/bugzilla/template/en/default/attachment/show-multiple.html.tmpl @@ -40,7 +40,7 @@
- @@ -62,6 +62,7 @@ +
+ Attachment #[% a.attachid %]
[% a.date FILTER time %][% a.datasize FILTER unitconvert %] [% IF a.statuses.size == 0 %]