mejoras en la gestión de nombres y códigos de proyectos y documentos según la norma ISO 19650
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled

This commit is contained in:
2025-10-25 11:30:59 +02:00
parent d8ae8c8894
commit 88e526cf6c
13 changed files with 917 additions and 46 deletions

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Helpers;
class ProjectNamingSchema
{
/**
* Generate a project name based on ISO 19650 schema.
*
* @param array $fields Associative array of required and optional fields.
* @return string Generated project name.
*/
public static function generate(array $fields): string
{
// Validate required fields
$requiredFields = ['project', 'creator', 'volume', 'level', 'documentType', 'discipline', 'number'];
foreach ($requiredFields as $field) {
if (empty($fields[$field])) {
throw new \InvalidArgumentException("The field '{$field}' is required.");
}
}
// Build the project name
$projectName = [
strtoupper($fields['project']),
strtoupper($fields['creator']),
strtoupper($fields['volume']),
strtoupper($fields['level']),
strtoupper($fields['documentType']),
strtoupper($fields['discipline']),
str_pad($fields['number'], 3, '0', STR_PAD_LEFT),
];
// Add optional fields if provided
if (!empty($fields['description'])) {
$projectName[] = $fields['description'];
}
if (!empty($fields['status'])) {
$projectName[] = strtoupper($fields['status']);
}
if (!empty($fields['revision'])) {
$projectName[] = str_pad($fields['revision'], 4, '0', STR_PAD_LEFT);
}
return implode('-', $projectName);
}
}

View File

@@ -53,7 +53,7 @@ class ProjectController extends Controller
public function store(Request $request)
{
$validated = $request->validate([
'reference' => 'required|string|max:255',
'reference' => 'required|string|max:12',
'name' => 'required|string|max:255',
'description' => 'nullable|string',
'status' => 'required|in:Activo,Inactivo',

View File

@@ -167,7 +167,7 @@ class ProjectShow extends Component
'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(),
'user_id' => Auth::id(),
//'status' => 'active' // Añadir si tu modelo lo requiere
]);
}
@@ -242,4 +242,9 @@ class ProjectShow extends Component
{
return view('livewire.project.show');
}
public function generateProjectCode(array $fields): string
{
return \App\Helpers\ProjectNamingSchema::generate($fields);
}
}

View File

@@ -21,7 +21,15 @@ class Document extends Model
'project_id', // Asegurar que está en fillable
'folder_id',
'user_id',
'status'
'status',
'revision',
'version',
'discipline',
'document_type',
'issuer',
'entry_date',
'current_version_id',
'code',
];

View File

