7d854ffb0a
- Translation system: lang/es/ PHP files (auth, validation, pagination, passwords)
- Rappasoft vendor translations published (lang/vendor/livewire-tables/es/)
- JSON files synced to 391 keys (EN + ES, full parity)
- APP_LOCALE changed to 'es', users.locale column default changed to 'es'
- Language switcher fixed: JS event + window.location.reload() avoids /livewire/update redirect
- SetLocale middleware fallback uses config('app.locale') instead of hardcoded 'en'
- setSortingPillsEnabled(false) on ProjectTable, CompanyTable, UserTable
- Translated 17 blade views: project-map, template-manager, layer-manager,
company-management, phase-list, media-manager, reports-dashboard,
client-projects, layer-upload, project-form, project-map-editor-tab,
admin/users, projects/media, projects/templates, layouts/client
- Navigation 'Empresas' link uses __('Companies')
- Fixed typo key 'Fases and layers' -> 'Phases and layers'
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
111 lines
3.5 KiB
PHP
111 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use Livewire\Component;
|
|
use Livewire\Attributes\Layout;
|
|
use App\Models\User;
|
|
use App\Models\Project;
|
|
use App\Models\Inspection;
|
|
use App\Models\Issue;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
#[Layout('layouts.app')]
|
|
class UserView extends Component
|
|
{
|
|
public User $user;
|
|
public string $activeTab = 'permissions';
|
|
|
|
// Projects tab
|
|
public ?int $addProjectId = null;
|
|
public string $addProjectRole = '';
|
|
public $availableProjects;
|
|
|
|
// Notes tab
|
|
public string $notes = '';
|
|
public bool $editingNotes = false;
|
|
|
|
// Recent activity (loaded once)
|
|
public $recentInspections;
|
|
public $recentIssues;
|
|
|
|
public function mount(User $user): void
|
|
{
|
|
if (!Auth::user()->hasRole('Admin')) abort(403);
|
|
|
|
$this->user = $user->load(['roles', 'company', 'projects.phases']);
|
|
$this->notes = $user->notes ?? '';
|
|
|
|
$this->loadAvailableProjects();
|
|
$this->loadActivity();
|
|
}
|
|
|
|
private function loadAvailableProjects(): void
|
|
{
|
|
$assignedIds = $this->user->projects->pluck('id');
|
|
$this->availableProjects = Project::whereNotIn('id', $assignedIds)
|
|
->orderBy('name')->get();
|
|
}
|
|
|
|
private function loadActivity(): void
|
|
{
|
|
$this->recentInspections = Inspection::where('user_id', $this->user->id)
|
|
->with(['feature.layer.phase.project', 'template'])
|
|
->latest()->take(8)->get();
|
|
|
|
$this->recentIssues = Issue::where('reported_by', $this->user->id)
|
|
->with(['feature', 'project'])
|
|
->latest()->take(8)->get();
|
|
}
|
|
|
|
// ── Tabs ─────────────────────────────────────────────────────────────────
|
|
|
|
public function setTab(string $tab): void
|
|
{
|
|
$this->activeTab = $tab;
|
|
}
|
|
|
|
// ── Projects ──────────────────────────────────────────────────────────────
|
|
|
|
public function assignProject(): void
|
|
{
|
|
$this->validate([
|
|
'addProjectId' => 'required|exists:projects,id',
|
|
'addProjectRole' => 'nullable|string|max:100',
|
|
], [], ['addProjectId' => 'proyecto', 'addProjectRole' => 'rol en proyecto']);
|
|
|
|
$this->user->projects()->attach($this->addProjectId, [
|
|
'role_in_project' => $this->addProjectRole ?: null,
|
|
]);
|
|
|
|
$this->user->load('projects.phases');
|
|
$this->addProjectId = null;
|
|
$this->addProjectRole = '';
|
|
$this->loadAvailableProjects();
|
|
$this->dispatch('notify', 'Proyecto asignado.');
|
|
}
|
|
|
|
public function removeProject(int $projectId): void
|
|
{
|
|
$this->user->projects()->detach($projectId);
|
|
$this->user->load('projects.phases');
|
|
$this->loadAvailableProjects();
|
|
$this->dispatch('notify', 'Proyecto desasignado.');
|
|
}
|
|
|
|
// ── Notes ─────────────────────────────────────────────────────────────────
|
|
|
|
public function saveNotes(): void
|
|
{
|
|
$this->validate(['notes' => 'nullable|string']);
|
|
$this->user->update(['notes' => $this->notes ?: null]);
|
|
$this->editingNotes = false;
|
|
$this->dispatch('notify', 'Notas guardadas.');
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.user-view');
|
|
}
|
|
}
|