Explorar el Código

fix pagination, filter window, added back button in reclamation

Alexander Musikhin hace 2 semanas
padre
commit
961a5151a8

+ 2 - 2
app/Http/Controllers/ContractController.php

@@ -39,8 +39,8 @@ class ContractController extends Controller
         $this->acceptFilters($q, $request);
         $this->setSortAndOrderBy($model, $request);
 
-        $q->orderBy($this->data['sortBy'], $this->data['orderBy']);
-        $this->data['contracts'] = $q->paginate(session('per_page', config('pagination.per_page')))->withQueryString();
+        $this->applyStableSorting($q);
+        $this->data['contracts'] = $q->paginate($this->data['per_page'])->withQueryString();
 
         return view('contracts.index', $this->data);
     }

+ 24 - 4
app/Http/Controllers/Controller.php

@@ -155,17 +155,37 @@ class Controller extends BaseController
             $this->data['sortBy'] = $model::DEFAULT_SORT_BY ?? 'created_at';
         }
 
-        if(!empty($request->per_page)) {
-            $this->data['per_page'] = $request->per_page;
+        $allowedPerPage = [50, 100, 200, 500, 2000];
+        $requestedPerPage = (int)$request->input('per_page', 0);
+        $sessionPerPage = (int)session('per_page', 0);
+        $defaultPerPage = (int)config('pagination.per_page');
+
+        if(in_array($requestedPerPage, $allowedPerPage, true)) {
+            $this->data['per_page'] = $requestedPerPage;
+        } elseif(in_array($sessionPerPage, $allowedPerPage, true)) {
+            $this->data['per_page'] = $sessionPerPage;
+        } elseif(in_array($defaultPerPage, $allowedPerPage, true)) {
+            $this->data['per_page'] = $defaultPerPage;
         } else {
-            $this->data['per_page'] = config('pagination.per_page');
+            $this->data['per_page'] = 50;
         }
-        session(['per_page' => $request->per_page]);
+        session(['per_page' => $this->data['per_page']]);
 
         // set order
         $this->data['orderBy'] = (empty($request->order)) ? 'asc' : 'desc';
     }
 
