Commit 6a688141 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 277377: Classifications should support sort keys - Patch by Olav Vitters…

Bug 277377: Classifications should support sort keys - Patch by Olav Vitters <bugzilla-mozilla@bkor.dhs.org> r=LpSolit a=justdave
parent 324479e5
...@@ -31,6 +31,7 @@ use constant DB_COLUMNS => qw( ...@@ -31,6 +31,7 @@ use constant DB_COLUMNS => qw(
classifications.id classifications.id
classifications.name classifications.name
classifications.description classifications.description
classifications.sortkey
); );
our $columns = join(", ", DB_COLUMNS); our $columns = join(", ", DB_COLUMNS);
...@@ -122,6 +123,7 @@ sub products { ...@@ -122,6 +123,7 @@ sub products {
sub id { return $_[0]->{'id'}; } sub id { return $_[0]->{'id'}; }
sub name { return $_[0]->{'name'}; } sub name { return $_[0]->{'name'}; }
sub description { return $_[0]->{'description'}; } sub description { return $_[0]->{'description'}; }
sub sortkey { return $_[0]->{'sortkey'}; }
############################### ###############################
#### Subroutines #### #### Subroutines ####
...@@ -131,7 +133,7 @@ sub get_all_classifications { ...@@ -131,7 +133,7 @@ sub get_all_classifications {
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
my $ids = $dbh->selectcol_arrayref(q{ my $ids = $dbh->selectcol_arrayref(q{
SELECT id FROM classifications ORDER BY name}); SELECT id FROM classifications ORDER BY sortkey, name});
my @classifications; my @classifications;
foreach my $id (@$ids) { foreach my $id (@$ids) {
......
...@@ -854,6 +854,7 @@ use constant ABSTRACT_SCHEMA => { ...@@ -854,6 +854,7 @@ use constant ABSTRACT_SCHEMA => {
PRIMARYKEY => 1}, PRIMARYKEY => 1},
name => {TYPE => 'varchar(64)', NOTNULL => 1}, name => {TYPE => 'varchar(64)', NOTNULL => 1},
description => {TYPE => 'MEDIUMTEXT'}, description => {TYPE => 'MEDIUMTEXT'},
sortkey => {TYPE => 'INT2', NOTNULL => 1, DEFAULT => '0'},
], ],
INDEXES => [ INDEXES => [
classifications_name_idx => {FIELDS => ['name'], classifications_name_idx => {FIELDS => ['name'],
......
...@@ -557,7 +557,8 @@ sub get_selectable_classifications { ...@@ -557,7 +557,8 @@ sub get_selectable_classifications {
$class->{$product->classification_id} ||= $class->{$product->classification_id} ||=
new Bugzilla::Classification($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; $self->{selectable_classifications} = \@sorted_class;
return $self->{selectable_classifications}; return $self->{selectable_classifications};
} }
......
...@@ -4229,6 +4229,25 @@ if ($dbh->bz_column_info("namedqueries", "linkinfooter")) { ...@@ -4229,6 +4229,25 @@ if ($dbh->bz_column_info("namedqueries", "linkinfooter")) {
$dbh->bz_drop_column("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 # If you had to change the --TABLE-- definition in any way, then add your
# differential change code *** A B O V E *** this comment. # differential change code *** A B O V E *** this comment.
# #
......
...@@ -108,12 +108,15 @@ if ($action eq 'new') { ...@@ -108,12 +108,15 @@ if ($action eq 'new') {
} }
my $description = trim($cgi->param('description') || ''); my $description = trim($cgi->param('description') || '');
my $sortkey = trim($cgi->param('sortkey') || 0);
trick_taint($description); trick_taint($description);
trick_taint($class_name); trick_taint($class_name);
detaint_natural($sortkey);
# Add the new classification. # Add the new classification.
$dbh->do("INSERT INTO classifications (name, description) $dbh->do("INSERT INTO classifications (name, description, sortkey)
VALUES (?, ?)", undef, ($class_name, $description)); VALUES (?, ?, ?)", undef, ($class_name, $description, $sortkey));
$vars->{'classification'} = $class_name; $vars->{'classification'} = $class_name;
...@@ -201,6 +204,7 @@ if ($action eq 'update') { ...@@ -201,6 +204,7 @@ if ($action eq 'update') {
my $class_old_name = trim($cgi->param('classificationold') || ''); my $class_old_name = trim($cgi->param('classificationold') || '');
my $description = trim($cgi->param('description') || ''); my $description = trim($cgi->param('description') || '');
my $sortkey = trim($cgi->param('sortkey') || 0);
my $class_old = my $class_old =
Bugzilla::Classification::check_classification($class_old_name); Bugzilla::Classification::check_classification($class_old_name);
...@@ -230,6 +234,15 @@ if ($action eq 'update') { ...@@ -230,6 +234,15 @@ if ($action eq 'update') {
$vars->{'updated_description'} = 1; $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(); $dbh->bz_unlock_tables();
LoadTemplate($action); LoadTemplate($action);
......
...@@ -79,7 +79,9 @@ if ($product_name eq '') { ...@@ -79,7 +79,9 @@ if ($product_name eq '') {
$class->{$product->classification_id} ||= $class->{$product->classification_id} ||=
new Bugzilla::Classification($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, # We know there is at least one classification available,
# else we would have stopped earlier. # else we would have stopped earlier.
......
...@@ -40,6 +40,11 @@ ...@@ -40,6 +40,11 @@
%] %]
</td> </td>
</tr> </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> </table>
<hr> <hr>
<input type=submit value="Add"> <input type=submit value="Add">
......
...@@ -42,6 +42,10 @@ ...@@ -42,6 +42,10 @@
[% END %] [% END %]
</td> </td>
</tr><tr>
<td valign="top">Sortkey:</td>
<td valign="top">[% classification.sortkey FILTER html %]</td>
</tr> </tr>
</table> </table>
......
...@@ -41,6 +41,11 @@ ...@@ -41,6 +41,11 @@
%] %]
</td> </td>
</tr> </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> <tr valign=top>
<th align="right"> <th align="right">
<a href="editproducts.cgi?classification=[% classification.name FILTER url_quote %]"> <a href="editproducts.cgi?classification=[% classification.name FILTER url_quote %]">
......
...@@ -40,6 +40,10 @@ ...@@ -40,6 +40,10 @@
</td> </td>
</tr><tr> </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>
<td valign="top">Products</td> <td valign="top">Products</td>
<td></td> <td></td>
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
<tr bgcolor="#6666ff"> <tr bgcolor="#6666ff">
<th align="left">Edit Classification ...</th> <th align="left">Edit Classification ...</th>
<th align="left">Description</th> <th align="left">Description</th>
<th align="left">Sortkey</th>
<th align="left">Products</th> <th align="left">Products</th>
<th align="left">Action</th> <th align="left">Action</th>
</tr> </tr>
...@@ -41,6 +42,7 @@ ...@@ -41,6 +42,7 @@
<font color="red">none</font> <font color="red">none</font>
[% END %] [% END %]
</td> </td>
<td valign="top">[% cl.sortkey FILTER html %]</td>
[% IF (cl.id == 1) %] [% IF (cl.id == 1) %]
<td valign="top">[% cl.product_count FILTER html %]</td> <td valign="top">[% cl.product_count FILTER html %]</td>
[% ELSE %] [% ELSE %]
...@@ -57,7 +59,7 @@ ...@@ -57,7 +59,7 @@
[% END %] [% END %]
<tr> <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> <td valign="top" align="center"><a href="editclassifications.cgi?action=add">Add</a></td>
</tr> </tr>
</table> </table>
......
...@@ -23,6 +23,10 @@ ...@@ -23,6 +23,10 @@
title = "Update classification" title = "Update classification"
%] %]
[% IF updated_sortkey %]
Updated sortkey.<br>
[% END %]
[% IF updated_description %] [% IF updated_description %]
Updated description.<br> Updated description.<br>
[% END %] [% END %]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment