Add comments to patches from patch view page.
authorRobert Haas <[email protected]>
Sat, 4 Jul 2009 02:57:19 +0000 (22:57 -0400)
committerRobert Haas <[email protected]>
Sat, 4 Jul 2009 02:57:19 +0000 (22:57 -0400)
As suggested by Tom Lane and others.

perl-lib/PgCommitFest/Patch.pm
perl-lib/PgCommitFest/PatchComment.pm
template/patch_comment_form.tt2
template/patch_view.tt2

index adad145d89834ab3bf83fafed6d61001a9b84b43..fe9a720203f501c4938e5b0450e1507c085dabf8 100644 (file)
@@ -159,6 +159,7 @@ EOM
 
 sub view {
        my ($r) = @_;
+       my $aa = $r->authenticate();
        my $id = $r->cgi_id();
        my $d = $r->db->select_one(<<EOM, $id) if defined $id;
 SELECT id, name, commitfest_id, commitfest, commitfest_topic_id,
@@ -174,8 +175,19 @@ to_char(v.creation_time, 'YYYY-MM-DD HH:MI:SS AM') AS creation_time
 FROM patch_comment_view v WHERE v.patch_id = ? ORDER BY v.creation_time
 EOM
 
-       $r->add_link('/action/patch_comment_form?patch=' . $id,
-               'New Comment');
+       # Add patch comment controls, so that users can add a patch comment
+       # without needing to visit a separate page.
+       if (defined $aa) {
+               my %value = PgCommitFest::PatchComment::controls($r, {});
+               if ($r->cgi('go') && ! $r->is_error()) {
+                       $value{'patch_id'} = $d->{'id'};
+                       $value{'creator'} = $aa->{'userid'};
+                       $r->db->insert('patch_comment', \%value);
+                       $r->db->commit;
+                       $r->redirect('/action/patch_view?id=' . $d->{'id'});
+               }
+       }
+
        $r->add_link('/action/patch_form?id=' . $id, 'Edit Patch');
        $r->add_link('/action/patch_bump?id=' . $id,
                'Move To Another CommitFest');
index 101a784a4fc0f2a60e57dbe767804cc3c58c436b..ccc804c77408e65e63210e5675573cd9cecb8a9a 100644 (file)
@@ -2,6 +2,18 @@ package PgCommitFest::PatchComment;
 use strict;
 use warnings;
 
+sub controls {
+       my ($r, $d) = @_;
+       $r->add_control('patch_comment_type', 'select', 'Comment Type',
+               'required' => 1);
+       $r->control('patch_comment_type')->choice($r->db->select(<<EOM));
+SELECT id, name FROM patch_comment_type ORDER BY id
+EOM
+       $r->add_control('message_id', 'text', 'Message-ID', 'maxlength' => 255);
+       $r->add_control('content', 'textarea', 'Content', 'required' => 1);
+       return $r->initialize_controls($d);
+}
+
 sub delete {
        my ($r) = @_;
        my $aa = $r->authenticate('require_login' => 1);
@@ -65,14 +77,7 @@ EOM
                if $r->cgi('cancel');
 
        # Add controls.
-       $r->add_control('patch_comment_type', 'select', 'Comment Type',
-               'required' => 1);
-       $r->control('patch_comment_type')->choice($r->db->select(<<EOM));
-SELECT id, name FROM patch_comment_type ORDER BY id
-EOM
-       $r->add_control('message_id', 'text', 'Message-ID', 'maxlength' => 255);
-       $r->add_control('content', 'textarea', 'Content', 'required' => 1);
-       my %value = $r->initialize_controls($d);
+       my %value = controls($r, $d);
 
        # Handle commit.
        if ($r->cgi('go') && ! $r->is_error()) {
index 624f73a670c1fdc8c6eed7a25c44c275f3607506..18fb56ffb2b595f0f0efdf2ddbdf01c58b72e82a 100644 (file)
@@ -22,4 +22,4 @@ provided.</p>
 <div><input type='submit' value='Submit'>
 <input name='cancel' type='submit' value='Cancel'>
 <input name='go' type='hidden' value='1'>
-[% IF id %]<input name='id' type='hidden' value='[% id %]'>[% ELSE %]<input name='patch' type='hidden' value='[% d.patch_id %]'>[% END %]</div>
+[% IF is_included %]<input name='id' type='hidden' value='[% d.id %]'>[% ELSIF id %]<input name='id' type='hidden' value='[% id %]'>[% ELSE %]<input name='patch' type='hidden' value='[% d.patch_id %]'>[% END %]</div>
index 37a9fa0bb3446d050a9c080e0d9af4ade949ff19..6448011fdda41800a3195ace33f0b7e9a6465e11 100644 (file)
 </tr>
 </table>
 </div>
+
+<h2 style='margin: 0px'>Add Comment</h2>
+[% IF authenticate %]
+[% INCLUDE patch_comment_form.tt2 is_included='1' %]
+[% ELSE %]
+<p>Please
+<a href='/action/login?uri=/action/patch_view?id=[% d.id %]'>log in</a>
+to comment on this patch.</p>
+[% END %]