Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "sort" field to Zone table for sorting Zones displayed in UI #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion etc/default_data
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ INSERT INTO ipblock (address, prefix, version, status, owner, used_by, descripti
INSERT INTO ipblock (address, prefix, version, status, owner, used_by, description) VALUES ('338288524927261089654018896841347694592', '10', '6', '1', '1', '1', 'Link-Local Unicast');


INSERT INTO zone (name, active, default_ttl, info, minimum, mname, refresh, retry, rname, serial, expire, export_file) VALUES ('defaultdomain', '0', '86400', 'Default Zone', '86400', 'localhost.defaultdomain', '7200', '900', 'hostmaster.defaultdomain', '0', 1577858400, '/tmp/zone_export.txt');
INSERT INTO zone (name, active, default_ttl, info, minimum, mname, refresh, retry, rname, serial, expire, export_file, sort) VALUES ('defaultdomain', '0', '86400', 'Default Zone', '86400', 'localhost.defaultdomain', '7200', '900', 'hostmaster.defaultdomain', '0', 1577858400, '/tmp/zone_export.txt', 100);
INSERT INTO rr (name, active, zone, auto_update) VALUES ('@', '0', '1', true);
INSERT INTO rrns (rr, nsdname, ttl) VALUES ('1', 'ns1.defaultdomain', '86400');
INSERT INTO rrns (rr, nsdname, ttl) VALUES ('1', 'ns2.defaultdomain', '86400');
13 changes: 11 additions & 2 deletions etc/netdot.meta
Original file line number Diff line number Diff line change
Expand Up @@ -8596,7 +8596,15 @@ $meta = {
nullable => 0,
tag => 'Serial',
type => 'bigint'
}
},
sort => {
default => 100,
description => 'Integer value that zones will be sorted by for display purposes.',
length => '',
nullable => 0,
tag => 'Sort',
type => 'integer'
},
},
description => 'A DNS Zone',
has_history => 0,
Expand Down Expand Up @@ -8626,7 +8634,8 @@ $meta = {
'export_file',
'default_ttl',
'include',
'info'
'sort',
'info',
],
brief => [
'name',
Expand Down
4 changes: 2 additions & 2 deletions htdocs/management/host.html
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
@select_list = ( $zone );
$ffargs{default} = $zone->id;
}
foreach my $z ( sort { $a->name cmp $b->name } Zone->retrieve_all ){
foreach my $z ( Zone->retrieve_all ){
next if $z->is_dot_arpa;
next unless $z->active;
next if $zone && ($z->id == $zone->id);
Expand Down Expand Up @@ -813,7 +813,7 @@
push( @cell_data, '<input name="RR__NEW__name" value="" type="text">' );
}
my $zone_select = '<select name="RR__NEW__zone">';
foreach my $z ( sort { $a->name cmp $b->name } Zone->retrieve_all ){
foreach my $z ( Zone->retrieve_all ){
next unless $z->is_dot_arpa;
if ( $rzone && $rzone->id == $z->id ){
$zone_select .= '<option value="'.$z.'" SELECTED>'.$z->get_label.'</option>';
Expand Down
6 changes: 3 additions & 3 deletions htdocs/management/ip.html
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@
if ( $zone ){
@zone_list = ( $zone );
}
foreach my $z ( sort { $a->name cmp $b->name } Zone->retrieve_all ){
foreach my $z ( Zone->retrieve_all ){
next if $z->is_dot_arpa;
next unless $z->active;
next if $zone && ($z->id == $zone->id);
Expand Down Expand Up @@ -1592,7 +1592,7 @@
<div class="containerbody">
% if ( $_action eq 'VIEW_ADD_FZONES' ){
% my $czone = ($o->forward_zone)? $o->forward_zone->name : "none";
% my @all_zones = sort { $a->name cmp $b->name } Zone->retrieve_all;
% my @all_zones = Zone->retrieve_all;
% my %cur_zones;
% map { $cur_zones{$_->zone->id} = 1 } @sz;
<form name="netdotform" action="ip.html" method="POST">
Expand Down Expand Up @@ -1648,7 +1648,7 @@
</div>
<div class="containerbody">
% if ( $_action eq 'VIEW_ADD_RZONES' ){
% my @all_zones = sort { $a->name cmp $b->name } Zone->retrieve_all;
% my @all_zones = Zone->retrieve_all;
<form name="netdotform" action="ip.html" method="POST">
<input type="hidden" name="id" value="<% $o->id %>">
<input type="hidden" name="_action" value="ADD_REV_ZONE">
Expand Down
2 changes: 1 addition & 1 deletion htdocs/management/zone_tasks.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*print_showtaskslink = $m->comp('SELF:.sub_print_showtaskslink');
my $hideheader = 'style="display:none"' if ( !$showheader );

my @all_zones = sort { $a->name cmp $b->name } Zone->retrieve_all();
my @all_zones = Zone->retrieve_all();

my $manager = $ui->get_permission_manager($r);
</%init>
Expand Down
32 changes: 31 additions & 1 deletion lib/Netdot/Model/Zone.pm
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,34 @@ sub search_like {
return wantarray ? @result : $result;
}

#########################################################################

=head2 retrieve_all - Return all Zone objects sorted or an iterator

Args:
none
Returns:
Sorted array of Zone objects or an iterator
Examples:
my @zones = Zone->retrieve_all();
my $iterator = Zone->retrieve_all;

=cut

sub retrieve_all {
my ($class, @args) = @_;
$class->isa_class_method('retrieve_all');

# Sort by the "sort" field in ascending order, then sort by the name field
# of the zone.
return $class->SUPER::retrieve_from_sql(
qq{
id IS NOT NULL
ORDER BY
sort, name
}
);
}

#########################################################################

Expand All @@ -168,6 +196,7 @@ sub search_like {
expire max time before zone no longer authoritative
minimum negative caching TTL (RFC 2308)
template (optional) Name or ID of another zone to clone from
sort integer to sort displayed zones
Returns:
Zone object
Examples:
Expand All @@ -193,7 +222,7 @@ sub insert {
);

# Copy values from template zone
foreach my $field ( qw(mname rname refresh retry expire minimum default_ttl include) ){
foreach my $field ( qw(mname rname refresh retry expire minimum default_ttl include sort) ){
$state{$field} = $tzone->$field;
}
$newzone = $class->SUPER::insert( \%state );
Expand Down Expand Up @@ -227,6 +256,7 @@ sub insert {
active => $argv->{active} || 1,
export_file => $argv->{export_file} || $argv->{name},
default_ttl => $argv->{default_ttl} || $class->config->get('ZONE_DEFAULT_TTL'),
sort => $argv->{sort} || 100,
);

$newzone = $class->SUPER::insert( \%state );
Expand Down
16 changes: 16 additions & 0 deletions upgrade/updatedb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ if ( $schema_version eq '1.0.1' ){
&upg_104_105();
&upg_105_106();
&upg_106_107();
&upg_107_108();

}elsif ( $schema_version eq '1.0.2' ){

Expand All @@ -45,29 +46,38 @@ if ( $schema_version eq '1.0.1' ){
&upg_104_105();
&upg_105_106();
&upg_106_107();
&upg_107_108();

}elsif ( $schema_version eq '1.0.3' ){

&upg_103_104();
&upg_104_105();
&upg_105_106();
&upg_106_107();
&upg_107_108();

}elsif ( $schema_version eq '1.0.4' ){

&upg_104_105();
&upg_105_106();
&upg_106_107();
&upg_107_108();

}elsif ( $schema_version eq '1.0.5' ){

&upg_105_106();
&upg_106_107();
&upg_107_108();

}elsif ( $schema_version eq '1.0.6' ){

&upg_106_107();
&upg_107_108();

}elsif ( $schema_version eq '1.0.7' ){

&upg_107_108();

}else{
die "Unsupported version for this upgrade: $schema_version\n";
}
Expand Down Expand Up @@ -340,3 +350,9 @@ sub upg_105_106 {
sub upg_106_107 {
push @statements, "UPDATE schemainfo SET version='1.0.7' WHERE id=1;",
}

#########################################################################
sub upg_107_108 {
push @statements, "ALTER TABLE zone ADD COLUMN sort INTEGER NOT NULL DEFAULT 100;";
push @statements, "UPDATE schemainfo SET version='1.0.8' WHERE id=1;",
}