updates to document handling and code editing features
This commit is contained in:
@@ -11,6 +11,8 @@ use App\Models\Document;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use App\Helpers\DocumentIdentifier;
|
||||
|
||||
class ProjectShow extends Component
|
||||
{
|
||||
|
||||
@@ -31,6 +33,8 @@ class ProjectShow extends Component
|
||||
public $selectedFiles = []; // Archivos temporales en el modal
|
||||
public $uploadProgress = [];
|
||||
|
||||
protected $listeners = ['documents-updated' => '$refresh'];
|
||||
|
||||
|
||||
public function mount(Project $project)
|
||||
{
|
||||
@@ -80,28 +84,6 @@ class ProjectShow extends Component
|
||||
$this->project->refresh();
|
||||
}
|
||||
|
||||
/*public function uploadFiles(): void
|
||||
{
|
||||
$this->validate([
|
||||
'files.*' => 'file|max:10240|mimes:pdf,docx,xlsx,jpg,png'
|
||||
]);
|
||||
dd($this->files);
|
||||
foreach ($this->files as $file) {
|
||||
Document::create([
|
||||
'name' => $file->getClientOriginalName(),
|
||||
'file_path' => $file->store("projects/{$this->project->id}/documents"),
|
||||
'project_id' => $this->project->id,
|
||||
'folder_id' => $this->currentFolder?->id
|
||||
]);
|
||||
}
|
||||
|
||||
$this->reset('files');
|
||||
if ($this->currentFolder) {
|
||||
$this->currentFolder->refresh(); // Recargar documentos
|
||||
}
|
||||
$this->reset('files');
|
||||
}*/
|
||||
|
||||
public function getDocumentsProperty()
|
||||
{
|
||||
return $this->currentFolder
|
||||
@@ -158,20 +140,41 @@ class ProjectShow extends Component
|
||||
$this->selectedFiles = array_values($this->selectedFiles); // Reindexar array
|
||||
}
|
||||
|
||||
// Método para confirmar y guardar
|
||||
public function uploadFiles(): void
|
||||
{
|
||||
foreach ($this->selectedFiles as $file) {
|
||||
Document::create([
|
||||
'name' => $file->getClientOriginalName(),
|
||||
'file_path' => $file->store("projects/{$this->project->id}/documents"),
|
||||
'project_id' => $this->project->id, // Asegurar que se envía
|
||||
'folder_id' => $this->currentFolder?->id,
|
||||
'user_id' => Auth::id(),
|
||||
//'status' => 'active' // Añadir si tu modelo lo requiere
|
||||
]);
|
||||
//$analizador = analizarDocumento();
|
||||
//print_r($analizador);
|
||||
//$resultado1 = $analizador->analizarDocumento($file->getClientOriginalName());
|
||||
|
||||
$code = $this->project->reference;
|
||||
|
||||
// Buscar si ya existe un documento con el mismo nombre en el mismo proyecto y carpeta
|
||||
$existingDocument = Document::where('project_id', $this->project->id)
|
||||
->where('folder_id', $this->currentFolder?->id)
|
||||
->where('name', $file->getClientOriginalName())
|
||||
->first();
|
||||
|
||||
if ($existingDocument) {
|
||||
// Si existe, crear una nueva versión/revisión
|
||||
$existingDocument->createVersion($file);
|
||||
|
||||
} else {
|
||||
// Si no existe, crear el documento con revisión 0
|
||||
$document = Document::create([
|
||||
'name' => $file->getClientOriginalName(),
|
||||
'file_path' => $file->store("projects/{$this->project->id}/documents"),
|
||||
'project_id' => $this->project->id,
|
||||
'folder_id' => $this->currentFolder?->id,
|
||||
'issuer_id' => Auth::id(),
|
||||
'code' => $code,
|
||||
'entry_date' => now(),
|
||||
'revision' => 0, // Revisión inicial
|
||||
]);
|
||||
$document->createVersion($file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->resetUpload();
|
||||
$this->project->refresh();
|
||||
}
|
||||
@@ -226,7 +229,8 @@ class ProjectShow extends Component
|
||||
'file_path' => $path,
|
||||
'project_id' => $this->project->id,
|
||||
'folder_id' => $this->currentFolder?->id,
|
||||
'user_id' => Auth::id()
|
||||
'user_id' => Auth::id(),
|
||||
'code' => $code,
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
@@ -247,4 +251,9 @@ class ProjectShow extends Component
|
||||
{
|
||||
return \App\Helpers\ProjectNamingSchema::generate($fields);
|
||||
}
|
||||
|
||||
public function sellectAllDocuments()
|
||||
{
|
||||
$this->selectedFiles = $this->documents->pluck('id')->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user