Changeset 2375
- Timestamp:
- 06/02/20 18:52:44 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Object.pm
r2374 r2375 58 58 my %ids = map { $_->id => 1 } @{$env->{_objects}}; 59 59 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 } 60 69 $ids{$_} and next; 70 $ids{$_} = 1; 61 71 my $o = $env->base->get_object($env->{_otype}, $_) or next; 62 72 push(@{$env->{_objects}}, $o); … … 68 78 my ($env, undef, @ids) = @_; 69 79 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})); 71 81 }, 72 82 } … … 76 86 code => sub { 77 87 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 } 79 98 my @newobjs = grep { !$ids{$_->id} } @{$env->{_objects}}; 80 99 … … 91 110 my ($env, undef, @ids) = @_; 92 111 my %ids = map { $_ => 1 } @ids; 93 grep { !$ids{$_} } map { $_->id } @{$env->{_objects}};112 '@', (grep { !$ids{$_} } map { $_->id } @{$env->{_objects}}); 94 113 }, 95 114 } … … 98 117 help => 'search objecttype filter1 [filter2...] - search object according filter', 99 118 completion => sub { 100 101 119 return( 102 120 map { ( $_ . '=', $_ . '~' ) } $_[0]->base->list_canonical_fields($_[0]->{_otype}, 'r') … … 109 127 print $OUT map { "$_\n" } @res; 110 128 $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}; 112 150 } else { 113 151 print $OUT "Object type missing\n"; … … 502 540 my ($env, $attrname, @objects) = @_; 503 541 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); 523 566 return if (!@objs); 524 567 print $OUT "Selecting $totype " . join(', ', map { $_->id } @objs) . "\n";
Note: See TracChangeset
for help on using the changeset viewer.