feat: i18n, language switcher fix, DataTable improvements, blade translations
- 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>
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\Attributes\Layout;
|
||||
use App\Models\Company;
|
||||
use App\Models\Project;
|
||||
use App\Models\User;
|
||||
use App\Models\Issue;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
#[Layout('layouts.app')]
|
||||
class CompanyView extends Component
|
||||
{
|
||||
public Company $company;
|
||||
public string $activeTab = 'summary';
|
||||
|
||||
// Projects tab
|
||||
public ?int $addProjectId = null;
|
||||
public string $addProjectRole = '';
|
||||
public $availableProjects;
|
||||
|
||||
// People tab
|
||||
public ?int $assignUserId = null;
|
||||
public $assignableUsers;
|
||||
|
||||
// Notes tab
|
||||
public string $notes = '';
|
||||
public bool $editingNotes = false;
|
||||
|
||||
// Stats (computed once in mount, refreshed on mutations)
|
||||
public int $usersCount = 0;
|
||||
public int $projectsCount = 0;
|
||||
public float $avgProgress = 0.0;
|
||||
public int $openIssues = 0;
|
||||
|
||||
public function mount(Company $company): void
|
||||
{
|
||||
if (!Auth::user()->hasRole('Admin')) abort(403);
|
||||
|
||||
$this->company = $company->load(['users.roles', 'projects.phases']);
|
||||
$this->notes = $company->notes ?? '';
|
||||
|
||||
$this->loadAvailableProjects();
|
||||
$this->loadAssignableUsers();
|
||||
$this->computeStats();
|
||||
}
|
||||
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────
|
||||
|
||||
private function loadAvailableProjects(): void
|
||||
{
|
||||
$assignedIds = $this->company->projects->pluck('id');
|
||||
$this->availableProjects = Project::whereNotIn('id', $assignedIds)
|
||||
->orderBy('name')->get();
|
||||
}
|
||||
|
||||
private function loadAssignableUsers(): void
|
||||
{
|
||||
$this->assignableUsers = User::where(function ($q) {
|
||||
$q->where('company_id', '!=', $this->company->id)
|
||||
->orWhereNull('company_id');
|
||||
})->orderBy('name')->get();
|
||||
}
|
||||
|
||||
private function computeStats(): void
|
||||
{
|
||||
$this->usersCount = $this->company->users->count();
|
||||
$this->projectsCount = $this->company->projects->count();
|
||||
$this->avgProgress = round(
|
||||
$this->company->projects->flatMap(fn($p) => $p->phases)->avg('progress_percent') ?? 0
|
||||
);
|
||||
$userIds = $this->company->users->pluck('id');
|
||||
$this->openIssues = $userIds->isNotEmpty()
|
||||
? Issue::whereIn('reported_by', $userIds)->where('status', 'open')->count()
|
||||
: 0;
|
||||
}
|
||||
|
||||
// ── Tabs ─────────────────────────────────────────────────────────────────
|
||||
|
||||
public function setTab(string $tab): void
|
||||
{
|
||||
$this->activeTab = $tab;
|
||||
}
|
||||
|
||||
// ── Projects ──────────────────────────────────────────────────────────────
|
||||
|
||||
public function assignProject(): void
|
||||
{
|
||||
$this->validate([
|
||||
'addProjectId' => 'required|exists:projects,id',
|
||||
'addProjectRole' => 'required|string|max:150',
|
||||
], [], ['addProjectId' => 'proyecto', 'addProjectRole' => 'rol en proyecto']);
|
||||
|
||||
$this->company->projects()->attach($this->addProjectId, [
|
||||
'role_in_project' => $this->addProjectRole,
|
||||
]);
|
||||
|
||||
$this->company->load('projects.phases');
|
||||
$this->addProjectId = null;
|
||||
$this->addProjectRole = '';
|
||||
$this->loadAvailableProjects();
|
||||
$this->computeStats();
|
||||
$this->dispatch('notify', 'Proyecto asignado correctamente.');
|
||||
}
|
||||
|
||||
public function removeProject(int $projectId): void
|
||||
{
|
||||
$this->company->projects()->detach($projectId);
|
||||
$this->company->load('projects.phases');
|
||||
$this->loadAvailableProjects();
|
||||
$this->computeStats();
|
||||
$this->dispatch('notify', 'Proyecto desasignado.');
|
||||
}
|
||||
|
||||
// ── People ────────────────────────────────────────────────────────────────
|
||||
|
||||
public function assignUser(): void
|
||||
{
|
||||
$this->validate([
|
||||
'assignUserId' => 'required|exists:users,id',
|
||||
], [], ['assignUserId' => 'usuario']);
|
||||
|
||||
User::find($this->assignUserId)?->update(['company_id' => $this->company->id]);
|
||||
|
||||
$this->company->load('users.roles');
|
||||
$this->assignUserId = null;
|
||||
$this->loadAssignableUsers();
|
||||
$this->computeStats();
|
||||
$this->dispatch('notify', 'Usuario vinculado a la empresa.');
|
||||
}
|
||||
|
||||
public function removeUser(int $userId): void
|
||||
{
|
||||
User::find($userId)?->update(['company_id' => null]);
|
||||
$this->company->load('users.roles');
|
||||
$this->loadAssignableUsers();
|
||||
$this->computeStats();
|
||||
$this->dispatch('notify', 'Usuario desvinculado de la empresa.');
|
||||
}
|
||||
|
||||
// ── Notes ─────────────────────────────────────────────────────────────────
|
||||
|
||||
public function saveNotes(): void
|
||||
{
|
||||
$this->validate(['notes' => 'nullable|string']);
|
||||
$this->company->update(['notes' => $this->notes ?: null]);
|
||||
$this->editingNotes = false;
|
||||
$this->dispatch('notify', 'Notas guardadas.');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.company-view');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user