diff --git a/skolehjem/app/Http/Controllers/WashingReservationController.php b/skolehjem/app/Http/Controllers/WashingReservationController.php index d363c54..49db808 100644 --- a/skolehjem/app/Http/Controllers/WashingReservationController.php +++ b/skolehjem/app/Http/Controllers/WashingReservationController.php @@ -11,6 +11,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Response; use App\WashingReservation; +use Illuminate\Support\Facades\DB; use Illuminate\View\View; class WashingReservationController extends Controller @@ -175,5 +176,66 @@ class WashingReservationController extends Controller return Response($output); } } + + + + + function search(Request $request){ + if($request->ajax()){ + $output = "<tr>". + "<th>Vaskemaskine</th>". + "<th>Tidspunkt</th>". + "<th>Bruger</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>"; + + + //Kan ikke søge på vaskemaskine da det er en foreign key + + //filter search + if($request->isCheck === "vaskemaskine") + $users = WashingReservation::query()->where('machine_id', 'LIKE',$request->search.'%')->get(); + elseif ($request->isCheck === "tidspunkt") + $users = WashingReservation::query()->where('time', 'LIKE',$request->search.'%')->get(); + else + $users = WashingReservation::query()->where('time', 'LIKE',$request->search.'%') + ->orWhere('machine','LIKE', $request->search.'%') + ->get(); + + + + if(count($users) !== 0){ + foreach ($users as $key => $user){ + $output.='<tr>'. + '<td>' . WashingMachine::query()->find($user->machine_id)->name . '</td>'. + '<td>' . $user->time . '</td>'. + '<td>' . ucfirst(User::query()->find($user->user_id)->name_first) . ' ' . ucfirst(User::query()->find($user->user_id)->name_last) . '</td>'. + '<td><a href="'. route("washing-reservations.edit", [ "washing_reservation" => $user->id ]) . '"><img class="w-100" src="'. asset('/images/icons/pencil-dark.svg') . '" alt="Update"></a></td>'. + '<td><form method="post" action="' .route("washing-reservations.destroy", [ "washing_reservation" => $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>'; + } + }else{ + $output.='<tr>'. + '<td>Intet match</td>'. + '<td></td>'. + '<td></td>'. + '<td></td>'. + '<td></td>'. + '</tr>'; + } + return Response($output); + } + } + + + + } diff --git a/skolehjem/resources/views/admin/washing-reservations/index.blade.php b/skolehjem/resources/views/admin/washing-reservations/index.blade.php index 133524d..587abea 100644 --- a/skolehjem/resources/views/admin/washing-reservations/index.blade.php +++ b/skolehjem/resources/views/admin/washing-reservations/index.blade.php @@ -13,11 +13,20 @@ <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") }}"> + <form method="post" action="{{ route("washing-reservations.store") }}"> @csrf <input type="text" class="form-controller" id="search" name="search" placeholder="Søg på Navn, Telefon"></input> </form> + + <input class="checkbox-inline" type="checkbox" name="checkbox" id="vaskemaskine" value="vaskemaskine"> + <label for="navn">Vaskemaskine</label> + <input class="checkbox-inline" type="checkbox" name="checkbox" id="tidspunkt" value="tidspunkt"> + <label for="efternavn">Tispunkt</label> + <input class="checkbox-inline" type="checkbox" name="checkbox" id="bruger" value="bruger"> + <label for="email">Bruger</label> + + </div> <table class="tbl mt-2"> <tr> @@ -45,4 +54,45 @@ </table> {{ $reservations->links() }} + + + <script> + $('#search').on('keyup', function () { + $value = $(this).val(); + $checkboxValue = $( "input:checked" ).val(); + $.ajax({ + type: 'get', + url: '{{route('washing-reservations.search')}}', + data: {'search':$value, 'isCheck': $checkboxValue}, + success:function (data) { + console.log($checkboxValue); + $('tbody').html(data); + }, + error:function (data) { + console.log(data); + } + }); + }) + </script> + + + + <script> + $(document).ready(function(){ + $("input:checkbox").on('click', function() { + var $box = $(this); + if ($box.is(":checked")) { + var group = "input:checkbox[name='" + $box.attr("name") + "']"; + $(group).prop("checked", false); + $box.prop("checked", true); + } else { + $box.prop("checked", false); + } + }); + }); + </script> + + + + @endsection diff --git a/skolehjem/routes/web.php b/skolehjem/routes/web.php index 2f66d27..74380a5 100644 --- a/skolehjem/routes/web.php +++ b/skolehjem/routes/web.php @@ -36,6 +36,7 @@ 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::get("/vaskeapi", "WashingReservationController@search")->name("washing-reservations.search"); Route::get("/washing-reservationsapi", "WashingReservationController@api")->name("washing-reservations.api");