Merge branch 'main' of https://homehud.duckdns.org/javier/Nexora
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled

This commit is contained in:
2025-05-07 00:21:14 +02:00
11 changed files with 378 additions and 0 deletions

View File

@@ -57,8 +57,12 @@ 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
@@ -73,12 +77,20 @@ 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();
}
@@ -130,11 +142,17 @@ 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'],
@@ -146,14 +164,21 @@ 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) {
@@ -171,6 +196,32 @@ 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: ';
@@ -179,11 +230,20 @@ 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();
}
@@ -193,13 +253,20 @@ 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
]);
}

View File

@@ -10,6 +10,7 @@ class ImageUploader extends Component
{
use WithFileUploads;
<<<<<<< HEAD
public $image;
public $imagePath;
public $fieldName; // Nombre del campo para el formulario
@@ -46,10 +47,41 @@ class ImageUploader extends Component
field: $this->fieldName,
path: $this->imagePath
);
=======
public $photo;
public $currentImage;
public $fieldName;
public $placeholder;
public $storagePath = 'tmp/uploads';
protected $rules = [
'photo' => 'nullable|image|max:2048', // 2MB Max
];
public function mount($fieldName = 'photo', $currentImage = null, $placeholder = null)
{
$this->fieldName = $fieldName;
$this->currentImage = $currentImage;
$this->placeholder = $placeholder ?? asset('images/default-avatar.png');
}
public function updatedPhoto()
{
$this->validate([
'photo' => 'image|max:2048', // 2MB Max
]);
}
public function removePhoto()
{
$this->photo = null;
$this->currentImage = null;
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
}
public function save()
{
<<<<<<< HEAD
$this->validate([
'image' => 'required|image|max:2048',
]);
@@ -79,6 +111,38 @@ class ImageUploader extends Component
$this->hover = $status;
}
=======
$this->validate();
if ($this->photo) {
$path = $this->photo->store($this->storagePath);
if ($this->model) {
// Eliminar imagen anterior si existe
if ($this->model->{$this->fieldName}) {
Storage::delete($this->model->{$this->fieldName});
}
$this->model->{$this->fieldName} = $path;
$this->model->save();
}
$this->currentUrl = Storage::url($path);
$this->showSavedMessage = true;
$this->photo = null; // Limpiar el input de subida
}
}
protected function getCurrentImageUrl()
{
if ($this->model && $this->model->{$this->fieldName}) {
return Storage::url($this->model->{$this->fieldName});
}
return $this->placeholder;
}
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
public function render()
{
return view('livewire.image-uploader');

View File

@@ -240,6 +240,7 @@ class ProjectShow extends Component
public function render()
{
<<<<<<< HEAD
return view('livewire.project.show')->layout('components.layouts.documents', [
'title' => __('Project: :name', ['name' => $this->project->name]),
'breadcrumbs' => [
@@ -247,5 +248,8 @@ class ProjectShow extends Component
['name' => $this->project->name, 'url' => route('projects.show', $this->project)],
],
]);
=======
return view('livewire.project-show');
>>>>>>> f97a7a84985ea300216ba3ea2ab4c31306e1659a
}
}