Added search

This commit is contained in:
Dan Brown 2015-07-16 19:53:24 +01:00
parent 787ad20ce7
commit 4c0783fdc7
8 changed files with 82 additions and 9 deletions

View File

@ -132,6 +132,15 @@ class PageController extends Controller
return redirect($page->getUrl());
}
public function searchAll(Request $request)
{
$searchTerm = $request->get('term');
if(empty($searchTerm)) return redirect()->back();
$pages = $this->pageRepo->getBySearch($searchTerm);
return view('pages/search-results', ['pages' => $pages, 'searchTerm' => $searchTerm]);
}
/**
* Remove the specified resource from storage.
*

View File

@ -36,6 +36,7 @@ Route::get('/images/all/{page}', 'ImageController@getAll');
Route::get('/images/{any}', 'ImageController@getImage')->where('any', '.*');
Route::get('/link/{id}', 'PageController@redirectFromLink');
Route::get('/pages/search/all', 'PageController@searchAll');
Route::get('/', function () {
return view('base');

View File

@ -49,4 +49,14 @@ class PageRepo
$page->delete();
}
public function getBySearch($term)
{
$terms = explode(' ', trim($term));
$query = $this->page;
foreach($terms as $term) {
$query = $query->where('text', 'like', '%'.$term.'%');
}
return $query->get();
}
}

View File

@ -1,9 +1,8 @@
.input-base {
background-color: #FFF;
border-radius: 2px;
border: 1px solid #BBB;
border-top: 1px solid #AAA;
border-radius: 3px;
border: 1px solid #CCC;
display: inline-block;
font-size: $fs-s;
font-family: $text;

View File

@ -164,6 +164,14 @@ p.secondary, p .secondary, span.secondary, .text-secondary {
color: $secondary;
}
/*
* Lists
*/
ul {
list-style: disc;
margin-left: $-m;
}
/*
* Generic text styling classes
*/

View File

@ -29,9 +29,10 @@ header hr {
header .menu {
margin-bottom: 0;
list-style: none;
margin-left: 0;
li {
display: inline-block;
margin-left: $-m;
margin-right: $-m;
}
}

View File

@ -16,6 +16,11 @@
}, 800); // Adjust to change animations speed (ms)
return this;
};
$.expr[":"].contains = $.expr.createPseudo(function(arg) {
return function( elem ) {
return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
};
});
</script>
@yield('head')
</head>
@ -23,11 +28,21 @@
<header>
<div class="container">
<div class="padded-vertical clearfix">
<div class="logo float left">Oxbow</div>
<ul class="menu float right">
<li><a href="/books"><i class="fa fa-book"></i>Books</a></li>
</ul>
<div class="padded-vertical row clearfix">
<div class="col-md-3">
<div class="logo float left">Oxbow</div>
</div>
<div class="col-md-9">
<ul class="menu float">
<li><a href="/books"><i class="fa fa-book"></i>Books</a></li>
</ul>
<div class="search-box float right">
<form action="/pages/search/all" id="search-form" method="GET">
{!! csrf_field() !!}
<input type="text" placeholder="Search all pages..." name="term" id="search-input">
</form>
</div>
</div>
</div>
</div>
</header>

View File

@ -0,0 +1,30 @@
@extends('base')
@section('content')
<div class="row">
<div class="col-md-3 page-menu">
</div>
<div class="col-md-9 page-content">
<h1>Search Results <span class="subheader">For '{{$searchTerm}}'</span></h1>
<div class="page-list">
@if(count($pages) > 0)
@foreach($pages as $page)
<a href="{{$page->getUrl() . '#' . $searchTerm}}">{{$page->name}}</a>
@endforeach
@else
<p class="text-muted">No pages matched this search</p>
@endif
</div>
</div>
</div>
@stop