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
This commit is contained in:
ro 2024-02-20 16:33:49 -06:00
parent 682360c140
commit 2a6b4b2c99
11 changed files with 180 additions and 39 deletions

View file

@ -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]);
'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'),
]);
}
}

View file

@ -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)
{
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']);
}
}
}

View file

@ -34,6 +34,7 @@ class Location extends Model
"silence_count",
"created_at",
"updated_at",
"actions_count"
"actions_count",
"archive_links"
];
}

View file

@ -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([

View file

@ -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;

View file

@ -1 +1 @@
/Users/ro/Projects/TheBadSpace/first/storage/app/reference
/Users/ro/Herd/TBS/storage/app/reference

View file

@ -0,0 +1,46 @@
@extends('frame',['front' => false])
@section('title', 'The Bad Space | Edit '.$title)
@section('main-content')
@parent
<section class="edit-location">
<article>
<h2>Editing {{$title}}</h2>
<form class="location-edit" action="/den/locations/edit" method="post" enctype="multipart/form-data">
@csrf
<label>Edit Location Name</label><br>
<input type="text" name="name" value="{{$location->name}}" /><br>
<label>Edit Location Comments</label><br>
<textarea name="description">{{$location->description}}</textarea><br>
<label>Edit Reference Links (comma seperated)</label><br>
<textarea name="archive_links">{{$location->archive_links}}</textarea><br>
<label>Edit Reference Images</label><br>
<input type="file" name="references[]" accept="image/png, image/jpeg, image/gif" / multiple><br />
<input type="hidden" name="id" value={{$location->uuid}} />
<input type="submit" value="Edit {{$location->name}}" name="submit_button">
</form>
<h2>References</h2>
<h3>Images</h3>
@if($images != null)
@foreach($images as $image)
<a href="/{{$image->path}}" class="location-image" style="background: url(/{{$image->path}}) no-repeat center center / cover #fc6399" />
</a>
@endforeach
@endif
@php
$action = $location->block_count + $location->silence_count;
$rating = ($action / $sources_count)*100;
@endphp
<h3>Links</h3>
@foreach($archive_links as $link)
@php
$link = trim($link);
@endphp
<a href="https://{{$link}}" target="_blank">{{$link}}</a><br />
@endforeach
<br />LAST UPDATED : {{$updated}}
</article>
</section>
@endsection

View file

@ -6,16 +6,32 @@
@parent
<section>
<article>
<h2>Location Listings</h2>
@if($action === "add")
@include('forms.add-location')
@elseif($action === "edit")
EDIT LOCATION
@elseif($action === "bulk-add")
ADD MANY LOCATIONS
@else
START
@endif
<h2>Page {{$pageNum}}</h2>
<a href="/listings/{{$prev}}">PREV</a>
{{$pageNum}} of {{$totalPages}}
<a href="/listings/{{$next}}">NEXT</a><br /><br />
@foreach($locations as $location)
@php
$action = $location->block_count + $location->silence_count;
$rating = ($action / $sources)*100;
@endphp
<a class="list-link" role="listitem" href="/den/location/edit/{{$location->uuid}}">
<span class="item-rating">{{$rating}}%</span>
<label class="item-name">{{$location->name}}</label>
<div class="item-silence">
<img class="item-icon" src="/assets/images/global/status-silence.svg" title="silenced" />
{{$location->silence_count}}
</div>
<div class="item-block">
<img class="item-icon" src="/assets/images/global/status-suspend.svg" title="suspended" />
{{$location->block_count}}
</div>
</a>
@endforeach
<br />
<a href="/listings/{{$prev}}">PREV</a>
{{$pageNum}} of {{$totalPages}}
<a href="/listings/{{$next}}">NEXT</a>
</article>
</section>
@endsection

View file

@ -8,7 +8,7 @@
<article>
<h2>Hey {{$handle}} </h2>
<a href="/den/member">Manage Member</a><br />
<a href="/den/locations">Manage Location</a>
<a href="/den/locations/1">Manage Location</a>
</article>
</section>
@endsection

View file

@ -8,7 +8,12 @@
<title>
@yield('title')
</title>
@if(isset($front) && $front == false)
<link rel="stylesheet" type="text/css" href="/assets/css/back/start.css?=sdfsdf">
@elseif(!isset($front) || $front == true)
<link rel="stylesheet" type="text/css" href="/assets/css/front/start.css?=sdfsdf">
@endif
</head>
<body>

View file

@ -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']);