diff --git a/src/DataProviders/DataProvider.php b/src/DataProviders/DataProvider.php new file mode 100644 index 0000000..d153404 --- /dev/null +++ b/src/DataProviders/DataProvider.php @@ -0,0 +1,7 @@ + true, 'id_name'=> 'NO', @@ -40,26 +37,9 @@ class ReportGenerator protected $actions = []; - public function __construct(string $view_object_class_name = null, string $view_factory_method = 'get') - { - $this->view_object_class_name = $view_object_class_name; - $this->view_factory_method = $view_factory_method; - $this->transformer = App::make(Transformer::class); - } - - public function setProvidedFactory($factory) - { - $this->provided_factory = $factory; - } - - public function setFilterManager(FilterManager $filter) - { - $this->filter = $filter; - } - - public function setDateRange(DateRange $range) + public function __construct(DataProvider $provider) { - $this->range = $range; + $this->provider = $provider; } public function setAsync(bool $async, string $async_route) @@ -78,11 +58,6 @@ public function settings(array $settings) $this->settings = array_merge($this->settings, $settings); } - public function with($field, $value) - { - $this->additional_data[$field] = $value; - } - public function col(string $display_name, string $field_name) { $this->fields[$field_name] = new ReportColumn($field_name, $display_name); @@ -125,8 +100,8 @@ public function generate() ]; } - $factory = $this->getFactory(); - $results = $factory->{$this->view_factory_method}($this->filter, $this->range); + $provider = $this->getDataProvider(); + $results = $provider->get(); if ($results === null) { return []; @@ -147,7 +122,7 @@ public function generate() } } - $totals = $this->getTotals($results, ReportType::HTML(), $factory); + $totals = $this->getTotals($results, ReportType::HTML(), $provider); $results = $this->format($results, ReportType::HTML()); return [ @@ -155,7 +130,7 @@ public function generate() 'data' => $results, 'aggregate' => $totals, // debug - 'view_object_class_name' => $this->view_object_class_name + 'provider' => get_class($this->provider) ]; } @@ -181,22 +156,11 @@ public function async($data) } } - if (isset($data['search']) && isset($data['search']['value'])) { - if (!$this->filter->has('search_term')) { - $this->filter->addValue('search_term', $data['search']['value']); - } - } - - $factory = $this->getFactory(); - - $method = 'paged'; - - $results = $factory->{$method}( + $provider = $this->getDataProvider(); + $results = $provider->getPaged( $data['start'], $data['length'], - $ordering, - $this->filter, - $this->range + $ordering ); foreach ($results as $row) { @@ -265,7 +229,7 @@ public function async($data) $process[] = $r; } - $total = $factory->count($this->filter, $this->range); + $total = $provider->getTotal(); $response['data'] = $process; $response['recordsTotal'] = $total; @@ -322,7 +286,7 @@ private function format($results, ReportType $type) return $results; } - private function getTotals(Collection $results, ReportType $type, $factory) : array + private function getTotals(Collection $results, ReportType $type, $provider) : array { $totals = []; @@ -334,7 +298,7 @@ private function getTotals(Collection $results, ReportType $type, $factory) : ar foreach ($aggregates as $ag) { if ($ag instanceof FactoryRequired) { - $ag->setFactory($factory); + $ag->setFactory($provider); } $totals[] = $ag->generate($this->fields, $results, $type); } @@ -344,9 +308,7 @@ private function getTotals(Collection $results, ReportType $type, $factory) : ar public function toArray() { - $results = $this->getFactory(); - $results = $results->{$this->view_factory_method}($this->filter, $this->range); - + $results = $this->getDataProvider()->get(); $results = $this->format($results, ReportType::PLAIN()); $flat = []; @@ -373,21 +335,8 @@ private function getSettingValue($key) return $this->settings[$key]; } - public function getFactory() + public function getDataProvider() { - $factory = null; - if ($this->provided_factory) { - $factory = $this->provided_factory; - } else { - $class = $this->view_object_class_name; - $factory = $class::getFactory(); - $factory = App::make($factory); - } - - if (method_exists($factory, 'setAdditionalData')) { - $factory->setAdditionalData($this->additional_data); - } - - return $factory; + return $this->provider; } } diff --git a/src/ReportGeneratorServiceProvider.php b/src/ReportGeneratorServiceProvider.php index e6e9fec..fccfd50 100644 --- a/src/ReportGeneratorServiceProvider.php +++ b/src/ReportGeneratorServiceProvider.php @@ -27,5 +27,9 @@ public function boot() $this->publishes([ __DIR__.'/resources/views' => resource_path('views/vendor/report_generator'), ]); + + $this->publishes([ + __DIR__.'/public' => public_path('vendor/focalstrategy/report_generator'), + ], 'public'); } } diff --git a/src/mix-manifest.json b/src/mix-manifest.json new file mode 100644 index 0000000..7113715 --- /dev/null +++ b/src/mix-manifest.json @@ -0,0 +1,5 @@ +{ + "/public/css/actions.css": "/public/css/actions.css", + "/packages/Actions/src/public/js/actions.js": "/packages/Actions/src/public/js/actions.js", + "/public/js/report_generator.js": "/public/js/report_generator.js" +} \ No newline at end of file diff --git a/src/public/css/actions.css b/src/public/css/actions.css new file mode 100644 index 0000000..a640c9b --- /dev/null +++ b/src/public/css/actions.css @@ -0,0 +1 @@ +.bigbox{position:fixed;bottom:0;left:0;right:0;top:0;display:none;background-color:#fff;z-index:10050;padding-left:20px;padding-right:20px;overflow-y:scroll}.bigbox.in{display:block}.bigbox .bigbox-content{overflow-y:scroll;padding-bottom:60px;padding-left:15px;padding-right:15px}.bigbox .bigbox-content .bigbox-header{position:fixed;background-color:#fff;width:100%;text-align:center;border-bottom:1px solid #ccc;margin-bottom:5px;z-index:10003}.bigbox .bigbox-content .bigbox-body{padding-top:60px;position:relative;z-index:10002}.bigbox .bigbox-content .bigbox-body .ql{color:#fff}.bigbox .bigbox-content .bigbox-body .ql img{width:63px;display:block;margin:0 auto;-webkit-filter:invert(100%);filter:invert(100%)}.bigbox .bigbox-content .bigbox-body .ql.prep_department_wheels,.bigbox .bigbox-content .bigbox-body .ql.prep_department_wheels:active .link,.bigbox .bigbox-content .bigbox-body .ql.prep_department_wheels:focus .link,.bigbox .bigbox-content .bigbox-body .ql.prep_department_wheels:hover .link{color:#000}.bigbox .bigbox-content .bigbox-body .ql.prep_department_wheels img{-webkit-filter:none;filter:none}.bigbox .bigbox-content .bigbox-body .ql .fa,.bigbox .bigbox-content .bigbox-body .ql:active .link,.bigbox .bigbox-content .bigbox-body .ql:focus .link,.bigbox .bigbox-content .bigbox-body .ql:hover .link{color:#fff}.bigbox .bigbox-content .bigbox-footer{background-color:#fff;position:fixed;padding:5px;bottom:0;left:0;right:0;z-index:10003}.bigbox .bigbox-content .bigbox-footer .btn{font-size:1.5em}.bigbox.no-scroll,.bigbox.no-scroll .bigbox-content{overflow-y:hidden}.bigbox.item_selected .bigbox-content .bigbox-body a.ql:not(.active){background-color:#fff!important;color:#000}.bigbox.item_selected .bigbox-content .bigbox-body a.ql:not(.active):active .link,.bigbox.item_selected .bigbox-content .bigbox-body a.ql:not(.active):focus .link,.bigbox.item_selected .bigbox-content .bigbox-body a.ql:not(.active):hover .link{color:#000}.bigbox.item_selected .bigbox-content .bigbox-body a.ql:not(.active) img{-webkit-filter:none;filter:none}.bigbox.item_selected .bigbox-content .bigbox-body a.ql:not(.active) .fa{color:#000}.bigbox.bigbox-sm{top:20px;bottom:78px;left:5%;right:5%;margin:0 auto;padding:0;-webkit-box-shadow:0 0 20px rgba(0,0,0,.95);box-shadow:0 0 20px rgba(0,0,0,.95)}.bigbox.bigbox-sm div.bigbox-footer{display:inline-block;width:100%;height:auto;position:inherit}.bigbox.bigbox-sm .bigbox-body{padding-top:0}.bigbox.bigbox-sm .bigbox-content{padding-bottom:0}.bigbox.bigbox-sm .bigbox-content .bigbox-header{position:unset}@media (min-width:700px){.bigbox.bigbox-sm{width:50%}}@media (min-width:1500px){.bigbox.bigbox-sm{width:35%}}@media (min-width:2000px){.bigbox.bigbox-sm{width:25%}}.bigbox-open{overflow:hidden}.bigbox-open .select2-container{z-index:100006}.bigbox-open .bigbox-modal-bg{position:fixed;background-color:rgba(0,0,0,.55);-webkit-backdrop-filter:blur(3px);backdrop-filter:blur(3px);width:100%;height:100%;top:0;bottom:0;left:0;right:0;z-index:10010}@media (min-width:1200px){.bigbox{top:20px;bottom:78px;left:5%;right:5%;width:90%;margin:0 auto;padding:0;-webkit-box-shadow:0 0 20px rgba(0,0,0,.95);box-shadow:0 0 20px rgba(0,0,0,.95)}.bigbox .bigbox-content .bigbox-header{position:static}.bigbox .bigbox-content .bigbox-body{padding-top:0}.bigbox .bigbox-content .bigbox-footer{width:90%;left:5%;right:5%;bottom:20px}.bigbox.small{width:50%;bottom:60%}.bigbox.small .bigbox-content .bigbox-footer{width:50%;left:5%;right:5%;bottom:60%;margin:auto}} \ No newline at end of file diff --git a/src/public/js/report_generator.js b/src/public/js/report_generator.js new file mode 100644 index 0000000..ad8c74b --- /dev/null +++ b/src/public/js/report_generator.js @@ -0,0 +1 @@ +$(function(){$(".async_table").each(function(){var a=$(this),e=[],t=0;a.find("th").each(function(a){var r=$(this),n={name:"",title:"",orderable:!0,searchable:!0};n.title=r.text(),n.name=r.data("name"),n.orderable=r.data("orderable"),n.searchable=r.data("searchable"),r.data("init-sort")&&(t=a),e.push(n)});var r=$(".table_search").length>0?"rtip":"lfrtip";a.DataTable({processing:!0,serverSide:!0,ajax:{url:a.data("route"),data:function(e){var t=a.data("filters");$.each(t,function(a,t){e[a]=t})}},pageLength:25,lengthChange:!1,orderClasses:!1,scrollX:!0,stateSave:!0,stateDuration:-1,order:[[t,"desc"]],searching:!0,columns:e,dom:r})}),$(document).on("filter_manager:change",function(a,e,t){$(".async_table").each(function(){if($(this).data("filters",e),$.fn.DataTable.isDataTable($(this))){var a=$(this).DataTable();e.search_term&&$(".dataTables_filter input",this).val()!=e.search_term&&a.search(e.search_term),a.ajax.reload()}})})}); \ No newline at end of file diff --git a/src/resources/js/fs-async-tables.js b/src/resources/js/fs-async-tables.js new file mode 100644 index 0000000..4d64efd --- /dev/null +++ b/src/resources/js/fs-async-tables.js @@ -0,0 +1,66 @@ +$(function() { + $('.async_table').each(function() { + var $self = $(this); + + var columns = []; + var init_sort = 0; + $self.find('th').each(function(i) { + var $th = $(this); + + var col = {name:'',title:'',orderable:true,searchable:true}; + col.title = $th.text(); + col.name = $th.data('name'); + col.orderable = $th.data('orderable'); + col.searchable = $th.data('searchable'); + + if($th.data('init-sort')) { + init_sort = i; + } + + columns.push(col); + }); + + var dom = $('.table_search').length > 0 ? 'rtip' : 'lfrtip'; + + $self.DataTable({ + processing: true, + serverSide: true, + ajax: { + 'url':$self.data('route'), + 'data':function ( d ) { + var data = $self.data('filters'); + $.each(data,function(i,itm) { + d[i] = itm; + }); + } + }, + pageLength: 25, + lengthChange: false, + orderClasses: false, + scrollX: true, + stateSave: true, + stateDuration: -1, + order: [[init_sort, 'desc']], + "searching": true, + columns: columns, + dom:dom + }); + }); + + $(document).on('filter_manager:change',function(e, filters, url) { + $('.async_table').each(function() { + $(this).data('filters',filters); + + if($.fn.DataTable.isDataTable( $(this) ) ) { + var dt = $(this).DataTable(); + + if(filters.search_term + && $('.dataTables_filter input',this).val() != filters.search_term) { + dt.search(filters.search_term); + } + + dt.ajax.reload(); + } + }); + }); +}); \ No newline at end of file diff --git a/src/resources/views/report.blade.php b/src/resources/views/report.blade.php index 71e04a6..26d1176 100644 --- a/src/resources/views/report.blade.php +++ b/src/resources/views/report.blade.php @@ -1,11 +1,14 @@ -@if (isset($view_object_class_name) && config('app.debug')) - +@if (isset($provider) && config('app.debug')) + @endif