Permission fixes and washing reservation fixes
This commit is contained in:
parent
fc0f97b04e
commit
569ace008a
|
@ -1,12 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Http\Response;
|
|
||||||
|
|
||||||
|
|
||||||
class CalendarController extends Controller
|
|
||||||
{
|
|
||||||
// public function index()
|
|
||||||
}
|
|
|
@ -1,95 +0,0 @@
|
||||||
<?php
|
|
||||||
//
|
|
||||||
//namespace App\Http\Controllers;
|
|
||||||
//
|
|
||||||
//use App\CalendarDate;
|
|
||||||
//use Illuminate\Http\Request;
|
|
||||||
//
|
|
||||||
//class CalendarDateController extends Controller
|
|
||||||
//{
|
|
||||||
// /**
|
|
||||||
// * Display a listing of the resource.
|
|
||||||
// *
|
|
||||||
// * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
||||||
// */
|
|
||||||
// public function index(Request $request)
|
|
||||||
// {
|
|
||||||
// $calendarDates = CalendarDate::query()->paginate($request->input("limit", 20));
|
|
||||||
//
|
|
||||||
// return view("calendar-date.index", [
|
|
||||||
// "calendarDates" => $calendarDates
|
|
||||||
// ]);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Show the form for creating a new resource.
|
|
||||||
// *
|
|
||||||
// * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
||||||
// */
|
|
||||||
// public function create()
|
|
||||||
// {
|
|
||||||
// return view("calendar-date.create");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Store a newly created resource in storage.
|
|
||||||
// *
|
|
||||||
// * @param \Illuminate\Http\Request $request
|
|
||||||
// * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
||||||
// */
|
|
||||||
// public function store(Request $request)
|
|
||||||
// {
|
|
||||||
// $fields = $request->validate([
|
|
||||||
// "" => ""
|
|
||||||
// ]);
|
|
||||||
//
|
|
||||||
// $calendarDate = new CalendarDate()
|
|
||||||
//
|
|
||||||
// return view("calendar-date.store");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Display the specified resource.
|
|
||||||
// *
|
|
||||||
// * @param int $id
|
|
||||||
// * @return \Illuminate\Http\Response
|
|
||||||
// */
|
|
||||||
// public function show($id)
|
|
||||||
// {
|
|
||||||
// //
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Show the form for editing the specified resource.
|
|
||||||
// *
|
|
||||||
// * @param int $id
|
|
||||||
// * @return \Illuminate\Http\Response
|
|
||||||
// */
|
|
||||||
// public function edit($id)
|
|
||||||
// {
|
|
||||||
// //
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Update the specified resource in storage.
|
|
||||||
// *
|
|
||||||
// * @param \Illuminate\Http\Request $request
|
|
||||||
// * @param int $id
|
|
||||||
// * @return \Illuminate\Http\Response
|
|
||||||
// */
|
|
||||||
// public function update(Request $request, $id)
|
|
||||||
// {
|
|
||||||
// //
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Remove the specified resource from storage.
|
|
||||||
// *
|
|
||||||
// * @param int $id
|
|
||||||
// * @return \Illuminate\Http\Response
|
|
||||||
// */
|
|
||||||
// public function destroy($id)
|
|
||||||
// {
|
|
||||||
// //
|
|
||||||
// }
|
|
||||||
//}
|
|
|
@ -9,6 +9,17 @@ use Spatie\Permission\Models\Role;
|
||||||
|
|
||||||
class rolesController extends Controller
|
class rolesController extends Controller
|
||||||
{
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->middleware([ "auth" ]);
|
||||||
|
|
||||||
|
$this->middleware([ "check.auth:roles.list" ])->only("index");
|
||||||
|
$this->middleware([ "check.auth:roles.show" ])->only("show");
|
||||||
|
$this->middleware([ "check.auth:roles.create" ])->only("create", "store");
|
||||||
|
$this->middleware([ "check.auth:roles.edit" ])->only("edit", "update");
|
||||||
|
$this->middleware([ "check.auth:roles.delete" ])->only("delete");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
|
|
|
@ -227,6 +227,7 @@ class UserController extends Controller
|
||||||
|
|
||||||
if(Auth::attempt($data)) {
|
if(Auth::attempt($data)) {
|
||||||
//TODO: Implement home?
|
//TODO: Implement home?
|
||||||
|
|
||||||
return redirect()->route("root.index");
|
return redirect()->route("root.index");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||||
use App\WashingMachine;
|
use App\WashingMachine;
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
|
use Illuminate\Foundation\Auth\User;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
@ -46,7 +47,8 @@ class WashingReservationController extends Controller
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
$machines = WashingMachine::all();
|
$machines = WashingMachine::all();
|
||||||
return Response::detect("washing-reservations.create", [ 'machines' => $machines ]);
|
$users = User::all();
|
||||||
|
return Response::detect("washing-reservations.create", [ 'machines' => $machines, 'users' => $users ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,7 +61,8 @@ class WashingReservationController extends Controller
|
||||||
{
|
{
|
||||||
$data = $request->validate([
|
$data = $request->validate([
|
||||||
"time" => "required",
|
"time" => "required",
|
||||||
"machine" => "required"
|
"machine_id" => "required|unique:washing_reservations,machine_id,NULL,id,time,' . $request->time",
|
||||||
|
"user_id" => "required"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$machineReservation = new WashingReservation($data);
|
$machineReservation = new WashingReservation($data);
|
||||||
|
@ -160,7 +163,15 @@ class WashingReservationController extends Controller
|
||||||
|
|
||||||
$machines = WashingMachine::all();
|
$machines = WashingMachine::all();
|
||||||
|
|
||||||
$output = json_encode(['date' => $date, 'washingmachines' => $machines]);
|
$reservations = WashingReservation::query()->where("time", "LIKE", substr($date, 1, strpos($date, "T"))."%")->get();
|
||||||
|
|
||||||
|
$times = [];
|
||||||
|
|
||||||
|
foreach ($reservations as $reservation){
|
||||||
|
array_push($times, $reservation->time);
|
||||||
|
}
|
||||||
|
//2020-07-28%
|
||||||
|
$output = json_encode(['date' => $date, 'washingmachines' => $machines, 'unavailable_times' => $times]);
|
||||||
return Response($output);
|
return Response($output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,6 @@ class WashingReservation extends Model
|
||||||
{
|
{
|
||||||
//protected variable which contains name of database field(s) to be filled.
|
//protected variable which contains name of database field(s) to be filled.
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'time', 'machine'
|
'time', 'machine_id', 'user_id'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,11 @@ class CreateWashingReservations extends Migration
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->timestamp("time");
|
$table->timestamp("time");
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
$table->unsignedBigInteger('machine');
|
$table->unsignedBigInteger('machine_id');
|
||||||
$table->foreign("machine")->references('id')->on('washing_machines');
|
$table->foreign("machine_id")->references('id')->on('washing_machines');
|
||||||
|
$table->unsignedBigInteger('user_id');
|
||||||
|
$table->foreign("user_id")->references('id')->on('users');
|
||||||
|
$table->unique(['time', 'machine_id']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,13 +15,20 @@
|
||||||
@csrf
|
@csrf
|
||||||
<label for="time">Tidspunkt:</label>
|
<label for="time">Tidspunkt:</label>
|
||||||
<input type="datetime-local" name="time" id="time" required>
|
<input type="datetime-local" name="time" id="time" required>
|
||||||
<label for="machine">Vaskemaskine:</label>
|
<label for="machine_id">Vaskemaskine:</label>
|
||||||
<select name="machine" id="machine" required>
|
<select name="machine_id" id="machine_id" required>
|
||||||
<option disabled selected value> -- Vælg Vaskemaskine -- </option>
|
<option disabled selected value> -- Vælg Vaskemaskine -- </option>
|
||||||
@foreach($machines as $machine)
|
@foreach($machines as $machine)
|
||||||
<option value="{{ $machine->id }}">{{ $machine->name }}</option>
|
<option value="{{ $machine->id }}">{{ $machine->name }}</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
</select>
|
</select>
|
||||||
|
<label for="user_id">Bruger:</label>
|
||||||
|
<select name="user_id" id="user_id" required>
|
||||||
|
<option disabled selected value> -- Vælg Bruger -- </option>
|
||||||
|
@foreach($users as $user)
|
||||||
|
<option value="{{ $user->id }}">{{ ucfirst($user->name_first) }} {{ ucfirst($user->name_last) }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
<input type="submit" class="btn btn-dark text-white" value="Opret">
|
<input type="submit" class="btn btn-dark text-white" value="Opret">
|
||||||
</form>
|
</form>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
@foreach($reservations as $reservation)
|
@foreach($reservations as $reservation)
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ \App\WashingMachine::query()->find($reservation->machine)->name }}</td>
|
<td>{{ \App\WashingMachine::query()->find($reservation->machine_id)->name }}</td>
|
||||||
<td>{{ $reservation->time }}</td>
|
<td>{{ $reservation->time }}</td>
|
||||||
<td><a href="{{ route('washing-reservations.edit', ['washing_reservation' => $reservation]) }}"><img class="w-100" src="{{ asset('/images/icons/pencil-dark.svg') }}" alt="Update"></a></td>
|
<td><a href="{{ route('washing-reservations.edit', ['washing_reservation' => $reservation]) }}"><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' => $reservation]) }}" class="w-100 nostyle">
|
<td><form method="post" action="{{ route('washing-reservations.destroy', ['washing_reservation' => $reservation]) }}" class="w-100 nostyle">
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
@extends("app.layout.base")
|
@extends("app.layout.base")
|
||||||
@extends("app.layout.header")
|
|
||||||
@section("title")
|
@section("title")
|
||||||
Booking Liste
|
Booking Liste
|
||||||
@endsection
|
@endsection
|
||||||
|
@ -27,6 +27,7 @@
|
||||||
</div>
|
</div>
|
||||||
<form method="post" action="{{ route("washing-reservations.store") }}" id="event-container" class="events-container">
|
<form method="post" action="{{ route("washing-reservations.store") }}" id="event-container" class="events-container">
|
||||||
@csrf
|
@csrf
|
||||||
|
<input type="hidden" value="{{auth()->user()->id}}" name="user_id">
|
||||||
<p>
|
<p>
|
||||||
Maskiner skal dynamisk opdateres alt efter om det er en fra bygning E eller en af de andre bygninger der vil vaske, da bygning E har egen vaskekælder!
|
Maskiner skal dynamisk opdateres alt efter om det er en fra bygning E eller en af de andre bygninger der vil vaske, da bygning E har egen vaskekælder!
|
||||||
</p>
|
</p>
|
||||||
|
@ -112,7 +113,7 @@
|
||||||
|
|
||||||
axios({
|
axios({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: '/washing-reservationsapi',
|
url: '{{ route("washing-reservations.api") }}',
|
||||||
params: { 'date': date }
|
params: { 'date': date }
|
||||||
}).then(function (response) {
|
}).then(function (response) {
|
||||||
var data = response.data;
|
var data = response.data;
|
||||||
|
@ -127,7 +128,7 @@
|
||||||
let select = document.createElement("select");
|
let select = document.createElement("select");
|
||||||
select.classList.add("events__title");
|
select.classList.add("events__title");
|
||||||
select.id = "washing-machines";
|
select.id = "washing-machines";
|
||||||
select.name = "machine";
|
select.name = "machine_id";
|
||||||
|
|
||||||
container.appendChild(span);
|
container.appendChild(span);
|
||||||
container.appendChild(select);
|
container.appendChild(select);
|
||||||
|
@ -139,7 +140,7 @@
|
||||||
else {
|
else {
|
||||||
let span = document.createElement("span");
|
let span = document.createElement("span");
|
||||||
span.classList.add("events__title");
|
span.classList.add("events__title");
|
||||||
span.innerText = "Tider";
|
span.innerText = "Tilgængelige tider";
|
||||||
|
|
||||||
let select = document.createElement("select");
|
let select = document.createElement("select");
|
||||||
select.classList.add("events__title");
|
select.classList.add("events__title");
|
||||||
|
@ -178,13 +179,33 @@
|
||||||
|
|
||||||
events.innerHTML = "";
|
events.innerHTML = "";
|
||||||
for (let hour = 8; hour <= 20; hour++) {
|
for (let hour = 8; hour <= 20; hour++) {
|
||||||
|
let value = data["date"].split("T")[0].slice(1, data["date"].split("T")[0].length) + "T" + prependZero(hour) + ":00";
|
||||||
let option = document.createElement("option");
|
let option = document.createElement("option");
|
||||||
option.text = prependZero(hour) + ":00";
|
|
||||||
option.value = data["date"].split("T")[0].slice(1, data["date"].split("T")[0].length) + "T" + prependZero(hour) + ":00";
|
|
||||||
|
|
||||||
|
option.text = prependZero(hour) + ":00";
|
||||||
|
option.value = value;
|
||||||
|
option.id = value;
|
||||||
events.appendChild(option);
|
events.appendChild(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let unavailable_times = data["unavailable_times"];
|
||||||
|
|
||||||
|
unavailable_times.forEach(function (item, index) {
|
||||||
|
console.log(item);
|
||||||
|
document.getElementById(item).remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
if(events.childElementCount == 0){
|
||||||
|
let option = document.createElement("option");
|
||||||
|
option.disabled = "disabled";
|
||||||
|
option.text = "Der er ingen tilgængelige tider";
|
||||||
|
option.selected = "selected";
|
||||||
|
events.appendChild(option);
|
||||||
|
|
||||||
|
document.getElementById("create-reservation").disabled = "disabled";
|
||||||
|
} else {
|
||||||
|
document.getElementById("create-reservation").disabled = "";
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
@extends("app.layout.base")
|
@extends("app.layout.base")
|
||||||
@extends("app.layout.header")
|
|
||||||
@section("title")
|
@section("title")
|
||||||
Booking Liste
|
Booking Liste
|
||||||
@endsection
|
@endsection
|
||||||
|
|
Loading…
Reference in New Issue