]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 277377: Classifications should support sort keys - Patch by Olav Vitters <bugzill...
authorlpsolit%gmail.com <>
Mon, 17 Jul 2006 06:22:32 +0000 (06:22 +0000)
committerlpsolit%gmail.com <>
Mon, 17 Jul 2006 06:22:32 +0000 (06:22 +0000)
12 files changed:
Bugzilla/Classification.pm
Bugzilla/DB/Schema.pm
Bugzilla/User.pm
checksetup.pl
editclassifications.cgi
enter_bug.cgi
template/en/default/admin/classifications/add.html.tmpl
template/en/default/admin/classifications/del.html.tmpl
template/en/default/admin/classifications/edit.html.tmpl
template/en/default/admin/classifications/reclassify.html.tmpl
template/en/default/admin/classifications/select.html.tmpl
template/en/default/admin/classifications/update.html.tmpl

index 63a826dc3216bba0619c85f4e20a1c30c4cf3f9f..3d264b704dff83e8483fb2349ce2c91c74248174 100644 (file)
@@ -31,6 +31,7 @@ use constant DB_COLUMNS => qw(
     classifications.id
     classifications.name
     classifications.description
+    classifications.sortkey
 );
 
 our $columns = join(", ", DB_COLUMNS);
@@ -122,6 +123,7 @@ sub products {
 sub id          { return $_[0]->{'id'};          }
 sub name        { return $_[0]->{'name'};        }
 sub description { return $_[0]->{'description'}; }
+sub sortkey     { return $_[0]->{'sortkey'};     }
 
 ###############################
 ####      Subroutines      ####
@@ -131,7 +133,7 @@ sub get_all_classifications {
     my $dbh = Bugzilla->dbh;
 
     my $ids = $dbh->selectcol_arrayref(q{
-        SELECT id FROM classifications ORDER BY name});
+        SELECT id FROM classifications ORDER BY sortkey, name});
 
     my @classifications;
     foreach my $id (@$ids) {
index 7c848bd5bd6d02ef01491c539992b73bd5c4e235..c885987bc6f67b4ce7d383b99bec60fba72b1532 100644 (file)
@@ -854,6 +854,7 @@ use constant ABSTRACT_SCHEMA => {
                             PRIMARYKEY => 1},
             name        => {TYPE => 'varchar(64)', NOTNULL => 1},
             description => {TYPE => 'MEDIUMTEXT'},
+            sortkey     => {TYPE => 'INT2', NOTNULL => 1, DEFAULT => '0'},
         ],
         INDEXES => [
             classifications_name_idx => {FIELDS => ['name'],
index 67ada8e2956b63aebbf5bcd058c843c93734f956..a5a50244626da6e25ce2628ce4975dc0e2e2db10 100644 (file)
@@ -557,7 +557,8 @@ sub get_selectable_classifications {
         $class->{$product->classification_id} ||= 
             new Bugzilla::Classification($product->classification_id);
     }
-    my @sorted_class = sort {lc($a->name) cmp lc($b->name)} (values %$class);
+    my @sorted_class = sort {$a->sortkey <=> $b->sortkey 
+                             || lc($a->name) cmp lc($b->name)} (values %$class);
     $self->{selectable_classifications} = \@sorted_class;
     return $self->{selectable_classifications};
 }
index 9033666ee6b270431085ed3f21c98e064462ca01..b0a2b296244acc6f283cdfc122af75a4904de881 100755 (executable)
@@ -4229,6 +4229,25 @@ if ($dbh->bz_column_info("namedqueries", "linkinfooter")) {
     $dbh->bz_drop_column("namedqueries", "linkinfooter");    
 }
 
+# 2006-07-07 olav@bkor.dhs.org - Bug 277377
+# Add a sortkey to the classifications
+if (!$dbh->bz_column_info('classifications', 'sortkey')) {
+    print "Adding sortkey column to classifications table...\n" unless $silent;
+
+    $dbh->bz_add_column('classifications', 'sortkey',
+                        {TYPE => 'INT2', NOTNULL => 1, DEFAULT => 0});
+
+    my $class_ids = $dbh->selectcol_arrayref('SELECT id FROM classifications ' .
+                                             'ORDER BY name');
+    my $sth = $dbh->prepare('UPDATE classifications SET sortkey = ? ' .
+                            'WHERE id = ?');
+    my $sortkey = 0;
+    foreach my $class_id (@$class_ids) {
+        $sth->execute($sortkey, $class_id);
+        $sortkey += 100;
+    }
+}
+
 # If you had to change the --TABLE-- definition in any way, then add your
 # differential change code *** A B O V E *** this comment.
 #
index 706d6891801aa917cc5cb5c1c066e71189cbfb08..6d75b67d27b8400670bb2f076fd0f176abc0e04f 100755 (executable)
@@ -108,12 +108,15 @@ if ($action eq 'new') {
     }
     
     my $description = trim($cgi->param('description')  || '');
+    my $sortkey = trim($cgi->param('sortkey') || 0);
+
     trick_taint($description);
     trick_taint($class_name);
+    detaint_natural($sortkey);
 
     # Add the new classification.
-    $dbh->do("INSERT INTO classifications (name, description)
-              VALUES (?, ?)", undef, ($class_name, $description));
+    $dbh->do("INSERT INTO classifications (name, description, sortkey)
+              VALUES (?, ?, ?)", undef, ($class_name, $description, $sortkey));
 
     $vars->{'classification'} = $class_name;
 
@@ -201,6 +204,7 @@ if ($action eq 'update') {
 
     my $class_old_name = trim($cgi->param('classificationold') || '');
     my $description    = trim($cgi->param('description')       || '');
+    my $sortkey        = trim($cgi->param('sortkey')           || 0);
 
     my $class_old =
         Bugzilla::Classification::check_classification($class_old_name);
@@ -230,6 +234,15 @@ if ($action eq 'update') {
         $vars->{'updated_description'} = 1;
     }
 
+    if ($sortkey ne $class_old->sortkey) {
+        detaint_natural($sortkey);
+        $dbh->do("UPDATE classifications SET sortkey = ?
+                  WHERE id = ?", undef,
+                 ($sortkey, $class_old->id));
+
+        $vars->{'updated_sortkey'} = 1;
+    }
+
     $dbh->bz_unlock_tables();
 
     LoadTemplate($action);
index 512650a7eb5e1d8a8dbafc17739d1739d50cf869..66f4109c73f769cae5e967b55831a950d0b65d05 100755 (executable)
@@ -79,7 +79,9 @@ if ($product_name eq '') {
             $class->{$product->classification_id} ||=
                 new Bugzilla::Classification($product->classification_id);
         }
-        my @classifications = sort {lc($a->name) cmp lc($b->name)} (values %$class);
+        my @classifications = sort {$a->sortkey <=> $b->sortkey
+                                    || lc($a->name) cmp lc($b->name)}
+                                   (values %$class);
 
         # We know there is at least one classification available,
         # else we would have stopped earlier.
index d11a8d36c0f4748319e1ba3287fbc953d80fab03..15b8fc3a26f7ca967ad3d1bac79db2fd64b68ce2 100644 (file)
         %]
       </td>
     </tr>
+    <tr>
+      <th align="right"><label for="sortkey">Sortkey:</label></th>
+      <td><input id="sortkey" size="20" maxlength="20" name="sortkey" 
+                 value=""></td>
+    </tr>
   </table>
   <hr>
   <input type=submit value="Add">
index c32e46b4df7f20a87db8b3297777d15df3069692..b450548b7c388d00d11079a3d39107b7b9a13f12 100644 (file)
     [% END %]
   </td>
 
+</tr><tr>
+  <td valign="top">Sortkey:</td>
+  <td valign="top">[% classification.sortkey FILTER html %]</td>
+
 </tr>
 </table>
 
index b00ea685325f86f2f3ce2412dfeb9b6bd14b6657..b1fc482c2abfa41bb65e4d5288f7519cf1a264f3 100644 (file)
         %]
       </td>
     </tr>
+    <tr>
+      <th align="right"><label for="sortkey">Sortkey:</label></th>
+      <td><input id="sortkey" size="20" maxlength="20" name="sortkey" value="
+      [%- classification.sortkey FILTER html %]"></td>
+    </tr>
     <tr valign=top>
       <th align="right">
         <a href="editproducts.cgi?classification=[% classification.name FILTER url_quote %]">
index 127aeea877662d48e149e74138715326cb08ee67..d45b88073d0221edf1f5233b108b37ea63e0e0b7 100644 (file)
         [% END %]
       </td>
 
+    </tr><tr>
+      <td valign="top">Sortkey:</td>
+      <td valign="top" colspan=3>[% classification.sortkey FILTER html %]</td>
+
     </tr><tr>
       <td valign="top">Products:</td>
       <td valign="top">Products</td>
index 789c40968bbe11401b49897ad856e11a6eb64afa..eaa2149f0b65f22dcf233b2c58e741685fdc33dd 100644 (file)
@@ -27,6 +27,7 @@
   <tr bgcolor="#6666ff">
     <th align="left">Edit Classification ...</th>
     <th align="left">Description</th>
+    <th align="left">Sortkey</th>
     <th align="left">Products</th>
     <th align="left">Action</th>
   </tr>
@@ -41,6 +42,7 @@
         <font color="red">none</font>
       [% END %]
       </td>
+      <td valign="top">[% cl.sortkey FILTER html %]</td>
       [% IF (cl.id == 1) %]
         <td valign="top">[% cl.product_count FILTER html %]</td>
       [% ELSE %]
@@ -57,7 +59,7 @@
   [% END %]
 
   <tr>
-    <td valign="top" colspan=3>Add a new classification</td>
+    <td valign="top" colspan=4>Add a new classification</td>
     <td valign="top" align="center"><a href="editclassifications.cgi?action=add">Add</a></td>
   </tr>
 </table>
index 3ad7bbc692d8fc96cd80bad49a644a2ad6fbc220..68ce277554d5ab509143d4939f298362d7658ed7 100644 (file)
   title = "Update classification"
 %]
 
+[% IF updated_sortkey %] 
+  Updated sortkey.<br>
+[% END %]
+
 [% IF updated_description %] 
   Updated description.<br>
 [% END %]