From 4a189a0de87434c858dbb81b66220d70491ef8db Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Sat, 27 Jun 2009 21:25:57 -0400 Subject: [PATCH] Support for moving patches to another CommitFest. --- perl-lib/PgCommitFest/Handler.pm | 1 + perl-lib/PgCommitFest/Patch.pm | 40 ++++++++++++++++++++++++++++++-- template/patch_bump.tt2 | 20 ++++++++++++++++ template/patch_form.tt2 | 15 ++++++++++-- 4 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 template/patch_bump.tt2 diff --git a/perl-lib/PgCommitFest/Handler.pm b/perl-lib/PgCommitFest/Handler.pm index 89ed024..d94e042 100644 --- a/perl-lib/PgCommitFest/Handler.pm +++ b/perl-lib/PgCommitFest/Handler.pm @@ -19,6 +19,7 @@ our %ACTION = ( 'commitfest_topic_delete' => \&PgCommitFest::CommitFestTopic::delete, 'commitfest_topic_form' => \&PgCommitFest::CommitFestTopic::form, 'commitfest_topic_search' => \&PgCommitFest::CommitFestTopic::search, + 'patch_bump' => \&PgCommitFest::Patch::bump, 'patch_form' => \&PgCommitFest::Patch::form, 'patch_delete' => \&PgCommitFest::Patch::delete, 'patch_view' => \&PgCommitFest::Patch::view, diff --git a/perl-lib/PgCommitFest/Patch.pm b/perl-lib/PgCommitFest/Patch.pm index eda67d7..adad145 100644 --- a/perl-lib/PgCommitFest/Patch.pm +++ b/perl-lib/PgCommitFest/Patch.pm @@ -2,6 +2,30 @@ package PgCommitFest::Patch; use strict; use warnings; +sub bump { + my ($r) = @_; + $r->authenticate('require_login' => 1); + $r->set_title('Move Patch To New CommitFest'); + + # Fetch patch. + my $d = $r->db->select_one(<cgi_required_id); +SELECT id, name, commitfest_id FROM patch_view WHERE id = ? +EOM + $r->error_exit('Patch not found.') if !defined $d; + $r->set_title("Move Patch %s To Another CommitFest", $d->{'name'}); + $r->add_link('/action/patch_view?id=' . $d->{'id'}, + 'Return to Patch View'); + + # Fetch list of commitfests. + my $list = $r->db->select(<{'commitfest_id'}); +SELECT id, name, commitfest_status FROM commitfest_view WHERE id != ? + ORDER BY name DESC +EOM + + # Display template. + $r->render_template('patch_bump', { 'd' => $d, 'list' => $list }); +} + sub delete { my ($r) = @_; $r->authenticate('require_login' => 1); @@ -38,7 +62,7 @@ sub form { # Decide whether this is a new patch or an edit of an existing # patch, and if editing reload data from database. - my $d; + my ($d, $cf); my $id = $r->cgi_id(); if (defined $id) { $r->set_title('Edit Patch'); @@ -49,6 +73,14 @@ FROM patch_view WHERE id = ? EOM $r->error_exit('Patch not found.') if !defined $d; $r->redirect('/action/patch_view?id=' . $id) if $r->cgi('cancel'); + my $cfid = $r->cgi_id('commitfest'); + if (defined $cfid && $cfid != $d->{'commitfest_id'}) { + $cf = $r->db->select_one(<error_exit('New CommitFest not found.') if !defined $cf; + $d->{'commitfest_id'} = $cf->{'id'}; + } } else { $d = $r->db->select_one(<cgi_required_id('commitfest')); @@ -67,6 +99,7 @@ EOM my $commitfest_topic = $r->db->select(<{'commitfest_id'}); SELECT id, name FROM commitfest_topic WHERE commitfest_id = ? ORDER BY name EOM + unshift @$commitfest_topic, { 'id' => '', 'name' => '(None Selected)' }; $r->control('commitfest_topic')->choice($commitfest_topic); $r->add_control('patch_status', 'select', 'Patch Status', 'required' => 1); $r->control('patch_status')->choice($r->db->select(<render_template('patch_form', { 'id' => $id, 'd' => $d, - 'commitfest_topic_warning' => !@$commitfest_topic }); + 'commitfest_topic_warning' => !@$commitfest_topic, + 'new_commitfest' => $cf }); } sub view { @@ -143,6 +177,8 @@ EOM $r->add_link('/action/patch_comment_form?patch=' . $id, 'New Comment'); $r->add_link('/action/patch_form?id=' . $id, 'Edit Patch'); + $r->add_link('/action/patch_bump?id=' . $id, + 'Move To Another CommitFest'); $r->add_link('/action/patch_delete?id=' . $id, 'Delete Patch', 'Are you sure you want to delete this patch?'); $r->render_template('patch_view', { 'd' => $d, 'patch_comment_list' diff --git a/template/patch_bump.tt2 b/template/patch_bump.tt2 new file mode 100644 index 0000000..da5730b --- /dev/null +++ b/template/patch_bump.tt2 @@ -0,0 +1,20 @@ +

Please select the CommitFest to which you wish to move this patch.

+ +[% IF list.size == 0 %] +

No other CommitFests exist.

+[% ELSE %] +
+ + + + + +[% FOREACH x = list %] + + + + +[% END %] +
CommitFest NameStatus
[% x.name | htmlsafe %][% x.commitfest_status | htmlsafe %]
+
+[% END %] diff --git a/template/patch_form.tt2 b/template/patch_form.tt2 index 6505fe9..91ed836 100644 --- a/template/patch_form.tt2 +++ b/template/patch_form.tt2 @@ -1,9 +1,20 @@ +[% IF new_commitfest %] +

You are moving this patch to a different CommitFest. Since +topics are CommitFest-specific, you must select an appropriate topic for this +patch from among those defined for the target CommitFest. +

+[% SET nopara = 1 %] +[% END %] + [% IF commitfest_topic_warning %]

Note: No topics have been defined for this CommitFest. Before you can add patches to this CommitFest, you will need to visit the CommitFest -Topics page and add one or more topics. -[% ELSE %] +Topics page and add one or more topics.

+[% SET nopara = 1 %] +[% END %] + +[% IF !nopara %]

[% END %] -- 2.39.5