updates to document handling and code editing features
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
<x-layouts.app :title="__('Show document')">
|
||||
<div class="grid grid-cols-2 gap-x-4 h-screen bg-gray-100">
|
||||
<div class="grid grid-cols-2 gap-x-0 h-screen bg-gray-100">
|
||||
<!-- Zona izquierda - Visualizador de documentos -->
|
||||
<div class="bg-gray-100 relative">
|
||||
<div class="bg-gray-500 relative">
|
||||
<div id="outerContainer">
|
||||
|
||||
<div id="sidebarContainer">
|
||||
<div id="toolbarSidebar" class="toolbarHorizontalGroup">
|
||||
<div id="toolbarSidebarLeft">
|
||||
@@ -49,8 +48,6 @@
|
||||
|
||||
|
||||
<div id="mainContainer">
|
||||
|
||||
|
||||
<div class="toolbar">
|
||||
<div id="toolbarContainer">
|
||||
<div id="toolbarViewer" class="toolbarHorizontalGroup">
|
||||
@@ -704,7 +701,46 @@
|
||||
</div>
|
||||
|
||||
<!-- Zona derecha - Tabs de información -->
|
||||
<div x-data="{ activeTab: 'properties' }" class="flex flex-col bg-white">
|
||||
<div x-data="{
|
||||
activeTab: 'properties',
|
||||
// Estado para el treeview de versiones y revisiones
|
||||
openVersion: null,
|
||||
openRevision: {},
|
||||
|
||||
toggleVersion(versionNumber) {
|
||||
this.openVersion = this.openVersion === versionNumber ? null : versionNumber;
|
||||
},
|
||||
|
||||
toggleRevision(versionNumber, revisionNumber) {
|
||||
const key = `v${versionNumber}r${revisionNumber}`;
|
||||
this.openRevision[key] = !this.openRevision[key];
|
||||
// Para asegurar la reactividad
|
||||
this.openRevision = {...this.openRevision};
|
||||
},
|
||||
|
||||
// Función para cargar PDF en el visor
|
||||
loadPdfInViewer(pdfUrl) {
|
||||
if (pdfUrl) {
|
||||
// Usar PDFViewerApplication para cargar el nuevo PDF
|
||||
PDFViewerApplication.open(pdfUrl).then(() => {
|
||||
console.log('PDF cargado en el visor:', pdfUrl);
|
||||
|
||||
// Opcional: Mostrar un mensaje de éxito
|
||||
this.showNotification('PDF cargado en el visor', 'success');
|
||||
}).catch(error => {
|
||||
console.error('Error al cargar el PDF:', error);
|
||||
this.showNotification('Error al cargar el PDF', 'error');
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// Función auxiliar para mostrar notificaciones
|
||||
showNotification(message, type = 'info') {
|
||||
// Puedes implementar un sistema de notificaciones toast aquí
|
||||
// Por ahora usamos alert para simplificar
|
||||
alert(message);
|
||||
}
|
||||
}" class="flex flex-col bg-white">
|
||||
<!-- Tabs de navegación -->
|
||||
<div class="border-b border-gray-200">
|
||||
<nav class="flex space-x-4 px-4 pt-2">
|
||||
@@ -752,20 +788,190 @@
|
||||
|
||||
<!-- Seguridad -->
|
||||
<div x-show="activeTab === 'security'" x-cloak>
|
||||
implementar
|
||||
Implementar
|
||||
</div>
|
||||
|
||||
<!-- Comentarios -->
|
||||
<div x-show="activeTab === 'comments'" x-cloak>
|
||||
|
||||
Implementar
|
||||
</div>
|
||||
|
||||
<!-- Historial -->
|
||||
<div x-show="activeTab === 'history'" x-cloak>
|
||||
<div class="space-y-4">
|
||||
@foreach($document->versions as $version)
|
||||
<x-version-item :version="$version" />
|
||||
<div class="space-y-2">
|
||||
@php
|
||||
// Agrupar las versiones por número de versión
|
||||
$groupedVersions = $document->versions->groupBy('version');
|
||||
@endphp
|
||||
|
||||
@foreach($groupedVersions as $versionNumber => $versions)
|
||||
<div class="border rounded-lg">
|
||||
<!-- Cabecera de la Versión (Rama principal) -->
|
||||
<div class="flex items-center justify-between p-4 bg-gray-50 cursor-pointer"
|
||||
@click="toggleVersion({{ $versionNumber }})">
|
||||
<div class="flex items-center space-x-3">
|
||||
<svg :class="{'rotate-90': openVersion === {{ $versionNumber }}}"
|
||||
class="w-4 h-4 transition-transform duration-200"
|
||||
fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
|
||||
</svg>
|
||||
<div class="flex items-center space-x-2">
|
||||
<svg class="w-5 h-5 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"/>
|
||||
</svg>
|
||||
<span class="font-medium text-gray-800">
|
||||
Versión {{ $versionNumber }}
|
||||
</span>
|
||||
</div>
|
||||
<span class="text-sm text-gray-500 bg-gray-200 px-2 py-1 rounded-full">
|
||||
{{ $versions->count() }} revisión{{ $versions->count() > 1 ? 'es' : '' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex items-center space-x-4">
|
||||
<span class="text-sm text-gray-500">
|
||||
{{ $versions->sortBy('created_at')->first()->created_at_formatted }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Contenido de la Versión - Revisiones como ramas hijas -->
|
||||
<div x-show="openVersion === {{ $versionNumber }}" class="border-t bg-white">
|
||||
<div class="space-y-0">
|
||||
@foreach($versions->sortByDesc('review') as $revisionIndex => $revision)
|
||||
<div class="border-b last:border-b-0">
|
||||
<!-- Cabecera de la Revisión (Rama hija) -->
|
||||
<div class="flex items-center justify-between p-4 pl-8 cursor-pointer hover:bg-gray-50"
|
||||
@click="toggleRevision({{ $versionNumber }}, {{ $revision->review }})">
|
||||
<div class="flex items-center space-x-3">
|
||||
<svg :class="{'rotate-90': openRevision['v{{ $versionNumber }}r{{ $revision->review }}']}"
|
||||
class="w-4 h-4 transition-transform duration-200"
|
||||
fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
|
||||
</svg>
|
||||
<div class="flex items-center space-x-2">
|
||||
<svg class="w-4 h-4 text-green-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
|
||||
</svg>
|
||||
<span class="font-medium text-gray-700">
|
||||
Revisión {{ $revision->review }}
|
||||
</span>
|
||||
@if($revision->review == 0)
|
||||
<span class="px-2 py-1 text-xs bg-blue-100 text-blue-800 rounded-full">Original</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center space-x-4">
|
||||
<button @click.stop="loadPdfInViewer('{{ $revision->file_url }}')"
|
||||
class="inline-flex items-center px-3 py-1 text-sm bg-green-600 text-white rounded hover:bg-green-700"
|
||||
title="Cargar en visor PDF">
|
||||
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
|
||||
</svg>
|
||||
Cargar en Visor
|
||||
</button>
|
||||
<span class="text-sm text-gray-500">{{ $revision->created_at_formatted }}</span>
|
||||
<span class="text-sm text-gray-400">{{ $revision->file_size_formatted }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Detalles de la Revisión (Contenido expandible) -->
|
||||
<div x-show="openRevision['v{{ $versionNumber }}r{{ $revision->review }}']"
|
||||
class="bg-gray-50 border-t">
|
||||
<div class="p-4 pl-12 space-y-4">
|
||||
<!-- Información básica -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<x-property-item label="ID" :value="$revision->id" />
|
||||
<x-property-item label="Document ID" :value="$revision->document_id" />
|
||||
<x-property-item label="Usuario" :value="$revision->user->name ?? 'Usuario no disponible'" />
|
||||
</div>
|
||||
|
||||
<!-- Archivo -->
|
||||
<div>
|
||||
<div class="mb-2">
|
||||
<span class="block text-sm font-medium text-gray-700">Archivo</span>
|
||||
<div class="mt-1 flex items-center space-x-2">
|
||||
<x-property-item label="Ruta" :value="$revision->file_path" />
|
||||
<button @click="loadPdfInViewer('{{ $revision->file_url }}')"
|
||||
class="inline-flex items-center px-3 py-1 text-sm bg-blue-600 text-white rounded hover:bg-blue-700">
|
||||
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
|
||||
</svg>
|
||||
Cargar en Visor
|
||||
</button>
|
||||
<a href="{{ $revision->file_url }}" target="_blank"
|
||||
class="inline-flex items-center px-3 py-1 text-sm bg-gray-600 text-white rounded hover:bg-gray-700">
|
||||
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/>
|
||||
</svg>
|
||||
Descargar
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Cambios -->
|
||||
<div>
|
||||
<span class="block text-sm font-medium text-gray-700 mb-2">Cambios realizados</span>
|
||||
@if(!empty($revision->changes) && count($revision->changes) > 0)
|
||||
<div class="bg-white rounded border p-3">
|
||||
<ul class="list-disc list-inside text-sm text-gray-600 space-y-1">
|
||||
@foreach($revision->changes as $change)
|
||||
<li class="hover:text-gray-800">{{ $change }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@else
|
||||
<div class="bg-white rounded border p-3 text-sm text-gray-500">
|
||||
No hay cambios registrados en esta revisión
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<!-- Fechas -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 pt-2 border-t">
|
||||
<x-property-item label="Fecha de creación" :value="$revision->created_at_formatted" />
|
||||
<x-property-item label="Última actualización"
|
||||
:value="$revision->updated_at ? \Carbon\Carbon::parse($revision->updated_at)->format('d/m/Y H:i') : 'N/A'" />
|
||||
</div>
|
||||
|
||||
<!-- Información adicional del usuario -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 pt-2 border-t">
|
||||
<div>
|
||||
<span class="block text-sm font-medium text-gray-700">Creado por</span>
|
||||
<div class="flex items-center space-x-2 mt-1">
|
||||
@if(isset($revision->user->avatar))
|
||||
<img src="{{ $revision->user->avatar }}" alt="{{ $revision->user->name }}" class="w-6 h-6 rounded-full">
|
||||
@else
|
||||
<div class="w-6 h-6 bg-gray-300 rounded-full flex items-center justify-center">
|
||||
<span class="text-xs text-gray-600">{{ substr($revision->user->name ?? 'U', 0, 1) }}</span>
|
||||
</div>
|
||||
@endif
|
||||
<span class="text-sm text-gray-600">{{ $revision->user->name ?? 'Usuario no disponible' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<span class="block text-sm font-medium text-gray-700">Email</span>
|
||||
<span class="text-sm text-gray-600">{{ $revision->user->email ?? 'No disponible' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
@if($groupedVersions->isEmpty())
|
||||
<div class="text-center py-8 text-gray-500">
|
||||
<svg class="w-12 h-12 mx-auto text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
|
||||
</svg>
|
||||
<p class="mt-2">No hay historial de versiones disponible</p>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -778,46 +984,183 @@
|
||||
</div>
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
window.OptionKind = window.OptionKind || { VIEWER: 0, API: 1 };
|
||||
<script>
|
||||
var ae_post_url = "{{ route('documents.update-pdf', $document) }}";
|
||||
|
||||
window.OptionKind = window.OptionKind || { VIEWER: 0, API: 1 };
|
||||
|
||||
const PDF_URL = @json(Storage::url($document->file_path));
|
||||
console.log("PDF URL:", PDF_URL);
|
||||
const PDF_URL = @json(Storage::url($document->file_path));
|
||||
const SAVE_URL = "{{ route('documents.update-pdf', $document) }}";
|
||||
const CSRF_TOKEN = "{{ csrf_token() }}";
|
||||
|
||||
window.PDFViewerApplicationOptions = {
|
||||
defaultUrl: {
|
||||
value: encodeURI(PDF_URL),
|
||||
kind: OptionKind.VIEWER
|
||||
},
|
||||
cMapUrl: '/js/pdfjs-5.2.133-dist/web/cmaps/',
|
||||
cMapPacked: true
|
||||
};
|
||||
</script>
|
||||
console.log("PDF URL:", PDF_URL);
|
||||
|
||||
@vite([
|
||||
'resources/js/pdfjs-5.2.133-dist/build/pdf.mjs',
|
||||
'resources/js/pdfjs-5.2.133-dist/web/viewer.mjs',
|
||||
'resources/js/pdfjs-5.2.133-dist/web/viewer.css'
|
||||
])
|
||||
window.PDFViewerApplicationOptions = {
|
||||
defaultUrl: {
|
||||
value: encodeURI(PDF_URL),
|
||||
kind: OptionKind.VIEWER
|
||||
},
|
||||
cMapUrl: '/js/pdfjs-5.2.133-dist/web/cmaps/',
|
||||
cMapPacked: true
|
||||
};
|
||||
</script>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
PDFViewerApplication.initializedPromise.then(() => {
|
||||
// Pasar un OBJETO con { url: TU_URL }
|
||||
PDFViewerApplication.open({
|
||||
url: encodeURI(PDF_URL), // Propiedad requerida
|
||||
originalUrl: PDF_URL // Opcional (para mostrar en la UI)
|
||||
}).catch(error => {
|
||||
console.error('Error cargando PDF:', error);
|
||||
@vite([
|
||||
'resources/js/pdfjs-5.2.133-dist/build/pdf.mjs',
|
||||
'resources/js/pdfjs-5.2.133-dist/web/viewer.mjs',
|
||||
'resources/js/pdfjs-5.2.133-dist/web/viewer.css',
|
||||
'resources/js/pdfjs-5.2.133-dist/pdfjs-annotation-extension.js'
|
||||
])
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
PDFViewerApplication.initializedPromise.then(() => {
|
||||
// Pasar un OBJETO con { url: TU_URL }
|
||||
PDFViewerApplication.open({
|
||||
url: encodeURI(PDF_URL),
|
||||
originalUrl: PDF_URL
|
||||
}).then(() => {
|
||||
// Una vez cargado el PDF, configurar los event listeners para guardar
|
||||
setupSaveFunctionality();
|
||||
}).catch(error => {
|
||||
console.error('Error cargando PDF:', error);
|
||||
});
|
||||
});
|
||||
|
||||
function setupSaveFunctionality() {
|
||||
// Interceptar el botón de descarga para guardar con anotaciones
|
||||
const downloadButton = document.getElementById('downloadButton');
|
||||
if (downloadButton) {
|
||||
downloadButton.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
savePdfWithAnnotations();
|
||||
});
|
||||
}
|
||||
|
||||
// También puedes agregar un botón personalizado para guardar
|
||||
addCustomSaveButton();
|
||||
}
|
||||
|
||||
function addCustomSaveButton() {
|
||||
// Agregar botón de guardar personalizado en la toolbar
|
||||
const toolbarRight = document.getElementById('toolbarViewerRight');
|
||||
if (toolbarRight) {
|
||||
const saveButton = document.createElement('button');
|
||||
saveButton.id = 'saveWithAnnotations';
|
||||
saveButton.className = 'toolbarButton';
|
||||
saveButton.innerHTML = '<span>Guardar con anotaciones</span>';
|
||||
saveButton.title = 'Guardar PDF con anotaciones, firmas y stamps';
|
||||
saveButton.addEventListener('click', savePdfWithAnnotations);
|
||||
|
||||
// Insertar antes del botón de descarga
|
||||
const downloadBtn = document.getElementById('downloadButton');
|
||||
if (downloadBtn) {
|
||||
toolbarRight.insertBefore(saveButton, downloadBtn);
|
||||
} else {
|
||||
toolbarRight.appendChild(saveButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function savePdfWithAnnotations() {
|
||||
try {
|
||||
// Mostrar indicador de carga
|
||||
showLoading('Guardando PDF con anotaciones...');
|
||||
|
||||
// Obtener el PDF modificado con anotaciones
|
||||
const pdfDocument = PDFViewerApplication.pdfDocument;
|
||||
const data = await pdfDocument.saveDocument();
|
||||
const pdfData = await data.arrayBuffer();
|
||||
|
||||
// Convertir a base64
|
||||
const base64Pdf = arrayBufferToBase64(pdfData);
|
||||
|
||||
// Enviar al servidor
|
||||
const response = await fetch('{{ route("documents.update-pdf", $document) }}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
pdf_data: 'data:application/pdf;base64,' + base64Pdf,
|
||||
annotations: getCurrentAnnotations(), // Si quieres guardar metadatos
|
||||
signatures: getCurrentSignatures(),
|
||||
stamps: getCurrentStamps()
|
||||
})
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
hideLoading();
|
||||
|
||||
if (result.success) {
|
||||
showSuccess('PDF guardado correctamente con todas las anotaciones');
|
||||
} else {
|
||||
showError('Error al guardar: ' + result.message);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
hideLoading();
|
||||
console.error('Error saving PDF:', error);
|
||||
showError('Error al guardar el PDF');
|
||||
}
|
||||
}
|
||||
|
||||
function arrayBufferToBase64(buffer) {
|
||||
let binary = '';
|
||||
const bytes = new Uint8Array(buffer);
|
||||
const len = bytes.byteLength;
|
||||
for (let i = 0; i < len; i++) {
|
||||
binary += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return window.btoa(binary);
|
||||
}
|
||||
|
||||
function getCurrentAnnotations() {
|
||||
// Obtener anotaciones actuales del visor
|
||||
// Esto depende de cómo la extensión almacena las anotaciones
|
||||
if (window.pdfAnnotationExtension) {
|
||||
return window.pdfAnnotationExtension.getAnnotations();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
function getCurrentSignatures() {
|
||||
// Obtener firmas actuales
|
||||
if (window.pdfAnnotationExtension) {
|
||||
return window.pdfAnnotationExtension.getSignatures();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
function getCurrentStamps() {
|
||||
// Obtener stamps actuales
|
||||
if (window.pdfAnnotationExtension) {
|
||||
return window.pdfAnnotationExtension.getStamps();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
function showLoading(message) {
|
||||
// Implementar un spinner o mensaje de carga
|
||||
console.log('Loading:', message);
|
||||
}
|
||||
|
||||
function hideLoading() {
|
||||
// Ocultar spinner
|
||||
console.log('Loading complete');
|
||||
}
|
||||
|
||||
function showSuccess(message) {
|
||||
alert(message); // Puedes usar un toast mejor
|
||||
}
|
||||
|
||||
function showError(message) {
|
||||
alert('Error: ' + message); // Puedes usar un toast mejor
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
<!-- ELIMINA EL SCRIPT versionTree() DE AQUÍ -->
|
||||
@endpush
|
||||
|
||||
</x-layouts.app>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</x-layouts.app>
|
||||
@@ -1,331 +0,0 @@
|
||||
<x-layouts.app :title="__('Show document')">
|
||||
<div class="flex h-screen bg-gray-100"
|
||||
@resize.window.debounce="renderPage(currentPage)">
|
||||
|
||||
<!-- Zona izquierda - Visualizador de documentos -->
|
||||
<div class="w-1/2 bg-gray-800 p-4 relative">
|
||||
<!-- Loading State -->
|
||||
<template x-if="loading">
|
||||
<div class="absolute inset-0 bg-white bg-opacity-90 flex items-center justify-center">
|
||||
<div class="text-center">
|
||||
<svg class="animate-spin h-12 w-12 text-blue-500 mx-auto mb-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
||||
</svg>
|
||||
<p class="text-gray-600">Cargando documento...</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Error State -->
|
||||
<template x-if="error">
|
||||
<div class="absolute inset-0 bg-red-50 flex items-center justify-center p-4">
|
||||
<div class="text-center text-red-600">
|
||||
<svg class="h-12 w-12 mx-auto mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
|
||||
</svg>
|
||||
<p x-text="error"></p>
|
||||
<p class="mt-2 text-sm">URL del documento: <span class="break-all" x-text="pdfUrl"></span></p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Controles del PDF -->
|
||||
<div class="flex items-center justify-between mb-4 bg-gray-700 p-2 rounded">
|
||||
<div class="flex items-center space-x-4 text-white">
|
||||
<button @click="previousPage" :disabled="currentPage <= 1" class="disabled:opacity-50">
|
||||
<x-icons icon="chevron-left" class="w-6 h-6" />
|
||||
</button>
|
||||
<span>Página <span x-text="currentPage"></span> de <span x-text="totalPages"></span></span>
|
||||
<button @click="nextPage" :disabled="currentPage >= totalPages" class="disabled:opacity-50">
|
||||
<x-icons icon="chevron-right" class="w-6 h-6" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="text-white">
|
||||
Zoom:
|
||||
<select x-model="scale" @change="renderPage(currentPage)" class="bg-gray-600 rounded px-2 py-1">
|
||||
<option value="0.25">25%</option>
|
||||
<option value="0.5">50%</option>
|
||||
<option value="0.75">75%</option>
|
||||
<option value="1">100%</option>
|
||||
<option value="1.5">150%</option>
|
||||
<option value="2">200%</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Canvas del PDF con comentarios -->
|
||||
<div class="flex-1 bg-white shadow-lg overflow-auto relative"
|
||||
id="pdf-container"
|
||||
@scroll.debounce="handleScroll">
|
||||
<div class="pdf-page-container" :style="`width: ${pageWidth}px`">
|
||||
<template x-for="(page, index) in renderedPages" :key="index">
|
||||
<div class="pdf-page">
|
||||
<canvas class="pdf-canvas"
|
||||
:id="`canvas-${page.pageNumber}`"></canvas>
|
||||
<div class="text-layer"
|
||||
:id="`text-layer-${page.pageNumber}`"></div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- Marcadores de comentarios existentes -->
|
||||
<template x-for="comment in comments" :key="comment.id">
|
||||
<div
|
||||
class="absolute w-4 h-4 bg-yellow-400 rounded-full cursor-pointer border-2 border-yellow-600"
|
||||
:style="`left: ${comment.x * 100}%; top: ${comment.y * 100}%;`"
|
||||
@click="scrollToComment(comment)"
|
||||
x-tooltip="'Ver comentario'"
|
||||
></div>
|
||||
</template>
|
||||
|
||||
<!-- Formulario flotante para nuevos comentarios -->
|
||||
<div
|
||||
class="absolute bg-white p-4 rounded-lg shadow-xl w-64"
|
||||
x-show="showCommentForm"
|
||||
:style="`top: ${clickY}px; left: ${clickX}px`"
|
||||
@click.outside="closeCommentForm"
|
||||
>
|
||||
<form @submit.prevent="submitComment">
|
||||
<textarea
|
||||
x-model="commentText"
|
||||
class="w-full mb-2 p-2 border rounded"
|
||||
placeholder="Escribe tu comentario..."
|
||||
rows="3"
|
||||
required
|
||||
></textarea>
|
||||
<button
|
||||
type="submit"
|
||||
class="btn btn-primary w-full flex items-center justify-center"
|
||||
>
|
||||
<x-icons icon="save" class="w-4 h-4 mr-2" /> Guardar
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Zona derecha - Tabs de información -->
|
||||
<div x-data="{ activeTab: 'properties' }" class="w-1/2 flex flex-col bg-white">
|
||||
<!-- Tabs de navegación -->
|
||||
<div class="border-b border-gray-200">
|
||||
<nav class="flex space-x-4 px-4 pt-2">
|
||||
<button @click="activeTab = 'properties'"
|
||||
:class="activeTab === 'properties' ? '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">
|
||||
Propiedades
|
||||
</button>
|
||||
<button @click="activeTab = 'security'"
|
||||
:class="activeTab === 'security' ? '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">
|
||||
Seguridad
|
||||
</button>
|
||||
<button @click="activeTab = 'comments'"
|
||||
:class="activeTab === 'comments' ? '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">
|
||||
Comentarios
|
||||
</button>
|
||||
<button @click="activeTab = 'history'"
|
||||
:class="activeTab === 'history' ? '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">
|
||||
Historial
|
||||
</button>
|
||||
<button @click="activeTab = 'relations'"
|
||||
:class="activeTab === 'relations' ? '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">
|
||||
Relaciones
|
||||
</button>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<!-- Contenido de los tabs -->
|
||||
<div class="flex-1 overflow-y-auto p-4 space-y-6">
|
||||
<!-- Propiedades -->
|
||||
<div x-show="activeTab === 'properties'">
|
||||
<div class="space-y-4">
|
||||
<x-property-item label="Nombre" :value="$document->name" />
|
||||
<x-property-item label="Tipo" :value="$document->type" />
|
||||
<x-property-item label="Tamaño" :value="$document->size_for_humans" />
|
||||
<x-property-item label="Creado por" :value="Storage::url($document->file_path)" />
|
||||
<x-property-item label="Fecha creación" :value="$document->created_at->format('d/m/Y H:i')" />
|
||||
<x-property-item label="Última modificación" :value="$document->updated_at->format('d/m/Y H:i')" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Seguridad -->
|
||||
<div x-show="activeTab === 'security'" x-cloak>
|
||||
implementar
|
||||
</div>
|
||||
|
||||
<!-- Comentarios -->
|
||||
<div x-show="activeTab === 'comments'" x-cloak>
|
||||
<template x-for="comment in comments" :key="comment.id">
|
||||
<div class="p-4 mb-2 border rounded hover:bg-gray-50">
|
||||
<div class="text-sm text-gray-500"
|
||||
x-text="`Página ${comment.page} - ${new Date(comment.created_at).toLocaleString()}`"></div>
|
||||
<div x-text="comment.text" class="mt-1"></div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- Historial -->
|
||||
<div x-show="activeTab === 'history'" x-cloak>
|
||||
<div class="space-y-4">
|
||||
@foreach($document->versions as $version)
|
||||
<x-version-item :version="$version" />
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Relaciones -->
|
||||
<div x-show="activeTab === 'relations'" x-cloak>
|
||||
implementar
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</x-layouts.app>
|
||||
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.338/pdf.min.js"></script>
|
||||
<script>
|
||||
// Configuración del Visor PDF
|
||||
var currentPage = 1;
|
||||
var nextPage = 2;
|
||||
|
||||
const url = "{{ Storage::url($document->file_path) }}";
|
||||
let pdfDoc = null,
|
||||
pageNum = 1,
|
||||
pageRendering = false,
|
||||
pageNumPending = null,
|
||||
scale = 0.8,
|
||||
canvas = document.getElementById('pdf-canvas');
|
||||
ctx = canvas.getContext('2d');
|
||||
|
||||
function renderPage(num) {
|
||||
pageRendering = true;
|
||||
pdfDoc.getPage(num).then(function(page) {
|
||||
const viewport = page.getViewport({ scale: 1.5 });
|
||||
canvas.height = viewport.height;
|
||||
canvas.width = viewport.width;
|
||||
|
||||
const renderContext = {
|
||||
canvasContext: ctx,
|
||||
viewport: viewport
|
||||
};
|
||||
|
||||
page.render(renderContext).promise.then(() => {
|
||||
pageRendering = false;
|
||||
loadCommentsForPage(num);
|
||||
});
|
||||
|
||||
// Wait for rendering to finish
|
||||
renderTask.promise.then(function() {
|
||||
pageRendering = false;
|
||||
if (pageNumPending !== null) {
|
||||
// New page rendering is pending
|
||||
renderPage(pageNumPending);
|
||||
pageNumPending = null;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function handleCanvasClick(event) {
|
||||
const rect = event.target.getBoundingClientRect();
|
||||
this.clickX = event.clientX - rect.left;
|
||||
this.clickY = event.clientY - rect.top;
|
||||
this.showCommentForm = true;
|
||||
}
|
||||
|
||||
// Cargar PDF
|
||||
pdfjsLib.getDocument(url).promise.then(function(pdf) {
|
||||
pdfDoc = pdf;
|
||||
renderPage(pageNum);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* If another page rendering in progress, waits until the rendering is
|
||||
* finised. Otherwise, executes rendering immediately.
|
||||
*/
|
||||
function queueRenderPage(num) {
|
||||
if (pageRendering) {
|
||||
pageNumPending = num;
|
||||
} else {
|
||||
renderPage(num);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays previous page.
|
||||
*/
|
||||
function onPrevPage() {
|
||||
if (pageNum <= 1) {
|
||||
return;
|
||||
}
|
||||
pageNum--;
|
||||
queueRenderPage(pageNum);
|
||||
}
|
||||
document.getElementById('prev').addEventListener('click', onPrevPage);
|
||||
|
||||
/**
|
||||
* Displays next page.
|
||||
*/
|
||||
function onNextPage() {
|
||||
if (pageNum >= pdfDoc.numPages) {
|
||||
return;
|
||||
}
|
||||
pageNum++;
|
||||
queueRenderPage(pageNum);
|
||||
}
|
||||
document.getElementById('next').addEventListener('click', onNextPage);
|
||||
|
||||
/**
|
||||
* Asynchronously downloads PDF.
|
||||
*/
|
||||
pdfjsLib.getDocument(url).promise.then(function(pdfDoc_) {
|
||||
pdfDoc = pdfDoc_;
|
||||
document.getElementById('page_count').textContent = pdfDoc.numPages;
|
||||
|
||||
// Initial/first page rendering
|
||||
renderPage(pageNum);
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.pdf-page-container {
|
||||
margin: 0 auto;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.pdf-page {
|
||||
position: relative;
|
||||
margin: 0 auto 20px;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.text-layer {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
overflow: hidden;
|
||||
opacity: 0.2;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.text-layer span {
|
||||
color: transparent;
|
||||
position: absolute;
|
||||
white-space: pre;
|
||||
cursor: text;
|
||||
transform-origin: 0% 0%;
|
||||
}
|
||||
|
||||
.text-layer ::selection {
|
||||
background: rgba(0,0,255,0.2);
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user