añadir nuevas funcionalidades
This commit is contained in:
66
app/Livewire/CountrySelect.php
Normal file
66
app/Livewire/CountrySelect.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class CountrySelect extends Component
|
||||
{
|
||||
public $selectedCountry;
|
||||
public $countrySearch = '';
|
||||
public $search = '';
|
||||
public $isOpen = false;
|
||||
public $initialCountry;
|
||||
|
||||
protected $rules = [
|
||||
'selectedCountry' => 'required',
|
||||
];
|
||||
|
||||
public function mount($initialCountry = null)
|
||||
{
|
||||
$this->selectedCountry = $initialCountry;
|
||||
}
|
||||
|
||||
public function selectCountry($code)
|
||||
{
|
||||
$this->selectedCountry = $code;
|
||||
$this->isOpen = false;
|
||||
$this->search = ''; // Limpiar la búsqueda al seleccionar
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$countries = collect(config('countries'))
|
||||
->when($this->search, function($collection) {
|
||||
// Corregimos el filtrado aquí
|
||||
return $collection->filter(function($name, $code) {
|
||||
$searchLower = strtolower($this->search);
|
||||
$nameLower = strtolower($name);
|
||||
$codeLower = strtolower($code);
|
||||
|
||||
return str_contains($nameLower, $searchLower) ||
|
||||
str_contains($codeLower, $searchLower);
|
||||
});
|
||||
});
|
||||
|
||||
return view('livewire.country-select', compact('countries'));
|
||||
}
|
||||
|
||||
public function formattedCountry($code, $name)
|
||||
{
|
||||
return $this->getFlagEmoji($code).' '.$name.' ('.strtoupper($code).')';
|
||||
}
|
||||
|
||||
protected function getFlagEmoji($countryCode)
|
||||
{
|
||||
$countryCode = strtoupper($countryCode);
|
||||
$flagOffset = 0x1F1E6;
|
||||
$asciiOffset = 0x41;
|
||||
|
||||
$firstChar = ord($countryCode[0]) - $asciiOffset + $flagOffset;
|
||||
$secondChar = ord($countryCode[1]) - $asciiOffset + $flagOffset;
|
||||
|
||||
return mb_convert_encoding('&#'.intval($firstChar).';', 'UTF-8', 'HTML-ENTITIES')
|
||||
. mb_convert_encoding('&#'.intval($secondChar).';', 'UTF-8', 'HTML-ENTITIES');
|
||||
}
|
||||
}
|
||||
79
app/Livewire/ImageUploader.php
Normal file
79
app/Livewire/ImageUploader.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ImageUploader extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.image-uploader');
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ class ProjectShow extends Component
|
||||
]);
|
||||
|
||||
$this->reset('folderName');
|
||||
$this->project->load('rootFolders'); // Recargar carpetas raíz
|
||||
$this->project->load('rootFolders'); // Recargar carpetas raíz
|
||||
if ($this->currentFolder) {
|
||||
$this->currentFolder->load('children'); // Recargar hijos si está en una subcarpeta
|
||||
}
|
||||
@@ -118,9 +118,6 @@ class ProjectShow extends Component
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.project-show')
|
||||
->layout('layouts.livewire-app', [
|
||||
'title' => $this->project->name
|
||||
]);
|
||||
return view('livewire.project-show');
|
||||
}
|
||||
}
|
||||
|
||||
81
app/Livewire/UserPhotoUpload.php
Normal file
81
app/Livewire/UserPhotoUpload.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\User;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class UserPhotoUpload extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public $photo;
|
||||
public $existingPhoto;
|
||||
public $tempPhoto;
|
||||
public $userId;
|
||||
|
||||
protected $listeners = ['photoUpdated' => 'refreshPhoto'];
|
||||
|
||||
public function mount($existingPhoto = null, $userId = null)
|
||||
{
|
||||
$this->existingPhoto = $existingPhoto;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
public function uploadPhoto()
|
||||
{
|
||||
$this->validate([
|
||||
'photo' => 'image|max:2048|mimes:jpg,png,jpeg,gif',
|
||||
]);
|
||||
|
||||
$this->tempPhoto = $this->photo->temporaryUrl();
|
||||
}
|
||||
|
||||
public function updatedPhoto()
|
||||
{
|
||||
$this->validate([
|
||||
'photo' => 'image|max:2048|mimes:jpg,png,jpeg,gif',
|
||||
]);
|
||||
|
||||
$this->tempPhoto = $this->photo->temporaryUrl();
|
||||
|
||||
// Emitir evento con la foto temporal
|
||||
$this->emit('photoUploaded', $this->photo->getRealPath());
|
||||
}
|
||||
|
||||
public function removePhoto()
|
||||
{
|
||||
$this->reset('photo', 'tempPhoto');
|
||||
}
|
||||
|
||||
public function deletePhoto()
|
||||
{
|
||||
if ($this->existingPhoto) {
|
||||
Storage::delete('public/photos/' . $this->existingPhoto);
|
||||
|
||||
if ($this->userId) {
|
||||
$user = User::find($this->userId);
|
||||
$user->update(['profile_photo_path' => null]);
|
||||
}
|
||||
|
||||
$this->existingPhoto = null;
|
||||
$this->emit('photoDeleted');
|
||||
}
|
||||
}
|
||||
|
||||
public function refreshPhoto()
|
||||
{
|
||||
$this->existingPhoto = User::find($this->userId)->profile_photo_path;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.user-photo-upload', [
|
||||
//'photo' => $this->photo,
|
||||
'tempPhoto' => $this->tempPhoto,
|
||||
'existingPhoto' => $this->existingPhoto,
|
||||
]);
|
||||
}
|
||||
}
|
||||
109
app/Livewire/UserTable.php
Normal file
109
app/Livewire/UserTable.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
use App\Models\User;
|
||||
|
||||
class UserTable extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
public $sortField = 'first_name';
|
||||
public $sortDirection = 'asc';
|
||||
|
||||
public $columns = [
|
||||
'full_name' => true,
|
||||
'is_active' => true,
|
||||
'username' => true,
|
||||
'email' => true,
|
||||
'phone' => false,
|
||||
'access_start' => false,
|
||||
'created_at' => false,
|
||||
'is_active' => false,
|
||||
];
|
||||
|
||||
public $filters = [
|
||||
'full_name' => '',
|
||||
'is_active' => '',
|
||||
'username' => '',
|
||||
'email' => '',
|
||||
'phone' => '',
|
||||
'access_start' => '',
|
||||
'created_at' => ''
|
||||
];
|
||||
|
||||
protected $queryString = [
|
||||
'filters' => ['except' => ''],
|
||||
'columns' => ['except' => '']
|
||||
];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
// Recuperar preferencias de columnas de la sesión
|
||||
$this->columns = session('user_columns', $this->columns);
|
||||
}
|
||||
|
||||
public function updatedColumns()
|
||||
{
|
||||
// Guardar preferencias en sesión
|
||||
session(['user_columns' => $this->columns]);
|
||||
}
|
||||
|
||||
public function sortBy($field)
|
||||
{
|
||||
if ($this->sortField === $field) {
|
||||
$this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc';
|
||||
} else {
|
||||
$this->sortDirection = 'asc';
|
||||
}
|
||||
|
||||
$this->sortField = $field;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$users = User::query()
|
||||
->when($this->filters['full_name'], fn($q, $search) =>
|
||||
$q->whereRaw("CONCAT(title, ' ', first_name, ' ', last_name) LIKE ?", ["%$search%"]))
|
||||
->when($this->sortField === 'full_name', fn($q) =>
|
||||
$q->orderByRaw("CONCAT(title, ' ', first_name, ' ', last_name) " . $this->sortDirection)
|
||||
)
|
||||
->when($this->sortField === 'created_at', fn($q) =>
|
||||
$q->orderBy('created_at', $this->sortDirection)
|
||||
)
|
||||
->when($this->sortField === 'access_start', fn($q) =>
|
||||
$q->orderBy('access_start', $this->sortDirection)
|
||||
)
|
||||
->when(in_array($this->sortField, ['username', 'email', 'phone']), fn($q) =>
|
||||
$q->orderBy($this->sortField, $this->sortDirection)
|
||||
)
|
||||
->when($this->filters['full_name'], fn($q, $search) =>
|
||||
$q->whereRaw("CONCAT(title, ' ', first_name, ' ', last_name) LIKE ?", ["%$search%"]))
|
||||
->when($this->filters['username'], fn($q, $search) =>
|
||||
$q->where('username', 'LIKE', "%$search%"))
|
||||
->when($this->filters['email'], fn($q, $search) =>
|
||||
$q->where('email', 'LIKE', "%$search%"))
|
||||
->when($this->filters['phone'], fn($q, $search) =>
|
||||
$q->where('phone', 'LIKE', "%$search%"))
|
||||
->when($this->filters['access_start'], fn($q, $date) =>
|
||||
$q->whereDate('access_start', $date))
|
||||
->when($this->filters['created_at'], fn($q, $date) =>
|
||||
$q->whereDate('created_at', $date))
|
||||
->paginate(10);
|
||||
|
||||
return view('livewire.user-table', [
|
||||
'users' => $users,
|
||||
'available_columns' => [
|
||||
'full_name' => 'Nombre Completo',
|
||||
'username' => 'Usuario',
|
||||
'email' => 'Correo',
|
||||
'phone' => 'Teléfono',
|
||||
'access_start' => 'Fecha de acceso',
|
||||
'created_at' => 'Fecha creación',
|
||||
'is_active' => 'Estado'
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user