summaryrefslogtreecommitdiff
path: root/perl-lib/PgCommitFest/CommitFest.pm
diff options
context:
space:
mode:
authorRobert Haas2009-05-22 14:41:10 +0000
committerRobert Haas2009-05-22 14:41:10 +0000
commit5bc9ab5aee7ff20941e0ea6a42aa9c80e5f8f946 (patch)
tree061857ffc98835b2151dec00f713b16aa6c43200 /perl-lib/PgCommitFest/CommitFest.pm
First attempt.
Diffstat (limited to 'perl-lib/PgCommitFest/CommitFest.pm')
-rw-r--r--perl-lib/PgCommitFest/CommitFest.pm156
1 files changed, 156 insertions, 0 deletions
diff --git a/perl-lib/PgCommitFest/CommitFest.pm b/perl-lib/PgCommitFest/CommitFest.pm
new file mode 100644
index 0000000..e6cadd9
--- /dev/null
+++ b/perl-lib/PgCommitFest/CommitFest.pm
@@ -0,0 +1,156 @@
+package PgCommitFest::CommitFest;
+use strict;
+use warnings;
+
+sub delete {
+ my ($r) = @_;
+ $r->authenticate('require_login' => 1);
+ $r->set_title('Delete CommitFest');
+ my $d;
+ eval {
+ $d = $r->db->select_one(<<EOM, $r->cgi_required_id);
+DELETE FROM commitfest WHERE id = ? RETURNING id
+EOM
+ };
+ my $err = $@;
+ if (! $err) {
+ $r->error_exit('CommitFest not found.') if !defined $d;
+ $r->db->commit;
+ $r->redirect('/');
+ }
+ if ($err =~ /commitfest_topic_commitfest_id_fkey/) {
+ $r->error_exit(<<EOM);
+This CommitFest contains one or more topics and can't be deleted.
+EOM
+ }
+ $r->error_exit("Internal error: $@");
+}
+
+sub form {
+ my ($r) = @_;
+ $r->authenticate('require_login' => 1);
+
+ # Decide whether this is a new commitfest or an edit of an existing
+ # commitfest, and if editing reload data from database.
+ my $d;
+ my $id = $r->cgi_id();
+ if (defined $id) {
+ $r->set_title('Edit CommitFest');
+ $d = $r->db->select_one(<<EOM, $id);
+SELECT id, name, commitfest_status_id AS commitfest_status FROM commitfest
+WHERE id = ?
+EOM
+ $r->error_exit('CommitFest not found.') if !defined $d;
+ $r->redirect('/action/commitfest_view?id=' . $id) if $r->cgi('cancel');
+ }
+ else {
+ $r->set_title('New CommitFest');
+ $r->redirect('/') if $r->cgi('cancel');
+ }
+
+ # Add controls.
+ $r->add_control('name', 'text', 'Name', 'required' => 1);
+ $r->add_control('commitfest_status', 'select', 'Status', 'required' => 1);
+ $r->control('commitfest_status')->choice($r->db->select(<<EOM));
+SELECT id, name FROM commitfest_status ORDER BY id
+EOM
+ my %value = $r->initialize_controls($d);
+
+ # Handle commit.
+ if ($r->cgi('go') && ! $r->is_error()) {
+ if (defined $id) {
+ $r->db->update('commitfest', { 'id' => $id }, \%value);
+ }
+ else {
+ $id = $r->db->insert_returning_id('commitfest', \%value);
+ }
+ $r->db->commit;
+ $r->redirect('/action/commitfest_view?id=' . $id);
+ }
+
+ # Display template.
+ $r->render_template('commitfest_form', { 'id' => $id });
+}
+
+sub search {
+ my ($r) = @_;
+ $r->set_title('CommitFest Index');
+ $r->add_link('/action/commitfest_form', 'New CommitFest');
+ my $list = $r->db->select(<<EOM);
+SELECT id, name, commitfest_status FROM commitfest_view ORDER BY name DESC
+EOM
+ $r->render_template('commitfest_search', { 'list' => $list });
+}
+
+sub view {
+ my ($r) = @_;
+ my $id = $r->cgi_id();
+ my $d = $r->db->select_one(<<EOM, $id) if defined $id;
+SELECT id, name, commitfest_status FROM commitfest_view WHERE id = ?
+EOM
+ $r->error_exit('CommitFest not found.') if !defined $d;
+ $r->set_title('CommitFest %s (%s)', $d->{'name'},
+ $d->{'commitfest_status'});
+
+ # Load list of patches.
+ my %patch_grouping;
+ my %patch_index;
+ my $patch_list = $r->db->select(<<EOM, $d->{'id'});
+SELECT id, name, patch_status_id, patch_status, author, reviewers,
+ commitfest_topic_id, commitfest_topic, commitfest_id, date_closed
+FROM patch_view WHERE commitfest_id = ?
+ ORDER BY date_closed, commitfest_topic, name
+EOM
+ for my $p (@$patch_list) {
+ if (grep { $_ eq $p->{'patch_status_id'} } qw(4 5 6)) {
+ push @{$patch_grouping{$p->{'patch_status_id'}}}, $p;
+ }
+ else {
+ push @{$patch_grouping{'p'}}, $p;
+ }
+ $patch_index{$p->{'id'}} = $p;
+ }
+
+ # Load list of comments.
+ my $comment_list = $r->db->select(<<EOM, $d->{'id'});
+SELECT v.id, v.patch_id, v.patch_comment_type, v.message_id, v.content,
+ v.creator, to_char(v.creation_time, 'MM/DD/YYYY') AS creation_time
+FROM most_recent_comments(?) v
+EOM
+ for my $c (@$comment_list) {
+ my $p = $patch_index{$c->{'patch_id'}};
+ unshift @{$p->{'comment_list'}}, $c;
+ }
+
+ # Add links and render template.
+ $r->add_link('/action/patch_form?commitfest=' . $id, 'New Patch');
+ $r->add_link('/action/commitfest_topic_search?id=' . $id,
+ 'CommitFest Topics');
+ $r->add_link('/action/commitfest_form?id=' . $id, 'Edit CommitFest');
+ $r->add_link('/action/commitfest_delete?id=' . $id, 'Delete CommitFest',
+ 'Are you sure you want to delete this CommitFest?');
+ $r->render_template('commitfest_view', { 'd' => $d, 'patch_grouping' => [
+ {
+ 'name' => 'Pending Patches',
+ 'patch_list' => $patch_grouping{'p'},
+ 'closed' => 0
+ },
+ {
+ 'name' => 'Committed Patches',
+ 'patch_list' => $patch_grouping{'4'},
+ 'closed' => 1
+ },
+ {
+ 'name' => 'Returned with Feedback',
+ 'patch_list' => $patch_grouping{'5'},
+ 'closed' => 1
+ },
+ {
+ 'name' => 'Rejected Patches',
+ 'patch_list' => $patch_grouping{'6'},
+ 'closed' => 1
+ },
+ ]});
+}
+
+1;