Made Live search is done

This commit is contained in:
victor 2020-07-27 16:03:49 +02:00
parent f1fb73beec
commit b9633d36a9
12 changed files with 296 additions and 5 deletions

View File

@ -168,8 +168,6 @@ class ContactController extends Controller
'</td>'.
'</tr>';
}
}else{
$output.= "</tbody></table><h1>Der er ingen resultater...</h1>";
}
return Response($output);
}

View File

@ -6,6 +6,7 @@ use App\Event;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
class EventController extends Controller
@ -130,4 +131,44 @@ class EventController extends Controller
$event->delete();
return redirect()->route("events.index");
}
public function search(Request $request){
if($request->ajax()){
$output = "<tr>".
"<th>Event Navn</th>".
"<th>Event Beskrivelse</th>".
"<th>Event Dato</th>".
"<th style=\"width: 1em;\"><img class=\"w-100\" src=\"http://127.0.0.1:8000/images/icons/pencil.svg\" alt=\"Update\"></th>".
"<th style=\"width: 1em;\"><img class=\"w-100\" src=\"http://127.0.0.1:8000/images/icons/trashcan.svg\" alt=\"Delete\"></th>".
"</tr>";
$events = DB::table('events')->where('name', 'LIKE',$request->search.'%')
->orWhere('date','LIKE', $request->search.'%')
->get();
if(count($events) !== 0){
foreach ($events as $key => $event){
$output.='<tr>'.
'<td>' . $event->name . '</td>'.
'<td>' . $event->description .'</td>'.
'<td>' . $event->date .'</td>'.
'<td><a href="'. route("events.edit", [ "event" => $event->id ]) . '"><img class="w-100" src="'. asset('/images/icons/pencil-dark.svg') . '" alt="Update"></a></td>'.
'<td><form method="post" action="' .route("events.destroy", [ "event" => $event->id ]). '" class="w-100 nostyle">'.
csrf_field().
method_field("delete").
'<button class="w-100 nostyle" onclick="return confirm(\'Are you sure you want to delete?\');" type="submit"><img class="w-100 cursor-pointer" src="'. asset('/images/icons/trashcan-dark.svg') . '" alt="Delete"></button>'.
'</form>'.
'</td>'.
'</tr>';
}
}
return Response($output);
}
}
}

View File

@ -6,6 +6,7 @@ use App\ExternalLink;
use App\MenuPlan;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
class MenuPlanController extends Controller
@ -130,4 +131,43 @@ class MenuPlanController extends Controller
$menuplan->delete();
return redirect()->route("menu-plans.index");
}
public function search(Request $request){
if($request->ajax()){
$output = "<tr>".
"<th>Uge</th>".
"<th>Mandag</th>".
"<th>Tirsdag</th>".
"<th>Onsdag</th>".
"<th>Torsdag</th>".
"<th style=\"width: 1em;\"><img class=\"w-100\" src=\"http://127.0.0.1:8000/images/icons/pencil.svg\" alt=\"Update\"></th>".
"<th style=\"width: 1em;\"><img class=\"w-100\" src=\"http://127.0.0.1:8000/images/icons/trashcan.svg\" alt=\"Delete\"></th>".
"</tr>";
$menuplans = DB::table('menu_plans')->where('week', 'LIKE',$request->search.'%')->get();
if(count($menuplans) !== 0){
foreach ($menuplans as $key => $menuplan){
$output.='<tr>'.
'<td>' . $menuplan->week . '</td>'.
'<td>' . $menuplan->monday . '</td>'.
'<td>' . $menuplan->tuesday . '</td>'.
'<td>' . $menuplan->wednesday .'</td>'.
'<td>' . $menuplan->thursday .'</td>'.
'<td><a href="'. route("menu-plans.edit", [ "menu_plan" => $menuplan->id ]) . '"><img class="w-100" src="'. asset('/images/icons/pencil-dark.svg') . '" alt="Update"></a></td>'.
'<td><form method="post" action="' .route("menu-plans.destroy", [ "menu_plan" => $menuplan->id ]). '" class="w-100 nostyle">'.
csrf_field().
method_field("delete").
'<button class="w-100 nostyle" onclick="return confirm(\'Are you sure you want to delete?\');" type="submit"><img class="w-100 cursor-pointer" src="'. asset('/images/icons/trashcan-dark.svg') . '" alt="Delete"></button>'.
'</form>'.
'</td>'.
'</tr>';
}
}
return Response($output);
}
}
}

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
use Spatie\Permission\Models\Role;
class rolesController extends Controller
@ -115,4 +116,38 @@ class rolesController extends Controller
$role->delete();
return redirect()->route("roles.index");
}
public function search(Request $request){
if($request->ajax()){
$output = "<tr>".
"<th>Navn</th>".
"<th>Beskrivelse</th>".
"<th style=\"width: 1em;\"><img class=\"w-100\" src=\"http://127.0.0.1:8000/images/icons/pencil.svg\" alt=\"Update\"></th>".
"<th style=\"width: 1em;\"><img class=\"w-100\" src=\"http://127.0.0.1:8000/images/icons/trashcan.svg\" alt=\"Delete\"></th>".
"</tr>";
$roles = DB::table('roles')->where('name', 'LIKE',$request->search.'%')->get();
if(count($roles) !== 0){
foreach ($roles as $key => $role){
$output.='<tr>'.
'<td>' . $role->name . '</td>'.
'<td>' . $role->description . '</td>'.
'<td><a href="'. route("roles.edit", [ "role" => $role->id ]) . '"><img class="w-100" src="'. asset('/images/icons/pencil-dark.svg') . '" alt="Update"></a></td>'.
'<td><form method="post" action="' .route("roles.destroy", [ "role" => $role->id ]). '" class="w-100 nostyle">'.
csrf_field().
method_field("delete").
'<button class="w-100 nostyle" onclick="return confirm(\'Are you sure you want to delete?\');" type="submit"><img class="w-100 cursor-pointer" src="'. asset('/images/icons/trashcan-dark.svg') . '" alt="Delete"></button>'.
'</form>'.
'</td>'.
'</tr>';
}
}
return Response($output);
}
}
}

