diff --git a/Bugzilla/Comment.pm b/Bugzilla/Comment.pm index 33cfddba4..66c842c28 100644 --- a/Bugzilla/Comment.pm +++ b/Bugzilla/Comment.pm @@ -30,6 +30,8 @@ use Bugzilla::User; use Bugzilla::Util; use Bugzilla::Template; +use Data::Dumper; + ############################### #### Initialization #### ############################### @@ -92,7 +94,6 @@ sub preload { ############################### sub already_wrapped { return $_[0]->{'already_wrapped'}; } -sub body { return $_[0]->{'thetext'}; } sub bug_id { return $_[0]->{'bug_id'}; } sub creation_ts { return $_[0]->{'bug_when'}; } sub is_private { return $_[0]->{'isprivate'}; } @@ -101,6 +102,21 @@ sub type { return $_[0]->{'type'}; } sub extra_data { return $_[0]->{'extra_data'} } sub who { return $_[0]->{'who'}; } +sub body +{ + my ($self, $preview) = @_; + $preview = 0 if !$preview; + if ($preview && !$self->check_length) + { + my $max_lines = Bugzilla->params->{preview_comment_lines} - 1; + my $line_length = Bugzilla->params->{comment_line_length} - 1; + my $result = $self->{'thetext'}; + $result =~ s/^((?>[^\n]{0,$line_length}.){0,$max_lines}(?>[^\n]{0,$line_length}\s)).*$/\1.../s; + return $result; + } + return $_[0]->{'thetext'}; +} + sub bug { my $self = shift; require Bugzilla::Bug; @@ -134,6 +150,7 @@ sub author { sub body_full { my ($self, $params) = @_; $params ||= {}; + my $preview = $params->{preview} ? $params->{preview} : 0; my $template = Bugzilla->template_inner; my $body; my $t = $self->type; @@ -146,17 +163,36 @@ sub body_full { $body =~ s/^X//; } else { - $body = $self->body; + $body = $self->body($preview); } if (!$params->{is_bugmail}) { $body = Bugzilla::Template::quoteUrls($body, $self->bug_id, $self); } if ($params->{wrap}) { $body = wrap_comment($body); + if (!$preview && !($self->check_length)) + { + $params->{preview} = 1; + my $new_body; + $template->process("bug/comment-preview-text.html.tmpl", + { preview => $self->body_full($params), body => $body, id => $self->id }, \$new_body) + || ThrowTemplateError($template->error()); + $body = $new_body; + } } return $body; } +sub check_length +{ + my $self = shift; + my $test = $self->{'thetext'}; + my $line_length = Bugzilla->params->{comment_line_length}; + my $length = $test =~ s/([^\n]{$line_length}|\n)/$1/g; + $length = 0 if !$length; + return $length <= Bugzilla->params->{preview_comment_lines}; +} + ############ # Mutators # ############ diff --git a/Bugzilla/Config/BugFields.pm b/Bugzilla/Config/BugFields.pm index b212f7880..6a06268be 100644 --- a/Bugzilla/Config/BugFields.pm +++ b/Bugzilla/Config/BugFields.pm @@ -197,6 +197,20 @@ sub get_param_list { type => 'b', default => 0, }, + + { + name => 'comment_line_length', + type => 't', + default => '80', + checker => \&check_numeric + }, + + { + name => 'preview_comment_lines', + type => 't', + default => '30', + checker => \&check_numeric + }, ); return @param_list; } diff --git a/js/bug.js b/js/bug.js index ca7590939..f5909bc86 100644 --- a/js/bug.js +++ b/js/bug.js @@ -49,6 +49,28 @@ function showhide_comment(comment_id, show) addClass(comment, 'collapsed'); } +function showhide_comment_preview(comment_id) +{ + var link = document.getElementById('comment-preview-link-' + comment_id); + var preview = document.getElementById('comment-preview-' + comment_id); + var body = document.getElementById('comment-body-' + comment_id); + var show = link.className.match(new RegExp(/\bshown\b/)) + if (show) + { + preview.style.display = 'block'; + body.style.display = 'none'; + removeClass(link, "shown"); + } + else + { + preview.style.display = 'none'; + body.style.display = 'block'; + addClass(link, "shown"); + } + link.innerHTML = (!show ? "Hide" : "Show") + " full text"; + return false; +} + // Mark comment as worktime-only or normal function toggle_wtonly(id, initial_wtonly, img) { diff --git a/template/en/custom/bug/comment-preview-text.html.tmpl b/template/en/custom/bug/comment-preview-text.html.tmpl new file mode 100755 index 000000000..03ef77e5c --- /dev/null +++ b/template/en/custom/bug/comment-preview-text.html.tmpl @@ -0,0 +1,5 @@ +
[% preview %]
+ +

+ Show full text +

diff --git a/template/en/default/admin/params/bugfields.html.tmpl b/template/en/default/admin/params/bugfields.html.tmpl index acbab223b..810808994 100644 --- a/template/en/default/admin/params/bugfields.html.tmpl +++ b/template/en/default/admin/params/bugfields.html.tmpl @@ -75,4 +75,8 @@ clear_requests_on_close => "Clear all unanswered flag requests when changing bug status to CLOSED", unauth_bug_details => "Show product name to the user in Unauthorized message if he doesn't have access to bug.", + + comment_line_length => "Symbols in one \"line\" whithout linebreaks.", + + preview_comment_lines => "If comment's count of lines (one line is <comment_line_length> symbols or linebreaked line) is greater this value preview of text is shown.", } %] diff --git a/template/en/default/bug/format_comment.txt.tmpl b/template/en/default/bug/format_comment.txt.tmpl index 589d18027..49b94714d 100644 --- a/template/en/default/bug/format_comment.txt.tmpl +++ b/template/en/default/bug/format_comment.txt.tmpl @@ -31,7 +31,7 @@ #%] [% IF comment.type == constants.CMT_DUPE_OF %] -X[% comment.body %] +X[% comment.body(preview) %] *** This [% terms.bug %] has been marked as a duplicate of [% terms.bug %] [%+ comment.extra_data %] *** [% ELSIF comment.type == constants.CMT_HAS_DUPE %] @@ -39,7 +39,7 @@ X[% comment.body %] [% ELSIF comment.type == constants.CMT_POPULAR_VOTES %] *** This [% terms.bug %] has been confirmed by popular vote. *** [% ELSIF comment.type == constants.CMT_MOVED_TO %] -X[% comment.body %] +X[% comment.body(preview) %] [%+ terms.Bug %] moved to [% Param("move-to-url") %]. If the move succeeded, [% comment.extra_data %] will receive a mail containing @@ -53,7 +53,7 @@ Created attachment [% comment.extra_data %] [% END %] [%+ comment.attachment.description %] -[%+ comment.body %] +[%+ comment.body(preview) %] [% ELSIF comment.type == constants.CMT_ATTACHMENT_UPDATED %] Comment on attachment [% comment.extra_data %] [% IF is_bugmail %] @@ -61,5 +61,5 @@ Comment on attachment [% comment.extra_data %] [% END %] [%+ comment.attachment.description %] -[%+ comment.body %] +[%+ comment.body(preview) %] [% END %]