+    protected function applyStableSorting(Builder $query, string $fallbackSortBy = 'id'): void
+    {
+        $sortBy = $this->data['sortBy'] ?? 'created_at';
+        $orderBy = $this->data['orderBy'] ?? 'asc';
+
+        $query->orderBy($sortBy, $orderBy);
+        if($sortBy !== $fallbackSortBy) {
+            $query->orderBy($fallbackSortBy, $orderBy);
+        }
+    }
+
     /**
      * @param Builder $query
      * @param Request $request

+ 2 - 2
app/Http/Controllers/ImportController.php

@@ -46,8 +46,8 @@ class ImportController extends Controller
         $this->acceptSearch($q, $request);
         $this->setSortAndOrderBy($model, $request);
 
-        $q->orderBy($this->data['sortBy'], $this->data['orderBy']);
-        $this->data['imports'] = $q->paginate(session('per_page', config('pagination.per_page')))->withQueryString();
+        $this->applyStableSorting($q);
+        $this->data['imports'] = $q->paginate($this->data['per_page'])->withQueryString();
 
         return view('import.index', $this->data);
     }

+ 2 - 2
app/Http/Controllers/MafOrderController.php

@@ -47,9 +47,9 @@ class MafOrderController extends Controller
         $this->acceptSearch($q, $request);
         $this->setSortAndOrderBy($model, $request);
 
-        $q->orderBy($this->data['sortBy'], $this->data['orderBy']);
+        $this->applyStableSorting($q);
 
-        $this->data['maf_orders'] = $q->paginate(session('per_page', config('pagination.per_page')))->withQueryString();
+        $this->data['maf_orders'] = $q->paginate($this->data['per_page'])->withQueryString();
         return view('maf_orders.index', $this->data);
     }
 

+ 2 - 2
app/Http/Controllers/OrderController.php

@@ -107,8 +107,8 @@ class OrderController extends Controller
             $q->where('brigadier_id', auth()->id());
         }
 
-        $q->orderBy($this->data['sortBy'], $this->data['orderBy']);
-        $this->data['orders'] = $q->paginate(session('per_page', config('pagination.per_page')))->withQueryString();
+        $this->applyStableSorting($q);
+        $this->data['orders'] = $q->paginate($this->data['per_page'])->withQueryString();
 
         foreach ($this->data['orders'] as $order) {
             Order::where('id', $order->id)->first()?->recalculateReadyToMount();

+ 6 - 1
app/Http/Controllers/PricingCodeController.php

@@ -23,6 +23,8 @@ class PricingCodeController extends Controller
 
     public function index(Request $request)
     {
+        $this->setSortAndOrderBy(new PricingCode(), $request);
+
         $sortBy = $request->get('sortBy', 'code');
         $allowedSort = ['id', 'type', 'code', 'description'];
         if (!in_array($sortBy, $allowedSort, true)) {
@@ -43,8 +45,11 @@ class PricingCodeController extends Controller
         }
 
         $q->orderBy($sortBy, $orderBy);
+        if ($sortBy !== 'id') {
+            $q->orderBy('id', $orderBy);
+        }
 
-        $this->data['pricing_codes'] = $q->paginate(session('per_page', config('pagination.per_page')))->withQueryString();
+        $this->data['pricing_codes'] = $q->paginate($this->data['per_page'])->withQueryString();
         $this->data['sortBy'] = $sortBy;
         $this->data['orderBy'] = $orderBy;
         $this->data['searchFields'] = ['type', 'code', 'description'];

+ 2 - 2
app/Http/Controllers/ProductController.php

@@ -73,9 +73,9 @@ class ProductController extends Controller
         $this->acceptSearch($q, $request);
 
         $this->setSortAndOrderBy($model, $request);
-        $q->orderBy($this->data['sortBy'], $this->data['orderBy']);
+        $this->applyStableSorting($q);
 
-        $this->data['products'] = $q->paginate(session('per_page', config('pagination.per_page')))->withQueryString();
+        $this->data['products'] = $q->paginate($this->data['per_page'])->withQueryString();
         return view('catalog.index', $this->data);
     }
 

+ 2 - 2
app/Http/Controllers/ProductSKUController.php

@@ -71,10 +71,10 @@ class ProductSKUController extends Controller
         $this->acceptSearch($q, $request);
         $this->setSortAndOrderBy($model, $request);
 
-        $q->orderBy($this->data['sortBy'], $this->data['orderBy']);
+        $this->applyStableSorting($q);
 
 //        dump($q->toRawSql());
-        $this->data['products_sku'] = $q->paginate(session('per_page', config('pagination.per_page')))->withQueryString();
+        $this->data['products_sku'] = $q->paginate($this->data['per_page'])->withQueryString();
         return view('products_sku.index', $this->data);
     }
 

+ 3 - 3
app/Http/Controllers/ReclamationController.php

@@ -78,8 +78,8 @@ class ReclamationController extends Controller
         $this->acceptSearch($q, $request);
         $this->setSortAndOrderBy($model, $request);
 
-        $q->orderBy($this->data['sortBy'], $this->data['orderBy']);
-        $this->data['reclamations'] = $q->paginate(session('per_page', config('pagination.per_page')))->withQueryString();
+        $this->applyStableSorting($q);
+        $this->data['reclamations'] = $q->paginate($this->data['per_page'])->withQueryString();
 
         return view('reclamations.index', $this->data);
     }
@@ -97,7 +97,7 @@ class ReclamationController extends Controller
         $this->acceptFilters($q, $filterRequest);
         $this->acceptSearch($q, $filterRequest);
         $this->setSortAndOrderBy($model, $filterRequest);
-        $q->orderBy($this->data['sortBy'], $this->data['orderBy']);
+        $this->applyStableSorting($q);
 
         $reclamationIds = $q->pluck('id')->toArray();
 

+ 2 - 2
app/Http/Controllers/ResponsibleController.php

@@ -49,8 +49,8 @@ class ResponsibleController extends Controller
         $this->acceptSearch($q, $request);
         $this->setSortAndOrderBy($model, $request);
 
-        $q->orderBy($this->data['sortBy'], $this->data['orderBy']);
-        $this->data['responsibles'] = $q->paginate(session('per_page', config('pagination.per_page')))->withQueryString();
+        $this->applyStableSorting($q);
+        $this->data['responsibles'] = $q->paginate($this->data['per_page'])->withQueryString();
 
         return view('responsibles.index', $this->data);
     }

+ 2 - 2
app/Http/Controllers/SparePartController.php

@@ -77,9 +77,9 @@ class SparePartController extends Controller
         $this->acceptSearch($q, $request);
 
         $this->setSortAndOrderBy($model, $request);
-        $q->orderBy($this->data['sortBy'], $this->data['orderBy']);
+        $this->applyStableSorting($q);
 
-        $this->data['spare_parts'] = $q->paginate(session('per_page', config('pagination.per_page')))->withQueryString();
+        $this->data['spare_parts'] = $q->paginate($this->data['per_page'])->withQueryString();
         $this->data['strings'] = $this->data['spare_parts'];
         $this->data['tab'] = 'catalog';
 

+ 2 - 2
app/Http/Controllers/SparePartOrderController.php

@@ -85,9 +85,9 @@ class SparePartOrderController extends Controller
         $this->acceptSearch($q, $request);
 
         $this->setSortAndOrderBy($model, $request);
-        $q->orderBy($this->data['sortBy'], $this->data['orderBy']);
+        $this->applyStableSorting($q);
 
-        $this->data['spare_part_orders'] = $q->paginate(session('per_page', config('pagination.per_page')))->withQueryString();
+        $this->data['spare_part_orders'] = $q->paginate($this->data['per_page'])->withQueryString();
         $this->data['strings'] = $this->data['spare_part_orders'];
         $this->data['tab'] = 'orders';
 

+ 2 - 2
app/Http/Controllers/UserController.php

@@ -51,8 +51,8 @@ class UserController extends Controller
         $this->acceptSearch($q, $request);
         $this->setSortAndOrderBy($model, $request);
 //        $q->withTrashed();
-        $q->orderBy($this->data['sortBy'], $this->data['orderBy']);
-        $this->data['users'] = $q->paginate(session('per_page', config('pagination.per_page')))->withQueryString();
+        $this->applyStableSorting($q);
+        $this->data['users'] = $q->paginate($this->data['per_page'])->withQueryString();
 
         return view('users.index', $this->data);
     }

+ 8 - 0
resources/sass/app.scss

@@ -62,6 +62,14 @@
   box-shadow: 0 8px 14px -10px rgba(0, 0, 0, 0.35);
 }
 
+.js-main-table-scroll thead th:has(.dropdown-menu.show) {
+  z-index: 10;
+}
+
+.js-main-table-scroll thead th .dropdown-menu {
+  z-index: 11;
+}
+
 .js-subtable-scroll {
   overflow: auto;
 }

+ 2 - 0
resources/views/reclamations/edit.blade.php

@@ -8,6 +8,8 @@
                 <h4>Рекламация</h4>
             </div>
             <div class="col-xl-6 action-toolbar mb-2">
+                <a href="{{ $previous_url ?? route('reclamations.index', session('gp_reclamations')) }}"
+                   class="btn btn-sm btn-outline-secondary">Назад</a>
                 @if(hasRole('admin') && !is_null($reclamation->brigadier_id) && !is_null($reclamation->start_work_date))
                     <button class="btn btn-sm btn-primary" id="createScheduleButton">Перенести в график</button>
                 @endif