diff options
author | Robert Haas | 2009-07-03 04:16:06 +0000 |
---|---|---|
committer | Robert Haas | 2009-07-03 04:16:06 +0000 |
commit | 39f8024eac35e3c8dcc86223f4afbf93ef514599 (patch) | |
tree | 2a5bd2ba46f9494d9c5a8c2a8ab49488bf3edfdd | |
parent | 45f4ced80004e2d220c500b7ee0e3d769cfa4356 (diff) |
Add "sortorder" property to commitfest topics.
-rw-r--r-- | etc/table.sql | 1 | ||||
-rw-r--r-- | etc/view.sql | 6 | ||||
-rw-r--r-- | perl-lib/PgCommitFest/CommitFest.pm | 2 | ||||
-rw-r--r-- | perl-lib/PgCommitFest/CommitFestTopic.pm | 18 | ||||
-rw-r--r-- | perl-lib/PgCommitFest/WebControl.pm | 38 | ||||
-rw-r--r-- | template/commitfest_topic_form.tt2 | 6 | ||||
-rw-r--r-- | template/commitfest_topic_search.tt2 | 2 |
7 files changed, 56 insertions, 17 deletions
diff --git a/etc/table.sql b/etc/table.sql index c60a298..f7ce483 100644 --- a/etc/table.sql +++ b/etc/table.sql @@ -34,6 +34,7 @@ CREATE TABLE commitfest_topic ( name varchar not null, PRIMARY KEY (id) ); +ALTER TABLE commitfest_topic ADD COLUMN sortorder INTEGER NOT NULL DEFAULT 50; CREATE TABLE patch_status ( id integer not null, diff --git a/etc/view.sql b/etc/view.sql index af10114..af98e1e 100644 --- a/etc/view.sql +++ b/etc/view.sql @@ -1,3 +1,8 @@ +DROP FUNCTION IF EXISTS most_recent_comments(integer); +DROP VIEW IF EXISTS patch_comment_view; +DROP VIEW IF EXISTS patch_view; +DROP VIEW IF EXISTS commitfest_view; + CREATE OR REPLACE VIEW commitfest_view AS SELECT v.id, v.name, v.commitfest_status_id, s.name AS commitfest_status @@ -7,6 +12,7 @@ FROM CREATE OR REPLACE VIEW patch_view AS SELECT v.id, v.commitfest_topic_id, s.name AS commitfest_topic, + s.sortorder AS commitfest_topic_sortorder, s.commitfest_id, f.name AS commitfest, v.name, v.patch_status_id, ps.name AS patch_status, v.author, v.reviewers, v.date_closed, v.creation_time diff --git a/perl-lib/PgCommitFest/CommitFest.pm b/perl-lib/PgCommitFest/CommitFest.pm index 06c725a..b553905 100644 --- a/perl-lib/PgCommitFest/CommitFest.pm +++ b/perl-lib/PgCommitFest/CommitFest.pm @@ -103,7 +103,7 @@ EOM 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, id + ORDER BY date_closed, commitfest_topic_sortorder, commitfest_topic, id EOM for my $p (@$patch_list) { if (grep { $_ eq $p->{'patch_status_id'} } qw(4 5 6)) { diff --git a/perl-lib/PgCommitFest/CommitFestTopic.pm b/perl-lib/PgCommitFest/CommitFestTopic.pm index 5c2eca8..3e101fc 100644 --- a/perl-lib/PgCommitFest/CommitFestTopic.pm +++ b/perl-lib/PgCommitFest/CommitFestTopic.pm @@ -38,13 +38,13 @@ sub form { if (defined $id) { $r->set_title('Edit CommitFest Topic'); $d = $r->db->select_one(<<EOM, $id); -SELECT id, commitfest_id, name FROM commitfest_topic WHERE id = ? +SELECT id, commitfest_id, name, sortorder FROM commitfest_topic WHERE id = ? EOM $r->error_exit('CommitFest not found.') if !defined $d; } else { $d = $r->db->select_one(<<EOM, $r->cgi_required_id('commitfest')); -SELECT id AS commitfest_id FROM commitfest WHERE id = ? +SELECT id AS commitfest_id, 50 AS sortorder FROM commitfest WHERE id = ? EOM $r->set_title('New CommitFest Topic'); } @@ -53,19 +53,19 @@ EOM # Add controls. $r->add_control('name', 'text', 'Name', 'required' => 1); + $r->add_control('sortorder', 'integer', 'Sort Order', 'required' => 1, + 'min_value' => 0); my %value = $r->initialize_controls($d); # Handle commit. if ($r->cgi('go') && ! $r->is_error()) { if (defined $id) { - $r->db->update('commitfest_topic', { 'id' => $id }, { - 'name' => $value{'name'}, - }); + $r->db->update('commitfest_topic', { 'id' => $id }, \%value); } else { $id = $r->db->insert_returning_id('commitfest_topic', { 'commitfest_id' => $d->{'commitfest_id'}, - 'name' => $value{'name'}, + %value }); } $r->db->commit; @@ -74,8 +74,7 @@ EOM } # Display template. - $r->render_template('commitfest_topic_form', { 'id' => $id, - 'd' => $d }); + $r->render_template('commitfest_topic_form', { 'id' => $id, 'd' => $d }); } sub search { @@ -88,7 +87,8 @@ EOM $r->set_title('CommitFest Topics: %s', $d->{'name'}); my $topic_list = $r->db->select(<<EOM, $d->{'id'}); -SELECT id, name FROM commitfest_topic WHERE commitfest_id = ? ORDER BY name +SELECT id, name, sortorder FROM commitfest_topic + WHERE commitfest_id = ? ORDER BY sortorder, name EOM $r->add_link('/action/commitfest_topic_form?commitfest=' . $id, diff --git a/perl-lib/PgCommitFest/WebControl.pm b/perl-lib/PgCommitFest/WebControl.pm index 6873dcb..7443a60 100644 --- a/perl-lib/PgCommitFest/WebControl.pm +++ b/perl-lib/PgCommitFest/WebControl.pm @@ -12,6 +12,11 @@ my %TYPE_ARGS = ( '_base' => 'text', }, 'hidden' => {}, + 'integer' => { + '_base' => 'text', + 'min_value' => qr/^\d+$/, + 'max_value' => qr/^\d+$/, + }, 'password' => { '_base' => 'text', }, @@ -127,14 +132,18 @@ sub new { sub render { my ($self) = @_; if ($self->{'istype'}{'text'}) { + my $size = 60; + my $maxlength = 200; + if ($self->{'istype'}{'date'} || $self->{'istype'}{'integer'}) { + $size = 10; + $maxlength = 10; + } return sprintf "<input name='%s' type='%s' size='%d' maxlength='%d' value='%s'>", $self->{'name'}, $self->{'istype'}{'password'} ? 'password' : 'text', - defined $self->{'size'} ? $self->{'size'} - : ($self->{'istype'}{'date'} ? 10 : 60), - defined $self->{'maxlength'} ? $self->{'maxlength'} - : ($self->{'istype'}{'date'} ? 10 : 120), + defined $self->{'size'} ? $self->{'size'} : $size, + defined $self->{'maxlength'} ? $self->{'maxlength'} : $maxlength, $self->{'istype'}{'password'} ? '' : escape($self->{'value'}); } elsif ($self->{'istype'}{'textarea'}) { @@ -245,8 +254,25 @@ sub set { $error = 'is not a valid date (use YYYY-MM-DD format).' if ! $ok; } - # We store NULL for empty dates. - if ($self->{'istype'}{'date'} && $value eq '') { + # If the field is an integer, complain if it doesn't look like a + # valid integer or is out of range. + if ($self->{'istype'}{'integer'} && $value ne '' && $r->cgi('go')) { + if ($value !~ /^-?\d+$/) { + $error = 'must be an integer.'; + } + elsif (defined $self->{'min_value'} && $value < $self->{'min_value'}) { + $error = 'is too small (the minimum value is ' + . $self->{'min_value'} . ').'; + } + elsif (defined $self->{'max_value'} && $value > $self->{'max_value'}) { + $error = 'is too large (the minimum value is ' + . $self->{'max_value'} . ').'; + } + } + + # We store NULL for empty dates and integers. + if (($self->{'istype'}{'date'} || $self->{'istype'}{'integer'}) + && $value eq '') { $db_value = undef; } diff --git a/template/commitfest_topic_form.tt2 b/template/commitfest_topic_form.tt2 index 0a5b937..f3a853c 100644 --- a/template/commitfest_topic_form.tt2 +++ b/template/commitfest_topic_form.tt2 @@ -2,10 +2,14 @@ <div class='tblBasic'> <table cellspacing='0' class='tblBasicGrey'> -<tr class='firstrow lastrow'> +<tr class='firstrow'> <td class='colFirst'>[% control.name.display_name_html %]</td> <td class='colLast'>[% control.name.render %]</td> </tr> +<tr class='lastrow'> + <td class='colFirst'>[% control.sortorder.display_name_html %]</td> + <td class='colLast'>[% control.sortorder.render %]</td> +</tr> </table> </div> diff --git a/template/commitfest_topic_search.tt2 b/template/commitfest_topic_search.tt2 index bd82515..17c0e71 100644 --- a/template/commitfest_topic_search.tt2 +++ b/template/commitfest_topic_search.tt2 @@ -4,11 +4,13 @@ <table cellspacing='0' class='tblBasicGrey'> <tr class='firstrow'> <th class='colFirst'>Topic</th> + <th>Sort Order</th> <th class='colLast'>Action</th> </tr> [% FOREACH t = topic_list %] <tr[% IF loop.last %] class='lastrow'[% END %]> <td class='colFirst'>[% t.name | htmlsafe %]</a></td> + <td>[% t.sortorder | htmlsafe %]</a></td> <td class='colLast'><a href='/https/git.postgresql.org/action/commitfest_topic_form?id=[% t.id %]'>Edit Topic</a> - <a href='/https/git.postgresql.org/action/commitfest_topic_delete?id=[% t.id %]' onClick='return confirm("Are you sure you want to delete this topic?");'>Delete Topic</a></td> </tr> |