@@ -12,6 +12,7 @@ return new class extends Migration
public function up(): void
{
Schema::table('projects', function (Blueprint $table) {
$table->string('reference', 12)->nullable()->after('id')->uniqidue();
$table->string('status')->nullable();
$table->string('project_image_path')->nullable();
$table->string('address')->nullable();
@@ -33,6 +34,7 @@ return new class extends Migration
public function down(): void
{
Schema::table('documents', function (Blueprint $table) {
$table->dropColumn('reference');
$table->dropColumn('status');
$table->dropColumn('project_image_path');
$table->dropColumn('address');

View File

@@ -1,28 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('projects', function (Blueprint $table) {
$table->string('reference')->nullable()->after('id')->uniqidue();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('projects', function (Blueprint $table) {
$table->dropColumn('reference');
});
}
};

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('documents', function (Blueprint $table) {
$table->string('code')->before('name');
$table->string('revision')->nullable();
$table->string('version')->nullable();
$table->string('discipline')->nullable();
$table->string('document_type')->nullable();
$table->string('issuer')->nullable();
$table->date('entry_date')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('documents', function (Blueprint $table) {
$table->dropColumn(['code', 'revision', 'version', 'discipline', 'document_type', 'issuer', 'entry_date']);
});
}
};

View File

@@ -0,0 +1,93 @@
# ISO 19650 Project Naming Convention
## Overview
This document outlines the naming convention for projects based on the ISO 19650 standard. The naming convention ensures consistency, clarity, and compliance with industry standards.
## Naming Fields
The naming convention consists of the following fields:
| Field | Definition | Requirement | Length |
|--------------------|---------------------------------------------------------------------------|-------------------|--------------|
| **Proyecto** | Identificador del expediente, contrato o proyecto | Requerido | 2-12 |
| **Creador** | Organización creadora del documento | Requerido | 3-6 |
| **Volumen o Sistema** | Agrupaciones, áreas o tramos representativos en los que se fragmenta el proyecto | Requerido | 2-3 |
| **Nivel o Localización** | Localización dentro de un Volumen o Sistema | Requerido | 3 |
| **Tipo de Documento** | Tipología de documento, entregable o auxiliar | Requerido | 3 |
| **Disciplina** | Ámbito al que se corresponde el documento | Requerido | 3 |
| **Número** | Enumerador de partes | Requerido | 3 |
| **Descripción** | Texto que describe el documento y su contenido | Opcional | Sin límite |
| **Estado** | Situación, temporal o definitiva, del documento | Opcional/Metadato | 2 |
| **Revisión** | Versión del documento | Opcional/Metadato | 4 |
## Field Details
### Proyecto
- **Definition**: Identifies the project, contract, or file.
- **Requirement**: Required
- **Length**: 2-12 characters
### Creador
- **Definition**: Organization responsible for creating the document.
- **Requirement**: Required
- **Length**: 3-6 characters
### Volumen o Sistema
- **Definition**: Representative groupings, areas, or sections of the project.
- **Requirement**: Required
- **Length**: 2-3 characters
### Nivel o Localización
- **Definition**: Location within a Volume or System.
- **Requirement**: Required
- **Length**: 3 characters
### Tipo de Documento
- **Definition**: Document type, deliverable, or auxiliary.
- **Requirement**: Required
- **Length**: 3 characters
### Disciplina
- **Definition**: Scope to which the document corresponds.
- **Requirement**: Required
- **Length**: 3 characters
### Número
- **Definition**: Part enumerator.
- **Requirement**: Required
- **Length**: 3 characters
### Descripción
- **Definition**: Text describing the document and its content.
- **Requirement**: Optional
- **Length**: Unlimited
### Estado
- **Definition**: Temporary or definitive status of the document.
- **Requirement**: Optional/Metadata
- **Length**: 2 characters
### Revisión
- **Definition**: Document version.
- **Requirement**: Optional/Metadata
- **Length**: 4 characters
## Example
A sample project name following this convention:
```
PRJ001-ORG01-V01-L01-DOC-ARC-001-Description-ST-0001
```
Where:
- **PRJ001**: Project identifier
- **ORG01**: Creator organization
- **V01**: Volume
- **L01**: Level
- **DOC**: Document type
- **ARC**: Discipline
- **001**: Part number
- **Description**: Description of the document
- **ST**: Status
- **0001**: Revision
## Notes
- All fields marked as "Required" must be included.
- Optional fields can be omitted if not applicable.

View File

@@ -0,0 +1,80 @@
# Project Naming Code Generator
## Overview
The `ProjectNamingSchema` class provides a utility to generate project names based on the ISO 19650 naming convention. This ensures consistency and compliance with industry standards.
## Installation
Ensure the `ProjectNamingSchema` class is located in the `App\Helpers` namespace. No additional installation steps are required.
## Usage
To generate a project name, use the `generate` method of the `ProjectNamingSchema` class. This method accepts an associative array of fields and returns the generated project name.
### Example
```php
use App\Helpers\ProjectNamingSchema;
$fields = [
'project' => 'PRJ001',
'creator' => 'ORG01',
'volume' => 'V01',
'level' => 'L01',
'documentType' => 'DOC',
'discipline' => 'ARC',
'number' => '1',
'description' => 'Description',
'status' => 'ST',
'revision' => '1',
];
$projectName = ProjectNamingSchema::generate($fields);
// Output: PRJ001-ORG01-V01-L01-DOC-ARC-001-Description-ST-0001
```
## Fields
The following fields are supported:
| Field | Definition | Requirement | Length |
|--------------------|---------------------------------------------------------------------------|-------------------|--------------|
| **project** | Identifies the project, contract, or file. | Required | 2-12 |
| **creator** | Organization responsible for creating the document. | Required | 3-6 |
| **volume** | Representative groupings, areas, or sections of the project. | Required | 2-3 |
| **level** | Location within a Volume or System. | Required | 3 |
| **documentType** | Document type, deliverable, or auxiliary. | Required | 3 |
| **discipline** | Scope to which the document corresponds. | Required | 3 |
| **number** | Part enumerator. | Required | 3 |
| **description** | Text describing the document and its content. | Optional | Unlimited |
| **status** | Temporary or definitive status of the document. | Optional | 2 |
| **revision** | Document version. | Optional | 4 |
## Validation
The `generate` method validates that all required fields are provided. If any required field is missing, an `InvalidArgumentException` is thrown.
### Example
```php
$fields = [
'creator' => 'ORG01',
'volume' => 'V01',
'level' => 'L01',
'documentType' => 'DOC',
'discipline' => 'ARC',
'number' => '1',
];
try {
$projectName = ProjectNamingSchema::generate($fields);
} catch (InvalidArgumentException $e) {
echo $e->getMessage(); // Output: The field 'project' is required.
}
```
## Testing
Unit tests for the `ProjectNamingSchema` class are located in the `tests/Unit/ProjectNamingSchemaTest.php` file. Run the tests using the following command:
```bash
vendor\bin\pest --filter ProjectNamingSchemaTest
```
## Notes
- All fields marked as "Required" must be included.
- Optional fields can be omitted if not applicable.

View File

@@ -0,0 +1,506 @@
<div>
<!-- Header y Breadcrumbs -->
<div class="bg-white mb-6 flex content-start justify-between">
<!-- User Info Left -->
<div class="flex space-x-6 content-start">
<!-- Icono -->
<flux:icon.bolt class="w-24 h-24 shadow-lg object-cover border-1 border-gray-600"/>
<!-- Project Details -->
<div class="flex flex-col content-start">
<h1 class="text-2xl font-bold text-gray-700">
{{ $project->name }}
</h1>
<!-- Contact Info -->
<div class="mt-2 ">
<div class="flex items-center text-gray-600">
<p class="text-sm text-gray-700">
{{ $project->reference }}
</p>
</div>
@if($project->phone)
<div class="flex items-center text-gray-600">
<svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 24 24">
<path d="M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"/>
</svg>
<a href="tel:{{ $project->phone }}" class="hover:text-blue-600">
{{ $project->phone }}
</a>
</div>
@endif
</div>
</div>
</div>
<!-- Right Section -->
<div class="flex flex-col items-end space-y-4">
<!-- Navigation Toolbar -->
<div class="flex space-x-2">
<flux:button
href="{{ route('projects.index') }}"
icon:trailing="arrow-uturn-left"
variant="ghost"
>
</flux:button>
<flux:button
href="{{ route('projects.index') }}"
icon:trailing="chevron-left"
variant="ghost"
>
</flux:button>
<flux:button
href="{{ route('projects.index') }}"
icon:trailing="chevron-right"
variant="ghost"
>
</flux:button>
</div>
<!-- Status Badge -->
<span class="px-4 py-2 w-30 rounded-lg text-sm text-center font-semibold
{{ $project->is_active ? 'bg-green-600 text-white' : 'bg-red-100 text-red-800' }}">
{{ $project->is_active ? 'Activo' : 'Inactivo' }}
</span>
</div>
</div>
<div wire:loading wire:target="files" class="fixed top-0 right-0 p-4 bg-blue-100 text-blue-800">
Subiendo archivos...
</div>
<!-- Contend: -->
<div x-data="{ activeTab: 'info' }" class="bg-white rounded-lg shadow-md border-1">
<!-- Tab Headers -->
<div class="border-b border-gray-200">
<nav class="flex space-x-8 px-6">
<button @click="activeTab = 'info'"
:class="activeTab === 'info' ? 'border-blue-500 text-blue-600' : 'border-transparent text-gray-500 hover:text-gray-700'"
class="py-4 px-1 border-b-2 font-medium">
Project
</button>
<button @click="activeTab = 'contacts'"
:class="activeTab === 'contacts' ? 'border-blue-500 text-blue-600' : 'border-transparent text-gray-500 hover:text-gray-700'"
class="py-4 px-1 border-b-2 font-medium">
Contactos
</button>
<button @click="activeTab = 'documents'"
:class="activeTab === 'documents' ? 'border-blue-500 text-blue-600' : 'border-transparent text-gray-500 hover:text-gray-700'"
class="py-4 px-1 border-b-2 font-medium">
Documentos
</button>
</nav>
</div>
<!-- Tab Content -->
<div class="p-6">
<!-- Info Tab -->
<div x-show="activeTab === 'info'">
<div class="flex flex-wrap gap-6">
<!-- Columna Izquierda - Información -->
<div class="w-full md:w-[calc(50%-12px)]">
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<tbody class="bg-white divide-y divide-gray-200">
@foreach(['name' => 'Nombre', 'last_name' => 'Apellido', 'email' => 'Email', 'phone' => 'Teléfono', 'created_at' => 'Fecha Registro'] as $field => $label)
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{{ $label }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{ $project->$field ?? 'N/A' }}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
<!-- Columna Derecha - Descripción del Proyecto -->
<div class="w-full md:w-[calc(50%-12px)]"> <!-- 50% - gap/2 -->
<div class="bg-white p-6 rounded-lg shadow-sm">
<h3 class="whitespace-nowrap text-sm font-medium text-gray-900"">Descripción</h3>
<div class="py-2 prose max-w-none text-gray-500">
{!! $project->description ? $project->description : '<p class="text-gray-400">N/A</p>' !!}
</div>
</div>
</div>
</div>
<!-- Action Buttons -->
<div class="mt-6 flex justify-end space-x-4">
<a href="{{ route('projects.edit', $project) }}"
class="w-[150px] px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg flex items-center justify-center">
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"/>
</svg>
Editar
</a>
{{-- Formulario de Edición --}}
<form method="POST" action="{{ route('projects.update', $project) }}">
@csrf
@method('PUT') <!-- Important! -->
<button type="submit"
class="w-[150px] px-4 py-2 bg-yellow-500 hover:bg-yellow-600 text-white rounded-lg flex items-center justify-center">
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"/>
</svg>
{{ $project->is_active ? 'Desactivar' : 'Activar' }}
</button>
</form>
{{-- Formulario de Eliminación --}}
<form method="POST" action="{{ route('projects.destroy', $project) }}">
@csrf
@method('DELETE') <!-- Important! -->
<button type="submit"
onclick="return confirm('¿Estás seguro de querer eliminar este usuario?')"
class="px-4 py-2 w-[150px] bg-red-600 hover:bg-red-700 text-white rounded-lg flex items-center justify-center">
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
</svg>
Eliminar
</button>
</form>
</div>
</div>
<!-- Contact Tab -->
<div x-show="activeTab === 'contacts'" x-cloak>
</div>
<!-- Permissions Tab -->
<div x-show="activeTab === 'documents'" x-cloak>
<!-- Contenedor principal con layout de explorador -->
<div class="flex flex-col h-full">
<!-- Barra de herramientas -->
<div class="flex items-center justify-between p-2 bg-white border-b">
<div class="flex items-center space-x-4">
<!-- Botón Nueva Carpeta -->
<button wire:click="showCreateFolderModal" class="flex items-center p-2 text-gray-600 hover:bg-gray-100 rounded">
<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 13h6m-3-3v6m-9 1V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z" />
</svg>
<span class="text-sm">Nueva carpeta</span>
</button>
<!-- Botón Subir Archivos (versión con button) -->
<div class="relative">
<button
wire:click="openUploadModal"
class="flex items-center p-2 text-gray-600 hover:bg-gray-100 rounded">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 16.5V9.75m0 0 3 3m-3-3-3 3M6.75 19.5a4.5 4.5 0 0 1-1.41-8.775 5.25 5.25 0 0 1 10.233-2.33 3 3 0 0 1 3.758 3.848A3.752 3.752 0 0 1 18 19.5H6.75Z" />
</svg>
<span class="text-sm">Subir archivos</span>
</button>
</div>
</div>
</div>
<!-- Contenido principal (treeview + documentos) -->
<div class="flex flex-1 overflow-hidden">
<!-- Treeview de Carpetas -->
<div class="w-64 h-full overflow-y-auto border bg-white">
<div class="">
<ul class="space-y-1">
@foreach($project->rootFolders as $folder)
<x-folder-item
:folder="$folder"
:currentFolder="$currentFolder"
:expandedFolders="$expandedFolders"
wire:key="folder-{{ $folder->id }}"
:itemsCount="$this->documents->count()"
/>
@endforeach
</ul>
</div>
</div>
<!-- Documentos -->
<div class="flex-1 overflow-auto bg-white">
<div class="p-2 bg-white border-b">
<div class="flex items-center justify-between">
<div>
<nav class="flex space-x-2 text-sm">
<a wire:click="currentFolder = null" class="flex cursor-pointer text-gray-600 hover:text-blue-600">
<flux:icon.home class="w-4 h-4"/> Inicio
</a>
@foreach($this->breadcrumbs as $folder)
<span class="text-gray-400">/</span>
<a wire:click="selectFolder({{ $folder->id }})"
class="cursor-pointer text-gray-600 hover:text-blue-600">
{{ $folder->name }}
</a>
@endforeach
</nav>
</div>
</div>
</div>
<div class="overflow-x-auto">
<table id="listofdocuments" class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50 sticky top-0">
<tr>
<th class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">
<div class="relative" x-data="{ open: false }">
<button @click="open = !open" class="text-gray-700 hover:text-gray-900 focus:outline-none">
Opciones
</button>
<div x-show="open" @click.away="open = false" class="absolute z-10 mt-2 bg-white border border-gray-300 rounded shadow-lg">
<ul class="py-1">
<template x-for="(column, index) in $store.columns.all" :key="index">
<li class="px-4 py-2">
<label class="inline-flex items-center">
<input type="checkbox" class="form-checkbox" :checked="$store.columns.visible.includes(column)" @change="$store.columns.toggle(column)">
<span class="ml-2" x-text="column"></span>
</label>
</li>
</template>
</ul>
</div>
</div>
<div>
Nombre
</div>
</th>
<template x-for="column in $store.columns.all" :key="column">
<th class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase" x-show="$store.columns.visible.includes(column)" x-text="column"></th>
</template>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@forelse($this->documents as $document)
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 whitespace-nowrap">
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<a href="{{ route('documents.show', $document) }}"
target="_blank"
class="flex items-center hover:text-blue-600 transition-colors">
@php
$type = App\Helpers\FileHelper::getFileType($document->name);
$iconComponent = "icons." . $type;
$iconClass = [
'pdf' => 'pdf text-red-500',
'word' => 'word text-blue-500',
'excel' => 'excel text-green-500',
][$type] ?? 'document text-gray-400';
@endphp
<x-dynamic-component
component="{{ $iconComponent }}"
class="w-5 h-5 mr-2 {{ explode(' ', $iconClass)[1] }}"
/>
{{ $document->name }}
</a>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Versiones')">
{{ $document->versions_count }}
</td>
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Última Actualización')">
{{ $document->updated_at->diffForHumans() }}
</td>
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Estado')">
<x-status-badge :status="$document->status" />
</td>
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Revisión')">
{{ $document->revision }}
</td>
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Disciplina')">
{{ $document->discipline }}
</td>
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Tipo de Documento')">
{{ $document->document_type }}
</td>
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Emisor')">
{{ $document->issuer }}
</td>
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Fecha de Entrada')">
{{ $document->entry_date }}
</td>
</tr>
@empty
<tr>
<td colspan="9" class="px-6 py-4 text-center text-gray-500">
No se encontraron documentos en esta carpeta
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modal para crear carpeta -->
@if($showFolderModal)
<div class="fixed inset-0 z-50 flex items-center justify-center bg-black/50">
<div class="w-full max-w-md p-6 bg-white rounded-lg shadow-xl">
<div class="mb-4">
<h3 class="text-lg font-medium text-gray-900">Crear nueva carpeta</h3>
<p class="mt-1 text-sm text-gray-500">Ingresa el nombre de la nueva carpeta</p>
</div>
<div class="mb-4">
<input
type="text"
wire:model="folderName"
placeholder="Nombre de la carpeta"
class="w-full p-2 border rounded focus:ring-blue-500 focus:border-blue-500"
autofocus
@keyup.enter="createFolder"
>
@error('folderName')
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<div class="flex justify-end space-x-3">
<button
wire:click="hideCreateFolderModal"
class="px-4 py-2 text-sm text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50">
Cancelar
</button>
<button
wire:click="createFolder"
class="px-4 py-2 text-sm text-white bg-blue-600 rounded-md hover:bg-blue-700">
Crear carpeta
</button>
</div>
</div>
</div>
@endif
<!-- Modal de subida -->
@if($showUploadModal)
<div
x-data="{ isDragging: false }"
x-on:drop.prevent="isDragging = false; $wire.selectFiles(Array.from($event.dataTransfer.files))"
x-on:dragover.prevent="isDragging = true"
x-on:dragleave.prevent="isDragging = false"
class="fixed inset-0 z-50 flex items-center justify-center bg-black/50">
<div class="w-full max-w-2xl p-6 bg-white rounded-lg shadow-xl">
<div class="mb-4">
<h3 class="text-lg font-medium text-gray-900">Subir archivos</h3>
<p class="mt-1 text-sm text-gray-500">
{{ $currentFolder ? "Carpeta destino: {$currentFolder->name}" : "Carpeta raíz del proyecto" }}
</p>
</div>
<!-- Área de drag & drop -->
<div
x-on:click="$refs.fileInput.click()"
:class="isDragging ? 'border-blue-500 bg-blue-50' : 'border-gray-300'"
class="flex flex-col items-center justify-center p-8 border-2 border-dashed rounded-lg cursor-pointer hover:bg-gray-50 transition-colors">
<input
type="file"
x-ref="fileInput"
wire:model="selectedFiles"
multiple
class="hidden"
wire:change="selectFiles($event.target.files)">
<svg xmlns="http://www.w3.org/2000/svg" class="w-12 h-12 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" />
</svg>
<div class="mt-4 text-center">
<p class="font-medium text-gray-900">
Arrastra archivos aquí o haz clic para seleccionar
</p>
<p class="text-sm text-gray-500">
Formatos soportados: PDF, DOCX, XLSX, JPG, PNG (Máx. 10MB)
</p>
</div>
</div>
<!-- Lista de archivos -->
<div class="mt-4 max-h-64 overflow-y-auto">
@if(count($selectedFiles) > 0)
<ul class="space-y-2">
@foreach($selectedFiles as $index => $file)
<li class="flex items-center justify-between p-2 bg-gray-50 rounded">
<div class="flex items-center truncate">
<x-icons icon="document" class="w-4 h-4 mr-2 text-gray-400" />
<span class="text-sm truncate">
{{ $file->getClientOriginalName() }} <!-- Ahora funciona -->
</span>
</div>
<div class="flex items-center space-x-2">
<span class="text-xs text-gray-500">
{{ number_format($file->getSize() / 1024, 2) }} KB
</span>
<button
wire:click="removeFile({{ $index }})"
type="button"
class="p-1 text-gray-400 hover:text-red-600">
</button>
</div>
</li>
@endforeach
</ul>
@endif
</div>
<!-- Footer del modal -->
<div class="flex justify-end mt-6 space-x-3">
<button
wire:click="resetUpload"
type="button"
class="px-4 py-2 text-sm text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50">
Cancelar
</button>
<button
wire:click="uploadFiles"
:disabled="!selectedFiles.length"
class="px-4 py-2 text-sm text-white bg-blue-600 rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed">
Subir archivos ({{ count($selectedFiles) }})
</button>
</div>
</div>
</div>
@endif
</div>
<script src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
<script>
document.addEventListener('alpine:init', () => {
Alpine.store('columns', {
all: ['Versiones', 'Última Actualización', 'Estado', 'Revisión', 'Disciplina', 'Tipo de Documento', 'Emisor', 'Fecha de Entrada'],
visible: ['Versiones', 'Última Actualización', 'Estado', 'Revisión', 'Disciplina', 'Tipo de Documento', 'Emisor', 'Fecha de Entrada'],
toggle(column) {
if (this.visible.includes(column)) {
this.visible = this.visible.filter(c => c !== column);
} else {
this.visible.push(column);
}
}
});
});
</script>
<script>
document.addEventListener('livewire:init', () => {
Livewire.on('upload-progress', (name, progress) => {
// Actualizar progreso en el frontend
const progressBar = document.querySelector(`[data-file="${name}"] .progress-bar`);
if (progressBar) {
progressBar.style.width = `${progress}%`;
}
});
});
</script>

View File

@@ -244,18 +244,41 @@
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<table id="listofdocuments" class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50 sticky top-0">
<tr>
<th class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">Nombre - javi</th>
<th class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">Versiones</th>
<th class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">Última Actualización</th>
<th class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">Estado</th>
<th class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">
<div class="flex items-center gap-2">
<div class="relative" x-data="{ open: false }">
<flux:dropdown>
<flux:button icon="ellipsis-horizontal" variant="subtle" size="sm"/>
<flux:menu>
<template x-for="(column, index) in $store.columns.all" :key="index">
<li class="px-4 py-2">
<label class="inline-flex items-center">
<input type="checkbox" class="form-checkbox" :checked="$store.columns.visible.includes(column)" @change="$store.columns.toggle(column)">
<span class="ml-2" x-text="column"></span>
</label>
</li>
</template>
</flux:menu>
</flux:dropdown>
</div>
<span><flux:checkbox /></span>
</div>
</th>
<th class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">
NOMBRE
</th>
<template x-for="column in $store.columns.all" :key="column">
<th class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase" x-show="$store.columns.visible.includes(column)" x-text="column"></th>
</template>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@forelse($this->documents as $document)
<tr class="hover:bg-gray-50">
<td class="w-4"></td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<a href="{{ route('documents.show', $document) }}"
@@ -263,38 +286,49 @@
class="flex items-center hover:text-blue-600 transition-colors">
@php
$type = App\Helpers\FileHelper::getFileType($document->name);
$iconComponent = $iconComponent = "icons." . $type;
$iconComponent = "icons." . $type;
$iconClass = [
'pdf' => 'pdf text-red-500',
'word' => 'word text-blue-500',
'excel' => 'excel text-green-500',
// ... agregar todos los tipos
][$type] ?? 'document text-gray-400';
@endphp
<x-dynamic-component
component="{{ $iconComponent }}"
class="w-5 h-5 mr-2 {{ explode(' ', $iconClass)[1] }}"
/>
{{ $document->name }}
</a>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Versiones')">
{{ $document->versions_count }}
</td>
<td class="px-6 py-4 whitespace-nowrap">
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Última Actualización')">
{{ $document->updated_at->diffForHumans() }}
</td>
<td class="px-6 py-4 whitespace-nowrap">
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Estado')">
<x-status-badge :status="$document->status" />
</td>
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Revisión')">
{{ $document->revision }}
</td>
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Disciplina')">
{{ $document->discipline }}
</td>
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Tipo de Documento')">
{{ $document->document_type }}
</td>
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Emisor')">
{{ $document->issuer }}
</td>
<td class="px-6 py-4 whitespace-nowrap" x-show="$store.columns.visible.includes('Fecha de Entrada')">
{{ $document->entry_date }}
</td>
</tr>
@empty
<tr>
<td colspan="4" class="px-6 py-4 text-center text-gray-500">
<td colspan="9" class="px-6 py-4 text-center text-gray-500">
No se encontraron documentos en esta carpeta
</td>
</tr>
@@ -442,6 +476,22 @@
@endif
</div>
<script>
document.addEventListener('alpine:init', () => {
Alpine.store('columns', {
all: ['Versiones', 'Última Actualización', 'Estado', 'Revisión', 'Disciplina', 'Tipo de Documento', 'Emisor', 'Fecha de Entrada'],
visible: ['Versiones', 'Última Actualización', 'Estado', 'Revisión', 'Disciplina', 'Tipo de Documento', 'Emisor', 'Fecha de Entrada'],
toggle(column) {
if (this.visible.includes(column)) {
this.visible = this.visible.filter(c => c !== column);
} else {
this.visible.push(column);
}
}
});
});
</script>
<script>
document.addEventListener('livewire:init', () => {
Livewire.on('upload-progress', (name, progress) => {

View File

@@ -97,8 +97,12 @@
<input type="text" name="reference" id="reference"
value="{{ old('reference', $project->reference ?? '') }}"
class="w-[250px] border-b-1 border-gray-300 focus:border-blue-500 focus:outline-none"
maxlength="12"
autofocus
required>
<flux:tooltip content="Máximo: 12 caracteres" position="right">
<flux:button icon="information-circle" size="sm" variant="ghost" />
</flux:tooltip>
@error('reference')
<p class="mt-2 text-sm text-red-600">{{ $message }}</p>

View File

@@ -0,0 +1,70 @@
<?php
namespace Tests\Unit;
use App\Helpers\ProjectNamingSchema;
use PHPUnit\Framework\TestCase;
class ProjectNamingSchemaTest extends TestCase
{
/**
* Test generating a valid project name with all required fields.
*/
public function testGenerateValidProjectName()
{
$fields = [
'project' => 'PRJ001',
'creator' => 'ORG01',
'volume' => 'V01',
'level' => 'L01',
'documentType' => 'DOC',
'discipline' => 'ARC',
'number' => '1',
];
$expected = 'PRJ001-ORG01-V01-L01-DOC-ARC-001';
$this->assertEquals($expected, ProjectNamingSchema::generate($fields));
}
/**
* Test generating a project name with optional fields.
*/
public function testGenerateProjectNameWithOptionalFields()
{
$fields = [
'project' => 'PRJ001',
'creator' => 'ORG01',
'volume' => 'V01',
'level' => 'L01',
'documentType' => 'DOC',
'discipline' => 'ARC',
'number' => '1',
'description' => 'Description',
'status' => 'ST',
'revision' => '1',
];
$expected = 'PRJ001-ORG01-V01-L01-DOC-ARC-001-Description-ST-0001';
$this->assertEquals($expected, ProjectNamingSchema::generate($fields));
}
/**
* Test generating a project name with missing required fields.
*/
public function testGenerateProjectNameWithMissingFields()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage("The field 'project' is required.");
$fields = [
'creator' => 'ORG01',
'volume' => 'V01',
'level' => 'L01',
'documentType' => 'DOC',
'discipline' => 'ARC',
'number' => '1',
];
ProjectNamingSchema::generate($fields);
}
}