Skip to content

Commit 0c29b8b

Browse files
committed
finalizing sorting, filtering and pagination with plans and songs
1 parent 61fec78 commit 0c29b8b

File tree

5 files changed

+51
-13
lines changed

5 files changed

+51
-13
lines changed

Diff for: app/Http/Controllers/Cspot/PlanController.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function nextSunday()
8888
*/
8989
public function index(Request $request)
9090
{
91+
$querystringArray = $request->input();
9192
// set default values
9293
$filterby = isset($request->filterby) ? $request->filterby : '';
9394
$filtervalue = isset($request->filtervalue )? $request->filtervalue : '';
@@ -162,9 +163,12 @@ public function index(Request $request)
162163
$heading = 'Your Service Plans';
163164
}
164165

166+
// for pagination, always append the original query string
167+
$plans = $plans->paginate(20)->appends($querystringArray);
168+
165169
return view(
166170
$this->view_all,
167-
array('plans' => $plans->paginate(20), 'heading' => $heading)
171+
array('plans' => $plans, 'heading' => $heading)
168172
);
169173
}
170174

Diff for: app/Http/Controllers/Cspot/SongController.php

+25-7
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,39 @@ public function __construct() {
4848
* @return \Illuminate\Http\Response
4949
*/
5050
public function index(Request $request )
51-
{
51+
{
52+
$querystringArray = $request->input();
5253
// set default values
5354
$orderBy = isset($request->orderby) ? $request->orderby : 'title';
5455
$order = isset($request->order) ? $request->order : 'asc';
5556

5657
// with filtering?
5758
if (isset($request->filterby) and isset($request->filtervalue)) {
58-
$songs = Song::orderBy($orderBy, $order)
59-
->where($request->filterby, 'like', '%'.$request->filtervalue.'%')
60-
->paginate(20);
61-
} else {
62-
$songs = Song::orderBy($orderBy, $order)
63-
->paginate(20);
59+
if ($request->filterby=='fulltext') {
60+
$songs = Song::orderBy($orderBy, $order)
61+
->where( 'title', 'like', '%'.$request->filtervalue.'%')
62+
->orWhere('title_2', 'like', '%'.$request->filtervalue.'%')
63+
->orWhere('author', 'like', '%'.$request->filtervalue.'%')
64+
->orWhere('book_ref', 'like', '%'.$request->filtervalue.'%')
65+
->orWhere('lyrics', 'like', '%'.$request->filtervalue.'%');
66+
}
67+
elseif ($request->filterby=='title') {
68+
$songs = Song::orderBy($orderBy, $order)
69+
->where( 'title', 'like', '%'.$request->filtervalue.'%')
70+
->orWhere('title_2', 'like', '%'.$request->filtervalue.'%');
71+
}
72+
else {
73+
$songs = Song::orderBy($orderBy, $order)
74+
->where($request->filterby, 'like', '%'.$request->filtervalue.'%');
75+
}
76+
}
77+
else {
78+
$songs = Song::orderBy($orderBy, $order);
6479
}
6580

81+
// for pagination, always append the original query string
82+
$songs = $songs->paginate(20)->appends($querystringArray);
83+
6684
$heading = 'Manage Songs';
6785
return view( $this->view_all, array(
6886
'songs' => $songs,

Diff for: public/js/helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ function reloadListOrderBy(field)
294294

295295

296296
/*
297-
Show input field in header to filter this column or apply the filter if already set
297+
Show input field in header to filter data in this column or apply the filter if already set
298298
*/
299299
function showFilterField(field)
300300
{
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
<span id="fulltext-search" class="link m-l-1 pull-xs-left" onclick="showFilterField('fulltext')" data-toggle="tooltip"
3+
@if ( Request::has('filterby') && Request::get('filterby')=='fulltext' )
4+
title="Clear filter">
5+
Search: <span class="bg-info">&nbsp;{{ Request::get('filtervalue') }} </span>
6+
<i id="filter-fulltext-clear" class="fa fa-close"> </i>
7+
@else
8+
title="Full-text search in titles, author lyrics etc">
9+
<i id="filter-fulltext-show" class="fa fa-search"> </i>
10+
@endif
11+
</span>
12+

Diff for: resources/views/cspot/songs.blade.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@
2121
</span>
2222
@endif
2323

24-
<h2 class="hidden-xs-down pull-xs-left">{{ $heading }}</h2>
24+
<h2 class="hidden-xs-down pull-xs-left">{{ $heading }}
25+
</h2>
26+
@include('cspot.snippets.fullTextSearch')
27+
2528

26-
<center>Page {{ $songs->currentPage() }} of {{ $songs->lastPage() }}</center>
29+
<center>
30+
Page {{ $songs->currentPage() }} of {{ $songs->lastPage() }}<br>
31+
<small>showing a total of {{ $songs->total() }} songs</small>
32+
</center>
2733

2834

2935
@if (count($songs))
3036

31-
<center><small>(Total: {{ $songs->total() }} Songs)</small></center>
32-
3337
<table class="table table-striped table-bordered
3438
@if(count($songs)>15)
3539
table-sm

0 commit comments

Comments
 (0)