From 4b0ad949bab072a64827330e91d8291f176f001e Mon Sep 17 00:00:00 2001 From: frederikpyt Date: Thu, 6 Aug 2020 10:32:34 +0200 Subject: [PATCH] v0.5.4 - Created the "reservations in location" screen and added a location option when creating reservations. --- .../Http/Controllers/LocationController.php | 4 +- .../WashingReservationController.php | 12 +++-- .../views/admin/events/index.blade.php | 4 +- .../views/admin/locations/index.blade.php | 2 + .../views/admin/locations/show.blade.php | 40 ++++++++++++++ .../app/washing-reservations/create.blade.php | 52 +++++++++++++++++-- 6 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 skolehjem/resources/views/admin/locations/show.blade.php diff --git a/skolehjem/app/Http/Controllers/LocationController.php b/skolehjem/app/Http/Controllers/LocationController.php index d766b01..92af4c5 100644 --- a/skolehjem/app/Http/Controllers/LocationController.php +++ b/skolehjem/app/Http/Controllers/LocationController.php @@ -72,11 +72,11 @@ class LocationController extends Controller * Display the specified resource. * * @param \App\Location $location - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function show(Location $location) { - + return view("admin.locations.show", [ "location" => $location]); } /** diff --git a/skolehjem/app/Http/Controllers/WashingReservationController.php b/skolehjem/app/Http/Controllers/WashingReservationController.php index 4da0d9e..11c77a5 100644 --- a/skolehjem/app/Http/Controllers/WashingReservationController.php +++ b/skolehjem/app/Http/Controllers/WashingReservationController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Location; use App\WashingMachine; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\Factory; @@ -142,10 +143,13 @@ class WashingReservationController extends Controller $date = $request->date; $datetext = $request->datetext; - $machines = WashingMachine::all(); + if($request->location_id == 0) + $request->location_id = Location::all()->first()->id; + + $machines = WashingMachine::query()->where("location_id", "=", $request->location_id)->orderBy("name", "asc")->get(); if($request->machine_id == 0) - $request->machine_id = WashingMachine::all()->first()->id; + $request->machine_id = WashingMachine::query()->orderBy("name", "asc")->first()->id; $reservations = WashingReservation::query()->where("machine_id", "=", $request->machine_id)->where("time", "LIKE", $datetext."%")->get(); @@ -155,7 +159,9 @@ class WashingReservationController extends Controller array_push($times, $reservation->time); } - $output = json_encode(['date' => $date, 'washingmachines' => $machines, 'unavailable_times' => $times ]); + $locations = Location::query()->orderBy("name", "asc")->get(); + + $output = json_encode(['date' => $date, 'washingmachines' => $machines, 'unavailable_times' => $times, "locations" => $locations ]); return Response($output); } } diff --git a/skolehjem/resources/views/admin/events/index.blade.php b/skolehjem/resources/views/admin/events/index.blade.php index 536ef83..01a1d5a 100644 --- a/skolehjem/resources/views/admin/events/index.blade.php +++ b/skolehjem/resources/views/admin/events/index.blade.php @@ -25,7 +25,7 @@ Event Navn Event Beskrivelse Event Dato - Update + Show Update Delete @@ -34,7 +34,7 @@ {{ $event->name }} {{ $event->description }} {{ \Illuminate\Support\Facades\Date::createFromTimeStamp(strtotime($event->date))->format('d/m/Y \k\l\. H:i') }} - $event ]) }}">Update + $event ]) }}">Show $event ]) }}">Update
$event ]) }}" class="w-100 nostyle"> @csrf diff --git a/skolehjem/resources/views/admin/locations/index.blade.php b/skolehjem/resources/views/admin/locations/index.blade.php index dadae12..ac1f6af 100644 --- a/skolehjem/resources/views/admin/locations/index.blade.php +++ b/skolehjem/resources/views/admin/locations/index.blade.php @@ -16,12 +16,14 @@ + @foreach($locations as $location) +
NavnShow Update Delete
{{$location->name}} $location ]) }}">Show $location ]) }}">Update $location ]) }}" class="w-100 nostyle"> @csrf diff --git a/skolehjem/resources/views/admin/locations/show.blade.php b/skolehjem/resources/views/admin/locations/show.blade.php new file mode 100644 index 0000000..297dbc7 --- /dev/null +++ b/skolehjem/resources/views/admin/locations/show.blade.php @@ -0,0 +1,40 @@ + + + + @yield("title") + + + + + + +
+ Syddansk Erhvervsskole +

Lokation: {{ $location->name }}

+
+
+ +
+ @foreach(\App\WashingMachine::query()->where("location_id", "=", $location->id)->get() as $machine) + @foreach(\App\WashingReservation::query()->where("machine_id", "=", $machine->id)->where("time", "LIKE", date("Y-m-d"). "%")->orderBy("time", "asc")->get() as $reservation) + @if($i % 3 == 1) +
+
+ @endif +
+

{{ \App\WashingMachine::query()->find($reservation->machine_id)->name }}

+
+ Dato: {{ \Illuminate\Support\Facades\Date::createFromTimeStamp(strtotime($reservation->time))->format('d/m/Y') }} + Tid: {{ \Illuminate\Support\Facades\Date::createFromTimeStamp(strtotime($reservation->time))->format('\k\l\. H:i') }} - {{ \App\User::query()->where("id", "=", $reservation->user_id)->first()->name_first }} {{ \App\User::query()->where("id", "=", $reservation->user_id)->first()->name_last }} +
+
+ + @endforeach + @endforeach +
+
+ + +@yield("scripts") + + diff --git a/skolehjem/resources/views/app/washing-reservations/create.blade.php b/skolehjem/resources/views/app/washing-reservations/create.blade.php index 6bf7bd4..fafdc9a 100644 --- a/skolehjem/resources/views/app/washing-reservations/create.blade.php +++ b/skolehjem/resources/views/app/washing-reservations/create.blade.php @@ -97,8 +97,8 @@ } function onDateSelect(date, dayHolder, datetext) { - console.log("Opdaterer selects"); let events; + let locationz; let machinez; let buttonz; @@ -114,20 +114,47 @@ dayHolder.classList.add("selected"); let machine_id; + let location_id; if(document.getElementById('washing-machines')) machine_id = document.getElementById('washing-machines').value; else machine_id = 0; + if(document.getElementById('locations')) + location_id = document.getElementById('locations').value; + else + location_id = 0; + axios({ method: 'get', url: '{{ route("washing-reservations.api") }}', - params: { 'date': date, 'machine_id': machine_id, 'datetext': datetext } + params: { 'date': date, 'machine_id': machine_id, 'datetext': datetext, 'location_id': location_id } }).then(function (response) { - console.log(response.data["unavailable_times"]); var data = response.data; + + if(document.getElementById("locations") != undefined) + locationz = document.getElementById("locations"); + else { + let span = document.createElement("span"); + span.classList.add("events__title"); + span.innerText = "Lokation"; + + let select = document.createElement("select"); + select.classList.add("events__title"); + select.id = "locations"; + select.name = "location_id"; + + select.onchange = function() { + onDateSelect(date, dayHolder, datetext); + } + + container.appendChild(span); + container.appendChild(select); + + locationz = document.getElementById("locations"); + } if(document.getElementById("washing-machines") != undefined) machinez = document.getElementById("washing-machines"); else { @@ -180,6 +207,24 @@ buttonz = document.getElementById("events"); } + let locations = data["locations"]; + + locationz.innerHTML = ""; + locationz.onchange = function () { + onDateSelect(date, dayHolder, datetext); + } + + for (let i = 0; i < locations.length; i++) { + let option = document.createElement("option"); + option.text = locations[i]["name"]; + option.value = locations[i]["id"]; + + if(location_id == locations[i]["id"]) + option.selected = "selected"; + + locationz.appendChild(option); + } + let machines = data["washingmachines"]; machinez.innerHTML = ""; @@ -213,7 +258,6 @@ let unavailable_times = data["unavailable_times"]; unavailable_times.forEach(function (item, index) { - console.log(item); document.getElementById(item).remove(); });