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

Use a generic filter to list objects

Location:
trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts
Files:
6 edited

Legend:

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

    r929 r1081  
    3131 
    3232__PACKAGE__->config( 
     33    objects => { 
     34        user => { 
     35            quick_search => [ qw(cn sn givenName) ], 
     36            list => [ qw(sn givenName mail) ], 
     37        }, 
     38        group => { 
     39            quick_search => [ qw(cn description) ], 
     40            list => [ qw(description) ], 
     41        }, 
     42        nethost => { 
     43            quick_search => [ qw(cn description ip cname otherName) ], 
     44            list => [ qw(description owner) ], 
     45        }, 
     46        netzone => { 
     47            quick_search => [ qw(cn description ip) ], 
     48            list => [ qw(type description) ], 
     49        }, 
     50        site => { 
     51            quick_search => [ qw(cn l) ], 
     52            list => [ qw(l) ], 
     53        }, 
     54        aliases => { 
     55            quick_search => [ qw(name) ], 
     56            list => [ qw() ], 
     57        }, 
     58 
     59    }, 
    3360    'attrs' => { 
    3461        'physicalDeliveryOfficeName' => { 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Ajax.pm

    r932 r1081  
    180180} 
    181181 
     182sub list_objects : Local { 
     183    my ($self, $c, $otype) = @_; 
     184    $c->stash->{ofilter} = $c->model('AttrFilter', $otype); 
     185} 
     186 
    182187sub end : Private { 
    183188    my ( $self, $c ) = @_; 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Aliases.pm

    r932 r1081  
    2525    my ( $self, $c ) = @_; 
    2626 
    27     my $db = $c->model('Accounts')->db; 
    28     my @al = $c->req->param('al'); 
    29     my @name = $c->req->param('name'); 
    30     my @forward = $c->req->param('forward'); 
    31     $c->stash->{page}{title} = "Gestion des alias"; 
    32     foreach my $idx (0 .. scalar(@name) - 1) { 
    33  
    34         if ($c->req->param('del' . ($idx+1))) { 
    35             $db->delete_object('aliases', $al[$idx]); 
    36         } elsif ($al[$idx] ne $name[$idx]) { 
    37             # delete old, create new 
    38             $db->delete_c_object('aliases', $al[$idx]) if($al[$idx]); 
    39             $db->create_c_object('aliases', $name[$idx], 
    40                 forward => [ split(/\s*,\s*/, $forward[$idx]) ], 
    41             ); 
    42         } else { 
    43             my $obj = $db->get_object('aliases', $al[$idx]); 
    44             $obj->set_c_fields( 
    45                 'forward' => [ split(/\s*,\s*/, $forward[$idx]) ], 
    46             ); 
    47         } 
    48     } 
    49  
    50     $db->commit; 
     27    $c->stash->{ofilter} = $c->model('AttrFilter', 'aliases'); 
    5128} 
    5229 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Users.pm

    r1051 r1081  
    2626 
    2727    $c->stash->{ofilter} = $c->model('AttrFilter', 'user'); 
    28     my $start = $c->req->param('start'); 
    29     $c->stash->{uparams} = { %{ $c->req->params || {} } }; 
    30     my %initials; 
    31     my @userlist; 
    32     foreach (map { $_->id } @{ $c->stash->{objectslist} }) { 
    33         $initials{substr($_, 0, 1)} = 1; 
    34         if ($start) { 
    35             if (index($_, $start) == 0) { 
    36                 push(@userlist, $_); 
    37             } 
    38         } 
    39     } 
    40     if (@{ $c->stash->{objectslist} } < 20) { 
    41         @userlist = map { $_->id } @{ $c->stash->{objectslist} }; 
    42     } else { 
    43         $c->stash->{initials} = [ sort keys %initials ]; 
    44     } 
    45     $c->stash->{page}{title} = 'Listes des utilisateurs (' . scalar(@{ 
    46                 $c->stash->{objectslist} }) . ')'; 
    47     $c->stash->{userslist} = \@userlist; 
    4828} 
    4929 
  • 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} 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/View/TTpart.pm

    r511 r1081  
    1010    LATMOS::Accounts::Web->path_to( 'root', 'html' ), 
    1111    ], 
     12    PRE_PROCESS  => 'includes/defs.tt', 
    1213); 
    1314 
Note: See TracChangeset for help on using the changeset viewer.