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>
120 lines
4.3 KiB
PHP
120 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use Livewire\Component;
|
|
use Livewire\Attributes\Layout;
|
|
use App\Models\Project;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
#[Layout('layouts.app')]
|
|
class ProjectForm extends Component
|
|
{
|
|
public ?Project $project = null;
|
|
|
|
// Identification
|
|
public string $name = '';
|
|
public string $reference = '';
|
|
public string $status = 'planning';
|
|
|
|
// Location
|
|
public string $address = '';
|
|
public string $country = '';
|
|
public string $lat = '';
|
|
public string $lng = '';
|
|
|
|
// Planning
|
|
public string $startDate = '';
|
|
public string $endDateEstimated = '';
|
|
|
|
public function mount(?Project $project = null): void
|
|
{
|
|
if ($project && $project->exists) {
|
|
Gate::authorize('edit projects', $project);
|
|
$this->project = $project;
|
|
$this->name = $project->name;
|
|
$this->reference = $project->reference ?? '';
|
|
$this->status = $project->status;
|
|
$this->address = $project->address;
|
|
$this->country = $project->country ?? '';
|
|
$this->lat = (string) ($project->lat ?? '');
|
|
$this->lng = (string) ($project->lng ?? '');
|
|
$this->startDate = $project->start_date->format('Y-m-d');
|
|
$this->endDateEstimated = $project->end_date_estimated?->format('Y-m-d') ?? '';
|
|
} else {
|
|
Gate::authorize('create projects');
|
|
$this->startDate = today()->format('Y-m-d');
|
|
}
|
|
}
|
|
|
|
// Called from JS after map click / marker drag + reverse geocode
|
|
public function setLocation(string $lat, string $lng, string $address = '', string $country = ''): void
|
|
{
|
|
$this->lat = $lat;
|
|
$this->lng = $lng;
|
|
if ($address) $this->address = $address;
|
|
if ($country) $this->country = strtolower($country);
|
|
}
|
|
|
|
protected function rules(): array
|
|
{
|
|
return [
|
|
'name' => 'required|string|max:255',
|
|
'reference' => 'nullable|string|max:100',
|
|
'status' => 'required|in:planning,in_progress,paused,completed',
|
|
'address' => 'required|string',
|
|
'country' => 'nullable|string|size:2',
|
|
'lat' => 'nullable|numeric|between:-90,90',
|
|
'lng' => 'nullable|numeric|between:-180,180',
|
|
'startDate' => 'required|date',
|
|
'endDateEstimated' => 'nullable|date|after_or_equal:startDate',
|
|
];
|
|
}
|
|
|
|
protected $validationAttributes = [
|
|
'name' => 'nombre',
|
|
'reference' => 'referencia',
|
|
'status' => 'estado',
|
|
'address' => 'dirección',
|
|
'country' => 'país',
|
|
'lat' => 'latitud',
|
|
'lng' => 'longitud',
|
|
'startDate' => 'fecha de inicio',
|
|
'endDateEstimated' => 'fecha de fin estimada',
|
|
];
|
|
|
|
public function save(): void
|
|
{
|
|
$this->validate();
|
|
|
|
$data = [
|
|
'name' => $this->name,
|
|
'reference' => $this->reference ?: null,
|
|
'status' => $this->status,
|
|
'address' => $this->address,
|
|
'country' => $this->country ?: null,
|
|
'lat' => $this->lat ?: null,
|
|
'lng' => $this->lng ?: null,
|
|
'start_date' => $this->startDate,
|
|
'end_date_estimated' => $this->endDateEstimated ?: null,
|
|
];
|
|
|
|
if ($this->project && $this->project->exists) {
|
|
$this->project->update($data);
|
|
session()->flash('notify', 'Proyecto actualizado correctamente.');
|
|
} else {
|
|
$project = Project::create(array_merge($data, ['created_by' => Auth::id()]));
|
|
$project->users()->attach(Auth::id(), ['role_in_project' => 'supervisor']);
|
|
session()->flash('notify', 'Proyecto creado correctamente.');
|
|
}
|
|
|
|
$this->redirect(route('projects.index'), navigate: true);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.projects.project-form');
|
|
}
|
|
}
|