Skip to content

Commit

Permalink
finalizing sorting, filtering and pagination with plans and songs
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiku committed Apr 20, 2016
1 parent 61fec78 commit 0c29b8b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 13 deletions.
6 changes: 5 additions & 1 deletion app/Http/Controllers/Cspot/PlanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 : '';
Expand Down Expand Up @@ -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)
);
}

Expand Down
32 changes: 25 additions & 7 deletions app/Http/Controllers/Cspot/SongController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion public/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
12 changes: 12 additions & 0 deletions resources/views/cspot/snippets/fullTextSearch.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

<span id="fulltext-search" class="link m-l-1 pull-xs-left" onclick="showFilterField('fulltext')" data-toggle="tooltip"
@if ( Request::has('filterby') && Request::get('filterby')=='fulltext' )
title="Clear filter">
Search: <span class="bg-info">&nbsp;{{ Request::get('filtervalue') }} </span>
<i id="filter-fulltext-clear" class="fa fa-close"> </i>
@else
title="Full-text search in titles, author lyrics etc">
<i id="filter-fulltext-show" class="fa fa-search"> </i>
@endif
</span>

12 changes: 8 additions & 4 deletions resources/views/cspot/songs.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@
</span>
@endif

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


<center>Page {{ $songs->currentPage() }} of {{ $songs->lastPage() }}</center>
<center>
Page {{ $songs->currentPage() }} of {{ $songs->lastPage() }}<br>
<small>showing a total of {{ $songs->total() }} songs</small>
</center>


@if (count($songs))

<center><small>(Total: {{ $songs->total() }} Songs)</small></center>

<table class="table table-striped table-bordered
@if(count($songs)>15)
table-sm
Expand Down

0 comments on commit 0c29b8b

Please sign in to comment.