| 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 | use Moose::Role; | ||
| 9 | |||
| 10 | # ========================================================================== # | ||
| 11 | |||
| 12 | =head1 NAME | ||
| 13 | |||
| 14 | JPList::Controls::Filter - JPList Filter controls | ||
| 15 | |||
| 16 | =head1 SYNOPSIS | ||
| 17 | |||
| 18 | with 'JPList::Controls::Filter' | ||
| 19 | |||
| 20 | =head1 DESCRIPTION | ||
| 21 | |||
| 22 | The Filter module allows you get the values filter controls | ||
| 23 | |||
| 24 | =head2 METHODS | ||
| 25 | |||
| 26 | =over 4 | ||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | # ========================================================================== # | ||
| 31 | |||
| 32 | =item C<textbox> | ||
| 33 | |||
| 34 | Params : filter_vals | ||
| 35 | |||
| 36 | { | ||
| 37 | 'type' => 'textbox', | ||
| 38 | 'action' => 'filter', | ||
| 39 | 'inStorage' => $VAR1->[0]{'inStorage'}, | ||
| 40 | 'data' => { | ||
| 41 | 'filterType' => 'TextFilter', | ||
| 42 | 'mode' => 'contains', | ||
| 43 | 'value' => '', | ||
| 44 | 'ignore' => '[~!@#$%^&*()+=`\'"/\\_]+', | ||
| 45 | 'path' => '.UserName' | ||
| 46 | }, | ||
| 47 | 'isAnimateToTop' => $VAR1->[0]{'isAnimateToTop'}, | ||
| 48 | 'initialIndex' => 1, | ||
| 49 | 'inDeepLinking' => $VAR1->[0]{'inStorage'}, | ||
| 50 | 'name' => 'username-filter', | ||
| 51 | 'inAnimation' => $VAR1->[0]{'inStorage'} | ||
| 52 | } | ||
| 53 | |||
| 54 | Returns: Returns the column and value for filter textbox | ||
| 55 | |||
| 56 | Desc : Returns the column and value for filter textbox | ||
| 57 | |||
| 58 | =cut | ||
| 59 | |||
| 60 | sub textbox | ||
| 61 | { | ||
| 62 | my ($self, $filter_vals) = @_; | ||
| 63 | |||
| 64 | my $data = $filter_vals->{'data'}; | ||
| 65 | my $result; | ||
| 66 | |||
| 67 | if (exists($data->{'path'}) && exists($data->{'value'}) && $data->{'value'}) { | ||
| 68 | |||
| 69 | $result->{'column'} = $data->{'path'}; | ||
| 70 | $result->{'column'} =~ s/\.//; | ||
| 71 | $result->{'value'} = $data->{'value'}; | ||
| 72 | if ($data->{'mode'} ne "integer") { | ||
| 73 | $result->{'type'} = 'like'; | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | return $result; | ||
| 78 | } | ||
| 79 | |||
| 80 | # ========================================================================== # | ||
| 81 | |||
| 82 | =item C<filterdropdown> | ||
| 83 | |||
| 84 | Params : filter_vals | ||
| 85 | |||
| 86 | { | ||
| 87 | 'type' => 'filter-drop-down', | ||
| 88 | 'data' => { | ||
| 89 | 'filterType' => 'ColumnName', | ||
| 90 | 'path' => 'default' | ||
| 91 | }, | ||
| 92 | 'action' => 'filter', | ||
| 93 | 'isAnimateToTop' => $VAR1->[0]{'isAnimateToTop'}, | ||
| 94 | 'initialIndex' => 5, | ||
| 95 | 'inDeepLinking' => $VAR1->[0]{'inDeepLinking'}, | ||
| 96 | 'inAnimation' => $VAR1->[0]{'inDeepLinking'}, | ||
| 97 | 'inStorage' => $VAR1->[0]{'inDeepLinking'}, | ||
| 98 | 'name' => 'category-dropdown-filter' | ||
| 99 | } | ||
| 100 | |||
| 101 | Returns: Returns the column and value for filter dropdown | ||
| 102 | |||
| 103 | Desc : Returns the column and value for filter dropdown | ||
| 104 | |||
| 105 | =cut | ||
| 106 | |||
| 107 | sub filterdropdown | ||
| 108 | { | ||
| 109 | my ($self, $filter_vals) = @_; | ||
| 110 | |||
| 111 | my $data = $filter_vals->{'data'}; | ||
| 112 | my $result; | ||
| 113 | |||
| 114 | if (exists($data->{'path'}) && ($data->{'path'} ne 'default')) { | ||
| 115 | my $column = $filter_vals->{'name'}; | ||
| 116 | |||
| 117 | $result->{'column'} = $column; | ||
| 118 | $result->{'value'} = $data->{'path'}; | ||
| 119 | $result->{'value'} =~ s/\.//; | ||
| 120 | $result->{'value'} =~ s/\.$column//; | ||
| 121 | |||
| 122 | } | ||
| 123 | |||
| 124 | return $result; | ||
| 125 | } | ||
| 126 | |||
| 127 | # ========================================================================== # | ||
| 128 | |||
| 129 | =item C<filterselect> | ||
| 130 | |||
| 131 | Params : filter_vals | ||
| 132 | |||
| 133 | { | ||
| 134 | 'isAnimateToTop' => $VAR1->[0]{'isAnimateToTop'}, | ||
| 135 | 'data' => { | ||
| 136 | 'path' => '.Electric', | ||
| 137 | 'filterType' => 'path' | ||
| 138 | }, | ||
| 139 | 'inDeepLinking' => $VAR1->[0]{'inDeepLinking'}, | ||
| 140 | 'action' => 'filter', | ||
| 141 | 'name' => 'ServiceType', | ||
| 142 | 'type' => 'filter-select', | ||
| 143 | 'inStorage' => $VAR1->[0]{'inDeepLinking'}, | ||
| 144 | 'inAnimation' => $VAR1->[0]{'inDeepLinking'} | ||
| 145 | } | ||
| 146 | |||
| 147 | Returns: Returns the column and value for filter select | ||
| 148 | |||
| 149 | Desc : Returns the column and value for filter select | ||
| 150 | |||
| 151 | =cut | ||
| 152 | |||
| 153 | sub filterselect | ||
| 154 | { | ||
| 155 | my ($self, $filter_vals) = @_; | ||
| 156 | |||
| 157 | my $data = $filter_vals->{'data'}; | ||
| 158 | my $result; | ||
| 159 | |||
| 160 | if (exists($data->{'path'}) && ($data->{'path'} ne 'default')) { | ||
| 161 | my $column = $filter_vals->{'name'}; | ||
| 162 | |||
| 163 | $result->{'column'} = $column; | ||
| 164 | $result->{'value'} = $data->{'path'}; | ||
| 165 | $result->{'value'} =~ s/\.$column//; | ||
| 166 | |||
| 167 | } | ||
| 168 | |||
| 169 | return $result; | ||
| 170 | } | ||
| 171 | |||
| 172 | # ========================================================================== # | ||
| 173 | |||
| 174 | =item C<filterdaterange> | ||
| 175 | |||
| 176 | Params : filter_vals | ||
| 177 | |||
| 178 | { | ||
| 179 | 'data' => { | ||
| 180 | 'path' => '.FromDate', | ||
| 181 | 'next_day' => 14, | ||
| 182 | 'prev_year' => 2017, | ||
| 183 | 'next_month' => 5, | ||
| 184 | 'next_year' => 2017, | ||
| 185 | 'format' => '{month}/{day}/{year}', | ||
| 186 | 'filterType' => 'dateRange', | ||
| 187 | 'prev_month' => 5, | ||
| 188 | 'prev_day' => 6 | ||
| 189 | }, | ||
| 190 | 'inDeepLinking' => $VAR1->[0]{'inAnimation'}, | ||
| 191 | 'action' => 'filter', | ||
| 192 | 'inStorage' => $VAR1->[0]{'inAnimation'}, | ||
| 193 | 'name' => 'FromDate', | ||
| 194 | 'type' => 'date-picker-range-filter', | ||
| 195 | 'isAnimateToTop' => $VAR1->[0]{'isAnimateToTop'}, | ||
| 196 | 'inAnimation' => $VAR1->[0]{'inAnimation'} | ||
| 197 | } | ||
| 198 | |||
| 199 | Returns: Returns the column and value for filter daterange | ||
| 200 | |||
| 201 | Desc : Returns the column and value for filter daterange | ||
| 202 | |||
| 203 | =cut | ||
| 204 | |||
| 205 | sub filterdaterange | ||
| 206 | { | ||
| 207 | my ($self, $filter_vals) = @_; | ||
| 208 | |||
| 209 | my $result; | ||
| 210 | |||
| 211 | if (exists($filter_vals->{'data'}) && $filter_vals->{'data'}{'prev_year'} && $filter_vals->{'data'}{'next_year'}) { | ||
| 212 | my $data = $filter_vals->{'data'}; | ||
| 213 | my ($from_date, $to_date); | ||
| 214 | |||
| 215 | $from_date = | ||
| 216 | $data->{'prev_year'} . "-" | ||
| 217 | . sprintf("%02d", ($data->{'prev_month'} + 1)) . "-" | ||
| 218 | . sprintf("%02d", $data->{'prev_day'}); | ||
| 219 | $to_date = | ||
| 220 | $data->{'next_year'} . "-" | ||
| 221 | . sprintf("%02d", ($data->{'next_month'} + 1)) . "-" | ||
| 222 | . sprintf("%02d", $data->{'next_day'}); | ||
| 223 | |||
| 224 | if ($from_date =~ /\d{4}-\d{2}-\d{2}/ && $to_date =~ /\d{4}-\d{2}-\d{2}/) { | ||
| 225 | $result->{'column'} = $filter_vals->{'name'}; | ||
| 226 | $result->{'from_date'} = $from_date; | ||
| 227 | $result->{'to_date'} = $to_date; | ||
| 228 | $result->{'type'} = 'between'; | ||
| 229 | } | ||
| 230 | } | ||
| 231 | |||
| 232 | return $result; | ||
| 233 | } | ||
| 234 | |||
| 235 | # ========================================================================== # | ||
| 236 | |||
| 237 | =item C<filterdatepicker> | ||
| 238 | |||
| 239 | Params : filter_vals | ||
| 240 | |||
| 241 | { | ||
| 242 | 'inDeepLinking' => $VAR1->[0]{'inAnimation'}, | ||
| 243 | 'inAnimation' => $VAR1->[0]{'inAnimation'}, | ||
| 244 | 'isAnimateToTop' => $VAR1->[0]{'isAnimateToTop'}, | ||
| 245 | 'action' => 'filter', | ||
| 246 | 'inStorage' => $VAR1->[0]{'inAnimation'}, | ||
| 247 | 'type' => 'date-picker-filter', | ||
| 248 | 'data' => { | ||
| 249 | 'year' => 2017, | ||
| 250 | 'format' => '{month}/{day}/{year}', | ||
| 251 | 'filterType' => 'date', | ||
| 252 | 'day' => 10, | ||
| 253 | 'path' => '.ReadDate', | ||
| 254 | 'month' => 6 | ||
| 255 | }, | ||
| 256 | 'name' => 'ReadDate' | ||
| 257 | } | ||
| 258 | |||
| 259 | Returns: Returns the column and value for filter daterange | ||
| 260 | |||
| 261 | Desc : Returns the column and value for filter daterange | ||
| 262 | |||
| 263 | =cut | ||
| 264 | |||
| 265 | sub filterdatepicker | ||
| 266 | { | ||
| 267 | my ($self, $filter_vals) = @_; | ||
| 268 | |||
| 269 | my $result; | ||
| 270 | |||
| 271 | if (exists($filter_vals->{'data'}) && $filter_vals->{'data'}{'year'}) { | ||
| 272 | my $data = $filter_vals->{'data'}; | ||
| 273 | my ($date); | ||
| 274 | |||
| 275 | $date = $data->{'year'} . "-" . sprintf("%02d", ($data->{'month'} + 1)) . "-" . sprintf("%02d", $data->{'day'}); | ||
| 276 | |||
| 277 | if ($date =~ /\d{4}-\d{2}-\d{2}/) { | ||
| 278 | $result->{'column'} = $filter_vals->{'name'}; | ||
| 279 | $result->{'value'} = $date; | ||
| 280 | } | ||
| 281 | } | ||
| 282 | |||
| 283 | return $result; | ||
| 284 | } | ||
| 285 | |||
| 286 | # ========================================================================== # | ||
| 287 | |||
| 288 | =item C<checkboxgroup> | ||
| 289 | |||
| 290 | Params : filter_vals | ||
| 291 | |||
| 292 | { | ||
| 293 | 'name' => 'SourceType', | ||
| 294 | 'action' => 'filter', | ||
| 295 | 'inStorage' => $VAR1->[0]{'inStorage'}, | ||
| 296 | 'isAnimateToTop' => $VAR1->[0]{'isAnimateToTop'}, | ||
| 297 | 'type' => 'checkbox-group-filter', | ||
| 298 | 'inAnimation' => $VAR1->[0]{'inStorage'}, | ||
| 299 | 'data' => { | ||
| 300 | 'pathGroup' => [ | ||
| 301 | '.Schedule', | ||
| 302 | '.Estimate' | ||
| 303 | ], | ||
| 304 | 'filterType' => 'pathGroup' | ||
| 305 | }, | ||
| 306 | 'inDeepLinking' => $VAR1->[0]{'inStorage'} | ||
| 307 | } | ||
| 308 | |||
| 309 | Returns: Returns the column and value for filter checkbox group | ||
| 310 | |||
| 311 | Desc : Returns the column and value for filter checkbox group | ||
| 312 | |||
| 313 | =cut | ||
| 314 | |||
| 315 | sub checkboxgroup | ||
| 316 | { | ||
| 317 | my ($self, $filter_vals) = @_; | ||
| 318 | |||
| 319 | my $result; | ||
| 320 | |||
| 321 | if (exists($filter_vals->{'data'})) { | ||
| 322 | my $data = $filter_vals->{'data'}; | ||
| 323 | |||
| 324 | if (exists($data->{'pathGroup'}) && ref($data->{'pathGroup'}) eq 'ARRAY') { | ||
| 325 | |||
| 326 | my $column = $filter_vals->{'name'}; | ||
| 327 | my $values = $data->{'pathGroup'}; | ||
| 328 | my @real_values = map { my $s = $_; $s =~ s/\.$column//g; $s } @$values; | ||
| 329 | |||
| 330 | if (scalar @real_values) { | ||
| 331 | $result->{'column'} = $column; | ||
| 332 | $result->{'values'} = \@real_values; | ||
| 333 | $result->{'type'} = 'in'; | ||
| 334 | } | ||
| 335 | |||
| 336 | } | ||
| 337 | } | ||
| 338 | |||
| 339 | return $result; | ||
| 340 | } | ||
| 341 | |||
| 342 | # ========================================================================== # | ||
| 343 | |||
| 344 | 1; | ||
| 345 | |||
| 346 | __END__ | ||
| 347 | |||
| 348 | =back | ||
| 349 | |||
| 350 | =head1 AUTHORS | ||
| 351 | |||
| 352 | Sheeju Alex, <sheeju@exceleron.com> | ||
| 353 | |||
| 354 | =head1 BUGS | ||
| 355 | |||
| 356 | https://github.com/sheeju/JPList/issues | ||
| 357 | |||
| 358 | =head1 SUPPORT | ||
| 359 | |||
| 360 | You can find documentation for this module with the perldoc command. | ||
| 361 | |||
| 362 | perldoc JPList | ||
| 363 | |||
| 364 | |||
| 365 | You can also look for information at: | ||
| 366 | |||
| 367 | =over 4 | ||
| 368 | |||
| 369 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 370 | |||
| 371 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=JPList> | ||
| 372 | |||
| 373 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 374 | |||
| 375 | L<http://annocpan.org/dist/JPList> | ||
| 376 | |||
| 377 | =item * CPAN Ratings | ||
| 378 | |||
| 379 | L<http://cpanratings.perl.org/d/JPList> | ||
| 380 | |||
| 381 | =item * Search CPAN | ||
| 382 | |||
| 383 | L<http://search.cpan.org/dist/JPList/> | ||
| 384 | |||
| 385 | =back | ||
| 386 | |||
| 387 | =head1 ACKNOWLEDGEMENTS | ||
| 388 | |||
| 389 | Development time supported by Exceleron L<www.exceleron.com|http://www.exceleron.com>. | ||
| 390 | |||
| 391 | =head1 LICENSE AND COPYRIGHT | ||
| 392 | |||
| 393 | Copyright (C) 2017 Exceleron Software, LLC | ||
| 394 | |||
| 395 | This program is free software; you can redistribute it and/or modify it | ||
| 396 | under the terms of the the Artistic License (2.0). You may obtain a | ||
| 397 | copy of the full license at: | ||
| 398 | |||
| 399 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||
| 400 | |||
| 401 | Any use, modification, and distribution of the Standard or Modified | ||
| 402 | Versions is governed by this Artistic License. By using, modifying or | ||
| 403 | distributing the Package, you accept this license. Do not use, modify, | ||
| 404 | or distribute the Package, if you do not accept this license. | ||
| 405 | |||
| 406 | If your Modified Version has been derived from a Modified Version made | ||
| 407 | by someone other than you, you are nevertheless required to ensure that | ||
| 408 | your Modified Version complies with the requirements of this license. | ||
| 409 | |||
| 410 | This license does not grant you the right to use any trademark, service | ||
| 411 | mark, tradename, or logo of the Copyright Holder. | ||
| 412 | |||
| 413 | This license includes the non-exclusive, worldwide, free-of-charge | ||
| 414 | patent license to make, have made, use, offer to sell, sell, import and | ||
| 415 | otherwise transfer the Package with respect to any patent claims | ||
| 416 | licensable by the Copyright Holder that are necessarily infringed by the | ||
| 417 | Package. If you institute patent litigation (including a cross-claim or | ||
| 418 | counterclaim) against any party alleging that the Package constitutes | ||
| 419 | direct or contributory patent infringement, then this Artistic License | ||
| 420 | to you shall terminate on the date that such litigation is filed. | ||
| 421 | |||
| 422 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||
| 423 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||
| 424 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
| 425 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||
| 426 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||
| 427 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||
| 428 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||
| 429 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 430 | |||
| 431 | =cut | ||
| 432 | |||
| 433 | # vim: ts=4 | ||
| 434 | # vim600: fdm=marker fdl=0 fdc=3 |