mejoras
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled

This commit is contained in:
2025-05-23 00:26:53 +02:00
parent 19fa52ca65
commit 28c225687a
431 changed files with 161955 additions and 2096 deletions

View File

@@ -24,10 +24,8 @@ class DashboardController extends Controller
// Documentos recientes (últimos 7 días)
$recentDocuments = Document::with(['project', 'currentVersion'])
->where('created_at', '>=', now()->subDays(7))
->orderBy('created_at', 'desc')
->limit(5)
->get();
->limit(5);
// Actividad reciente
$recentActivities = DB::table('activity_log')
@@ -35,7 +33,9 @@ class DashboardController extends Controller
->limit(10)
->get();
return view('dashboard', compact('stats', 'recentDocuments', 'recentActivities'));
$showSidebar = true; // Variable para mostrar el sidebar
return view('dashboard', compact('stats', 'recentDocuments', 'recentActivities', 'showSidebar'));
}
private function calculateStorageUsed()

View File

@@ -7,6 +7,7 @@ use App\Models\Project;
use App\Models\User;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class ProjectController extends Controller
{
@@ -37,8 +38,9 @@ class ProjectController extends Controller
public function create()
{
$this->authorize('create projects');
$project = new Project();
return view('projects.create', [
'project' => $project,
'categories' => Category::orderBy('name')->get(),
'users' => User::where('id', '!=', auth()->id())->get(),
]);
@@ -50,25 +52,22 @@ class ProjectController extends Controller
public function store(Request $request)
{
$validated = $request->validate([
'reference' => 'required|string|max:255',
'name' => 'required|string|max:255',
'description' => 'nullable|string',
'status' => 'required|in:Activo,Inactivo',
//'team' => 'sometimes|array',
//'team.*' => 'exists:users,id',
'project_image' => 'nullable|image|mimes:jpeg,png,jpg,gif|max:2048',
'address' => 'nullable|string|max:255',
'province' => 'nullable|string|max:100',
//'country' => 'nullable|string|size:2',
'country' => 'nullable|string|size:2',
'postal_code' => 'nullable|string|max:10',
'latitude' => 'required|numeric|between:-90,90',
'longitude' => 'required|numeric|between:-180,180',
//'icon' => 'nullable|in:'.implode(',', config('project.icons')),
'start_date' => 'nullable|date',
'deadline' => 'nullable|date|after:start_date',
'categories' => 'nullable|array|exists:categories,id',
//'categories' => 'required|array',
//'categories.*' => 'exists:categories,id',
//'documents.*' => 'file|max:5120|mimes:pdf,docx,xlsx,jpg,png'
'project_image_path' => 'nullable|string',
]);
@@ -79,11 +78,14 @@ class ProjectController extends Controller
]);
// Manejar la imagen
if ($request->hasFile('project_image')) {
$path = $request->file('project_image')->store('project-images', 'public');
$validated['project_image_path'] = $path; // Usar el nombre correcto de columna
if ($request->has('project_image_path') && $request->project_image_path) {
$tempPath = $request->project_image_path;
$newPath = 'images/projects/' . basename($tempPath);
Storage::move($tempPath, $newPath); // Mover el archivo
$validated['project_image_path'] = $newPath; // Actualizar path
}
// Crear el proyecto con todos los datos validados
$project = Project::create($validated);
@@ -92,17 +94,6 @@ class ProjectController extends Controller
$project->categories()->sync($request->categories);
}
// Manejar documentos adjuntos
/*
if($request->hasFile('documents')) {
foreach ($request->file('documents') as $file) {
$project->documents()->create([
'file_path' => $file->store('project-documents', 'public'),
'original_name' => $file->getClientOriginalName()
]);
}
}*/
return redirect()->route('projects.show', $project)->with('success', 'Proyecto creado exitosamente');
} catch (\Exception $e) {
@@ -110,6 +101,19 @@ class ProjectController extends Controller
}
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Project $project)
{
$this->authorize('update', $project);
return view('projects.create', [
'project' => $project,
'categories' => Category::orderBy('name')->get(),
'users' => User::where('id', '!=', auth()->id())->get(),
]);
}
/**
* Display the specified resource.
*/
@@ -125,14 +129,6 @@ class ProjectController extends Controller
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Project $project)
{
//
}
/**
* Update the specified resource in storage.
*/

View File

