User: sits    
  Date: 08/02/28 03:01:58

  Modified:    lib/Codestriker/Action ViewTopic.pm
               lib/Codestriker/Http Render.pm
               template/en/default viewtopic.html.tmpl
  Added:       lib/Codestriker/Template/Plugin CommentLine.pm
  Log:
  Render the add general comment link via TT rather than Render.pm
  
  
  
  Index: ViewTopic.pm
  ===================================================================
  RCS file: 
/cvsroot/codestriker/codestriker/lib/Codestriker/Action/ViewTopic.pm,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- ViewTopic.pm      28 Feb 2008 06:26:18 -0000      1.53
  +++ ViewTopic.pm      28 Feb 2008 11:01:58 -0000      1.54
  @@ -227,6 +227,30 @@
       }
       $vars->{'filetable'} = [EMAIL PROTECTED];
   
  +    # Pass in existing comment information.
  +    # Build a hash from filenumber|fileline|new -> comment array, so that
  +    # when rendering, lines can be coloured appropriately.  Also build a list
  +    # of what points in the review have a comment.  Also record a mapping
  +    # from filenumber|fileline|new -> the comment number.
  +    my %comment_hash = ();
  +    my @comment_locations = ();
  +    my %comment_location_map = ();
  +    for (my $i = 0; $i <= $#comments; $i++) {
  +     my $comment = $comments[$i];
  +     my $key = $comment->{filenumber} . "|" . $comment->{fileline} . "|" .
  +         $comment->{filenew};
  +     if (! exists $comment_hash{$key}) {
  +         push @comment_locations, $key;
  +         $comment_location_map{$key} = $#comment_locations;
  +     }
  +        push @{ $comment_hash{$key} }, $comment;
  +    }
  +
  +    $vars->{'query'} = $query;
  +    $vars->{'comment_hash'} = \%comment_hash;
  +    $vars->{'comment_locations'} = [EMAIL PROTECTED];
  +    $vars->{'comment_location_map'} = \%comment_location_map;
  +
       # Fire the template for generating the view topic screen.
       my $template = Codestriker::Http::Template->new("viewtopic");
       $template->process($vars);
  @@ -250,11 +274,7 @@
                                                [EMAIL PROTECTED], -1,
                                                $brmode, $fview);
   
  -    # Display the data that is being reviewed.
  -    $render->start();
  -
       # Retrieve the delta set comprising this review.
  -
       my $old_filename = "";
       
       # Determine which deltas are to be retrieved.
  
  
  
  
  
  Index: Render.pm
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Render.pm,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- Render.pm 28 Feb 2008 06:26:18 -0000      1.55
  +++ Render.pm 28 Feb 2008 11:01:58 -0000      1.56
  @@ -18,9 +18,6 @@
   # against.
   my $CONTEXT_COLOUR = "red";
   
  -sub _normal_mode_start( $ );
  -sub _normal_mode_finish( $ );
  -sub _coloured_mode_start( $ );
   sub _coloured_mode_finish( $ );
   
   # New lines within a diff block.
  @@ -841,18 +838,6 @@
       return $query->a($params, $text);
   }
   
  -# Start hook called when about to start rendering to a page.
  -sub start($) {
  -    my ($self) = @_;
  -
  -    # Now create the start of the rendering tables.
  -    if ($self->{mode} == $Codestriker::NORMAL_MODE) {
  -     $self->_normal_mode_start();
  -    } else {
  -     $self->_coloured_mode_start();
  -    }
  -}
  -
   # Finished hook called when finished rendering to a page.
   sub finish($) {
       my ($self) = @_;
  @@ -865,18 +850,6 @@
       $self->_print_legend();
   }
   
  -# Start topic view display hook for normal mode.
  -sub _normal_mode_start($) {
  -    my ($self) = @_;
  -    print "<PRE>\n";
  -}
  -
  -# Finish topic view display hook for normal mode.
  -sub _normal_mode_finish($) {
  -    my ($self) = @_;
  -    print "</PRE>\n";
  -}
  -
   # Private functon to print the diff legend out at the bottom of the topic 
