Added search
This commit is contained in:
		
							parent
							
								
									787ad20ce7
								
							
						
					
					
						commit
						4c0783fdc7
					
				| 
						 | 
					@ -132,6 +132,15 @@ class PageController extends Controller
 | 
				
			||||||
        return redirect($page->getUrl());
 | 
					        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.
 | 
					     * Remove the specified resource from storage.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,6 +36,7 @@ Route::get('/images/all/{page}', 'ImageController@getAll');
 | 
				
			||||||
Route::get('/images/{any}', 'ImageController@getImage')->where('any', '.*');
 | 
					Route::get('/images/{any}', 'ImageController@getImage')->where('any', '.*');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Route::get('/link/{id}', 'PageController@redirectFromLink');
 | 
					Route::get('/link/{id}', 'PageController@redirectFromLink');
 | 
				
			||||||
 | 
					Route::get('/pages/search/all', 'PageController@searchAll');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Route::get('/', function () {
 | 
					Route::get('/', function () {
 | 
				
			||||||
    return view('base');
 | 
					    return view('base');
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,4 +49,14 @@ class PageRepo
 | 
				
			||||||
        $page->delete();
 | 
					        $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();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,8 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.input-base {
 | 
					.input-base {
 | 
				
			||||||
  background-color: #FFF;
 | 
					  background-color: #FFF;
 | 
				
			||||||
  border-radius: 2px;
 | 
					  border-radius: 3px;
 | 
				
			||||||
  border: 1px solid #BBB;
 | 
					  border: 1px solid #CCC;
 | 
				
			||||||
  border-top: 1px solid #AAA;
 | 
					 | 
				
			||||||
  display: inline-block;
 | 
					  display: inline-block;
 | 
				
			||||||
  font-size: $fs-s;
 | 
					  font-size: $fs-s;
 | 
				
			||||||
  font-family: $text;
 | 
					  font-family: $text;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -164,6 +164,14 @@ p.secondary, p .secondary, span.secondary, .text-secondary {
 | 
				
			||||||
	color: $secondary;
 | 
						color: $secondary;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Lists
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					ul {
 | 
				
			||||||
 | 
					  list-style: disc;
 | 
				
			||||||
 | 
					  margin-left: $-m;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Generic text styling classes
 | 
					 * Generic text styling classes
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,9 +29,10 @@ header hr {
 | 
				
			||||||
header .menu {
 | 
					header .menu {
 | 
				
			||||||
  margin-bottom: 0;
 | 
					  margin-bottom: 0;
 | 
				
			||||||
  list-style: none;
 | 
					  list-style: none;
 | 
				
			||||||
 | 
					  margin-left: 0;
 | 
				
			||||||
  li {
 | 
					  li {
 | 
				
			||||||
    display: inline-block;
 | 
					    display: inline-block;
 | 
				
			||||||
    margin-left: $-m;
 | 
					    margin-right: $-m;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,6 +16,11 @@
 | 
				
			||||||
            }, 800); // Adjust to change animations speed (ms)
 | 
					            }, 800); // Adjust to change animations speed (ms)
 | 
				
			||||||
            return this;
 | 
					            return this;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					        $.expr[":"].contains = $.expr.createPseudo(function(arg) {
 | 
				
			||||||
 | 
					            return function( elem ) {
 | 
				
			||||||
 | 
					                return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    </script>
 | 
					    </script>
 | 
				
			||||||
    @yield('head')
 | 
					    @yield('head')
 | 
				
			||||||
</head>
 | 
					</head>
 | 
				
			||||||
| 
						 | 
					@ -23,11 +28,21 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <header>
 | 
					    <header>
 | 
				
			||||||
        <div class="container">
 | 
					        <div class="container">
 | 
				
			||||||
            <div class="padded-vertical clearfix">
 | 
					            <div class="padded-vertical row clearfix">
 | 
				
			||||||
 | 
					                <div class="col-md-3">
 | 
				
			||||||
                    <div class="logo float left">Oxbow</div>
 | 
					                    <div class="logo float left">Oxbow</div>
 | 
				
			||||||
                <ul class="menu float right">
 | 
					                </div>
 | 
				
			||||||
 | 
					                <div class="col-md-9">
 | 
				
			||||||
 | 
					                    <ul class="menu float">
 | 
				
			||||||
                        <li><a href="/books"><i class="fa fa-book"></i>Books</a></li>
 | 
					                        <li><a href="/books"><i class="fa fa-book"></i>Books</a></li>
 | 
				
			||||||
                    </ul>
 | 
					                    </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>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
    </header>
 | 
					    </header>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
				
			||||||
		Loading…
	
		Reference in New Issue