diff --git a/skolehjem/app/Http/Controllers/ContactController.php b/skolehjem/app/Http/Controllers/ContactController.php index 7251f4b..e3e706c 100644 --- a/skolehjem/app/Http/Controllers/ContactController.php +++ b/skolehjem/app/Http/Controllers/ContactController.php @@ -57,7 +57,7 @@ class ContactController extends Controller "contactname" => "required|max:255", "title" => "required|max:255", "email" => "required|max:255", - "phone" => "required|max:255", + "phone" => "max:255", ]); $contact = new Contact($requestContact); diff --git a/skolehjem/app/Http/Controllers/GuideController.php b/skolehjem/app/Http/Controllers/GuideController.php index 0a85ad7..7c73f01 100644 --- a/skolehjem/app/Http/Controllers/GuideController.php +++ b/skolehjem/app/Http/Controllers/GuideController.php @@ -9,18 +9,18 @@ use Illuminate\Http\Request; class GuideController extends Controller { - /* + public function __construct() { $this->middleware([ "auth" ]); - $this->middleware([ "check.auth:contact.list" ])->only("index"); - $this->middleware([ "check.auth:contact.show" ])->only("show"); - $this->middleware([ "check.auth:contact.create" ])->only("create", "store"); - $this->middleware([ "check.auth:contact.edit" ])->only("edit", "update"); - $this->middleware([ "check.auth:contact.delete" ])->only("delete"); + $this->middleware([ "check.auth:guides.list" ])->only("index"); + $this->middleware([ "check.auth:guides.show" ])->only("show"); + $this->middleware([ "check.auth:guides.create" ])->only("create", "store"); + $this->middleware([ "check.auth:guides.edit" ])->only("edit", "update"); + $this->middleware([ "check.auth:guides.delete" ])->only("delete"); } - */ + /** diff --git a/skolehjem/app/Http/Controllers/LocationController.php b/skolehjem/app/Http/Controllers/LocationController.php new file mode 100644 index 0000000..92af4c5 --- /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\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function show(Location $location) + { + return view("admin.locations.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/NewsController.php b/skolehjem/app/Http/Controllers/NewsController.php new file mode 100644 index 0000000..2586ef1 --- /dev/null +++ b/skolehjem/app/Http/Controllers/NewsController.php @@ -0,0 +1,116 @@ +middleware([ "auth" ]); + + $this->middleware([ "check.auth:news.list" ])->only("index"); + $this->middleware([ "check.auth:news.show" ])->only("show"); + $this->middleware([ "check.auth:news.create" ])->only("create", "store"); + $this->middleware([ "check.auth:news.edit" ])->only("edit", "update"); + $this->middleware([ "check.auth:news.delete" ])->only("delete"); + } + + /** + * Display a listing of the resource. + * + * @return \Illuminate\Http\Response + */ + public function index(Request $request) + { + $news = News::query()->paginate($request->input("limit", 20)); + + return Response::detect("news.index", [ "news" => $news ]); + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + return Response::detect("news.create"); + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\RedirectResponse + */ + public function store(Request $request) + { + $data = $request->validate([ + "name" => "required", + "content" => "required" + ]); + + $news = new News($data); + $news->save(); + + return redirect()->route("news.index"); + } + + /** + * Display the specified resource. + * + * @param \App\News $news + * @return \Illuminate\Http\Response + */ + public function show(News $news) + { + // + } + + /** + * Show the form for editing the specified resource. + * + * @param \App\News $news + * @return \Illuminate\Http\Response + */ + public function edit(News $news) + { + return Response::detect("news.edit", [ "news" => $news ]); + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param \App\News $news + * @return \Illuminate\Http\RedirectResponse + */ + public function update(Request $request, News $news) + { + $data = $request->validate([ + "name" => "required", + "content" => "required" + ]); + + $news->update($data); + + return redirect()->route("news.index"); + } + + /** + * Remove the specified resource from storage. + * + * @param \App\News $news + * @return \Illuminate\Http\RedirectResponse + * @throws \Exception + */ + public function destroy(News $news) + { + $news->delete(); + return redirect()->route("news.index"); + } +} diff --git a/skolehjem/app/Http/Controllers/UserController.php b/skolehjem/app/Http/Controllers/UserController.php index 13b09b8..c9964df 100644 --- a/skolehjem/app/Http/Controllers/UserController.php +++ b/skolehjem/app/Http/Controllers/UserController.php @@ -53,7 +53,6 @@ class UserController extends Controller { $roles = Role::all(); return Response::detect("users.create", ['roles' => $roles]); - } /** @@ -169,9 +168,7 @@ class UserController extends Controller } $users = User::query()->paginate(20); - return Response::detect("users.index", [ - "users" => $users - ]); + return redirect()->route("users.index"); } /** @@ -309,9 +306,7 @@ class UserController extends Controller } $users = User::query()->paginate(20); - return Response::detect("users.index", [ - "users" => $users - ]); + return redirect()->route("users.index"); } public function search(Request $request){ 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..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; @@ -103,10 +104,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 +116,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]); - } } /** @@ -164,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(); @@ -177,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); } } @@ -246,4 +230,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/migrations/2020_08_06_092000_create_news_table.php b/skolehjem/database/migrations/2020_08_06_092000_create_news_table.php new file mode 100644 index 0000000..7d6abc8 --- /dev/null +++ b/skolehjem/database/migrations/2020_08_06_092000_create_news_table.php @@ -0,0 +1,33 @@ +id(); + $table->string("name"); + $table->text("content"); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('news'); + } +} diff --git a/skolehjem/database/seeds/ContactSeeder.php b/skolehjem/database/seeds/ContactSeeder.php index 2b289be..b63d9e9 100644 --- a/skolehjem/database/seeds/ContactSeeder.php +++ b/skolehjem/database/seeds/ContactSeeder.php @@ -30,28 +30,28 @@ class ContactSeeder extends Seeder 'contactname' => "Thomas Thomsen", 'email' => "thth@sde.dk", 'title' => "Kollegieassistent", - 'phone' => "24629450", + 'phone' => "", 'phonetimes' => "", ], [ 'contactname' => "Anja Holm Brix", 'email' => "ahb@sde.dk", 'title' => "Kollegieassistent", - 'phone' => "24629450", + 'phone' => "", 'phonetimes' => "", ], [ 'contactname' => "Britta Overgaard Brink Olsen", 'email' => "brio@sde.dk", 'title' => "Kollegieassistent", - 'phone' => "24629450", + 'phone' => "", 'phonetimes' => "", ], [ 'contactname' => "Jesper Sandberg", 'email' => "jesa@sde.dk", 'title' => "Kollegieassistent", - 'phone' => "24629450", + 'phone' => "", 'phonetimes' => "", ], ]; 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..db58e11 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,118 @@ 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 NEWS specific permissions + */ + "news.create" => "Create a new location", + "news.list" => "Shows all locations", + "news.show" => "Shows a specific location", + "news.edit" => "Allows editing of locations", + "news.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/contacts/create.blade.php b/skolehjem/resources/views/admin/contacts/create.blade.php index 947c007..243d360 100644 --- a/skolehjem/resources/views/admin/contacts/create.blade.php +++ b/skolehjem/resources/views/admin/contacts/create.blade.php @@ -27,7 +27,7 @@ - + diff --git a/skolehjem/resources/views/admin/contacts/edit.blade.php b/skolehjem/resources/views/admin/contacts/edit.blade.php index afc0a5a..acaf58d 100644 --- a/skolehjem/resources/views/admin/contacts/edit.blade.php +++ b/skolehjem/resources/views/admin/contacts/edit.blade.php @@ -28,7 +28,7 @@ - + diff --git a/skolehjem/resources/views/admin/events/index.blade.php b/skolehjem/resources/views/admin/events/index.blade.php index 9ce8a1c..6d18017 100644 --- a/skolehjem/resources/views/admin/events/index.blade.php +++ b/skolehjem/resources/views/admin/events/index.blade.php @@ -25,7 +25,7 @@Navn | +|||
---|---|---|---|
{{$location->name}} | + $location ]) }}"> |
+ $location ]) }}"> |
+ + | +
Lokation: {{ $location->name }}
+Navn | +||
---|---|---|
{{$new->name}} | + $new ]) }}"> |
+ + | +