Changeset 533 for trunk


Ignore:
Timestamp:
10/18/13 17:26:11 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Fix up poor edge-case handling of pagination offsets when changing groups or
filter options. Fix pagination on bulk domain page.
Required:

  • reordering pagination/offset/filter munging to/from %webvar and session yet again
  • re-adding the offset if we're on a live record list page
  • fix call to $dnsdb->getDomList() for bulk changes (offset missing completely)
  • explicitly fork $uri_self for group tree, and explicitly trim offset
  • remove old code that only handled a limited subset of cases (letter filter and search)
  • fix call to $dnsdb->getDomList() in listzones() to use the global $offset instead of blindly obeying whatever might be left over in $webvar{offset}
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r516 r533  
    131131$webvar{searchsubs} =~ s/[^yn]//g if $webvar{searchsubs};
    132132
    133 $session->param($webvar{page}.'startwith', $webvar{startwith}) if defined($webvar{startwith});
    134 $session->param($webvar{page}.'filter', $webvar{filter}) if defined($webvar{filter});
     133# pagination
     134my $perpage = 15;  # Just In Case
     135$perpage = $dnsdb->{perpage} if $dnsdb->{perpage};
     136my $offset = ($webvar{offset} ? $webvar{offset} : 0);
     137
     138## set up "URL to self" (whereami edition)
     139# @#$%@%@#% XHTML - & in a URL must be escaped.  >:(
     140my $uri_self = $ENV{REQUEST_URI};
     141$uri_self =~ s/\&([a-z])/\&amp\;$1/g;
     142
     143# le sigh.  and we need to strip any previous action
     144$uri_self =~ s/\&action=[^&]+//g;
     145
     146# much magic happens.  if startwith or a search string change (to, from, or
     147# across, in the request vs whatever's in the session) then the offset should
     148# be reset to 0 so that the first/prev/next/last widget populates correctly,
     149# and so that the list of whatever we're looking at actually shows things
     150# (since we may have started on page 42 of 300 with a LOOOOONG list, but we
     151# now only need 3 pages for the filtered list).
     152# while we're at it, plonk these into the session for safekeeping.
     153if (defined($webvar{startwith})) {
     154  if ($webvar{startwith} ne $session->param($webvar{page}.'startwith')) {
     155    $uri_self =~ s/\&offset=[^&]//;
     156    $offset = 0;
     157  }
     158  $session->param($webvar{page}.'startwith', $webvar{startwith});
     159}
     160if (defined($webvar{filter})) {
     161  if ($webvar{filter} ne $session->param($webvar{page}.'filter')) {
     162    $uri_self =~ s/\&offset=[^&]//;
     163    $offset = 0;
     164  }
     165  $session->param($webvar{page}.'filter', $webvar{filter})
     166}
    135167$session->param($webvar{page}.'searchsubs', $webvar{searchsubs}) if defined($webvar{searchsubs});
    136168
     169# and now that the search/filter criteria for this page are set, put them in some globals for actual use.
    137170my $startwith = $session->param($webvar{page}.'startwith');
    138171my $filter = $session->param($webvar{page}.'filter');
     
    143176push @filterargs, "^[$startwith]" if $startwith;
    144177push @filterargs, $filter if $filter;
    145 
    146 ## set up "URL to self" (whereami edition)
    147 # @#$%@%@#% XHTML - & in a URL must be escaped.  >:(
    148 my $uri_self = $ENV{REQUEST_URI};
    149 $uri_self =~ s/\&([a-z])/\&amp\;$1/g;
    150 
    151 # le sigh.  and we need to strip any previous action
    152 $uri_self =~ s/\&action=[^&]+//g;
    153178
    154179# and search filter options.  these get stored in the session, but discarded
     
    166191
    167192## end uri_self monkeying
    168 
    169 # pagination
    170 my $perpage = 15;  # Just In Case
    171 $perpage = $dnsdb->{perpage} if $dnsdb->{perpage};
    172 my $offset = ($webvar{offset} ? $webvar{offset} : 0);
    173193
    174194# NB:  these must match the field name and SQL ascend/descend syntax respectively
     
    314334      changepage(%args);
    315335    }
    316 
    317   }
     336    # add offset back *into* $uri_self if we're also currently looking at a live record list.
     337    if ($webvar{page} eq 'reclist' && $webvar{defrec} eq 'n') {
     338      $uri_self .= "\&offset=$offset";
     339    }
     340  } # done action=chgroup
    318341} # handle global webvar{action}s
    319342
     
    10591082  $page->param(perpage => $perpage);
    10601083
    1061   my $domlist = $dnsdb->getZoneList(revrec => 'n', curgroup => $curgroup);
     1084  my $domlist = $dnsdb->getZoneList(revrec => 'n', curgroup => $curgroup, offset => $offset);
    10621085  my $rownum = 0;
    10631086  foreach my $dom (@{$domlist}) {
     
    18281851  my @childlist;
    18291852
     1853  # some magic to control bad offsets on group change
     1854  my $grp_uri_self = $uri_self;
     1855  $grp_uri_self =~ s/\&offset=[^&]+// unless ($webvar{page} eq 'reclist' && $webvar{defrec} eq 'n');
     1856
    18301857  my $grptree = HTML::Template->new(filename => 'templates/grptree.tmpl');
    18311858  $dnsdb->getChildren($root, \@childlist, 'immediate');
     
    18361863    $row{grpname} = $dnsdb->groupName($_);
    18371864    $row{grpnum} = $_;
    1838     $row{whereami} = $uri_self;
     1865    $row{whereami} = $grp_uri_self;
    18391866    $row{curgrp} = ($_ == $cur);
    18401867    $row{expanded} = $dnsdb->isParent($_, 'group', $cur, 'group');
     
    20662093  my $parent = shift;
    20672094
    2068   # Fix display/UI bug where if you are not on the first page of the list, and
    2069   # you add a search term or click one of the "starts with" links, you end up
    2070   # on a page showing nothing.
    2071   # For bonus points, this reverts to the original offset on clicking the "All" link (mostly)
    2072   if ($offset ne 'all') {
    2073     $offset-- while ($offset * $perpage) >= $pgcount;
    2074   }
    2075 
    20762095  $page->param(ntot => $pgcount);
    20772096  $page->param(nfirst => (($offset eq 'all' ? 0 : $offset)*$perpage+1));
     
    21322151  my $zonelist = $dnsdb->getZoneList(childlist => $childlist, curgroup => $curgroup, revrec => $webvar{revrec},
    21332152        filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef),
    2134         offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder
     2153        offset => $offset, sortby => $sortby, sortorder => $sortorder
    21352154        );
    21362155# probably don't need this, keeping for reference for now
Note: See TracChangeset for help on using the changeset viewer.