As suggested by Tom Lane and others.
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,
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');
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);
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()) {
<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>
</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 %]