Ignore:
Timestamp:
07/28/12 09:20:21 (12 years ago)
Author:
nanardon
Message:

Use a generic filter to list objects

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrFilter.pm

    r959 r1081  
    2121    nethost => [ qw(name cname otherName ip macaddr owner serialNumber) ], 
    2222    netzone => [ qw(net group type site) ], 
     23    aliases => [ qw(as) ], 
    2324}; 
    2425 
     
    3738        otype => $otype, 
    3839    } unless($c->stash->{filter}); 
    39     if (exists($c->req->params->{'attr'})) { 
     40    $c->stash->{ofilter} = bless($new, __PACKAGE__); 
     41 
     42    $c->stash->{db} ||= $c->model('Accounts')->db; # need in stash ? 
     43    my $base = $c->stash->{db}; 
     44 
     45    my @objlist = (); 
     46    if ($c->req->params->{'q'}) { 
     47        my %objs; 
     48        foreach my $attr (@{ $c->config->{objects}{$otype}{quick_search} || [ 'cn' ]}) { 
     49            foreach ($base->search_objects( 
     50                    $otype, "$attr~" . $c->req->params->{'q'})) { 
     51                $objs{$_} = 1; 
     52            } 
     53            @objlist = sort keys %objs; 
     54        } 
     55    } elsif (exists($c->req->params->{'attr'})) { 
    4056        $c->stash->{filter}{'attr'} = [ $c->req->param('attr') ]; 
    4157        $c->stash->{filter}{'attrval'} = [ $c->req->param('attrval') ]; 
     58        my @filter = $c->stash->{ofilter}->filter; 
     59        @objlist = $base->search_objects($otype, @filter); 
     60    } else { 
     61        @objlist = $base->list_objects($otype); 
    4262    } 
    43      
    44     $c->stash->{ofilter} = bless($new, __PACKAGE__); 
    45     $c->stash->{db} ||= $c->model('Accounts')->db; 
    46     my $base = $c->stash->{db}; 
    4763 
    48     my @filter = $c->stash->{ofilter}->filter; 
    4964    $c->stash->{objectslist} = [ 
    5065        map { $base->get_object($otype, $_) } 
    51         (@filter 
    52             ? ($base->search_objects($otype, @filter) ) 
    53             : ($base->list_objects($otype) )) 
     66         @objlist 
    5467    ]; 
     68 
     69    my $start = $c->req->param('start'); 
     70    $c->stash->{uparams} = { %{ $c->req->params || {} } }; 
     71    my %initials; 
     72    my @sublist; 
     73    foreach (@{ $c->stash->{objectslist} }) { 
     74        $initials{substr($_->id, 0, 1)} = 1; 
     75        if ($start) { 
     76            if (index($_->id, $start) == 0) { 
     77                push(@sublist, $_); 
     78            } 
     79        } 
     80    } 
     81    $c->stash->{sublist} = [ @sublist ]; 
     82    $c->stash->{initials} = [ sort keys %initials ]; 
    5583 
    5684    $c->stash->{ofilter} 
Note: See TracChangeset for help on using the changeset viewer.