JPList/Controls/Filter.pm

filter: Statementstmt 47.9% 35 / 73 Branchbran 36.3% 8 / 22 Conditioncond 22.2% 6 / 27 MC/DCmcdc 12.5% 2 / 16 Subroutinesub 57.1% 4 / 7 Podpod 100% 6 / 6 totaltotal 40.4% 61 / 151 CC 21 SCAR 27.9
CC
21
Cov
40%
filterdaterange
42.0
filterdatepicker
20.0
filterselect
12.0
CRAP 16.3
« JPList/Request.pm ↑ Summary JPList/Controls/Sort.pm »
1 # ========================================================================== #
2 # lib/JPList/Controls/Filter.pm - JPList Filter controls
3 # Copyright (C) 2017 Exceleron Software, LLC
4 # ========================================================================== #
5  
6 package JPList::Controls::Filter;
7  
8 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ========================================================================== #
11  
12 =head1 NAME
13  
14 JPList::Controls::Filter - JPList Filter controls
15  
16 =head1 VERSION
17  
18 Version 0.05
19  
20 =cut
21  
22 2 our $VERSION = '0.05';
23  
24 =head1 SYNOPSIS
25  
26 with 'JPList::Controls::Filter'
27  
28 =head1 DESCRIPTION
29  
30 The Filter module allows you get the values filter controls
31  
32 =head2 METHODS
33  
34 =over 4
35  
36 =cut
37  
38 # ========================================================================== #
39  
40 =item C<textbox>
41  
42 Params : filter_vals
43  
44 {
45 'type' => 'textbox',
46 'action' => 'filter',
47 'inStorage' => $VAR1->[0]{'inStorage'},
48 'data' => {
49 'filterType' => 'TextFilter',
50 'mode' => 'contains',
51 'value' => '',
52 'ignore' => '[~!@#$%^&*()+=`\'"/\\_]+',
53 'path' => '.UserName'
54 },
55 'isAnimateToTop' => $VAR1->[0]{'isAnimateToTop'},
56 'initialIndex' => 1,
57 'inDeepLinking' => $VAR1->[0]{'inStorage'},
58 'name' => 'username-filter',
59 'inAnimation' => $VAR1->[0]{'inStorage'}
60 }
61  
62 Returns: Returns the column and value for filter textbox
63  
64 Desc : Returns the column and value for filter textbox
65  
66 =cut
67  
68 sub textbox
69 19 ▶{
Subroutine textbox: called CC=5 SCAR=16.5
Pod documented
70 19 my ($self, $filter_vals) = @_;
71  
72 19 my $data = $filter_vals->{'data'};
73 19 my $result;
74  
75 19 ▶ if (exists($data->{'path'}) && exists($data->{'value'}) && $data->{'value'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{"path"} and exists $data->{"value"} and $data->{"value"}) 1 18 19
Condition50%3/6
exists $data->{"path"} and exists $data->{"value"} and $data->{"value"}
!ll&&!rl&&r
0181
exists $data->{"path"} and exists $data->{"value"}
!ll&&!rl&&r
0019
MC/DC33%1/3
exists $data->{"path"} and exists $data->{"value"} and $data->{"value"}
exists $data->{"path"} exists $data->{"value"} $data->{"value"}
Truth table50%2/4
A and B and C
A= exists $data->{"path"}B= exists $data->{"value"}C= $data->{"value"}
ABCresult
0XX0
10X0
1100
1111
76  
77 1 $result->{'column'} = $data->{'path'};
78 1 $result->{'column'} =~ s/\.//;
79 1 $result->{'value'} = $data->{'value'};
80 1 ▶ if ($data->{'mode'} ne "integer") {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"mode"} ne "integer") 1 0 1
81 1 $result->{'type'} = 'like';
82 }
83 }
84  
85 19 return $result;
86 }
87  
88 # ========================================================================== #
89  
90 =item C<filterdropdown>
91  
92 Params : filter_vals
93  
94 {
95 'type' => 'filter-drop-down',
96 'data' => {
97 'filterType' => 'ColumnName',
98 'path' => 'default'
99 },
100 'action' => 'filter',
101 'isAnimateToTop' => $VAR1->[0]{'isAnimateToTop'},
102 'initialIndex' => 5,
103 'inDeepLinking' => $VAR1->[0]{'inDeepLinking'},
104 'inAnimation' => $VAR1->[0]{'inDeepLinking'},
105 'inStorage' => $VAR1->[0]{'inDeepLinking'},
106 'name' => 'category-dropdown-filter'
107 }
108  
109 Returns: Returns the column and value for filter dropdown
110  
111 Desc : Returns the column and value for filter dropdown
112  
113 =cut
114  
115 sub filterdropdown
116 7 ▶{
Subroutine filterdropdown: called CC=3 SCAR=11.0
Pod documented
117 7 my ($self, $filter_vals) = @_;
118  
119 7 my $data = $filter_vals->{'data'};
120 7 my $result;
121  
122 7 ▶ if (exists($data->{'path'}) && ($data->{'path'} ne 'default')) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{"path"} and $data->{"path"} ne "default") 2 5 7
Condition66%2/3
exists $data->{"path"} and $data->{"path"} ne "default"
!ll&&!rl&&r
052
MC/DC50%1/2
exists $data->{"path"} and $data->{"path"} ne "default"
exists $data->{"path"} $data->{"path"} ne "default"
Truth table66%2/3
A and B
A= exists $data->{"path"}B= $data->{"path"} ne "default"
ABresult
0X0
100
111
123 2 my $column = $filter_vals->{'name'};
124  
125 2 $result->{'column'} = $column;
126 2 $result->{'value'} = $data->{'path'};
127 2 $result->{'value'} =~ s/\.//;
128 2 $result->{'value'} =~ s/\.$column//;
129  
130 }
131  
132 7 return $result;
133 }
134  
135 # ========================================================================== #
136  
137 =item C<filterselect>
138  
139 Params : filter_vals
140  
141 {
142 'isAnimateToTop' => $VAR1->[0]{'isAnimateToTop'},
143 'data' => {
144 'path' => '.Electric',
145 'filterType' => 'path'
146 },
147 'inDeepLinking' => $VAR1->[0]{'inDeepLinking'},
148 'action' => 'filter',
149 'name' => 'ServiceType',
150 'type' => 'filter-select',
151 'inStorage' => $VAR1->[0]{'inDeepLinking'},
152 'inAnimation' => $VAR1->[0]{'inDeepLinking'}
153 }
154  
155 Returns: Returns the column and value for filter select
156  
157 Desc : Returns the column and value for filter select
158  
159 =cut
160  
161 sub filterselect
162 0 ▶{
Subroutine filterselect: not called CC=3 SCAR=24.8
Pod documented
163 0 my ($self, $filter_vals) = @_;
164  
165 0 my $data = $filter_vals->{'data'};
166 0 my $result;
167  
168 0 ▶ if (exists($data->{'path'}) && ($data->{'path'} ne 'default')) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{"path"} and $data->{"path"} ne "default") 0 0 0
Condition0%0/3
exists $data->{"path"} and $data->{"path"} ne "default"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $data->{"path"} and $data->{"path"} ne "default"
exists $data->{"path"} $data->{"path"} ne "default"
Truth table0%0/3
A and B
A= exists $data->{"path"}B= $data->{"path"} ne "default"
ABresult
0X0
100
111
169 0 my $column = $filter_vals->{'name'};
170  
171 0 $result->{'column'} = $column;
172 0 $result->{'value'} = $data->{'path'};
173 0 $result->{'value'} =~ s/\.$column//;
174  
175 }
176  
177 0 return $result;
178 }
179  
180 # ========================================================================== #
181  
182 =item C<filterdaterange>
183  
184 Params : filter_vals
185  
186 {
187 'data' => {
188 'path' => '.FromDate',
189 'next_day' => 14,
190 'prev_year' => 2017,
191 'next_month' => 5,
192 'next_year' => 2017,
193 'format' => '{month}/{day}/{year}',
194 'filterType' => 'dateRange',
195 'prev_month' => 5,
196 'prev_day' => 6
197 },
198 'inDeepLinking' => $VAR1->[0]{'inAnimation'},
199 'action' => 'filter',
200 'inStorage' => $VAR1->[0]{'inAnimation'},
201 'name' => 'FromDate',
202 'type' => 'date-picker-range-filter',
203 'isAnimateToTop' => $VAR1->[0]{'isAnimateToTop'},
204 'inAnimation' => $VAR1->[0]{'inAnimation'}
205 }
206  
207 Returns: Returns the column and value for filter daterange
208  
209 Desc : Returns the column and value for filter daterange
210  
211 =cut
212  
213 sub filterdaterange
214 0 ▶{
Subroutine filterdaterange: not called CC=6 SCAR=37.4
Pod documented
215 0 my ($self, $filter_vals) = @_;
216  
217 0 my $result;
218  
219 0 ▶ if (exists($filter_vals->{'data'}) && $filter_vals->{'data'}{'prev_year'} && $filter_vals->{'data'}{'next_year'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $filter_vals->{"data"} and $filter_vals->{"data"}{"prev_year"} and $filter_vals->{"data"}{"next_year"}) 0 0 0
Condition0%0/6
exists $filter_vals->{"data"} and $filter_vals->{"data"}{"prev_year"} and $filter_vals->{"data"}{"next_year"}
!ll&&!rl&&r
000
exists $filter_vals->{"data"} and $filter_vals->{"data"}{"prev_year"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $filter_vals->{"data"} and $filter_vals->{"data"}{"prev_year"} and $filter_vals->{"data"}{"next_year"}
exists $filter_vals->{"data"} $filter_vals->{"data"}{"prev_year"} $filter_vals->{"data"}{"next_year"}
Truth table0%0/4
A and B and C
A= exists $filter_vals->{"data"}B= $filter_vals->{"data"}{"prev_year"}C= $filter_vals->{"data"}{"next_year"}
ABCresult
0XX0
10X0
1100
1111
220 0 my $data = $filter_vals->{'data'};
221 0 my ($from_date, $to_date);
222  
223 $from_date =
224 $data->{'prev_year'} . "-"
225 . sprintf("%02d", ($data->{'prev_month'} + 1)) . "-"
226 0 . sprintf("%02d", $data->{'prev_day'});
227 $to_date =
228 $data->{'next_year'} . "-"
229 . sprintf("%02d", ($data->{'next_month'} + 1)) . "-"
230 0 . sprintf("%02d", $data->{'next_day'});
231  
232 0 ▶ if ($from_date =~ /\d{4}-\d{2}-\d{2}/ && $to_date =~ /\d{4}-\d{2}-\d{2}/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from_date =~ /\d{4}-\d{2}-\d{2}/ and $to_date =~ /\d{4}-\d{2}-\d{2}/) 0 0 0
Condition0%0/3
$from_date =~ /\d{4}-\d{2}-\d{2}/ and $to_date =~ /\d{4}-\d{2}-\d{2}/
!ll&&!rl&&r
000
MC/DC0%0/2
$from_date =~ /\d{4}-\d{2}-\d{2}/ and $to_date =~ /\d{4}-\d{2}-\d{2}/
$from_date =~ /\d{4}-\d{2}-\d{2}/ $to_date =~ /\d{4}-\d{2}-\d{2}/
Truth table0%0/3
A and B
A= $from_date =~ /\d{4}-\d{2}-\d{2}/B= $to_date =~ /\d{4}-\d{2}-\d{2}/
ABresult
0X0
100
111
233 0 $result->{'column'} = $filter_vals->{'name'};
234 0 $result->{'from_date'} = $from_date;
235 0 $result->{'to_date'} = $to_date;
236 0 $result->{'type'} = 'between';
237 }
238 }
239  
240 0 return $result;
241 }
242  
243 # ========================================================================== #
244  
245 =item C<filterdatepicker>
246  
247 Params : filter_vals
248  
249 {
250 'inDeepLinking' => $VAR1->[0]{'inAnimation'},
251 'inAnimation' => $VAR1->[0]{'inAnimation'},
252 'isAnimateToTop' => $VAR1->[0]{'isAnimateToTop'},
253 'action' => 'filter',
254 'inStorage' => $VAR1->[0]{'inAnimation'},
255 'type' => 'date-picker-filter',
256 'data' => {
257 'year' => 2017,
258 'format' => '{month}/{day}/{year}',
259 'filterType' => 'date',
260 'day' => 10,
261 'path' => '.ReadDate',
262 'month' => 6
263 },
264 'name' => 'ReadDate'
265 }
266  
267 Returns: Returns the column and value for filter daterange
268  
269 Desc : Returns the column and value for filter daterange
270  
271 =cut
272  
273 sub filterdatepicker
274 0 ▶{
Subroutine filterdatepicker: not called CC=4 SCAR=30.0
Pod documented
275 0 my ($self, $filter_vals) = @_;
276  
277 0 my $result;
278  
279 0 ▶ if (exists($filter_vals->{'data'}) && $filter_vals->{'data'}{'year'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $filter_vals->{"data"} and $filter_vals->{"data"}{"year"}) 0 0 0
Condition0%0/3
exists $filter_vals->{"data"} and $filter_vals->{"data"}{"year"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $filter_vals->{"data"} and $filter_vals->{"data"}{"year"}
exists $filter_vals->{"data"} $filter_vals->{"data"}{"year"}
Truth table0%0/3
A and B
A= exists $filter_vals->{"data"}B= $filter_vals->{"data"}{"year"}
ABresult
0X0
100
111
280 0 my $data = $filter_vals->{'data'};
281 0 my ($date);
282  
283 0 $date = $data->{'year'} . "-" . sprintf("%02d", ($data->{'month'} + 1)) . "-" . sprintf("%02d", $data->{'day'});
284  
285 0 ▶ if ($date =~ /\d{4}-\d{2}-\d{2}/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($date =~ /\d{4}-\d{2}-\d{2}/) 0 0 0
286 0 $result->{'column'} = $filter_vals->{'name'};
287 0 $result->{'value'} = $date;
288 }
289 }
290  
291 0 return $result;
292 }
293  
294 # ========================================================================== #
295  
296 =item C<checkboxgroup>
297  
298 Params : filter_vals
299  
300 {
301 'name' => 'SourceType',
302 'action' => 'filter',
303 'inStorage' => $VAR1->[0]{'inStorage'},
304 'isAnimateToTop' => $VAR1->[0]{'isAnimateToTop'},
305 'type' => 'checkbox-group-filter',
306 'inAnimation' => $VAR1->[0]{'inStorage'},
307 'data' => {
308 'pathGroup' => [
309 '.Schedule',
310 '.Estimate'
311 ],
312 'filterType' => 'pathGroup'
313 },
314 'inDeepLinking' => $VAR1->[0]{'inStorage'}
315 }
316  
317 Returns: Returns the column and value for filter checkbox group
318  
319 Desc : Returns the column and value for filter checkbox group
320  
321 =cut
322  
323 sub checkboxgroup
324 14 ▶{
Subroutine checkboxgroup: called CC=5 SCAR=19.6
Pod documented
325 14 my ($self, $filter_vals) = @_;
326  
327 14 my $result;
328  
329 14 ▶ if (exists($filter_vals->{'data'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $filter_vals->{"data"}) 14 0 14
330 14 my $data = $filter_vals->{'data'};
331  
332 14 ▶ if (exists($data->{'pathGroup'}) && ref($data->{'pathGroup'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{"pathGroup"} and ref $data->{"pathGroup"} eq "ARRAY") 14 0 14
Condition33%1/3
exists $data->{"pathGroup"} and ref $data->{"pathGroup"} eq "ARRAY"
!ll&&!rl&&r
0014
MC/DC0%0/2
exists $data->{"pathGroup"} and ref $data->{"pathGroup"} eq "ARRAY"
exists $data->{"pathGroup"} ref $data->{"pathGroup"} eq "ARRAY"
Truth table33%1/3
A and B
A= exists $data->{"pathGroup"}B= ref $data->{"pathGroup"} eq "ARRAY"
ABresult
0X0
100
111
333  
334 14 my $column = $filter_vals->{'name'};
335 14 my $values = $data->{'pathGroup'};
336 0 my @real_values = map { my $s = $_; $s =~ s/\.$column//g; $s } @$values;
337  
338 14 ▶ if (scalar @real_values) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @real_values) 0 14 14
339 0 $result->{'column'} = $column;
340 0 $result->{'values'} = \@real_values;
341 0 $result->{'type'} = 'in';
342 }
343  
344 }
345 }
346  
347 14 return $result;
348 }
349  
350 # ========================================================================== #
351  
352 2 1;
353  
354 __END__
« JPList/Request.pm ↑ Summary JPList/Controls/Sort.pm »