# 🔧 Guía de Integración Práctica ## 🎯 Integración Rápida (5 minutos) ### Paso 1: Inicializar en App.vue ```vue ``` ### Paso 2: Añadir a la Navegación ```vue ``` --- ## 📋 Caso de Uso 1: Rastrear Ediciones ### En MonacoEditor.vue ```typescript import { invoke } from '@tauri-apps/api/core'; // Referencias const editor = ref(null); const currentFile = ref(''); const lastSaveTime = ref(0); // Detectar cambios editor.value?.onDidChangeModelContent(async (e) => { const content = editor.value!.getValue(); const now = Date.now(); // Registrar edición (debounce de 5 segundos) if (now - lastSaveTime.value > 5000) { await invoke('save_activity_log', { entry: { type: 'edit', action: 'Archivo modificado', file: currentFile.value, lines: content.split('\n').length, details: `${e.changes.length} cambios realizados` } }); lastSaveTime.value = now; } // Analizar errores en tiempo real await invoke('analyze_file_diagnostics', { filePath: currentFile.value, content: content }); }); // Guardar archivo const saveFile = async () => { const content = editor.value!.getValue(); try { // 1. Guardar archivo await invoke('write_file_content', { filePath: currentFile.value, content: content }); // 2. Registrar actividad await invoke('save_activity_log', { entry: { type: 'save', action: 'Archivo guardado', file: currentFile.value, lines: content.split('\n').length, details: 'Guardado exitoso' } }); // 3. Limpiar errores previos await invoke('clear_file_diagnostics', { filePath: currentFile.value }); console.log('✅ Archivo guardado y registrado'); } catch (error) { console.error('❌ Error guardando:', error); } }; // Abrir archivo const openFile = async (filePath: string) => { try { const content = await invoke('read_file_content', { filePath }); // Actualizar editor editor.value?.setValue(content); currentFile.value = filePath; // Registrar apertura await invoke('save_activity_log', { entry: { type: 'open', action: 'Archivo abierto', file: filePath, details: 'Abierto para edición' } }); // Analizar errores iniciales await invoke('analyze_file_diagnostics', { filePath: filePath, content: content }); } catch (error) { console.error('❌ Error abriendo archivo:', error); } }; ``` --- ## 🐛 Caso de Uso 2: Panel de Errores Interactivo ### En ErrorPanel.vue (uso extendido) ```vue ``` --- ## 💾 Caso de Uso 3: Sistema de Respaldo Inteligente ### Auto-respaldo en eventos críticos ```typescript import { invoke } from '@tauri-apps/api/core'; // Crear respaldo antes de operaciones peligrosas const refactorCommand = async () => { // 1. Crear respaldo de seguridad try { await invoke('create_backup', { name: 'Pre-refactor backup', description: 'Respaldo automático antes de refactorizar comandos', type: 'manual' }); console.log('✅ Respaldo de seguridad creado'); } catch (error) { console.error('❌ Error creando respaldo:', error); if (!confirm('No se pudo crear respaldo. ¿Continuar de todos modos?')) { return; } } // 2. Realizar refactorización await performRefactoring(); // 3. Registrar actividad await invoke('save_activity_log', { entry: { type: 'edit', action: 'Refactorización completada', file: 'múltiples archivos', details: 'Refactorización de comandos exitosa' } }); }; // Respaldo automático cada 5 minutos let backupTimer: number | null = null; const startAutoBackup = () => { backupTimer = window.setInterval(async () => { try { await invoke('create_backup', { name: `Auto-backup ${new Date().toLocaleTimeString()}`, type: 'auto' }); console.log('✅ Auto-backup creado'); } catch (error) { console.error('❌ Error en auto-backup:', error); } }, 5 * 60 * 1000); // 5 minutos }; const stopAutoBackup = () => { if (backupTimer) { clearInterval(backupTimer); backupTimer = null; } }; // Restaurar desde respaldo const restoreFromBackup = async (backupId: string) => { if (!confirm('¿Estás seguro? Esto sobrescribirá el código actual.')) { return; } try { // 1. Crear respaldo del estado actual antes de restaurar await invoke('create_backup', { name: 'Pre-restore backup', description: 'Estado antes de restaurar desde respaldo', type: 'manual' }); // 2. Restaurar await invoke('restore_backup', { backupId }); // 3. Recargar proyecto await reloadProject(); alert('✅ Proyecto restaurado exitosamente'); } catch (error) { console.error('❌ Error restaurando:', error); alert('Error al restaurar respaldo'); } }; ``` --- ## 🔄 Caso de Uso 4: Comparación de Versiones ### En BackupManager.vue ```typescript const compareWithBackup = async (backupId: string) => { try { const { current, backup } = await invoke('compare_backup', { backupId }); // Crear vista de comparación showComparisonModal.value = true; currentContent.value = current; backupContent.value = backup; // Calcular diferencias const diff = calculateDiff(current, backup); // Mostrar estadísticas console.log(` 📊 Estadísticas de cambios: - Líneas añadidas: ${diff.added} - Líneas eliminadas: ${diff.removed} - Líneas modificadas: ${diff.modified} `); } catch (error) { console.error('❌ Error comparando:', error); } }; // Función para calcular diff simple const calculateDiff = (current: string, backup: string) => { const currentLines = current.split('\n'); const backupLines = backup.split('\n'); let added = 0; let removed = 0; let modified = 0; const maxLength = Math.max(currentLines.length, backupLines.length); for (let i = 0; i < maxLength; i++) { if (!backupLines[i]) { added++; } else if (!currentLines[i]) { removed++; } else if (currentLines[i] !== backupLines[i]) { modified++; } } return { added, removed, modified }; }; ``` --- ## 🎨 Caso de Uso 5: Notificaciones y Feedback ### Sistema de notificaciones ```typescript // Crear componente de notificación const showNotification = (type: 'success' | 'error' | 'info', message: string) => { const notification = { id: Date.now(), type, message, timestamp: Date.now() }; notifications.value.push(notification); // Auto-remover después de 3 segundos setTimeout(() => { notifications.value = notifications.value.filter(n => n.id !== notification.id); }, 3000); }; // Usar en operaciones const saveWithNotification = async () => { try { await saveFile(); await invoke('save_activity_log', { entry: {...} }); showNotification('success', '✅ Archivo guardado correctamente'); } catch (error) { showNotification('error', '❌ Error guardando archivo'); } }; const backupWithNotification = async () => { try { await invoke('create_backup', { type: 'manual' }); showNotification('success', '✅ Respaldo creado exitosamente'); } catch (error) { showNotification('error', '❌ Error creando respaldo'); } }; ``` --- ## 🔍 Caso de Uso 6: Búsqueda en Activity Log ### Filtrado avanzado ```typescript // En ActivityLog.vue const searchTerm = ref(''); const dateRange = ref<[Date, Date] | null>(null); const selectedTypes = ref(['all']); const filteredLogs = computed(() => { let result = logs.value; // Filtrar por tipo if (!selectedTypes.value.includes('all')) { result = result.filter(log => selectedTypes.value.includes(log.type)); } // Filtrar por búsqueda if (searchTerm.value) { const term = searchTerm.value.toLowerCase(); result = result.filter(log => log.action.toLowerCase().includes(term) || log.file.toLowerCase().includes(term) || log.details?.toLowerCase().includes(term) ); } // Filtrar por rango de fechas if (dateRange.value) { const [start, end] = dateRange.value; result = result.filter(log => { const date = new Date(log.timestamp); return date >= start && date <= end; }); } return result; }); ``` --- ## 📊 Caso de Uso 7: Dashboard de Estadísticas ### Crear vista de resumen ```vue ``` --- ## ✅ Checklist de Implementación - [ ] Inicializar managers en App.vue - [ ] Añadir componentes al router/navigation - [ ] Integrar activity log en MonacoEditor - [ ] Configurar análisis de errores en tiempo real - [ ] Activar auto-respaldo cada 5 minutos - [ ] Añadir notificaciones de feedback - [ ] Crear atajos de teclado - [ ] Probar restauración de respaldos - [ ] Verificar rendimiento con proyecto grande - [ ] Documentar configuración personalizada --- **¡Listo para implementar! 🚀**