Changeset 2375


Ignore:
Timestamp:
06/02/20 18:52:44 (4 years ago)
Author:
nanardon
Message:

Add +/-/select(@), add filter() to la-cli

File:
1 edited

Legend:

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

    r2374 r2375  
    5858            my %ids = map { $_->id => 1 } @{$env->{_objects}}; 
    5959            foreach (@ids) { 
     60                if ( $_ eq '@' ) { 
     61                    foreach ( @{ $self->{_lastsearch} || [] } ) { 
     62                        $ids{ $_ } and next; 
     63                        $ids{ $_ } = 1; 
     64                        my $o = $env->base->get_object($env->{_otype}, $_) or next; 
     65                        push(@{$env->{_objects}}, $o); 
     66                    } 
     67                    next; 
     68                } 
    6069                $ids{$_} and next; 
     70                $ids{$_} = 1; 
    6171                my $o = $env->base->get_object($env->{_otype}, $_) or next; 
    6272                push(@{$env->{_objects}}, $o); 
     
    6878            my ($env, undef, @ids) = @_; 
    6979            my %ids = map { $_->id => 1 } @{$env->{_objects}}; 
    70             return ( grep { ! $ids{$_} } $env->base->list_objects($env->{_otype})); 
     80            return ( '@', grep { ! $ids{$_} } $env->base->list_objects($env->{_otype})); 
    7181        }, 
    7282        } 
     
    7686        code => sub { 
    7787            my ($env, @ids) = @_; 
    78             my %ids = map { $_ => 1 } @ids; 
     88            my %ids = (); 
     89            foreach ( @ids ) { 
     90                if ( $_ eq '@' ) { 
     91                    foreach ( @{ $self->{_lastsearch} || [] } ) { 
     92                        $ids{ $_ } = 1; 
     93                    } 
     94                } else { 
     95                    $ids{ $_ } = 1; 
     96                } 
     97            } 
    7998            my @newobjs = grep { !$ids{$_->id} } @{$env->{_objects}}; 
    8099 
     
    91110            my ($env, undef, @ids) = @_; 
    92111            my %ids = map { $_ => 1 } @ids; 
    93             grep { !$ids{$_} } map { $_->id } @{$env->{_objects}}; 
     112            '@', (grep { !$ids{$_} } map { $_->id } @{$env->{_objects}}); 
    94113        }, 
    95114        } 
     
    98117        help => 'search objecttype filter1 [filter2...] - search object according filter', 
    99118        completion => sub { 
    100  
    101119            return( 
    102120                map { ( $_ . '=', $_ . '~' ) } $_[0]->base->list_canonical_fields($_[0]->{_otype}, 'r') 
     
    109127                print $OUT map { "$_\n" } @res; 
    110128                $self->{_lastsearch} = \@res; 
    111                 $self->{_lastsearchtype} = $args[0]; 
     129                $self->{_lastsearchtype} = $self->{_otype}; 
     130            } else { 
     131                print $OUT "Object type missing\n"; 
     132            } 
     133        }, 
     134    }); 
     135    $self->add_func('filter', { 
     136        help => 'filter filter1 [filter2...] - filter object according filter', 
     137        completion => sub { 
     138            return( 
     139                map { ( $_ . '=', $_ . '~' ) } $_[0]->base->list_canonical_fields($_[0]->{_otype}, 'r') 
     140            ); 
     141        }, 
     142        code => sub { 
     143            my ($self, @args) = @_; 
     144            if ($_[1]) { 
     145                my %ids = map { $_->id => 1 } @{$self->{_objects}}; 
     146                my @res = grep { $ids{ $_ } } $self->base->search_objects($self->{_otype}, @args); 
     147                print $OUT map { "$_\n" } @res; 
     148                $self->{_lastsearch} = \@res; 
     149                $self->{_lastsearchtype} = $self->{_otype}; 
    112150            } else { 
    113151                print $OUT "Object type missing\n"; 
     
    502540                my ($env, $attrname, @objects) = @_; 
    503541 
    504                 my $attr = $env->base->attribute( 
    505                     $env->{_otype}, 
    506                     $attrname 
    507                 ) or do { 
    508                     print $OUT "No attribute $attrname"; 
    509                     return; 
    510                 }; 
    511                 my $totype = $attr->reference or return; 
    512  
    513                 if (! @objects) { 
    514                     @objects = grep { $_ } 
    515                       map { $_->get_attributes($attrname) } @{$env->{_objects}}; 
    516                 } 
    517                 { 
    518                     my %uniq = map { $_ => 1 } @objects; 
    519                     @objects = keys %uniq; 
    520                 } 
    521                 my @objs = (grep { $_ } map { $env->base->get_object($totype, $_) } 
    522                         @objects); 
     542                my $totype; 
     543                if ( $attrname eq '@' ) { 
     544                    $totype = $env->{_otype}; 
     545                    @objects = @{ $self->{_lastsearch} || [] }; 
     546                } else { 
     547                    my $attr = $env->base->attribute( 
     548                        $env->{_otype}, 
     549                        $attrname 
     550                    ) or do { 
     551                        print $OUT "No attribute $attrname"; 
     552                        return; 
     553                    }; 
     554                    $totype = $attr->reference or return; 
     555 
     556                    if (! @objects) { 
     557                        @objects = grep { $_ } 
     558                          map { $_->get_attributes($attrname) } @{$env->{_objects}}; 
     559                    } 
     560                    { 
     561                        my %uniq = map { $_ => 1 } @objects; 
     562                        @objects = keys %uniq; 
     563                    } 
     564                } 
     565                my @objs = (grep { $_ } map { $env->base->get_object($totype, $_) } @objects); 
    523566                return if (!@objs); 
    524567                print $OUT "Selecting $totype " . join(', ', map { $_->id } @objs) . "\n"; 
Note: See TracChangeset for help on using the changeset viewer.