fix: correcciones parciales - ProjectController, ProfileController, Phase features, project-map JS
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the profile edit form.
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
return view('profile');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user's profile information.
|
||||
*/
|
||||
public function update(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'required|email|max:255|unique:users,email,' . $user->id,
|
||||
]);
|
||||
|
||||
$user->update($validated);
|
||||
|
||||
return redirect()->route('profile')->with('success', 'Perfil actualizado.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the user's account.
|
||||
*/
|
||||
public function destroy(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'password' => ['required', 'current_password'],
|
||||
]);
|
||||
|
||||
$user = Auth::user();
|
||||
Auth::logout();
|
||||
$user->delete();
|
||||
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use App\Models\Project;
|
||||
|
||||
class ProjectController extends Controller
|
||||
{
|
||||
@@ -53,9 +54,9 @@ class ProjectController extends Controller
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
public function show(Project $project)
|
||||
{
|
||||
// No usamos show, redirigimos al mapa o a edición
|
||||
// No usamos show, redirigimos al mapa
|
||||
return redirect()->route('projects.map', $project);
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +101,7 @@ class ProjectMap extends Component
|
||||
*/
|
||||
public function selectFeature($featureId)
|
||||
{
|
||||
$this->selectedFeature = null;
|
||||
$feature = Feature::with('template')->find($featureId);
|
||||
if (!$feature) return;
|
||||
|
||||
|
||||
@@ -30,4 +30,12 @@ class Phase extends Model
|
||||
{
|
||||
return $this->hasOne(Layer::class)->latestOfMany();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all features across all layers of this phase.
|
||||
*/
|
||||
public function features()
|
||||
{
|
||||
return $this->hasManyThrough(Feature::class, Layer::class);
|
||||
}
|
||||
}
|
||||
@@ -140,31 +140,50 @@
|
||||
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
||||
}).addTo(map);*/
|
||||
|
||||
// Add geojson layers for active phases
|
||||
// Add geojson layers for active phases - features loaded from DB via features() relationship
|
||||
@foreach($phases as $phase)
|
||||
const phase{{ $phase->id }}Data = @json($phase->currentLayer?->geojson_data);
|
||||
if (phase{{ $phase->id }}Data) {
|
||||
@php
|
||||
$phaseFeatures = $phase->features()->with('layer')->get();
|
||||
$fc = [
|
||||
'type' => 'FeatureCollection',
|
||||
'features' => $phaseFeatures->map(function($f) {
|
||||
return [
|
||||
'type' => 'Feature',
|
||||
'id' => $f->id,
|
||||
'geometry' => $f->geometry,
|
||||
'properties' => array_merge($f->properties ?? [], [
|
||||
'name' => $f->name,
|
||||
'progress' => $f->progress,
|
||||
'responsible' => $f->responsible,
|
||||
'template_id' => $f->template_id,
|
||||
'_feature_id' => $f->id,
|
||||
])
|
||||
];
|
||||
})->values()->toArray()
|
||||
];
|
||||
@endphp
|
||||
const phase{{ $phase->id }}Data = @json($fc);
|
||||
if (phase{{ $phase->id }}Data && phase{{ $phase->id }}Data.features && phase{{ $phase->id }}Data.features.length > 0) {
|
||||
layers[{{ $phase->id }}] = L.geoJSON(phase{{ $phase->id }}Data, {
|
||||
style: { color: '{{ $phase->color }}', weight: 3, opacity: 0.8, fillOpacity: 0.3 },
|
||||
onEachFeature: function (feature, layer) {
|
||||
const props = feature.properties;
|
||||
const props = feature.properties || {};
|
||||
const featId = props._feature_id || feature.id;
|
||||
let content = `<b>${props.name || 'Elemento'}</b><br>
|
||||
Progreso: ${props.progress || 'N/A'}%<br>
|
||||
Responsable: ${props.responsible || '-'}<br>
|
||||
<input type="range" min="0" max="100" value="${props.progress || 0}" id="slider-${feature.id}" class="range range-sm" />
|
||||
<button class="btn btn-xs btn-primary mt-1" onclick="updatePhaseProgress({{ $phase->id }}, document.getElementById('slider-${feature.id}').value)">Actualizar</button>
|
||||
<button class="btn btn-xs btn-secondary mt-1" onclick="addNote({{ $phase->id }})">Añadir nota</button>`;
|
||||
<input type="range" min="0" max="100" value="${props.progress || 0}" id="slider-${featId}" class="range range-sm" />
|
||||
<button class="btn btn-xs btn-primary mt-1" onclick="window.updateFeatureProgress(${featId}, document.getElementById('slider-${featId}').value)">Actualizar</button>`;
|
||||
layer.bindPopup(content);
|
||||
layer.on('click', function(e) {
|
||||
@this.selectFeature(feature.properties.id, feature.properties);
|
||||
@this.selectFeature(featId);
|
||||
});
|
||||
}
|
||||
});
|
||||
if (@json(in_array($phase->id, $activeLayers))) {
|
||||
layers[{{ $phase->id }}].addTo(map);
|
||||
}
|
||||
}
|
||||
@endforeach
|
||||
|
||||
|
||||
// 🔁 Forzar que el mapa recalcule su tamaño (por si el contenedor no está visible al 100%)
|
||||
setTimeout(() => {
|
||||
@@ -242,8 +261,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
window.updatePhaseProgress = function(phaseId, progress) {
|
||||
@this.updateProgress(phaseId, progress);
|
||||
window.updateFeatureProgress = function(featureId, progress) {
|
||||
@this.updateProgress(featureId, progress, 'Actualizado desde mapa');
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
Reference in New Issue
Block a user