mirror of
https://koodu.h-i.works/projects/thebadspace
synced 2025-06-25 16:04:37 -05:00
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:
@ -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'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ class Location extends Model
|
||||
"silence_count",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"actions_count"
|
||||
"actions_count",
|
||||
"archive_links"
|
||||
];
|
||||
}
|
||||
|
@ -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([
|
||||
|
Reference in New Issue
Block a user