View File

@ -256,4 +256,58 @@ class UserController extends Controller
}
public function search(Request $request){
if($request->ajax()){
$output = "<tr>".
"<th>Fornavn</th>".
"<th>Efternavn</th>".
"<th>Email</th>".
"<th>Tlf nr</th>".
"<th>Rolle(r)</th>".
"<th style=\"width: 1em;\"><img class=\"w-100\" src=\"http://127.0.0.1:8000/images/icons/pencil.svg\" alt=\"Update\"></th>".
"<th style=\"width: 1em;\"><img class=\"w-100\" src=\"http://127.0.0.1:8000/images/icons/trashcan.svg\" alt=\"Delete\"></th>".
"</tr>";
$users = DB::table('users')->where('name_first', 'LIKE',$request->search.'%')
->orWhere('name_last','LIKE', $request->search.'%')
->orWhere('phone','LIKE', $request->search.'%')
->orWhere('email','LIKE',$request->search. '%')->get();
if(count($users) !== 0){
foreach ($users as $key => $user){
$roles = null;
$rolesString = null;
foreach (User::all() as $usr) {
if($usr->id == $user->id)
$roles = $usr->roles;
}
for($i = 0; $i < count($roles); $i++) {
if(count($roles)-1 != $i) {
$rolesString .= $roles[$i]->name.",";
}else {
$rolesString = $roles[$i]->name;
}
}
$output.='<tr>'.
'<td>' . $user->name_first . '</td>'.
'<td>' . $user->name_last . '</td>'.
'<td>' . $user->email . '</td>'.
'<td>' . $user->phone .'</td>'.
'<td>' . $rolesString .'</td>'.
'<td><a href="'. route("users.edit", [ "user" => $user->id ]) . '"><img class="w-100" src="'. asset('/images/icons/pencil-dark.svg') . '" alt="Update"></a></td>'.
'<td><form method="post" action="' .route("users.destroy", [ "user" => $user->id ]). '" class="w-100 nostyle">'.
csrf_field().
method_field("delete").
'<button class="w-100 nostyle" onclick="return confirm(\'Are you sure you want to delete?\');" type="submit"><img class="w-100 cursor-pointer" src="'. asset('/images/icons/trashcan-dark.svg') . '" alt="Delete"></button>'.
'</form>'.
'</td>'.
'</tr>';
}
}
return Response($output);
}
}
}

View File

