Add sortkey for versions

3col
Vitaliy Filippov 2015-09-07 15:54:49 +03:00
parent 36905704ea
commit 1433ff9073
5 changed files with 21 additions and 1 deletions

View File

@ -618,6 +618,7 @@ use constant ABSTRACT_SCHEMA => {
id => {TYPE => 'INTSERIAL', NOTNULL => 1, PRIMARYKEY => 1},
value => {TYPE => 'varchar(255)', NOTNULL => 1},
product_id => {TYPE => 'INT4', NOTNULL => 1, REFERENCES => {TABLE => 'products', COLUMN => 'id', DELETE => 'CASCADE'}},
sortkey => {TYPE => 'INT4', NOTNULL => 1, DEFAULT => 0},
isactive => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'TRUE'},
],
INDEXES => [

View File

@ -861,6 +861,8 @@ WHERE description LIKE \'%[CC:%]%\'');
$dbh->bz_alter_column('bugs', $_->name, Bugzilla::Field->SQL_DEFINITIONS->{FIELD_TYPE_NUMERIC()});
}
$dbh->bz_add_column('versions', 'sortkey');
_move_old_defaults($old_params);
################################################################

View File

@ -43,6 +43,7 @@ use constant DB_COLUMNS => qw(
id
value
product_id
sortkey
isactive
);
@ -54,11 +55,13 @@ use constant REQUIRED_CREATE_FIELDS => qw(
use constant UPDATE_COLUMNS => qw(
value
isactive
sortkey
);
use constant VALIDATORS => {
product => \&_check_product,
isactive => \&Bugzilla::Object::check_boolean,
sortkey => \&_check_sortkey,
};
use constant UPDATE_VALIDATORS => {
@ -107,7 +110,7 @@ sub _do_list_select
{
my $self = shift;
my $list = $self->SUPER::_do_list_select(@_);
return [ sort { vers_cmp(lc($a->{value}), lc($b->{value})) } @$list ];
return [ sort { ($a->{sortkey} <=> $b->{sortkey}) || vers_cmp(lc $a->{value}, lc $b->{value}) } @$list ];
}
sub run_create_validators
@ -180,6 +183,7 @@ sub update
sub product_id { return $_[0]->{product_id}; }
sub is_active { return $_[0]->{isactive}; }
sub sortkey { return $_[0]->{sortkey}; }
sub product
{
@ -195,6 +199,7 @@ sub product
sub set_name { $_[0]->set('value', $_[1]); }
sub set_is_active { $_[0]->set('isactive', $_[1]); }
sub set_sortkey { $_[0]->set('sortkey', $_[1]); }
sub _check_value
{
@ -226,6 +231,12 @@ sub _check_product
return Bugzilla->user->check_can_admin_product($product->name);
}
sub _check_sortkey
{
my ($invocant, $sortkey) = @_;
return int($sortkey || 0);
}
1;
__END__

View File

@ -122,6 +122,7 @@ if ($action eq 'new')
my $version = Bugzilla::Version->create({
name => $version_name,
product => $product,
sortkey => $ARGS->{sortkey} || 0,
});
delete_token($token);
$vars->{message} = 'version_created';
@ -210,6 +211,7 @@ if ($action eq 'update')
$version->set_name($version_name);
$version->set_is_active($isactive);
$version->set_sortkey($ARGS->{sortkey});
my $changes = $version->update();
$changes->{control_lists} = 1 if $version->field->update_control_lists($version->id, $ARGS);

View File

@ -27,6 +27,10 @@
<th class="field_label"><label for="version">Version:</label></th>
<td><input id="version" size="64" maxlength="64" name="version" id="version" value="[%- version.name | html %]" /></td>
</tr>
<tr>
<th class="field_label"><label for="sortkey">Sortkey:</label></th>
<td><input id="sortkey" size="20" maxlength="20" name="sortkey" value="[%- version.sortkey | html %]" /></td>
</tr>
[% IF version.id %]
<tr>
<th class="field_label"><label for="isactive">Enabled For [% terms.Bugs %]:</label></th>