text page.
   sub _print_legend($) {
       my ($self) = @_;
  @@ -901,26 +874,6 @@
       print $query->end_table(), "\n";
   }
   
  -
  -# Start topic view display hook for coloured mode.  This displays a simple
  -# legend, displays the files involved in the review, and opens up the initial
  -# table.
  -sub _coloured_mode_start($) {
  -    my ($self) = @_;
  -
  -    my $query = $self->{query};
  -
  -    
  -    # Render the "Add comment to topic" link.
  -    print $query->p;
  -    print $self->render_comment_link(-1, -1, 1, "Add General Comment",
  -                                  "general_comment", undef);
  -    print " to topic.";
  -    print $query->p;
  -
  -    print $query->start_table() ;
  -}
  -
   # Render the initial start of the coloured table, with an empty row setting
   # the widths.
   sub print_coloured_table($)
  
  
  
  
  
  Index: CommentLine.pm
  ===================================================================
  RCS file: CommentLine.pm
  diff -N CommentLine.pm
  --- /dev/null 1 Jan 1970 00:00:00 -0000
  +++ CommentLine.pm    28 Feb 2008 11:01:58 -0000      1.1
  @@ -0,0 +1,78 @@
  +package Codestriker::Template::Plugin::CommentLine;
  +
  +# Template toolkit plugin module for outputting the anchor text
  +# for a specific line.
  +
  +use Template::Plugin::Filter;
  +use Codestriker;
  +use Codestriker::Http::UrlBuilder;
  +
  +use base qw( Template::Plugin::Filter );
  +
  +# Indicate that the filter should be re-created on each filter call.
  +our $DYNAMIC = 1;
  +
  +sub filter {
  +    my ($self, $text, $args, $conf) = @_;
  +
  +    $conf = $self->merge_config($conf);
  +
  +    # Constructor parameters.
  +    my $query = $conf->{query};
  +    my $comment_hash = %{ $conf->{comment_hash} };
  +    my $comment_location_map = %{ $conf->{comment_location_map} };
  +    my $mode = $conf->{mode};
  +
  +    # Filter parameters.
  +    my $filenumber = $conf->{filenumber};
  +    my $line = $conf->{line};
  +    my $new = $conf->{new};
  +
  +    # Determine the comment class to use.
  +    my $comment_class = $mode eq 'coloured' ? 'com' : 'smscom';
  +    my $no_comment_class = $mode eq 'coloured' ? 'nocom' : 'smsnocom';
  +
  +    # Determine the anchor and edit URL for this line number.
  +    my $anchor = "$filenumber|$line|$new";
  +    my $edit_url = "javascript:eo('$filenumber','$line','$new')";
  +
  +    # Set the anchor to this line number.
  +    my $params = {};
  +    $params->{name} = $anchor;
  +
  +    # Only set the href attribute if the comment is in open state.
  +    if (!Codestriker::topic_readonly($self->{topic_state})) {
  +     $params->{href} = $edit_url;
  +    }
  +
  +    # If a comment exists on this line, set span and the overlib hooks onto
  +    # it.
  +    my $comment_number = undef;
  +    if (exists $comment_hash{$anchor}) {
  +     # Determine what comment number this anchor refers to.
  +     $comment_number = $comment_location_map{$anchor};
  +
  +     if (defined $comment_class) {
  +         $text = $query->span({-id=>"c$comment_number"}, "") .
  +             $query->span({-class=>$comment_class}, $text);
  +     }
  +
  +     # Determine what the next comment in line is.
  +     my $index = -1;
  +     my @comment_locations = @{ $self->{comment_locations} };
  +     for ($index = 0; $index <= $#comment_locations; $index++) {
  +         last if $anchor eq $comment_locations[$index];
  +     }
  +
  +     $params->{onmouseover} = "return 
overlib(comment_text[$index],STICKY,DRAGGABLE,ALTCUT);";
  +     $params->{onmouseout} = "return nd();";
  +    } else {
  +     if (defined $no_comment_class) {
  +         $text = $query->span({-class=>$no_comment_class}, $text);
  +     }
  +    }
  +
  +    return $query->a($params, $text);
  +}
  +
  +1;
  
  
  
  
  
  Index: viewtopic.html.tmpl
  ===================================================================
  RCS file: 
/cvsroot/codestriker/codestriker/template/en/default/viewtopic.html.tmpl,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- viewtopic.html.tmpl       28 Feb 2008 06:26:19 -0000      1.39
  +++ viewtopic.html.tmpl       28 Feb 2008 11:01:58 -0000      1.40
  @@ -93,6 +93,13 @@
   
   </table>
   
  +[% USE CommentLine query = query comment_hash = comment_hash
  +                   comment_location_map = comment_location_map
  +                   mode = mode %]
  +
  +<p>
  +[% FILTER $CommentLine filenumber = -1 line = -1 new = 1 %]Add General 
Comment[% END %] to topic.
  +
   [%# The perl script takes control from here, rendering the topic data. #%]
   
   
  
  
  

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Codestriker-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/codestriker-commits

Reply via email to