v0.10.12a - Made filter for washing machines done

This commit is contained in:
Neerholt 2020-08-21 10:54:00 +02:00
parent e35c8ae491
commit 522cf9cdf7
2 changed files with 60 additions and 29 deletions

View File

@ -7,6 +7,8 @@ use App\WashingMachine;
use App\WashingReservation;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
use function GuzzleHttp\Promise\all;
class LocationController extends Controller
{
@ -176,23 +178,20 @@ class LocationController extends Controller
"<th style=\"width: 1em;\"><img class=\"w-100\" src=\"http://127.0.0.1:8000/images/icons/trashcan.svg\" alt=\"Delete\"></th>".
"</tr>";
if($request) {
$locations = Location::query()->orderBy('created_at', 'desc')->where('name', '=', $request->option)->get();
//$machines = WashingMachine::query()->where('created_at', '=', $locations->created_at)->get();
}
elseif($request->option == "all"){
$locations = Location::all();
}
if($request->option !== 'all') {
$locations = DB::table('washing_machines')
->join('locations', 'washing_machines.location_id','=', 'locations.id')
->select(DB::raw('washing_machines.name as washing_name, locations.name as location_name, locations.id as id'))
->where('locations.id', '=', $request->option)
->get();
if(count($locations) !== 0){
foreach ($locations as $key => $location){
$output.='<tr>'.
//'<td>' . $location->name . '</td>'.
'<td><p>Test data</p></td>'.
'<td>' . $location->name . '</td>'.
'<td><form method="post" action="' .route("locations.destroy", [ "location" => $location ]). '" class="w-100 nostyle">'.
'<td><form method="post" action="' .route("locations.edit", [ "location" => $location ]). '" class="w-100 nostyle">'.
'<td>' . $location->washing_name . '</td>'.
'<td>' . $location->location_name . '</td>'.
'<td><form method="post" action="' .route("locations.destroy", [ "location" => $location->id ]). '" class="w-100 nostyle">'.
'<td><form method="post" action="' .route("locations.edit", [ "location" => $location->id ]). '" class="w-100 nostyle">'.
csrf_field().
method_field("delete").
@ -209,6 +208,37 @@ class LocationController extends Controller
'<td></td>'.
'</tr>';
}
}
elseif($request->option === "all"){
$machines = WashingMachine::all();
if(count($machines) !== 0){
foreach($machines as $machine) {
$output.= '<tr>'.
'<td>'.$machine->name.'</td>'.
'<td>'.Location::query()->where("id", "=", $machine->location_id)->first()->name.'</td>'.
'<td><a href="'. route("washing-machines.edit", [ "washing_machine" => $machine->id]) . '"><img class="w-100" src="'. asset('/images/icons/pencil-dark.svg') . '" alt="Update"></a></td>'.
'<td><form method="post" action="'. route('washing-machines.destroy', [ 'washing_machine' => $machine->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>Det er ikke blivet oprettet nogen vaskmaskine på denne lokation i nu</td>'.
'<td></td>'.
'<td></td>'.
'<td></td>'.
'</tr>';
}
}
return Response($output);
}
}

View File

@ -16,7 +16,7 @@
<select name="risRosName" id="locationID">
<option selected="selected" name="all" value="all">Alle</option>
@foreach(\App\Location::query()->get() as $location)
<option value="{{$location->name}}">{{$location->name}}</option>
<option value="{{$location->id}}">{{$location->name}}</option>
@endforeach
</select> <label>Vælg bygning</label>
</div>
@ -46,12 +46,13 @@
<script>
$('#locationID').change(function () {
$value = $('#locationID').find(":selected").val();
// alert($value);
console.log($value);
$.ajax({
type: 'get',
url: '{{route('locations.search')}}',
data: {'option':$value},
success:function (data) {
console.log($value);
$('tbody').html(data);
},
error:function (data) {