@ -16,7 +16,7 @@
<form method="post" action="{{ route("users.store") }}">
@csrf
<input type="text" class="form-controller" id="search" name="search" placeholder="Søg på navn,email,telefon"></input>
<input type="text" class="form-controller" id="search" name="search" placeholder="Søg på Navn, Email, Telefon"></input>
</form>
@ -50,7 +50,6 @@
<script>
$('#search').on('keyup', function () {
//alert('Test');
$value = $(this).val();
$.ajax({
type: 'get',
@ -58,7 +57,6 @@
data: {'search':$value},
success:function (data) {
$('tbody').html(data);
console.log(data)
},
error:function (data) {
console.log(data);

View File

@ -10,8 +10,15 @@
@endsection
@section("content")
<script src="http://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<div class="row align-items-center">
<a class="btn btn-inline btn-sde-blue mb-0" href="{{ route('events.create') }}"><img src="{{ asset('/images/icons/plus.svg') }}" alt="Create">Opret Event</a>
<form method="post" action="{{ route("events.store") }}">
@csrf
<input type="text" class="form-controller" id="search" name="search" placeholder="Søg på Evt Navn, Evt Dato"></input>
</form>
</div>
<table class="tbl mt-2">
<tr>
@ -40,4 +47,24 @@
{{ $events->links() }}
<script>
$('#search').on('keyup', function () {
$value = $(this).val();
$.ajax({
type: 'get',
url: '{{route('events.search')}}',
data: {'search':$value},
success:function (data) {
$('tbody').html(data);
console.log(data);
},
error:function (data) {
console.log(data);
}
});
})
</script>
@endsection

View File

@ -10,8 +10,15 @@
@endsection
@section("content")
<script src="http://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<div class="row align-items-center">
<a class="btn btn-inline btn-sde-blue mb-0" href="{{ route('menu-plans.create') }}"><img src="{{ asset('/images/icons/plus.svg') }}" alt="Create">Opret Menuplan</a>
<form method="post" action="{{ route("menu-plans.store") }}">
@csrf
<input type="number" class="form-controller" id="search" name="search" pattern="[0-9]{2}" placeholder="Søg efter ugenummer"></input>
</form>
</div>
<table class="tbl mt-2">
<tr>
@ -43,4 +50,24 @@
</table>
{{ $menuPlans->links() }}
<script>
$('#search').on('keyup', function () {
$value = $(this).val();
$.ajax({
type: 'get',
url: '{{route('menu-plans.search')}}',
data: {'search':$value},
success:function (data) {
$('tbody').html(data);
},
error:function (data) {
console.log(data);
}
});
})
</script>
@endsection

View File

@ -10,8 +10,16 @@
@endsection
@section("content")
<script src="http://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<div class="row align-items-center">
<a class="btn btn-inline btn-sde-blue mb-0" href="{{ route('roles.create') }}"><img src="{{ asset('/images/icons/plus.svg') }}" alt="Create">Opret Rolle</a>
<form method="post" action="{{ route("roles.store") }}">
@csrf
<input type="text" class="form-controller" id="search" name="search" placeholder="Søg efter navn"></input>
</form>
</div>
<table class="tbl mt-2">
<tr>
@ -35,4 +43,26 @@
</tr>
@endforeach
</table>
<script>
$('#search').on('keyup', function () {
$value = $(this).val();
$.ajax({
type: 'get',
url: '{{route('roles.search')}}',
data: {'search':$value},
success:function (data) {
$('tbody').html(data);
console.log(data);
},
error:function (data) {
console.log(data);
}
});
})
</script>
@endsection

View File

@ -10,11 +10,17 @@
@endsection
@section("content")
<script src="http://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<div class="row align-items-center">
<a class="btn btn-inline btn-sde-blue mb-0" href="{{ route('users.create') }}"><img src="{{ asset('/images/icons/plus.svg') }}" alt="Create">Opret Bruger</a>
<form method="post" action="{{ route("users.store") }}">
@csrf
<input type="text" class="form-controller" id="search" name="search" placeholder="Søg efter navn"></input>
</form>
</div>
<table class="tbl mt-2">
<tr>
@ -54,4 +60,26 @@
@endforeach
</table>
{{ $users->links() }}
<script>
$('#search').on('keyup', function () {
$value = $(this).val();
$.ajax({
type: 'get',
url: '{{route('users.search')}}',
data: {'search':$value},
success:function (data) {
$('tbody').html(data);
console.log(data);
},
error:function (data) {
console.log(data);
}
});
})
</script>
@endsection

View File

@ -12,6 +12,12 @@
@section("content")
<div class="row align-items-center">
<a class="btn btn-inline btn-sde-blue mb-0" href="{{ route('washing-reservations.create') }}"><img src="{{ asset('/images/icons/plus.svg') }}" alt="Create">Opret Reservation</a>
<form method="post" action="{{ route("users.store") }}">
@csrf
<input type="text" class="form-controller" id="search" name="search" placeholder="Søg på Navn, Telefon"></input>
</form>
</div>
<table class="tbl mt-2">
<tr>

View File

@ -31,6 +31,13 @@ Route::get("/account/editpass", "UserController@accounteditpass")->name("users.a
Route::post("/account/update", "UserController@update")->name("users.accountupdate");
Route::get("phones", "PhoneController@index")->name("phones.index");
Route::get("/contactsapi", "ContactController@search")->name("contacts.search");
Route::get("/eventsapi", "EventController@search")->name("events.search");
Route::get("/menuplansapi", "MenuPlanController@search")->name("menu-plans.search");
Route::get("/rolesapi", "RolesController@search")->name("roles.search");
Route::get("/userapi", "UserController@search")->name("users.search");
Route::resource("contacts", "ContactController");
Route::resource("menu-plans", "MenuPlanController");