Initial commit - construprogress app
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class VerifyEmailController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mark the authenticated user's email address as verified.
|
||||
*/
|
||||
public function __invoke(EmailVerificationRequest $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
|
||||
}
|
||||
|
||||
if ($request->user()->markEmailAsVerified()) {
|
||||
event(new Verified($request->user()));
|
||||
}
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\features;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FeaturesController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(features $features)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(features $features)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, features $features)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(features $features)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\PendingSync;
|
||||
use App\Models\Phase;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class OfflineSyncController extends Controller
|
||||
{
|
||||
public function storePending(Request $request)
|
||||
{
|
||||
$payload = $request->validate([
|
||||
'action' => 'required|in:progress_update,task_complete',
|
||||
'payload' => 'required|array',
|
||||
]);
|
||||
$pending = PendingSync::create([
|
||||
'user_id' => Auth::id() ?? 1,
|
||||
'action' => $payload['action'],
|
||||
'payload' => $payload['payload'],
|
||||
]);
|
||||
return response()->json(['queued' => true]);
|
||||
}
|
||||
|
||||
public function sync(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$pendings = PendingSync::where('user_id', $user->id)->whereNull('synced_at')->get();
|
||||
foreach ($pendings as $pending) {
|
||||
if ($pending->action === 'progress_update') {
|
||||
$phase = Phase::find($pending->payload['phase_id']);
|
||||
if ($phase) {
|
||||
$phase->progress_percent = $pending->payload['progress'];
|
||||
$phase->save();
|
||||
$phase->progressUpdates()->create([
|
||||
'user_id' => $user->id,
|
||||
'progress_percent' => $pending->payload['progress'],
|
||||
'comment' => $pending->payload['comment'] ?? '',
|
||||
'location' => $pending->payload['location'] ?? null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
$pending->synced_at = now();
|
||||
$pending->save();
|
||||
}
|
||||
return response()->json(['synced' => count($pendings)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\User;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class ProjectController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
Gate::authorize('view projects');
|
||||
return view('projects.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Gate::authorize('create projects');
|
||||
return view('projects.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Gate::authorize('create projects');
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'address' => 'required',
|
||||
'lat' => 'required|numeric',
|
||||
'lng' => 'required|numeric',
|
||||
'start_date' => 'required|date',
|
||||
'end_date_estimated' => 'nullable|date',
|
||||
]);
|
||||
$project = Project::create(array_merge($validated, ['created_by' => Auth::id(), 'status' => 'planning']));
|
||||
|
||||
// Assign creator as supervisor in project
|
||||
$project->users()->attach(Auth::id(), ['role_in_project' => 'supervisor']);
|
||||
return redirect()->route('projects.map', $project)->with('success', 'Proyecto creado');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
// No usamos show, redirigimos al mapa o a edición
|
||||
return redirect()->route('projects.map', $project);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Project $project) // <--- ROUTE MODEL BINDING
|
||||
{
|
||||
Gate::authorize('edit projects', $project);
|
||||
return view('projects.edit', compact('project'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Project $project) // <--- ROUTE MODEL BINDING
|
||||
{
|
||||
Gate::authorize('edit projects', $project);
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'address' => 'required|string',
|
||||
'lat' => 'required|numeric',
|
||||
'lng' => 'required|numeric',
|
||||
'status' => 'required|in:planning,in_progress,paused,completed',
|
||||
'start_date' => 'required|date',
|
||||
'end_date_estimated' => 'nullable|date|after:start_date',
|
||||
]);
|
||||
|
||||
$project->update($validated);
|
||||
|
||||
return redirect()->route('projects.index')
|
||||
->with('success', 'Proyecto actualizado correctamente.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified project from storage.
|
||||
*/
|
||||
public function destroy(Project $project) // <--- ROUTE MODEL BINDING
|
||||
{
|
||||
Gate::authorize('delete projects', $project);
|
||||
|
||||
$project->delete();
|
||||
|
||||
return redirect()->route('projects.index')
|
||||
->with('success', 'Proyecto eliminado correctamente.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the map view for a specific project.
|
||||
*/
|
||||
public function map(Project $project)
|
||||
{
|
||||
// Cualquier usuario autenticado puede ver el mapa si tiene acceso al proyecto
|
||||
// (lo validaremos dentro del componente Livewire)
|
||||
return view('projects.map', compact('project'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user