From 2a6b4b2c99d06ec2085520a1b09f6d6e39c1da02 Mon Sep 17 00:00:00 2001 From: ro Date: Tue, 20 Feb 2024 16:33:49 -0600 Subject: [PATCH] Location editing, part 1 The plumbing for editing location info has been updated, so that data can be changed by authorized memebers. Also added a new data point for locations to store archive links part 2 will focus on setting up permissions and authorizations as well as smoothing out adding new members and member roles. an edit link will be added to locations, which will be visible for members with the correct permissions --- app/Http/Controllers/DenController.php | 51 +++++++++++++++++++-- app/Http/Controllers/LocationController.php | 22 +++++++-- app/Models/Location.php | 3 +- app/Repositories/LocationRepository.php | 26 +++++++++++ public/assets/css/back/locations.css | 19 ++------ public/reference | 2 +- resources/views/back/location.blade.php | 46 +++++++++++++++++++ resources/views/back/locations.blade.php | 36 +++++++++++---- resources/views/back/start.blade.php | 2 +- resources/views/frame.blade.php | 7 ++- routes/web.php | 5 +- 11 files changed, 180 insertions(+), 39 deletions(-) create mode 100644 resources/views/back/location.blade.php diff --git a/app/Http/Controllers/DenController.php b/app/Http/Controllers/DenController.php index 7054e3b..a1d5aa9 100644 --- a/app/Http/Controllers/DenController.php +++ b/app/Http/Controllers/DenController.php @@ -4,9 +4,25 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use App\Repositories\LocationRepository; +use App\Repositories\SourceRepository; +use App\Services\PaginationService; class DenController extends Controller { + protected $pagination; + protected $source; + + public function __construct( + PaginationService $paginationService, + SourceRepository $sourceRepository, + LocationRepository $locationRepository + ) { + $this->pagination = $paginationService; + $this->source = $sourceRepository; + $this->location = $locationRepository; + } + // public function start(Request $request) { @@ -25,12 +41,39 @@ class DenController extends Controller 'title' => "Manage Members"]); } - public function location(Request $request, string $action = "index") + public function location(Request $request, $pageNum = 1) { $member = Auth::user(); + $page = $this->pagination->getPage($pageNum); return view('back.locations', [ - 'handle' => $member->handle, - 'title' => "Manage Locations", - "action" => $action]); + 'handle' => $member->handle, + 'title' => "Manage Locations", + 'sources' => count($this->source->getActive()), + "totalPages" => $page['pageCount'], + "prev" => $page['prev'], + "next" => $page['next'], + 'pageNum' => $pageNum, + 'locations' => $page['locations'] + ]); + } + + public function locationEdit(Request $request, $uuid = 0) + { + $location = $this->location->getLocation($uuid); + $sources = $this->source->getActive(); + $name = "NO LOCATION FOUND"; + if ($location) { + $name = $location->name; + } + $links = explode(",", $location->archive_links); + return view('back.location', [ + 'title' => str_replace(".", " ", $name), + 'location' => $location, + 'actions' => $location->block_count + $location->silence_count, + 'sources_count' => count($sources), + 'images' => json_decode($location->images), + 'archive_links' => $links, + 'updated' => $location->updated_at->format('Y M d'), + ]); } } diff --git a/app/Http/Controllers/LocationController.php b/app/Http/Controllers/LocationController.php index c6ada97..292fbb0 100644 --- a/app/Http/Controllers/LocationController.php +++ b/app/Http/Controllers/LocationController.php @@ -2,15 +2,20 @@ namespace App\Http\Controllers; +use Illuminate\Http\Request; use App\Services\UpdateService; +use App\Repositories\LocationRepository; class LocationController extends Controller { protected $update; - public function __construct(UpdateService $updateService) - { - $this->update = $updateService; + public function __construct( + UpdateService $updateService, + LocationRepository $locationRepository + ) { + $this->update = $updateService; + $this->location = $locationRepository; } public function updateLocations() @@ -32,4 +37,15 @@ class LocationController extends Controller $result ); } + + public function editLocation(Request $request) + { + $token = csrf_token(); + $response = $this->location->editLocation($request); + if ($response['status']) { + return back()->with('message', $response['message']); + } else { + return back()->withErrors('message', $response['message']); + } + } } diff --git a/app/Models/Location.php b/app/Models/Location.php index e5a6b93..a7a12cc 100644 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -34,6 +34,7 @@ class Location extends Model "silence_count", "created_at", "updated_at", - "actions_count" + "actions_count", + "archive_links" ]; } diff --git a/app/Repositories/LocationRepository.php b/app/Repositories/LocationRepository.php index 09d785a..28425be 100644 --- a/app/Repositories/LocationRepository.php +++ b/app/Repositories/LocationRepository.php @@ -3,6 +3,7 @@ namespace App\Repositories; use App\Models\Location; +use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Auth; @@ -53,6 +54,31 @@ class LocationRepository ->orderByDesc('updated_at')->limit(10)->get(); } + public function editLocation($request) + { + $location = $this->getLocation($request->id); + $images = []; + if ($request->hasfile("references")) { + foreach ($request->references as $file) { + $path = $file->store('reference'); + array_push($images, ["path" => $path]); + } + } + $request->merge(['images' => json_encode($images)]); + $location->name = $request->name; + $location->description = $request->description; + $location->archive_links = $request->archive_links; + $location->images = json_encode($images); + + $result = []; + + if ($location->save()) { + return ['status' => true, 'message' => "Location Editited -IMG- " . $request->hasfile("references")]; + } else { + return ['status' => false, 'message' => "Location Not Editited"]; + } + } + public function addLocation(Request $request) { $fields = $request->validate([ diff --git a/public/assets/css/back/locations.css b/public/assets/css/back/locations.css index 1995019..47c527a 100644 --- a/public/assets/css/back/locations.css +++ b/public/assets/css/back/locations.css @@ -1,25 +1,12 @@ -section[role="loc-index"] { - width: 100%; - max-width: 600px; - padding: 10px; - margin: 0 auto; -} - -section[role="loc-index"] img { - width: 150px; - vertical-align: top; - border-radius: 3px; -} - -section[role="loc-index"] label { +section.edit-location > article > form.location-edit > label { color: var(--white); } -section[role="loc-index"] input { +section.edit-location > article > form.location-edit > input { width: 290px; } -section[role="loc-index"] textarea { +section.edit-location > article > form.location-edit > textarea { width: 290px; padding: 5px; height: 100px; diff --git a/public/reference b/public/reference index 3cf38b9..43b2f12 120000 --- a/public/reference +++ b/public/reference @@ -1 +1 @@ -/Users/ro/Projects/TheBadSpace/first/storage/app/reference \ No newline at end of file +/Users/ro/Herd/TBS/storage/app/reference \ No newline at end of file diff --git a/resources/views/back/location.blade.php b/resources/views/back/location.blade.php new file mode 100644 index 0000000..9de2829 --- /dev/null +++ b/resources/views/back/location.blade.php @@ -0,0 +1,46 @@ +@extends('frame',['front' => false]) + +@section('title', 'The Bad Space | Edit '.$title) + + @section('main-content') + @parent +
+
+

Editing {{$title}}

+
+ @csrf +
+
+
+
+
+
+
+
+ uuid}} /> + +
+

