Add "sortorder" property to commitfest topics.
authorRobert Haas <robertmhaas@gmail.com>
Fri, 3 Jul 2009 04:16:06 +0000 (00:16 -0400)
committerRobert Haas <robertmhaas@gmail.com>
Fri, 3 Jul 2009 04:16:06 +0000 (00:16 -0400)
etc/table.sql
etc/view.sql
perl-lib/PgCommitFest/CommitFest.pm
perl-lib/PgCommitFest/CommitFestTopic.pm
perl-lib/PgCommitFest/WebControl.pm
template/commitfest_topic_form.tt2
template/commitfest_topic_search.tt2

index c60a298c863ef3e88dcfd16572781d2b435ca629..f7ce483f2a8f28fb587950c36b170ea19d324b4a 100644 (file)
@@ -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,
index af101147cee641420ddb22c31527c73576eed4b6..af98e1e64d43dea02393d3aecbc9fa5d47edc443 100644 (file)
@@ -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
index 06c725a69963968cb7971e2f77422dc9dc123761..b5539054ad24e8506dd36c514f75f30678317a31 100644 (file)
@@ -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)) {
index 5c2eca80ace3a53112198f5a6dafbc3db51008b9..3e101fcef4cdc0681fdf07bb224635b688a4e8df 100644 (file)
@@ -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,
index 6873dcbe408b034acd72c808ada8f7d4192810df..7443a60320ddd34d2b568e79829179c4f33239c4 100644 (file)
@@ -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;
        }
 
index 0a5b93798d6fee1e2583ff68bfdf1463505cf256..f3a853c7102ea125f94a113329326ebf5ae5a591 100644 (file)
@@ -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>
 
index bd82515347a4472fa6eb7b03ede0c493c8f8f039..17c0e716b2ade9fcda9a1ffbbd5f421b60bfc3d3 100644 (file)
@@ -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='/action/commitfest_topic_form?id=[% t.id %]'>Edit Topic</a> -
   <a href='/action/commitfest_topic_delete?id=[% t.id %]' onClick='return confirm("Are you sure you want to delete this topic?");'>Delete Topic</a></td>
 </tr>