Added search

This commit is contained in:
Deon George 2021-06-27 00:34:15 +10:00
parent 945afbfe4b
commit dfc4e305f1
7 changed files with 154 additions and 2 deletions

View File

@ -3,9 +3,10 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use App\Models\{Domain,Setup}; use App\Models\{Address,Domain,Setup};
class HomeController extends Controller class HomeController extends Controller
{ {
@ -26,6 +27,34 @@ class HomeController extends Controller
->with('user',Auth::user()); ->with('user',Auth::user());
} }
public function search(Request $request): Collection
{
$this->middleware('auth');
$result = collect();
list($zone_id,$host_id,$node_id,$point_id,$domain) = sscanf($request->query('term'),'%d:%d/%d.%d@%s');
# Look for Opportunities
foreach (Address::select(['domain_id','addresses.zone_id','host_id','node_id','point_id','addresses.system_id'])
->join('systems',['systems.id'=>'addresses.system_id'])
->join('zones',['zones.id'=>'addresses.zone_id'])
->when($zone_id,function($q,$zone_id) { return $q->where('zones.zone_id','ilike','%'.$zone_id.'%'); })
->when($host_id,function($q,$host_id) { return $q->where('host_id','ilike','%'.$host_id.'%'); })
->when($node_id,function($q,$node_id) { return $q->where('node_id','ilike','%'.$node_id.'%'); })
->orWhere('systems.name','ilike','%'.$request->query('term').'%')
->orWhere('systems.sysop','ilike','%'.$request->query('term').'%')
->limit(10)
->OrderBy('systems.name')
->with(['system'])
->get() as $o)
{
$result->push(['name'=>sprintf('%s (%s)',$o->system->name,$o->ftn),'value'=>url('ftn/system/addedit',[$o->system_id]),'category'=>'Systems']);
}
return $result;
}
/** /**
* System Setup * System Setup
* *

View File

@ -197,6 +197,24 @@ sup:after {
#nav-menu ul li a:focus span:after { #nav-menu ul li a:focus span:after {
color:#aaa color:#aaa
} }
div#search_results ul {
color:#eeeeee;
background-color:#292929;
font-size: .85rem;
}
div#search_results ul li.dropdown-header {
display: block;
color: #fff !important;
padding: 5px 0 5px 5px !important;
}
div#search_results ul li,
div#search_results ul li a {
display: block;
color: #aaa !important;
margin: 2px 0 2px 0 !important;
border: 0 !important;
width: inherit;
}
a.thispage, a.thispage,
a.thispage:hover { a.thispage:hover {
@ -215,6 +233,25 @@ a.thispage span:after {
ul#navlist-desktop { ul#navlist-desktop {
position: absolute; position: absolute;
} }
ul#searchbar li {
margin: 7px;
}
ul#searchbar li input {
padding-top: 8px;
padding-bottom: 7px;
background-color: #2e2e2e;
color: #222222;
border: 1px dashed #aaa;
}
ul#searchbar li input:focus {
background-color: #eee;
color: #000;
border: 1px solid #aaa;
}
ul#searchbar li i {
left: -1.5em;
position:relative
}
#sidebar { #sidebar {
position:absolute; position:absolute;

File diff suppressed because one or more lines are too long

View File

@ -5,6 +5,9 @@
<!-- JavaScript Bundle with Popper --> <!-- JavaScript Bundle with Popper -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
<!-- Additional Utilities -->
<script src="{{ asset('plugin/bootstrap3-typeahead/bootstrap3-typeahead.min.js') }}"></script>
<script type="text/javascript"> <script type="text/javascript">
// Example starter JavaScript for disabling form submissions if there are invalid fields // Example starter JavaScript for disabling form submissions if there are invalid fields
(function () { (function () {

View File

@ -23,6 +23,12 @@
@endguest @endguest
</ul> </ul>
@auth
<ul class="float-end" id="searchbar">
<li><input type="text" id="q" name="search" placeholder="Search..."><i class="bi bi-search"></i><div id="search_results"></div></li>
</ul>
@endauth
{{-- {{--
<div id="fontwidget"> <div id="fontwidget">
<span id="row1"> <span id="row1">
@ -72,3 +78,78 @@
@include('layouts.partials.sidebar') @include('layouts.partials.sidebar')
</div> </div>
</div> </div>
@section('page-scripts')
<style>
/* Solid border */
div.typeahead.dropdown-menu > .dropdown-header {
color: #000000;
text-align: left;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$("input[id=q]").typeahead({
autoSelect: false,
scrollHeight: 10,
theme: 'bootstrap5',
delay: 500,
minLength: 2,
items: {{ $search_limit ?? 100 }},
fitToElement: false,
selectOnBlur: false,
appendTo: "#search_results",
source: function (query,process) {
search('{{ url('search') }}',query,process);
},
matcher: function () { return true; },
// Disable sorting and just return the items (items should by the ajax method)
sorter: function(items) {
return items;
},
updater: function (item) {
window.parent.location.href = item.value;
},
})
.on('keyup keypress', function(event) {
var key = event.keyCode || event.which;
if (key === 13) {
event.preventDefault();
return false;
}
});
});
var c=0;
var search = _.debounce(function(url,query,process,icon){
$.ajax({
url : url,
type : 'GET',
data : 'term=' + query,
dataType : 'JSON',
async : true,
cache : false,
beforeSend : function() {
if (c++ == 0) {
$('i.bi-search').addClass('spinner-grow spinner-grow-sm');
}
},
success : function(data) {
// if json is null, means no match, won't do again.
if(data==null || (data.length===0)) return;
process(data);
},
complete : function() {
if (--c == 0) {
$('i.bi-search').removeClass('spinner-grow spinner-grow-sm');
}
}
})
}, 500);
</script>
@append

View File

@ -288,7 +288,7 @@
<tbody> <tbody>
@foreach ($o->addresses->sortBy(['region_id','host_id']) as $oo) @foreach ($o->addresses->sortBy(['region_id','host_id']) as $oo)
<tr> <tr>
<td>{{ $oo->ftn_4d }}</td> <td>{{ $oo->ftn }}</td>
<td>{{ $oo->active ? 'YES' : 'NO' }}</td> <td>{{ $oo->active ? 'YES' : 'NO' }}</td>
<td>{{ $oo->role }}</td> <td>{{ $oo->role }}</td>
</tr> </tr>

View File

@ -52,6 +52,7 @@ Route::middleware(['verified','activeuser'])->group(function () {
Route::get('network/{o}',[HomeController::class,'network']); Route::get('network/{o}',[HomeController::class,'network']);
Route::get('permissions',[HomeController::class,'permissions']); Route::get('permissions',[HomeController::class,'permissions']);
Route::get('search',[HomeController::class,'search']);
Route::middleware(['auth','can:admin'])->group(function () { Route::middleware(['auth','can:admin'])->group(function () {
Route::match(['get','post'],'setup',[HomeController::class,'setup']); Route::match(['get','post'],'setup',[HomeController::class,'setup']);