From 6a688141978ccd79300218f48cce9a42e1ad1a91 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Mon, 17 Jul 2006 06:22:32 +0000 Subject: Bug 277377: Classifications should support sort keys - Patch by Olav Vitters r=LpSolit a=justdave --- Bugzilla/Classification.pm | 4 +++- Bugzilla/DB/Schema.pm | 1 + Bugzilla/User.pm | 3 ++- checksetup.pl | 19 +++++++++++++++++++ editclassifications.cgi | 17 +++++++++++++++-- enter_bug.cgi | 4 +++- .../en/default/admin/classifications/add.html.tmpl | 5 +++++ .../en/default/admin/classifications/del.html.tmpl | 4 ++++ .../en/default/admin/classifications/edit.html.tmpl | 5 +++++ .../admin/classifications/reclassify.html.tmpl | 4 ++++ .../en/default/admin/classifications/select.html.tmpl | 4 +++- .../en/default/admin/classifications/update.html.tmpl | 4 ++++ 12 files changed, 68 insertions(+), 6 deletions(-) diff --git a/Bugzilla/Classification.pm b/Bugzilla/Classification.pm index 63a826dc3..3d264b704 100644 --- a/Bugzilla/Classification.pm +++ b/Bugzilla/Classification.pm @@ -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) { diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index 7c848bd5b..c885987bc 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -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'], diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index 67ada8e29..a5a502446 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -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}; } diff --git a/checksetup.pl b/checksetup.pl index 9033666ee..b0a2b2962 100755 --- a/checksetup.pl +++ b/checksetup.pl @@ -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. # diff --git a/editclassifications.cgi b/editclassifications.cgi index 706d68918..6d75b67d2 100755 --- a/editclassifications.cgi +++ b/editclassifications.cgi @@ -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); diff --git a/enter_bug.cgi b/enter_bug.cgi index 512650a7e..66f4109c7 100755 --- a/enter_bug.cgi +++ b/enter_bug.cgi @@ -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. diff --git a/template/en/default/admin/classifications/add.html.tmpl b/template/en/default/admin/classifications/add.html.tmpl index d11a8d36c..15b8fc3a2 100644 --- a/template/en/default/admin/classifications/add.html.tmpl +++ b/template/en/default/admin/classifications/add.html.tmpl @@ -40,6 +40,11 @@ %] + + + +
diff --git a/template/en/default/admin/classifications/del.html.tmpl b/template/en/default/admin/classifications/del.html.tmpl index c32e46b4d..b450548b7 100644 --- a/template/en/default/admin/classifications/del.html.tmpl +++ b/template/en/default/admin/classifications/del.html.tmpl @@ -42,6 +42,10 @@ [% END %] + + Sortkey: + [% classification.sortkey FILTER html %] + diff --git a/template/en/default/admin/classifications/edit.html.tmpl b/template/en/default/admin/classifications/edit.html.tmpl index b00ea6853..b1fc482c2 100644 --- a/template/en/default/admin/classifications/edit.html.tmpl +++ b/template/en/default/admin/classifications/edit.html.tmpl @@ -41,6 +41,11 @@ %] + + + + diff --git a/template/en/default/admin/classifications/reclassify.html.tmpl b/template/en/default/admin/classifications/reclassify.html.tmpl index 127aeea87..d45b88073 100644 --- a/template/en/default/admin/classifications/reclassify.html.tmpl +++ b/template/en/default/admin/classifications/reclassify.html.tmpl @@ -39,6 +39,10 @@ [% END %] + + Sortkey: + [% classification.sortkey FILTER html %] + Products: Products diff --git a/template/en/default/admin/classifications/select.html.tmpl b/template/en/default/admin/classifications/select.html.tmpl index 789c40968..eaa2149f0 100644 --- a/template/en/default/admin/classifications/select.html.tmpl +++ b/template/en/default/admin/classifications/select.html.tmpl @@ -27,6 +27,7 @@ Edit Classification ... Description + Sortkey Products Action @@ -41,6 +42,7 @@ none [% END %] + [% cl.sortkey FILTER html %] [% IF (cl.id == 1) %] [% cl.product_count FILTER html %] [% ELSE %] @@ -57,7 +59,7 @@ [% END %] - Add a new classification + Add a new classification Add diff --git a/template/en/default/admin/classifications/update.html.tmpl b/template/en/default/admin/classifications/update.html.tmpl index 3ad7bbc69..68ce27755 100644 --- a/template/en/default/admin/classifications/update.html.tmpl +++ b/template/en/default/admin/classifications/update.html.tmpl @@ -23,6 +23,10 @@ title = "Update classification" %] +[% IF updated_sortkey %] + Updated sortkey.
+[% END %] + [% IF updated_description %] Updated description.
[% END %] -- cgit v1.2.3-24-g4f1b