From 4c0783fdc7ecd64d78426b3cd06134f6e3375704 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Thu, 16 Jul 2015 19:53:24 +0100 Subject: [PATCH] Added search --- app/Http/Controllers/PageController.php | 9 ++++++ app/Http/routes.php | 1 + app/Repos/PageRepo.php | 10 +++++++ resources/assets/sass/_forms.scss | 5 ++-- resources/assets/sass/_text.scss | 8 +++++ resources/assets/sass/styles.scss | 3 +- resources/views/base.blade.php | 25 ++++++++++++---- .../views/pages/search-results.blade.php | 30 +++++++++++++++++++ 8 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 resources/views/pages/search-results.blade.php diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index 0a9f11844..57901573b 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -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. * diff --git a/app/Http/routes.php b/app/Http/routes.php index 52394c564..c190da616 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -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'); diff --git a/app/Repos/PageRepo.php b/app/Repos/PageRepo.php index 62fbe9d8f..a62907472 100644 --- a/app/Repos/PageRepo.php +++ b/app/Repos/PageRepo.php @@ -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(); + } + } \ No newline at end of file diff --git a/resources/assets/sass/_forms.scss b/resources/assets/sass/_forms.scss index 37e03c3cf..861cfbb9f 100644 --- a/resources/assets/sass/_forms.scss +++ b/resources/assets/sass/_forms.scss @@ -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; diff --git a/resources/assets/sass/_text.scss b/resources/assets/sass/_text.scss index 584b12b5b..7c8e025dd 100644 --- a/resources/assets/sass/_text.scss +++ b/resources/assets/sass/_text.scss @@ -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 */ diff --git a/resources/assets/sass/styles.scss b/resources/assets/sass/styles.scss index 853e98454..9dc65cb8d 100644 --- a/resources/assets/sass/styles.scss +++ b/resources/assets/sass/styles.scss @@ -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; } } diff --git a/resources/views/base.blade.php b/resources/views/base.blade.php index e61944e37..6345de2b4 100644 --- a/resources/views/base.blade.php +++ b/resources/views/base.blade.php @@ -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; + }; + }); @yield('head') @@ -23,11 +28,21 @@
-
- - +
+
+ +
+
+ + +
diff --git a/resources/views/pages/search-results.blade.php b/resources/views/pages/search-results.blade.php new file mode 100644 index 000000000..cf3066d70 --- /dev/null +++ b/resources/views/pages/search-results.blade.php @@ -0,0 +1,30 @@ +@extends('base') + +@section('content') + + +
+ + + +
+

Search Results For '{{$searchTerm}}'

+
+ @if(count($pages) > 0) + @foreach($pages as $page) + {{$page->name}} + @endforeach + @else +

No pages matched this search

+ @endif +
+
+ +
+ + + + +@stop \ No newline at end of file