References

+

Images

+ @if($images != null) + @foreach($images as $image) + + + @endforeach + @endif + @php + $action = $location->block_count + $location->silence_count; + $rating = ($action / $sources_count)*100; + @endphp +

Links

+ @foreach($archive_links as $link) + @php + $link = trim($link); + @endphp + {{$link}}
+ @endforeach + +
LAST UPDATED : {{$updated}} +
+
+ @endsection \ No newline at end of file diff --git a/resources/views/back/locations.blade.php b/resources/views/back/locations.blade.php index 69f37c0..3402815 100644 --- a/resources/views/back/locations.blade.php +++ b/resources/views/back/locations.blade.php @@ -6,16 +6,32 @@ @parent
-

Location Listings

- @if($action === "add") - @include('forms.add-location') - @elseif($action === "edit") - EDIT LOCATION - @elseif($action === "bulk-add") - ADD MANY LOCATIONS - @else - START - @endif +

Page {{$pageNum}}

+ PREV + {{$pageNum}} of {{$totalPages}} + NEXT

+ @foreach($locations as $location) + @php + $action = $location->block_count + $location->silence_count; + $rating = ($action / $sources)*100; + @endphp + + {{$rating}}% + +
+ + {{$location->silence_count}} +
+
+ + {{$location->block_count}} +
+
+ @endforeach +
+ PREV + {{$pageNum}} of {{$totalPages}} + NEXT
@endsection \ No newline at end of file diff --git a/resources/views/back/start.blade.php b/resources/views/back/start.blade.php index 10cc9f3..4f09322 100644 --- a/resources/views/back/start.blade.php +++ b/resources/views/back/start.blade.php @@ -8,7 +8,7 @@

Hey {{$handle}}

Manage Member
- Manage Location + Manage Location
@endsection \ No newline at end of file diff --git a/resources/views/frame.blade.php b/resources/views/frame.blade.php index 25360cb..160e670 100644 --- a/resources/views/frame.blade.php +++ b/resources/views/frame.blade.php @@ -8,7 +8,12 @@ @yield('title') - + @if(isset($front) && $front == false) + + @elseif(!isset($front) || $front == true) + + @endif + diff --git a/routes/web.php b/routes/web.php index ad95f26..b7ac2de 100644 --- a/routes/web.php +++ b/routes/web.php @@ -41,8 +41,9 @@ Route::get("/logout", [AuthController::class, 'leave']); Route::group(['prefix' => 'den', 'middleware' => 'member.check'], function () { Route::get("/", [DenController::class, 'start']); Route::get("/member", [DenController::class, 'member']); - Route::get("/locations/{action?}", [DenController::class, 'location']); - Route::post("/locations/add", [LocationController::class, 'addLocation']); + Route::get("/locations/{pageNum}", [DenController::class, 'location']); + Route::get("/location/edit/{uuid}", [DenController::class, 'locationEdit']); + Route::post("/locations/edit", [LocationController::class, 'editLocation']); //admin actions Route::get("/admin/update", [LocationController::class, 'updateLocations']); Route::get("/admin/compile", [LocationController::class, 'compileLocations']);