diff --git a/skolehjem/app/Http/Controllers/LocationController.php b/skolehjem/app/Http/Controllers/LocationController.php new file mode 100644 index 0000000..d766b01 --- /dev/null +++ b/skolehjem/app/Http/Controllers/LocationController.php @@ -0,0 +1,133 @@ +middleware([ "auth" ]); + + $this->middleware([ "check.auth:locations.list" ])->only("index"); + $this->middleware([ "check.auth:locations.show" ])->only("show"); + $this->middleware([ "check.auth:locations.create" ])->only("create", "store"); + $this->middleware([ "check.auth:locations.edit" ])->only("edit", "update"); + $this->middleware([ "check.auth:locations.delete" ])->only("delete"); + } + + /** + * Display a listing of the resource. + * + * @param Request $request + * @return \Illuminate\Http\Response + */ + public function index(Request $request) + { + $locations = Location::query()->paginate($request->input("limit", 20)); + + return Response::detect("locations.index", [ "locations" => $locations ]); + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + return Response::detect("locations.create"); + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(Request $request) + { + $data = $request->validate([ + "name" => "required", + ]); + + $location = new Location($data); + + $locations = Location::query()->where('name', '=', $request->name)->get(); + + // If there already is a washing machine with that name, then don't add it + if (count($locations) > 0) + return redirect()->route("locations.store")->with('NameExists', '

Der findes allerede en lokation med det navn!

'); + else { // Else - Add it + $location->save(); + $locations = Location::query()->paginate($request->input("limit", 20)); + return redirect()->route("locations.index", ['locations' => $locations]); + } + } + + /** + * Display the specified resource. + * + * @param \App\Location $location + * @return \Illuminate\Http\Response + */ + public function show(Location $location) + { + + } + + /** + * Show the form for editing the specified resource. + * + * @param \App\Location $location + * @return \Illuminate\Http\Response + */ + public function edit(Location $location) + { + return Response::detect("locations.edit", [ "location" => $location] ); + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param \App\Location $location + * @return \Illuminate\Http\Response + */ + public function update(Request $request, $id) + { + $data = $request->validate([ + "name" => "required", + ]); + + $location = Location::find($id); + + + $allMachines = Location::query()->where('name', '=', $request->name)->where('id', '!=', $id)->get(); + + // If there already is a washing machine with that name, then don't change it + if (count($allMachines) > 0) + return redirect()->route("locations.store")->with('NameExists', '

Der findes allerede en lokation med det navn!

'); + else { // Else - Change the name + $location->update($data); + $location->save(); + + $locations = Location::query()->paginate($request->input("limit", 20)); + return redirect()->route("locations.index", ["locations" => $locations]); + } + } + + /** + * Remove the specified resource from storage. + * + * @param \App\Location $location + * @return \Illuminate\Http\Response + */ + public function destroy(Location $location) + { + + } +} diff --git a/skolehjem/app/Http/Controllers/WashingMachineController.php b/skolehjem/app/Http/Controllers/WashingMachineController.php index 07b1940..9ef3096 100644 --- a/skolehjem/app/Http/Controllers/WashingMachineController.php +++ b/skolehjem/app/Http/Controllers/WashingMachineController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Location; use App\WashingReservation; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\Factory; @@ -44,7 +45,9 @@ class WashingMachineController extends Controller */ public function create() { - return Response::detect("washing-machines.create"); + $locations = Location::all(); + + return Response::detect("washing-machines.create", ["locations" => $locations] ); } /** @@ -56,12 +59,13 @@ class WashingMachineController extends Controller public function store(Request $request) { $data = $request->validate([ - "name" => "required" + "name" => "required", + "location_id" => "required" ]); $machine = new WashingMachine($data); - $allMachines = WashingMachine::query()->where('name', '=', $request->name)->get(); + $allMachines = WashingMachine::query()->where('name', '=', $request->name)->where('location_id', "=", $request->location_id)->get(); // If there already is a washing machine with that name, then don't add it if (count($allMachines) > 0) @@ -81,11 +85,7 @@ class WashingMachineController extends Controller */ public function show($id) { - $machine = WashingMachine::find($id); - return Response::detect("washing-machines.show", [ - "machine" => $machine - ]); } /** @@ -97,9 +97,11 @@ class WashingMachineController extends Controller public function edit($id) { $machine = WashingMachine::find($id); + $locations = Location::all(); return Response::detect("washing-machines.edit", [ - "machine" => $machine + "machine" => $machine, + "locations" => $locations ]); } @@ -113,13 +115,14 @@ class WashingMachineController extends Controller public function update(Request $request, $id) { $data = $request->validate([ - "name" => "required" + "name" => "required", + "location_id" => "required", ]); $machine = WashingMachine::find($id); - $allMachines = WashingMachine::query()->where('name', '=', $request->name)->where('id', '!=', $id)->get(); + $allMachines = WashingMachine::query()->where('name', '=', $request->name)->where('location_id', "=", $request->location_id)->where('id', '!=', $id)->get(); // If there already is a washing machine with that name, then don't change it if (count($allMachines) > 0) diff --git a/skolehjem/app/Http/Controllers/WashingReservationController.php b/skolehjem/app/Http/Controllers/WashingReservationController.php index afbcf38..4da0d9e 100644 --- a/skolehjem/app/Http/Controllers/WashingReservationController.php +++ b/skolehjem/app/Http/Controllers/WashingReservationController.php @@ -103,10 +103,7 @@ class WashingReservationController extends Controller */ public function edit($id) { - $reservation = WashingReservation::query()->find($id); - $machines = WashingMachine::all(); - return Response::detect("washing-reservations.edit", ['washing_reservation' => $reservation, 'machines' => $machines ]); } /** @@ -118,26 +115,7 @@ class WashingReservationController extends Controller */ public function update(Request $request, $id) { - $data = $request->validate([ - "time" => "required", - "machine" => "required" - ]); - $machineReservation = WashingReservation::find($id); - - $machineReservation->update($data); - - $saved = $machineReservation->save(); - - if(!$saved){ - return Response::detect("washing-reservations.update", [ - "washing_reservation" => $machineReservation - ]); - }else{ - $reservations = WashingReservation::query()->paginate($request->query("limit", 20)); - - return Response::detect("washing-reservations.index", [ "reservations" => $reservations]); - } } /** @@ -246,4 +224,3 @@ class WashingReservationController extends Controller return Response::detect("washing-reservations.index", [ "reservations" => $reservations]); } } - diff --git a/skolehjem/app/Location.php b/skolehjem/app/Location.php new file mode 100644 index 0000000..75056e0 --- /dev/null +++ b/skolehjem/app/Location.php @@ -0,0 +1,12 @@ +id(); + $table->string("name")->unique(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('locations'); + } +} diff --git a/skolehjem/database/migrations/2020_06_08_073954_create_washing_machines.php b/skolehjem/database/migrations/2020_06_08_073954_create_washing_machines.php index 8b9ded4..10d4b50 100644 --- a/skolehjem/database/migrations/2020_06_08_073954_create_washing_machines.php +++ b/skolehjem/database/migrations/2020_06_08_073954_create_washing_machines.php @@ -17,8 +17,11 @@ class CreateWashingMachines extends Migration { Schema::create('washing_machines', function (Blueprint $table) { $table->id(); - $table->string("name")->unique(); + $table->string("name"); + + $table->foreignId("location_id")->constrained("locations", "id"); $table->timestamps(); + $table->unique(['name', 'location_id']); }); } diff --git a/skolehjem/database/seeds/DatabaseSeeder.php b/skolehjem/database/seeds/DatabaseSeeder.php index b099698..dfd923b 100644 --- a/skolehjem/database/seeds/DatabaseSeeder.php +++ b/skolehjem/database/seeds/DatabaseSeeder.php @@ -15,5 +15,6 @@ class DatabaseSeeder extends Seeder $this->call(RoleSeeder::class); $this->call(UserSeeder::class); $this->call(ContactSeeder::class); + $this->call(LocationSeeder::class); } } diff --git a/skolehjem/database/seeds/LocationSeeder.php b/skolehjem/database/seeds/LocationSeeder.php new file mode 100644 index 0000000..e1250f7 --- /dev/null +++ b/skolehjem/database/seeds/LocationSeeder.php @@ -0,0 +1,31 @@ + "Bygning B" + ], + [ + "name" => "Bygning E" + ] + ]; + + foreach ($locationdata as $data) { + $location = new \App\Location(); + + $location->name = $data["name"]; + + $location->save(); + } + } +} diff --git a/skolehjem/database/seeds/PermissionSeeder.php b/skolehjem/database/seeds/PermissionSeeder.php index fb01e2a..c79720a 100644 --- a/skolehjem/database/seeds/PermissionSeeder.php +++ b/skolehjem/database/seeds/PermissionSeeder.php @@ -25,7 +25,7 @@ class PermissionSeeder extends Seeder "ownuser.edit" => "Allows editing of your own user", /** - * The CALENDAR specific permissions + * The CALENDAR specific permissions //TODO: Do we use them? */ "calendar.create" => "Create a new event.", "calendar.list" => "Shows all events.", @@ -51,63 +51,109 @@ class PermissionSeeder extends Seeder "event.edit" => "Allows editing of events", "event.delete" => "Allows deletion of events", + /** + * The CONTACT specific permissions + */ "contact.create" => "Creates a new contact", "contact.list" => "Shows all contacts", "contact.show" => "Shows a specific contact", "contact.edit" => "allows editing of contacts", "contact.delete" => "Allows deletion of contacts", + /** + * The FEEDBACK specific permissions + */ "feedback.create" => "Creates a new feedback message", "feedback.list" => "Shows all feedback messages", "feedback.show" => "Shows a specific feedback message", "feedback.edit" => "allows editing of feedback messages", "feedback.delete" => "allows deletion of feedback messages", + /** + * The MENUPLAN specific permissions + */ "menuplan.create" => "Create a new menuplan", "menuplan.list" => "Shows all menuplans", "menuplan.show" => "Shows a specific menuplan", "menuplan.edit" => "Allows editing of menuplans", "menuplan.delete" => "Allows deletion of menuplans", + /** + * The RESOURCE CATEGORY specific permissions + */ "resource.category.create" => "Create a new resource category", "resource.category.list" => "Shows all resource categories", "resource.category.show" => "Shows a specific resource category", "resource.category.edit" => "Allows editing of resource categories", "resource.category.delete" => "Allows deletion of resource categories", + /** + * The RESOURCE EXTENSION specific permissions + */ "resource.extension.create" => "Create a new resource extension", "resource.extension.list" => "Shows all resource extensions", "resource.extension.show" => "Shows a specific resource extension", "resource.extension.edit" => "Allows editing of resource extensions", "resource.extension.delete" => "Allows deletion of resource extensions", + /** + * The RESOURCE specific permissions + */ "resource.create" => "Create a new resource", "resource.list" => "Shows all resources", "resource.show" => "Shows a specific resource", "resource.edit" => "Allows editing of resources", "resource.delete" => "Allows deletion of resources", + /** + * The WASHING MACHINE specific permissions + */ "washing.machine.create" => "Create a new washing machine", "washing.machine.list" => "Shows all washing machines", "washing.machine.show" => "Shows a specific washing machine", "washing.machine.edit" => "Allows editing of washing machines", "washing.machine.delete" => "Allows deletion of washing machines", + /** + * The WASHING MACHINE RESERVATION specific permissions + */ "washing.machine.reservation.create" => "Create a new washing machine reservation", "washing.machine.reservation.list" => "Shows all washing machine reservations", "washing.machine.reservation.show" => "Shows a specific washing machine reservation", "washing.machine.reservation.edit" => "Allows editing of washing machine reservations", "washing.machine.reservation.delete" => "Allows deletion of washing machine reservations", + /** + * The ROLES specific permissions + */ "roles.create" => "Create a new role", "roles.list" => "Shows all roles", "roles.show" => "Shows a specific role", "roles.edit" => "Allows editing of roles", "roles.delete" => "Allows deletion of roles", - //Allows access to the admin panel - "admin.panel.show" => "Allows access to administration panel", + /** + * The GUIDE specific permissions + */ + "guides.create" => "Create a new guide", + "guides.list" => "Shows all guides", + "guides.show" => "Shows a specific guide", + "guides.edit" => "Allows editing of guides", + "guides.delete" => "Allows deletion of guides", + /** + * The LOCATION specific permissions + */ + "locations.create" => "Create a new location", + "locations.list" => "Shows all locations", + "locations.show" => "Shows a specific location", + "locations.edit" => "Allows editing of locations", + "locations.delete" => "Allows deletion of locations", + + /** + * The ADMIN PANEL specific permissions + */ + "admin.panel.show" => "Allows access to administration panel", ]; foreach ($permissions as $key => $value) { diff --git a/skolehjem/resources/views/admin/layout/base.blade.php b/skolehjem/resources/views/admin/layout/base.blade.php index 554104c..21dc2b2 100644 --- a/skolehjem/resources/views/admin/layout/base.blade.php +++ b/skolehjem/resources/views/admin/layout/base.blade.php @@ -23,6 +23,9 @@

Aktiviteter

+
+

Lokationer

+

Vaskemaskiner

diff --git a/skolehjem/resources/views/admin/locations/create.blade.php b/skolehjem/resources/views/admin/locations/create.blade.php new file mode 100644 index 0000000..eed7c55 --- /dev/null +++ b/skolehjem/resources/views/admin/locations/create.blade.php @@ -0,0 +1,20 @@ +@extends("admin.layout.base") +@extends("admin.layout.header") + +@section("title") + Opret Lokation +@endsection + +@section("path") + Opret Lokation / +@endsection + +@section("content") +

Opret Lokation

+
+ @csrf + + + +
+@endsection diff --git a/skolehjem/resources/views/admin/locations/delete.blade.php b/skolehjem/resources/views/admin/locations/delete.blade.php new file mode 100644 index 0000000..cf31266 --- /dev/null +++ b/skolehjem/resources/views/admin/locations/delete.blade.php @@ -0,0 +1,13 @@ +@extends("admin.layout.base") +@extends("admin.layout.header") + +@section("title") + Vejledning - Fjern +@endsection + +@section("path") + Fjern Guide / +@endsection + +@section("content") +@endsection diff --git a/skolehjem/resources/views/admin/locations/edit.blade.php b/skolehjem/resources/views/admin/locations/edit.blade.php new file mode 100644 index 0000000..b0d8dfd --- /dev/null +++ b/skolehjem/resources/views/admin/locations/edit.blade.php @@ -0,0 +1,21 @@ +@extends("admin.layout.base") +@extends("admin.layout.header") + +@section("title") + Lokation - Rediger +@endsection + +@section("path") + Rediger lokation / +@endsection + +@section("content") +

Rediger Lokation

+
$location ]) }}"> + @csrf + @method("put") + + + +
+@endsection diff --git a/skolehjem/resources/views/admin/locations/index.blade.php b/skolehjem/resources/views/admin/locations/index.blade.php new file mode 100644 index 0000000..dadae12 --- /dev/null +++ b/skolehjem/resources/views/admin/locations/index.blade.php @@ -0,0 +1,38 @@ +@extends("admin.layout.base") +@extends("admin.layout.header") + +@section("title") + Vis Lokationer +@endsection + +@section("path") + Vis lokationer / +@endsection + +@section("content") +
+ CreateOpret Lokation +
+ + + + + + + @foreach($locations as $location) + + + + + + @endforeach +
NavnUpdateDelete
{{$location->name}} $location ]) }}">Update
$location ]) }}" class="w-100 nostyle"> + @csrf + @method("delete") + + +
+
+ + {{ $locations->links() }} +@endsection diff --git a/skolehjem/resources/views/admin/locations/store.blade.php b/skolehjem/resources/views/admin/locations/store.blade.php new file mode 100644 index 0000000..239ca01 --- /dev/null +++ b/skolehjem/resources/views/admin/locations/store.blade.php @@ -0,0 +1,14 @@ +@extends("admin.layout.base") +@extends("admin.layout.header") + +@section("title") + Vejledning - Opret +@endsection + +@section("path") + Opret vejledning / +@endsection + +@section("content") + vejledning blev (ikke) oprettet. +@endsection diff --git a/skolehjem/resources/views/admin/locations/update.blade.php b/skolehjem/resources/views/admin/locations/update.blade.php new file mode 100644 index 0000000..4b9788d --- /dev/null +++ b/skolehjem/resources/views/admin/locations/update.blade.php @@ -0,0 +1,14 @@ +@extends("admin.layout.base") +@extends("admin.layout.header") + +@section("title") + Vejledning - Rediger +@endsection + +@section("path") + $link]) }}" class="text-white">Vejledning / +@endsection + +@section("content") + Din vejledning blev (ikke) redigeret. +@endsection diff --git a/skolehjem/resources/views/admin/users/edit.blade.php b/skolehjem/resources/views/admin/users/edit.blade.php index 17b2ed3..d32f68c 100644 --- a/skolehjem/resources/views/admin/users/edit.blade.php +++ b/skolehjem/resources/views/admin/users/edit.blade.php @@ -56,8 +56,7 @@ @endforeach @endif - - + @endsection diff --git a/skolehjem/resources/views/admin/washing-machines/create.blade.php b/skolehjem/resources/views/admin/washing-machines/create.blade.php index c81e7c9..c7e2191 100644 --- a/skolehjem/resources/views/admin/washing-machines/create.blade.php +++ b/skolehjem/resources/views/admin/washing-machines/create.blade.php @@ -15,6 +15,17 @@ @csrf + + @endsection diff --git a/skolehjem/resources/views/admin/washing-machines/edit.blade.php b/skolehjem/resources/views/admin/washing-machines/edit.blade.php index 7e080d5..0f1ca12 100644 --- a/skolehjem/resources/views/admin/washing-machines/edit.blade.php +++ b/skolehjem/resources/views/admin/washing-machines/edit.blade.php @@ -15,6 +15,16 @@ @method("put") + @endsection diff --git a/skolehjem/resources/views/admin/washing-machines/index.blade.php b/skolehjem/resources/views/admin/washing-machines/index.blade.php index 3d06030..f8332da 100644 --- a/skolehjem/resources/views/admin/washing-machines/index.blade.php +++ b/skolehjem/resources/views/admin/washing-machines/index.blade.php @@ -17,12 +17,14 @@ + @foreach($machines as $machine) +
NavnLokation Update Delete
{{$machine->name}}{{\App\Location::query()->where("id", "=", $machine->location_id)->first()->name}} Update
@csrf diff --git a/skolehjem/routes/web.php b/skolehjem/routes/web.php index 11b2bac..8d3be43 100644 --- a/skolehjem/routes/web.php +++ b/skolehjem/routes/web.php @@ -54,3 +54,4 @@ Route::resource("resource-extensions", "ResourceExtensionController"); Route::resource("resource-categories", "ResourceCategoryController"); Route::resource("roles", "RolesController"); Route::resource("guides", "GuideController"); +Route::resource("locations", "LocationController");