diff --git a/skolehjem/app/Http/Controllers/WashingReservationController.php b/skolehjem/app/Http/Controllers/WashingReservationController.php index 050a38a..a38660c 100644 --- a/skolehjem/app/Http/Controllers/WashingReservationController.php +++ b/skolehjem/app/Http/Controllers/WashingReservationController.php @@ -164,7 +164,10 @@ class WashingReservationController extends Controller $machines = WashingMachine::all(); - $reservations = WashingReservation::query()->where("time", "LIKE", substr($date, 1, strpos($date, "T"))."%")->get(); + if($request->machine_id == 0) + $request->machine_id = WashingMachine::all()->first()->id; + + $reservations = WashingReservation::query()->where("machine_id", "=", $request->machine_id)->where("time", "LIKE", substr($date, 1, strpos($date, "T"))."%")->get(); $times = []; diff --git a/skolehjem/database/migrations/2020_06_08_080402_create_permission_tables.php b/skolehjem/database/migrations/2020_06_08_080402_create_permission_tables.php index 2ddad31..1d3d3b8 100644 --- a/skolehjem/database/migrations/2020_06_08_080402_create_permission_tables.php +++ b/skolehjem/database/migrations/2020_06_08_080402_create_permission_tables.php @@ -37,6 +37,7 @@ class CreatePermissionTables extends Migration Schema::create($tableNames['roles'], function (Blueprint $table) { $table->bigIncrements('id'); $table->string('name'); + $table->unique('name'); $table->string('description'); $table->string('guard_name'); $table->timestamps(); diff --git a/skolehjem/database/migrations/2020_06_09_081126_alter_washing_reservations.php b/skolehjem/database/migrations/2020_06_09_081126_alter_washing_reservations.php deleted file mode 100644 index d39a3bb..0000000 --- a/skolehjem/database/migrations/2020_06_09_081126_alter_washing_reservations.php +++ /dev/null @@ -1,29 +0,0 @@ -string('tuesday', 255); $table->string('wednesday', 255); $table->string('thursday', 255); + $table->unique('week'); $table->timestamps(); //$table->text('description'); }); diff --git a/skolehjem/resources/views/admin/washing-reservations/index.blade.php b/skolehjem/resources/views/admin/washing-reservations/index.blade.php index 587abea..073bbab 100644 --- a/skolehjem/resources/views/admin/washing-reservations/index.blade.php +++ b/skolehjem/resources/views/admin/washing-reservations/index.blade.php @@ -11,7 +11,7 @@ @section("content")
- CreateOpret Reservation +
@csrf diff --git a/skolehjem/resources/views/app/layout/base.blade.php b/skolehjem/resources/views/app/layout/base.blade.php index b668497..99479b2 100644 --- a/skolehjem/resources/views/app/layout/base.blade.php +++ b/skolehjem/resources/views/app/layout/base.blade.php @@ -26,7 +26,7 @@ Aktiviteter Aktiviteter - + Reservationer Reservationer diff --git a/skolehjem/resources/views/app/washing-reservations/create.blade.php b/skolehjem/resources/views/app/washing-reservations/create.blade.php index 82ab9f0..25a48ad 100644 --- a/skolehjem/resources/views/app/washing-reservations/create.blade.php +++ b/skolehjem/resources/views/app/washing-reservations/create.blade.php @@ -92,13 +92,14 @@ } function onDateSelect(date, dayHolder) { + console.log("Opdaterer selects"); let events; let machinez; let buttonz; let container = document.getElementById("event-container"); - NodeList.prototype.forEach = Array.prototype.forEach + NodeList.prototype.forEach = Array.prototype.forEach; var children = document.getElementById("calenderRow").childNodes; children.forEach(function(item){ @@ -107,11 +108,19 @@ dayHolder.classList.add("selected"); + let machine_id; + + if(document.getElementById('washing-machines')) + machine_id = document.getElementById('washing-machines').value; + else + machine_id = 0; + axios({ method: 'get', url: '{{ route("washing-reservations.api") }}', - params: { 'date': date } + params: { 'date': date, 'machine_id': machine_id } }).then(function (response) { + console.log(response.data["unavailable_times"]); var data = response.data; if(document.getElementById("washing-machines") != undefined) @@ -126,6 +135,10 @@ select.id = "washing-machines"; select.name = "machine_id"; + select.onchange = function() { + onDateSelect(date, dayHolder); + } + container.appendChild(span); container.appendChild(select); @@ -165,11 +178,18 @@ let machines = data["washingmachines"]; machinez.innerHTML = ""; + machinez.onchange = function () { + onDateSelect(date, dayHolder); + } + for (let i = 0; i < machines.length; i++) { let option = document.createElement("option"); option.text = machines[i]["name"]; option.value = machines[i]["id"]; + if(machine_id == machines[i]["id"]) + option.selected = "selected"; + machinez.appendChild(option); } @@ -187,7 +207,6 @@ let unavailable_times = data["unavailable_times"]; unavailable_times.forEach(function (item, index) { - console.log(item); document.getElementById(item).remove(); }); diff --git a/skolehjem/routes/web.php b/skolehjem/routes/web.php index 85cde52..0a59aa6 100644 --- a/skolehjem/routes/web.php +++ b/skolehjem/routes/web.php @@ -28,6 +28,7 @@ Route::put("/account/update", "UserController@accountupdate")->name("users.accou Route::get("/events/signups", "EventController@signups")->name("events.signups"); Route::get("phones", "PhoneController@index")->name("phones.index"); Route::get("/washing-reservationsapi", "WashingReservationController@api")->name("washing-reservations.api"); +Route::get("/app/washing-reservations", "WashingReservationController@appindex")->name("washing-reservations.appindex"); //Search/Filter Route::get("/contactsapi", "ContactController@search")->name("contacts.search");