Revision 35d63a9f
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
SL/Controller/Helper/Filtered.pm | ||
---|---|---|
12 | 12 |
my %controller_filter_spec; |
13 | 13 |
|
14 | 14 |
sub make_filtered { |
15 |
my ($class, %specs) = @_; |
|
15 |
my ($class, %specs) = @_;
|
|
16 | 16 |
|
17 |
$specs{MODEL} //= $class->controller_name; |
|
18 |
$specs{MODEL} =~ s{ ^ SL::DB:: (?: .* :: )? }{}x; |
|
19 |
$specs{FORM_PARAMS} //= 'filter'; |
|
20 |
$specs{LAUNDER_TO} = '__INPLACE__' unless exists $specs{LAUNDER_TO}; |
|
21 |
$specs{ONLY} //= []; |
|
22 |
$specs{ONLY} = [ $specs{ONLY} ] if !ref $specs{ONLY}; |
|
23 |
$specs{ONLY_MAP} = @{ $specs{ONLY} } ? { map { ($_ => 1) } @{ $specs{ONLY} } } : { '__ALL__' => 1 }; |
|
17 |
$specs{MODEL} //= $class->controller_name;
|
|
18 |
$specs{MODEL} =~ s{ ^ SL::DB:: (?: .* :: )? }{}x;
|
|
19 |
$specs{FORM_PARAMS} //= 'filter';
|
|
20 |
$specs{LAUNDER_TO} = '__INPLACE__' unless exists $specs{LAUNDER_TO};
|
|
21 |
$specs{ONLY} //= [];
|
|
22 |
$specs{ONLY} = [ $specs{ONLY} ] if !ref $specs{ONLY};
|
|
23 |
$specs{ONLY_MAP} = @{ $specs{ONLY} } ? { map { ($_ => 1) } @{ $specs{ONLY} } } : { '__ALL__' => 1 };
|
|
24 | 24 |
|
25 | 25 |
$controller_filter_spec{$class} = \%specs; |
26 | 26 |
|
27 |
my %hook_params = @{ $specs{ONLY} } ? ( only => $specs{ONLY} ) : (); |
|
27 |
my %hook_params = @{ $specs{ONLY} } ? ( only => $specs{ONLY} ) : ();
|
|
28 | 28 |
$class->run_before('_save_current_filter_params', %hook_params); |
29 | 29 |
|
30 | 30 |
SL::Controller::Helper::GetModels::register_get_models_handlers( |
... | ... | |
76 | 76 |
|
77 | 77 |
$calculated_params{query} = [ |
78 | 78 |
@{ $calculated_params{query} || [] }, |
79 |
@{ $filter_args{query} || [] }, |
|
80 |
@{ $params{query} || [] }, |
|
79 |
@{ $filter_args{ query} || [] },
|
|
80 |
@{ $params{ query} || [] },
|
|
81 | 81 |
]; |
82 | 82 |
|
83 | 83 |
$calculated_params{with_objects} = [ |
84 | 84 |
uniq |
85 | 85 |
@{ $calculated_params{with_objects} || [] }, |
86 |
@{ $filter_args{with_objects} || [] }, |
|
87 |
@{ $params{with_objects} || [] }, |
|
86 |
@{ $filter_args{ with_objects} || [] },
|
|
87 |
@{ $params{ with_objects} || [] },
|
|
88 | 88 |
]; |
89 | 89 |
|
90 | 90 |
if ($laundered) { |
... | ... | |
114 | 114 |
sub _get_filter_args { |
115 | 115 |
my ($self, $spec) = @_; |
116 | 116 |
|
117 |
$spec ||= $self->get_filter_spec; |
|
117 |
$spec ||= $self->get_filter_spec;
|
|
118 | 118 |
|
119 |
my %filter_args = ref($spec->{FILTER_ARGS}) eq 'CODE' ? %{ $spec->{FILTER_ARGS}->($self) }
|
|
120 |
: $spec->{FILTER_ARGS} ? do { my $sub = $spec->{FILTER_ARGS}; %{ $self->$sub() } }
|
|
121 |
: ();
|
|
119 |
my %filter_args = ref($spec->{FILTER_ARGS}) eq 'CODE' ? %{ $spec->{FILTER_ARGS}->($self) } |
|
120 |
: $spec->{FILTER_ARGS} ? do { my $sub = $spec->{FILTER_ARGS}; %{ $self->$sub() } } |
|
121 |
: (); |
|
122 | 122 |
} |
123 | 123 |
|
124 | 124 |
sub _save_current_filter_params { |
... | ... | |
137 | 137 |
my $priv = _priv($self); |
138 | 138 |
|
139 | 139 |
if (_is_enabled($self) && $priv->{filter}) { |
140 |
my $filter_spec = $self->get_filter_spec;
|
|
140 |
my $filter_spec = $self->get_filter_spec; |
|
141 | 141 |
my ($flattened) = SL::Controller::Helper::ParseFilter::flatten($priv->{filter}, undef, $filter_spec->{FORM_PARAMS}); |
142 |
%params = (%params, @$flattened); |
|
142 |
%params = (%params, @$flattened);
|
|
143 | 143 |
} |
144 | 144 |
|
145 | 145 |
# $::lxdebug->dump(0, "CB handler for filtered; params after flatten:", \%params); |
... | ... | |
172 | 172 |
return !_priv($self)->{disabled} && ($self->get_filter_spec->{ONLY_MAP}->{$self->action_name} || $self->get_filter_spec->{ONLY_MAP}->{'__ALL__'}); |
173 | 173 |
} |
174 | 174 |
|
175 |
|
|
176 | 175 |
1; |
177 | 176 |
|
178 | 177 |
__END__ |
SL/Controller/Helper/Paginated.pm | ||
---|---|---|
12 | 12 |
my %controller_paginate_spec; |
13 | 13 |
|
14 | 14 |
sub make_paginated { |
15 |
my ($class, %specs) = @_; |
|
15 |
my ($class, %specs) = @_;
|
|
16 | 16 |
|
17 |
$specs{MODEL} ||= $class->controller_name; |
|
18 |
$specs{MODEL} =~ s{ ^ SL::DB:: (?: .* :: )? }{}x; |
|
19 |
$specs{PER_PAGE} ||= "SL::DB::Manager::$specs{MODEL}"->default_objects_per_page; |
|
20 |
$specs{FORM_PARAMS} ||= [ qw(page per_page) ]; |
|
21 |
$specs{PAGINATE_ARGS} ||= '__FILTER__'; |
|
22 |
$specs{ONLY} ||= []; |
|
23 |
$specs{ONLY} = [ $specs{ONLY} ] if !ref $specs{ONLY}; |
|
24 |
$specs{ONLY_MAP} = @{ $specs{ONLY} } ? { map { ($_ => 1) } @{ $specs{ONLY} } } : { '__ALL__' => 1 }; |
|
17 |
$specs{MODEL} ||= $class->controller_name;
|
|
18 |
$specs{MODEL} =~ s{ ^ SL::DB:: (?: .* :: )? }{}x;
|
|
19 |
$specs{PER_PAGE} ||= "SL::DB::Manager::$specs{MODEL}"->default_objects_per_page;
|
|
20 |
$specs{FORM_PARAMS} ||= [ qw(page per_page) ];
|
|
21 |
$specs{PAGINATE_ARGS} ||= '__FILTER__';
|
|
22 |
$specs{ONLY} ||= [];
|
|
23 |
$specs{ONLY} = [ $specs{ONLY} ] if !ref $specs{ONLY};
|
|
24 |
$specs{ONLY_MAP} = @{ $specs{ONLY} } ? { map { ($_ => 1) } @{ $specs{ONLY} } } : { '__ALL__' => 1 };
|
|
25 | 25 |
|
26 | 26 |
$controller_paginate_spec{$class} = \%specs; |
27 | 27 |
|
28 |
my %hook_params = @{ $specs{ONLY} } ? ( only => $specs{ONLY} ) : (); |
|
28 |
my %hook_params = @{ $specs{ONLY} } ? ( only => $specs{ONLY} ) : ();
|
|
29 | 29 |
$class->run_before('_save_current_paginate_params', %hook_params); |
30 | 30 |
|
31 | 31 |
SL::Controller::Helper::GetModels::register_get_models_handlers( |
SL/Controller/Helper/ParseFilter.pm | ||
---|---|---|
80 | 80 |
next if !defined $value || $value eq ''; # 0 is fine |
81 | 81 |
if ('HASH' eq ref $value) { |
82 | 82 |
my ($query, $more_objects) = flatten($value, _prefix($prefix, $key)); |
83 |
push @result, @$query if $query;
|
|
83 |
push @result, @$query if $query;
|
|
84 | 84 |
_add_uniq($with_objects, $_) for _prefix($prefix, $key), @$more_objects; |
85 | 85 |
} else { |
86 | 86 |
push @result, _prefix($prefix, $key) => $value; |
SL/Controller/Part.pm | ||
---|---|---|
21 | 21 |
__PACKAGE__->run_before(sub { $::auth->assert('part_service_assembly_edit') }); |
22 | 22 |
|
23 | 23 |
__PACKAGE__->make_filtered( |
24 |
ONLY => [ qw(part_picker_search part_picker_result ajax_autocomplete) ],
|
|
25 |
LAUNDER_TO => 'filter',
|
|
24 |
ONLY => [ qw(part_picker_search part_picker_result ajax_autocomplete) ], |
|
25 |
LAUNDER_TO => 'filter', |
|
26 | 26 |
); |
27 | 27 |
__PACKAGE__->make_paginated( |
28 |
ONLY => [ qw(part_picker_search part_picker_result ajax_autocomplete) ],
|
|
28 |
ONLY => [ qw(part_picker_search part_picker_result ajax_autocomplete) ], |
|
29 | 29 |
); |
30 | 30 |
|
31 | 31 |
__PACKAGE__->make_sorted( |
32 |
ONLY => [ qw(part_picker_search part_picker_result ajax_autocomplete) ],
|
|
32 |
ONLY => [ qw(part_picker_search part_picker_result ajax_autocomplete) ], |
|
33 | 33 |
|
34 |
DEFAULT_BY => 'partnumber',
|
|
35 |
DEFAULT_DIR => 1,
|
|
34 |
DEFAULT_BY => 'partnumber', |
|
35 |
DEFAULT_DIR => 1, |
|
36 | 36 |
|
37 |
partnumber => t8('Partnumber'),
|
|
37 |
partnumber => t8('Partnumber'), |
|
38 | 38 |
); |
39 | 39 |
|
40 | 40 |
sub action_ajax_autocomplete { |
SL/DB/Manager/Part.pm | ||
---|---|---|
43 | 43 |
|
44 | 44 |
for my $type (@types) { |
45 | 45 |
if ($type =~ m/^part/) { |
46 |
push @filter, (and => [ or => [ $prefix . assembly => 0, $prefix . assembly => undef ], |
|
47 |
"!${prefix}inventory_accno_id" => 0, |
|
48 |
"!${prefix}inventory_accno_id" => undef, |
|
46 |
push @filter, (and => [ or => [ $prefix . assembly => 0, $prefix . assembly => undef ],
|
|
47 |
"!${prefix}inventory_accno_id" => 0,
|
|
48 |
"!${prefix}inventory_accno_id" => undef,
|
|
49 | 49 |
]); |
50 | 50 |
} elsif ($type =~ m/^service/) { |
51 | 51 |
push @filter, (and => [ or => [ $prefix . assembly => 0, $prefix . assembly => undef ], |
52 |
or => [ $prefix . inventory_accno_id => 0, $prefix . inventory_accno_id => undef ], |
|
52 |
or => [ $prefix . inventory_accno_id => 0, $prefix . inventory_accno_id => undef ],
|
|
53 | 53 |
]); |
54 | 54 |
} elsif ($type =~ m/^assembl/) { |
55 | 55 |
push @filter, ($prefix . assembly => 1); |
56 | 56 |
} |
57 | 57 |
} |
58 | 58 |
|
59 |
return @filter > 2 ? (or => \@filter) : |
|
60 |
@filter ? @filter : (); |
|
59 |
return @filter > 2 ? (or => \@filter) : @filter; |
|
61 | 60 |
} |
62 | 61 |
|
63 | 62 |
sub get_ordered_qty { |
Auch abrufbar als: Unified diff
Kosmetik: Alignment, Einrückung