@@ -17,18 +17,25 @@ use Spatie\Permission\Models\Role;
class UserController extends Controller
{
public $collapsedGroups = [];
public function index()
{
$this->authorize('viewAny', User::class);
$users = User::paginate(10);
return view('users.index', compact('users'));
return view('users.index', ['users' => $users,
'showSidebar' => 'true',]);
}
public function create()
{
$this->authorize('create', User::class);
$roles = Role::all();
return view('users.create', compact('roles'));
$user = new User();
return view('users.create', ['user' => $user,
'roles' => $roles,
'showSidebar' => 'true',
]);
}
public function store(Request $request)
@@ -57,12 +64,8 @@ class UserController extends Controller
'end_date' => 'nullable|date|after_or_equal:start_date',
'email' => 'required|email|unique:users',
'phone' => 'nullable|string|max:20',
<<<<<<< HEAD
'address' => 'nullable|string|max:255',
'profile_photo_path' => 'nullable|string' // Ruta de la imagen subida por Livewire
=======
'address' => 'nullable|string|max:255'
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
]);
// Creación del usuario
@@ -77,20 +80,12 @@ class UserController extends Controller
'address' => $validated['address'],
'access_start' => $validated['start_date'],
'access_end' => $validated['end_date'],
<<<<<<< HEAD
'is_active' => true,
'profile_photo_path' => $validated['profile_photo_path'] ?? null
]);
if ($request->hasFile('image_path')) {
$path = $request->file('image_path')->store('public/photos');
=======
'is_active' => true
]);
if ($request->hasFile('photo')) {
$path = $request->file('photo')->store('public/photos');
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
$user->profile_photo_path = basename($path);
$user->save();
}
@@ -142,17 +137,11 @@ class UserController extends Controller
Rule::unique('users')->ignore($user->id)
],
'phone' => 'nullable|string|max:20',
<<<<<<< HEAD
'address' => 'nullable|string|max:255',
'profile_photo_path' => 'nullable|string', // Añadido para la ruta de la imagen
//'is_active' => 'nullable|boolean' // Añadido para el estado activo
]);
=======
'address' => 'nullable|string|max:255'
]);
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
// Preparar datos para actualización
$updateData = [
'title' => $validated['title'],
@@ -164,21 +153,14 @@ class UserController extends Controller
'address' => $validated['address'],
'access_start' => $validated['start_date'],
'access_end' => $validated['end_date'],
<<<<<<< HEAD
'is_active' => $validated['is_active'] ?? false,
'profile_photo_path' => $validated['profile_photo_path'] ?? $user->profile_photo_path
];
=======
'is_active' => $request->has('is_active') // Si usas un checkbox
];
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
// Actualizar contraseña solo si se proporciona
if (!empty($validated['password'])) {
$updateData['password'] = Hash::make($validated['password']);
}
<<<<<<< HEAD
// Eliminar imagen anterior si se está actualizando
if (isset($validated['profile_photo_path']) && $user->profile_photo_path) {
@@ -196,32 +178,6 @@ class UserController extends Controller
return redirect()->back()->withErrors($e->validator)->withInput();
} catch (QueryException $e) {
=======
if ($request->hasFile('photo')) {
// Eliminar foto anterior si existe
if ($user->prfile_photo_path) {
Storage::delete('public/photos/'.$user->profile_photo_path);
}
$path = $request->file('photo')->store('public/photos');
$user->update(['profile_photo_path' => basename($path)]);
}
// Actualizar el usuario
$user->update($updateData);
// Redireccionar con mensaje de éxito
return redirect()->route('users.show', $user)
->with('success', 'Usuario actualizado exitosamente');
} catch (ValidationException $e) {
// Redireccionar con errores de validación
return redirect()->back()->withErrors($e->validator)->withInput();
} catch (QueryException $e) {
// Manejar errores de base de datos
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
$errorCode = $e->errorInfo[1];
$errorMessage = 'Error al actualizar el usuario: ';
@@ -230,20 +186,11 @@ class UserController extends Controller
} else {
$errorMessage .= 'Error en la base de datos';
}
<<<<<<< HEAD
Log::error("Error actualizando usuario ID {$user->id}: " . $e->getMessage());
return redirect()->back()->with('error', $errorMessage)->withInput();
} catch (\Exception $e) {
=======
Log::error("Error actualizando usuario ID {$user->id}: " . $e->getMessage());
return redirect()->back()->with('error', $errorMessage)->withInput();
} catch (\Exception $e) {
// Manejar otros errores
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
Log::error("Error general actualizando usuario ID {$user->id}: " . $e->getMessage());
return redirect()->back()->with('error', 'Ocurrió un error inesperado al actualizar el usuario')->withInput();
}
@@ -253,20 +200,15 @@ class UserController extends Controller
{
$previousUser = User::where('id', '<', $user->id)->latest('id')->first();
$nextUser = User::where('id', '>', $user->id)->oldest('id')->first();
<<<<<<< HEAD
$permissionGroups = $this->getPermissionGroups($user);
=======
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
return view('users.show', [
'user' => $user,
'previousUser' => $previousUser,
'nextUser' => $nextUser,
<<<<<<< HEAD
'permissionGroups' => $permissionGroups,
=======
'permissionGroups' => Permission::all()->groupBy('group')
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
'showSidebar' => true,
'collapsedGroups' => $this->collapsedGroups,
]);
}
@@ -340,4 +282,14 @@ class UserController extends Controller
return $descriptions[$permissionName] ?? str_replace('.', ' ', $permissionName);
}
public function toggleGroupCollapse($groupName)
{
if (in_array($groupName, $this->collapsedGroups)) {
$this->collapsedGroups = array_diff($this->collapsedGroups, [$groupName]);
} else {
$this->collapsedGroups[] = $groupName;
}
}
}