From 0c29b8ba5d6e3cb0a4eba61d716fbec3974f77b5 Mon Sep 17 00:00:00 2001 From: Matthias Kuhs Date: Wed, 20 Apr 2016 10:58:24 +0100 Subject: [PATCH] finalizing sorting, filtering and pagination with plans and songs --- app/Http/Controllers/Cspot/PlanController.php | 6 +++- app/Http/Controllers/Cspot/SongController.php | 32 +++++++++++++++---- public/js/helpers.js | 2 +- .../cspot/snippets/fullTextSearch.blade.php | 12 +++++++ resources/views/cspot/songs.blade.php | 12 ++++--- 5 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 resources/views/cspot/snippets/fullTextSearch.blade.php diff --git a/app/Http/Controllers/Cspot/PlanController.php b/app/Http/Controllers/Cspot/PlanController.php index 17b14b4c..0531087d 100644 --- a/app/Http/Controllers/Cspot/PlanController.php +++ b/app/Http/Controllers/Cspot/PlanController.php @@ -88,6 +88,7 @@ public function nextSunday() */ public function index(Request $request) { + $querystringArray = $request->input(); // set default values $filterby = isset($request->filterby) ? $request->filterby : ''; $filtervalue = isset($request->filtervalue )? $request->filtervalue : ''; @@ -162,9 +163,12 @@ public function index(Request $request) $heading = 'Your Service Plans'; } + // for pagination, always append the original query string + $plans = $plans->paginate(20)->appends($querystringArray); + return view( $this->view_all, - array('plans' => $plans->paginate(20), 'heading' => $heading) + array('plans' => $plans, 'heading' => $heading) ); } diff --git a/app/Http/Controllers/Cspot/SongController.php b/app/Http/Controllers/Cspot/SongController.php index 73f4b274..afb6a5fc 100644 --- a/app/Http/Controllers/Cspot/SongController.php +++ b/app/Http/Controllers/Cspot/SongController.php @@ -48,21 +48,39 @@ public function __construct() { * @return \Illuminate\Http\Response */ public function index(Request $request ) - { + { + $querystringArray = $request->input(); // set default values $orderBy = isset($request->orderby) ? $request->orderby : 'title'; $order = isset($request->order) ? $request->order : 'asc'; // with filtering? if (isset($request->filterby) and isset($request->filtervalue)) { - $songs = Song::orderBy($orderBy, $order) - ->where($request->filterby, 'like', '%'.$request->filtervalue.'%') - ->paginate(20); - } else { - $songs = Song::orderBy($orderBy, $order) - ->paginate(20); + if ($request->filterby=='fulltext') { + $songs = Song::orderBy($orderBy, $order) + ->where( 'title', 'like', '%'.$request->filtervalue.'%') + ->orWhere('title_2', 'like', '%'.$request->filtervalue.'%') + ->orWhere('author', 'like', '%'.$request->filtervalue.'%') + ->orWhere('book_ref', 'like', '%'.$request->filtervalue.'%') + ->orWhere('lyrics', 'like', '%'.$request->filtervalue.'%'); + } + elseif ($request->filterby=='title') { + $songs = Song::orderBy($orderBy, $order) + ->where( 'title', 'like', '%'.$request->filtervalue.'%') + ->orWhere('title_2', 'like', '%'.$request->filtervalue.'%'); + } + else { + $songs = Song::orderBy($orderBy, $order) + ->where($request->filterby, 'like', '%'.$request->filtervalue.'%'); + } + } + else { + $songs = Song::orderBy($orderBy, $order); } + // for pagination, always append the original query string + $songs = $songs->paginate(20)->appends($querystringArray); + $heading = 'Manage Songs'; return view( $this->view_all, array( 'songs' => $songs, diff --git a/public/js/helpers.js b/public/js/helpers.js index 8a8cad28..c9a9e9d8 100644 --- a/public/js/helpers.js +++ b/public/js/helpers.js @@ -294,7 +294,7 @@ function reloadListOrderBy(field) /* - Show input field in header to filter this column or apply the filter if already set + Show input field in header to filter data in this column or apply the filter if already set */ function showFilterField(field) { diff --git a/resources/views/cspot/snippets/fullTextSearch.blade.php b/resources/views/cspot/snippets/fullTextSearch.blade.php new file mode 100644 index 00000000..f4c9fc42 --- /dev/null +++ b/resources/views/cspot/snippets/fullTextSearch.blade.php @@ -0,0 +1,12 @@ + + + Search:  {{ Request::get('filtervalue') }} + + @else + title="Full-text search in titles, author lyrics etc"> + + @endif + + diff --git a/resources/views/cspot/songs.blade.php b/resources/views/cspot/songs.blade.php index a4b41bad..1c42f956 100644 --- a/resources/views/cspot/songs.blade.php +++ b/resources/views/cspot/songs.blade.php @@ -21,15 +21,19 @@ @endif -

{{ $heading }}

+

{{ $heading }} +

+ @include('cspot.snippets.fullTextSearch') + -
Page {{ $songs->currentPage() }} of {{ $songs->lastPage() }}
+
+ Page {{ $songs->currentPage() }} of {{ $songs->lastPage() }}
+ showing a total of {{ $songs->total() }} songs +
@if (count($songs)) -
(Total: {{ $songs->total() }} Songs)
-