Files
ebaysnipeextension/test-appwrite-repair-tool.html
Kenso Grimm 216a972fef chore: initialize project repository with core extension files
- Add .gitignore to exclude node_modules, dist, logs, and system files
- Add comprehensive project documentation including README, deployment guide, and development setup
- Add .kiro project specifications for amazon-product-bar-extension, appwrite-cloud-storage, appwrite-userid-repair, blacklist-feature, and enhanced-item-management
- Add .kiro steering documents for product, structure, styling, and tech guidelines
- Add VSCode settings configuration for consistent development environment
- Add manifest.json and babel/vite configuration for extension build setup
- Add complete source code implementation including AppWrite integration, storage managers, UI components, and services
- Add comprehensive test suite with Jest configuration and 30+ test files covering all major modules
- Add test HTML files for integration testing and validation
- Add coverage reports and build validation scripts
- Add AppWrite setup and repair documentation for database schema management
- Add migration guides and responsive accessibility implementation documentation
- Establish foundation for Amazon product bar extension with full feature set including blacklist management, enhanced item workflows, and real-time synchronization
2026-01-12 17:46:42 +01:00

1331 lines
48 KiB
HTML

<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AppWrite Schema Reparatur Tool - Amazon Extension</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
color: #333;
}
.container {
max-width: 1000px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.95);
padding: 30px;
border-radius: 16px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
backdrop-filter: blur(10px);
}
.header {
text-align: center;
margin-bottom: 30px;
padding-bottom: 20px;
border-bottom: 2px solid #e9ecef;
}
.header h1 {
color: #2c3e50;
margin: 0 0 10px 0;
font-size: 2.2rem;
font-weight: 600;
}
.header p {
color: #6c757d;
margin: 0;
font-size: 1.1rem;
}
.status-card {
padding: 20px;
margin: 20px 0;
border-radius: 12px;
font-weight: 500;
border-left: 5px solid;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.status-success {
background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
color: #155724;
border-left-color: #28a745;
}
.status-error {
background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
color: #721c24;
border-left-color: #dc3545;
}
.status-warning {
background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
color: #856404;
border-left-color: #ffc107;
}
.status-info {
background: linear-gradient(135deg, #d1ecf1 0%, #bee5eb 100%);
color: #0c5460;
border-left-color: #17a2b8;
}
.controls {
display: flex;
gap: 15px;
justify-content: center;
margin: 30px 0;
flex-wrap: wrap;
}
.btn {
background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
color: white;
border: none;
padding: 14px 28px;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
font-weight: 500;
transition: all 0.3s ease;
box-shadow: 0 4px 12px rgba(0,123,255,0.3);
min-width: 160px;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(0,123,255,0.4);
}
.btn:active {
transform: translateY(0);
}
.btn-secondary {
background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
box-shadow: 0 4px 12px rgba(108,117,125,0.3);
}
.btn-secondary:hover {
box-shadow: 0 8px 20px rgba(108,117,125,0.4);
}
.btn-danger {
background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
box-shadow: 0 4px 12px rgba(220,53,69,0.3);
}
.btn-danger:hover {
box-shadow: 0 8px 20px rgba(220,53,69,0.4);
}
.btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none !important;
}
.progress-section {
background: rgba(248, 249, 250, 0.8);
border: 2px solid #e9ecef;
border-radius: 12px;
padding: 25px;
margin: 25px 0;
display: none;
}
.progress-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}
.progress-title {
font-size: 1.3rem;
font-weight: 600;
color: #2c3e50;
margin: 0;
}
.progress-percentage {
font-size: 1.5rem;
font-weight: 700;
color: #007bff;
}
.progress-bar-container {
background: #e9ecef;
border-radius: 10px;
height: 12px;
overflow: hidden;
margin: 15px 0;
box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}
.progress-bar {
background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
height: 100%;
transition: width 0.5s ease;
border-radius: 10px;
position: relative;
overflow: hidden;
}
.progress-bar::after {
content: '';
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: linear-gradient(
90deg,
transparent,
rgba(255,255,255,0.4),
transparent
);
animation: shimmer 2s infinite;
}
@keyframes shimmer {
0% { transform: translateX(-100%); }
100% { transform: translateX(100%); }
}
.progress-details {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 15px;
margin-top: 20px;
}
.progress-detail {
background: white;
padding: 12px;
border-radius: 8px;
border-left: 4px solid #007bff;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.progress-detail-label {
font-weight: 600;
color: #495057;
font-size: 0.9rem;
margin-bottom: 4px;
}
.progress-detail-value {
color: #2c3e50;
font-size: 1rem;
}
.results-section {
background: rgba(248, 249, 250, 0.8);
border: 2px solid #e9ecef;
border-radius: 12px;
padding: 25px;
margin: 25px 0;
display: none;
}
.results-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.results-title {
font-size: 1.4rem;
font-weight: 600;
color: #2c3e50;
margin: 0;
}
.summary-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin: 20px 0;
}
.summary-card {
background: white;
padding: 20px;
border-radius: 12px;
text-align: center;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
border-top: 4px solid;
}
.summary-card.success { border-top-color: #28a745; }
.summary-card.error { border-top-color: #dc3545; }
.summary-card.info { border-top-color: #17a2b8; }
.summary-card.warning { border-top-color: #ffc107; }
.summary-value {
font-size: 2rem;
font-weight: 700;
margin-bottom: 8px;
}
.summary-label {
color: #6c757d;
font-size: 0.9rem;
font-weight: 500;
}
.collection-list {
margin-top: 25px;
}
.collection-item {
background: white;
border: 1px solid #e9ecef;
border-radius: 8px;
margin: 10px 0;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.collection-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px 20px;
background: #f8f9fa;
border-bottom: 1px solid #e9ecef;
cursor: pointer;
transition: background-color 0.2s ease;
}
.collection-header:hover {
background: #e9ecef;
}
.collection-name {
font-weight: 600;
color: #2c3e50;
font-family: 'Courier New', monospace;
}
.collection-status {
padding: 4px 12px;
border-radius: 20px;
font-size: 0.85rem;
font-weight: 500;
}
.collection-status.success {
background: #d4edda;
color: #155724;
}
.collection-status.error {
background: #f8d7da;
color: #721c24;
}
.collection-status.warning {
background: #fff3cd;
color: #856404;
}
.collection-details {
padding: 20px;
display: none;
background: #fdfdfe;
}
.collection-details.expanded {
display: block;
}
.detail-section {
margin: 15px 0;
padding: 15px;
background: white;
border-radius: 8px;
border-left: 4px solid #007bff;
}
.detail-section h4 {
margin: 0 0 10px 0;
color: #2c3e50;
font-size: 1.1rem;
}
.detail-list {
list-style: none;
padding: 0;
margin: 0;
}
.detail-list li {
padding: 5px 0;
border-bottom: 1px solid #f1f3f4;
}
.detail-list li:last-child {
border-bottom: none;
}
.error-instructions {
background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
border: 2px solid #ffc107;
border-radius: 12px;
padding: 25px;
margin: 25px 0;
display: none;
}
.error-instructions h3 {
color: #856404;
margin: 0 0 15px 0;
font-size: 1.3rem;
}
.instruction-step {
background: rgba(255,255,255,0.8);
margin: 12px 0;
padding: 15px;
border-radius: 8px;
border-left: 4px solid #ffc107;
}
.instruction-step strong {
color: #856404;
}
.log-section {
margin-top: 30px;
}
.log-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}
.log-container {
background: #2c3e50;
color: #ecf0f1;
padding: 20px;
border-radius: 8px;
font-family: 'Courier New', monospace;
font-size: 14px;
max-height: 400px;
overflow-y: auto;
box-shadow: inset 0 2px 8px rgba(0,0,0,0.3);
}
.log-entry {
margin: 4px 0;
padding: 2px 0;
}
.log-timestamp {
color: #95a5a6;
}
.log-info { color: #3498db; }
.log-success { color: #2ecc71; }
.log-warning { color: #f39c12; }
.log-error { color: #e74c3c; }
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
display: none;
align-items: center;
justify-content: center;
z-index: 10000;
backdrop-filter: blur(5px);
}
.modal {
background: white;
border-radius: 16px;
padding: 30px;
max-width: 500px;
width: 90%;
box-shadow: 0 20px 40px rgba(0,0,0,0.3);
transform: scale(0.9);
transition: transform 0.3s ease;
}
.modal-overlay.show {
display: flex;
}
.modal-overlay.show .modal {
transform: scale(1);
}
.modal h3 {
margin: 0 0 15px 0;
color: #2c3e50;
font-size: 1.4rem;
}
.modal-actions {
display: flex;
gap: 15px;
justify-content: flex-end;
margin-top: 25px;
}
.spinner {
display: inline-block;
width: 20px;
height: 20px;
border: 3px solid rgba(255,255,255,.3);
border-radius: 50%;
border-top-color: #fff;
animation: spin 1s ease-in-out infinite;
margin-right: 10px;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.hidden {
display: none !important;
}
@media (max-width: 768px) {
.container {
margin: 10px;
padding: 20px;
}
.controls {
flex-direction: column;
align-items: center;
}
.btn {
width: 100%;
max-width: 300px;
}
.summary-grid {
grid-template-columns: 1fr;
}
.progress-details {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🔧 AppWrite Schema Reparatur Tool</h1>
<p>Automatische Erkennung und Reparatur fehlender userId-Attribute in AppWrite-Sammlungen</p>
</div>
<div id="connection-status" class="status-card status-info">
<strong>🔄 Verbindung wird überprüft...</strong><br>
Teste AppWrite-Verbindung und Authentifizierung...
</div>
<div class="controls">
<button id="start-analysis-btn" class="btn btn-secondary" disabled>
<span id="analysis-spinner" class="spinner hidden"></span>
🔍 Nur Analyse
</button>
<button id="start-repair-btn" class="btn" disabled>
<span id="repair-spinner" class="spinner hidden"></span>
🔧 Reparatur starten
</button>
<button id="cancel-btn" class="btn btn-danger hidden">
⏹️ Abbrechen
</button>
<button id="clear-log-btn" class="btn btn-secondary">
🗑️ Log löschen
</button>
</div>
<div id="progress-section" class="progress-section">
<div class="progress-header">
<h3 class="progress-title">Fortschritt</h3>
<span id="progress-percentage" class="progress-percentage">0%</span>
</div>
<div class="progress-bar-container">
<div id="progress-bar" class="progress-bar" style="width: 0%"></div>
</div>
<div class="progress-details">
<div class="progress-detail">
<div class="progress-detail-label">Aktueller Schritt</div>
<div id="progress-step" class="progress-detail-value">Warten...</div>
</div>
<div class="progress-detail">
<div class="progress-detail-label">Sammlung</div>
<div id="progress-collection" class="progress-detail-value">-</div>
</div>
<div class="progress-detail">
<div class="progress-detail-label">Vorgang</div>
<div id="progress-operation" class="progress-detail-value">-</div>
</div>
<div class="progress-detail">
<div class="progress-detail-label">Status</div>
<div id="progress-message" class="progress-detail-value">-</div>
</div>
</div>
</div>
<div id="results-section" class="results-section">
<div class="results-header">
<h3 class="results-title">Reparatur Ergebnisse</h3>
<button id="export-report-btn" class="btn btn-secondary">
📄 Bericht exportieren
</button>
</div>
<div id="overall-status"></div>
<div class="summary-grid">
<div class="summary-card info">
<div id="analyzed-count" class="summary-value">0</div>
<div class="summary-label">Analysierte Sammlungen</div>
</div>
<div class="summary-card success">
<div id="repaired-count" class="summary-value">0</div>
<div class="summary-label">Reparierte Sammlungen</div>
</div>
<div class="summary-card warning">
<div id="validated-count" class="summary-value">0</div>
<div class="summary-label">Validierte Sammlungen</div>
</div>
<div class="summary-card error">
<div id="failed-count" class="summary-value">0</div>
<div class="summary-label">Fehlgeschlagene Vorgänge</div>
</div>
</div>
<div id="operation-summary"></div>
<div id="collection-results" class="collection-list"></div>
<div id="recommendations"></div>
</div>
<div id="error-instructions" class="error-instructions">
<h3>🔧 Manuelle Reparatur erforderlich</h3>
<p><strong>Einige Vorgänge sind fehlgeschlagen. Folgen Sie diesen Schritten zur manuellen Behebung:</strong></p>
<div class="instruction-step">
<strong>1. AppWrite Console öffnen:</strong><br>
Gehen Sie zu Ihrer AppWrite-Instanz und melden Sie sich an.
</div>
<div class="instruction-step">
<strong>2. Zu Datenbank navigieren:</strong><br>
Wählen Sie Databases → amazon-extension-db
</div>
<div class="instruction-step">
<strong>3. Fehlgeschlagene Sammlungen reparieren:</strong><br>
Für jede fehlgeschlagene Sammlung:
<ul>
<li>Sammlung auswählen → Attributes Tab</li>
<li>"Create Attribute" klicken</li>
<li>Typ: <strong>String</strong>, Schlüssel: <strong>userId</strong></li>
<li>Größe: <strong>255</strong>, Erforderlich: <strong>✅ Ja</strong></li>
</ul>
</div>
<div class="instruction-step">
<strong>4. Berechtigungen setzen:</strong><br>
Für jede Sammlung:
<ul>
<li>Settings Tab → Permissions</li>
<li>Create: <strong>users</strong></li>
<li>Read/Update/Delete: <strong>user:$userId</strong></li>
</ul>
</div>
<div class="instruction-step">
<strong>5. Erneut testen:</strong><br>
Nach den manuellen Änderungen das Reparatur-Tool erneut ausführen.
</div>
</div>
<div class="log-section">
<div class="log-header">
<h3>Aktivitätsprotokoll</h3>
<button id="download-log-btn" class="btn btn-secondary">
💾 Log herunterladen
</button>
</div>
<div id="log-container" class="log-container">
<div class="log-entry">
<span class="log-timestamp">[Warten]</span>
<span class="log-info">Reparatur-Tool geladen, warten auf Benutzeraktion...</span>
</div>
</div>
</div>
</div>
<!-- Confirmation Modal -->
<div id="confirmation-modal" class="modal-overlay">
<div class="modal">
<h3 id="modal-title">Bestätigung erforderlich</h3>
<p id="modal-message">Sind Sie sicher, dass Sie fortfahren möchten?</p>
<div class="modal-actions">
<button id="modal-cancel" class="btn btn-secondary">Abbrechen</button>
<button id="modal-confirm" class="btn">Bestätigen</button>
</div>
</div>
</div>
<!-- Load the extension content script -->
<script src="dist/content.js"></script>
<script>
// Global state
let repairInterface = null;
let repairController = null;
let currentOperation = null;
let logEntries = [];
// DOM elements
const connectionStatus = document.getElementById('connection-status');
const startAnalysisBtn = document.getElementById('start-analysis-btn');
const startRepairBtn = document.getElementById('start-repair-btn');
const cancelBtn = document.getElementById('cancel-btn');
const clearLogBtn = document.getElementById('clear-log-btn');
const downloadLogBtn = document.getElementById('download-log-btn');
const exportReportBtn = document.getElementById('export-report-btn');
const progressSection = document.getElementById('progress-section');
const resultsSection = document.getElementById('results-section');
const errorInstructions = document.getElementById('error-instructions');
const logContainer = document.getElementById('log-container');
const confirmationModal = document.getElementById('confirmation-modal');
// Logging function
function log(message, type = 'info') {
const timestamp = new Date().toLocaleTimeString('de-DE');
const logEntry = {
timestamp,
message,
type,
fullTimestamp: new Date().toISOString()
};
logEntries.push(logEntry);
const logElement = document.createElement('div');
logElement.className = 'log-entry';
logElement.innerHTML = `
<span class="log-timestamp">[${timestamp}]</span>
<span class="log-${type}">${message}</span>
`;
logContainer.appendChild(logElement);
logContainer.scrollTop = logContainer.scrollHeight;
}
// Clear log function
function clearLog() {
logEntries = [];
logContainer.innerHTML = `
<div class="log-entry">
<span class="log-timestamp">[${new Date().toLocaleTimeString('de-DE')}]</span>
<span class="log-info">Log gelöscht</span>
</div>
`;
}
// Download log function
function downloadLog() {
const logText = logEntries.map(entry =>
`[${entry.fullTimestamp}] ${entry.type.toUpperCase()}: ${entry.message}`
).join('\n');
const blob = new Blob([logText], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `appwrite-repair-log-${new Date().toISOString().replace(/[:.]/g, '-')}.txt`;
a.click();
URL.revokeObjectURL(url);
}
// Show confirmation modal
function showConfirmation(title, message, onConfirm) {
document.getElementById('modal-title').textContent = title;
document.getElementById('modal-message').textContent = message;
confirmationModal.classList.add('show');
const confirmBtn = document.getElementById('modal-confirm');
const cancelBtn = document.getElementById('modal-cancel');
const handleConfirm = () => {
confirmationModal.classList.remove('show');
confirmBtn.removeEventListener('click', handleConfirm);
cancelBtn.removeEventListener('click', handleCancel);
onConfirm(true);
};
const handleCancel = () => {
confirmationModal.classList.remove('show');
confirmBtn.removeEventListener('click', handleConfirm);
cancelBtn.removeEventListener('click', handleCancel);
onConfirm(false);
};
confirmBtn.addEventListener('click', handleConfirm);
cancelBtn.addEventListener('click', handleCancel);
}
// Update progress display
function updateProgress(step, progress, details = {}) {
document.getElementById('progress-percentage').textContent = `${Math.round(progress)}%`;
document.getElementById('progress-bar').style.width = `${progress}%`;
document.getElementById('progress-step').textContent = step;
if (details.collectionId) {
document.getElementById('progress-collection').textContent = details.collectionId;
}
if (details.operation) {
document.getElementById('progress-operation').textContent = details.operation;
}
if (details.message) {
document.getElementById('progress-message').textContent = details.message;
}
progressSection.style.display = 'block';
resultsSection.style.display = 'none';
}
// Update results display
function updateResults(report) {
// Hide progress, show results
progressSection.style.display = 'none';
resultsSection.style.display = 'block';
// Update summary cards
document.getElementById('analyzed-count').textContent = report.collectionsAnalyzed || 0;
document.getElementById('repaired-count').textContent = report.collectionsRepaired || 0;
document.getElementById('validated-count').textContent = report.collectionsValidated || 0;
document.getElementById('failed-count').textContent = (report.summary?.failedRepairs || 0);
// Update overall status
const overallStatus = document.getElementById('overall-status');
const statusClass = report.overallStatus === 'success' ? 'status-success' :
report.overallStatus === 'partial' ? 'status-warning' : 'status-error';
const statusText = {
'success': 'Erfolgreich abgeschlossen',
'partial': 'Teilweise erfolgreich',
'failed': 'Fehlgeschlagen'
}[report.overallStatus] || report.overallStatus;
overallStatus.innerHTML = `
<div class="${statusClass}">
<strong>Gesamtstatus: ${statusText}</strong><br>
Dauer: ${formatDuration(report.summary?.duration || 0)}
</div>
`;
// Show error instructions if there are failures
if (report.summary?.failedRepairs > 0) {
errorInstructions.style.display = 'block';
} else {
errorInstructions.style.display = 'none';
}
// Update collection results
updateCollectionResults(report);
// Update operation summary if available
if (repairInterface && typeof repairInterface.generateOperationSummary === 'function') {
const operationSummary = repairInterface.generateOperationSummary(report);
const summaryHtml = repairInterface.formatOperationSummary(operationSummary);
document.getElementById('operation-summary').innerHTML = summaryHtml;
}
// Update recommendations
updateRecommendations(report);
}
// Update collection results
function updateCollectionResults(report) {
const collectionResults = document.getElementById('collection-results');
if (!report.collections || Object.keys(report.collections).length === 0) {
collectionResults.innerHTML = '<p>Keine Sammlungsdetails verfügbar</p>';
return;
}
let html = '<h4>Sammlungsdetails:</h4>';
for (const [collectionId, collectionReport] of Object.entries(report.collections)) {
const statusClass = collectionReport.status === 'success' ? 'success' :
collectionReport.status === 'partial' ? 'warning' : 'error';
const statusText = {
'success': 'Erfolgreich',
'partial': 'Teilweise',
'error': 'Fehlgeschlagen'
}[collectionReport.status] || collectionReport.status;
html += `
<div class="collection-item">
<div class="collection-header" onclick="toggleCollectionDetails('${collectionId}')">
<span class="collection-name">${collectionId}</span>
<span class="collection-status ${statusClass}">${statusText}</span>
</div>
<div id="details-${collectionId}" class="collection-details">
${generateCollectionDetailsHtml(collectionReport)}
</div>
</div>
`;
}
collectionResults.innerHTML = html;
}
// Generate collection details HTML
function generateCollectionDetailsHtml(collectionReport) {
let html = '';
// Analysis details
if (collectionReport.analysis) {
const analysis = collectionReport.analysis;
html += `
<div class="detail-section">
<h4>📊 Analyse</h4>
<ul class="detail-list">
<li>userId-Attribut vorhanden: ${analysis.hasUserId ? '✅ Ja' : '❌ Nein'}</li>
<li>Schweregrad: ${analysis.severity}</li>
${analysis.issues?.length > 0 ? `<li>Probleme: ${analysis.issues.join(', ')}</li>` : ''}
</ul>
</div>
`;
}
// Repair details
if (collectionReport.repairs && collectionReport.repairs.length > 0) {
html += `
<div class="detail-section">
<h4>🔧 Reparaturen</h4>
<ul class="detail-list">
`;
collectionReport.repairs.forEach(repair => {
const repairStatus = repair.success ? '✅ Erfolgreich' : '❌ Fehlgeschlagen';
const operationText = {
'add_attribute': 'Attribut hinzufügen',
'set_permissions': 'Berechtigungen setzen',
'validate': 'Validieren'
}[repair.operation] || repair.operation;
html += `<li>${operationText}: ${repairStatus}</li>`;
if (!repair.success && repair.error) {
html += `<li style="color: #dc3545; margin-left: 20px;">Fehler: ${repair.error}</li>`;
}
});
html += `
</ul>
</div>
`;
}
// Validation details
if (collectionReport.validation) {
const validation = collectionReport.validation;
html += `
<div class="detail-section">
<h4>✅ Validierung</h4>
<ul class="detail-list">
<li>userId-Abfrage-Test: ${validation.userIdQueryTest ? '✅ Bestanden' : '❌ Fehlgeschlagen'}</li>
<li>Berechtigungstest: ${validation.permissionTest ? '✅ Bestanden' : '❌ Fehlgeschlagen'}</li>
${validation.issues?.length > 0 ? `<li>Probleme: ${validation.issues.join(', ')}</li>` : ''}
</ul>
</div>
`;
}
return html;
}
// Toggle collection details
function toggleCollectionDetails(collectionId) {
const details = document.getElementById(`details-${collectionId}`);
if (details) {
details.classList.toggle('expanded');
}
}
// Update recommendations
function updateRecommendations(report) {
const recommendations = document.getElementById('recommendations');
if (!report.recommendations || report.recommendations.length === 0) {
recommendations.innerHTML = '';
return;
}
let html = `
<div class="detail-section">
<h4>💡 Empfehlungen</h4>
<ul class="detail-list">
`;
report.recommendations.forEach(recommendation => {
html += `<li>${recommendation}</li>`;
});
html += `
</ul>
</div>
`;
recommendations.innerHTML = html;
}
// Format duration
function formatDuration(duration) {
if (duration < 1000) {
return `${duration}ms`;
} else if (duration < 60000) {
return `${(duration / 1000).toFixed(1)}s`;
} else {
const minutes = Math.floor(duration / 60000);
const seconds = Math.floor((duration % 60000) / 1000);
return `${minutes}m ${seconds}s`;
}
}
// Set button states
function setButtonStates(analyzing = false, repairing = false) {
startAnalysisBtn.disabled = analyzing || repairing;
startRepairBtn.disabled = analyzing || repairing;
document.getElementById('analysis-spinner').classList.toggle('hidden', !analyzing);
document.getElementById('repair-spinner').classList.toggle('hidden', !repairing);
cancelBtn.classList.toggle('hidden', !analyzing && !repairing);
}
// Initialize repair interface
async function initializeRepairInterface() {
log('🔄 Initialisiere Reparatur-Interface...', 'info');
try {
// Wait for extension to load
await waitForExtension();
// Check if repair components are available
if (!window.AppWriteRepairController || !window.AppWriteRepairInterface) {
throw new Error('Reparatur-Komponenten nicht verfügbar');
}
// Create repair interface instance
const interfaceContainer = document.createElement('div');
repairInterface = new window.AppWriteRepairInterface(interfaceContainer, {
language: 'de',
showProgress: true,
allowCancel: true
});
// Create repair controller instance - use the global instances if available
if (window.amazonExtRepairController) {
repairController = window.amazonExtRepairController;
log('✅ Verwende vorhandene Reparatur-Controller-Instanz', 'success');
} else if (window.appWriteManager || window.amazonExtAppWriteManager) {
const appWriteManager = window.appWriteManager || window.amazonExtAppWriteManager;
// Create instances if not available globally
const schemaAnalyzer = window.amazonExtSchemaAnalyzer || new window.AppWriteSchemaAnalyzer(appWriteManager);
const schemaRepairer = window.amazonExtSchemaRepairer || new window.AppWriteSchemaRepairer(appWriteManager);
const schemaValidator = window.amazonExtSchemaValidator || new window.AppWriteSchemaValidator(appWriteManager);
repairController = new window.AppWriteRepairController(
appWriteManager,
schemaAnalyzer,
schemaRepairer,
schemaValidator
);
log('✅ Neue Reparatur-Controller-Instanz erstellt', 'success');
} else {
throw new Error('AppWriteManager nicht verfügbar');
}
// Set up event listeners
setupRepairInterfaceEvents();
log('✅ Reparatur-Interface erfolgreich initialisiert', 'success');
// Update connection status
connectionStatus.innerHTML = `
<strong>✅ Verbindung erfolgreich</strong><br>
AppWrite-Reparatur-System ist bereit für den Einsatz.
`;
connectionStatus.className = 'status-card status-success';
// Enable buttons
startAnalysisBtn.disabled = false;
startRepairBtn.disabled = false;
} catch (error) {
log(`❌ Fehler bei der Initialisierung: ${error.message}`, 'error');
connectionStatus.innerHTML = `
<strong>❌ Verbindungsfehler</strong><br>
${error.message}<br>
<small>Stellen Sie sicher, dass die Extension geladen ist und AppWrite konfiguriert ist.</small>
`;
connectionStatus.className = 'status-card status-error';
}
}
// Wait for extension to load
function waitForExtension() {
return new Promise((resolve, reject) => {
let attempts = 0;
const maxAttempts = 30; // 15 seconds
const checkExtension = () => {
attempts++;
// Check for both the manager and the repair components
const hasManager = window.appWriteManager || window.amazonExtAppWriteManager;
const hasRepairComponents = window.AppWriteRepairController && window.AppWriteRepairInterface;
if (hasManager && hasRepairComponents) {
resolve();
} else if (attempts >= maxAttempts) {
reject(new Error('Extension konnte nicht geladen werden (Timeout)'));
} else {
setTimeout(checkExtension, 500);
}
};
checkExtension();
});
}
// Setup repair interface events
function setupRepairInterfaceEvents() {
if (!repairInterface) return;
// Progress events
repairInterface.addEventListener('progress', (progressData) => {
updateProgress(
progressData.step,
progressData.progress,
{
collectionId: progressData.collectionId,
operation: progressData.operation,
message: progressData.message
}
);
log(`📊 ${progressData.step} (${Math.round(progressData.progress)}%)`, 'info');
// Emit to extension event bus if available
if (window.amazonExtEventBus) {
window.amazonExtEventBus.emit('repair:progress', progressData);
}
});
// Results events
repairInterface.addEventListener('results', (report) => {
updateResults(report);
log('📋 Reparatur abgeschlossen, Ergebnisse angezeigt', 'success');
setButtonStates(false, false);
currentOperation = null;
// Emit to extension event bus if available
if (window.amazonExtEventBus) {
window.amazonExtEventBus.emit('repair:completed', report);
}
});
// Error events
repairInterface.addEventListener('error', (error) => {
log(`❌ Fehler: ${error.message || error}`, 'error');
setButtonStates(false, false);
currentOperation = null;
// Use extension error handler if available
if (window.amazonExtEventBus) {
window.amazonExtEventBus.emit('repair:error', error);
}
});
// Listen for extension events if event bus is available
if (window.amazonExtEventBus) {
// Listen for authentication changes
window.amazonExtEventBus.on('appwrite:authenticated', (user) => {
log(`✅ AppWrite-Authentifizierung erfolgreich: ${user.email}`, 'success');
// Re-enable repair functionality
startAnalysisBtn.disabled = false;
startRepairBtn.disabled = false;
connectionStatus.innerHTML = `
<strong>✅ Authentifiziert als ${user.email}</strong><br>
AppWrite-Reparatur-System ist bereit für den Einsatz.
`;
connectionStatus.className = 'status-card status-success';
});
window.amazonExtEventBus.on('appwrite:auth_failed', (error) => {
log(`❌ AppWrite-Authentifizierung fehlgeschlagen: ${error}`, 'error');
// Disable repair functionality
startAnalysisBtn.disabled = true;
startRepairBtn.disabled = true;
connectionStatus.innerHTML = `
<strong>❌ Authentifizierung fehlgeschlagen</strong><br>
${error}<br>
<small>Bitte melden Sie sich über die Extension an.</small>
`;
connectionStatus.className = 'status-card status-error';
});
window.amazonExtEventBus.on('appwrite:logged_out', () => {
log('🚪 AppWrite-Abmeldung erkannt', 'warning');
// Disable repair functionality
startAnalysisBtn.disabled = true;
startRepairBtn.disabled = true;
connectionStatus.innerHTML = `
<strong>⚠️ Nicht angemeldet</strong><br>
Bitte melden Sie sich über die Extension an, um das Reparatur-Tool zu verwenden.
`;
connectionStatus.className = 'status-card status-warning';
});
}
}
// Start analysis
async function startAnalysis() {
log('🔍 Starte Analyse-Modus...', 'info');
setButtonStates(true, false);
currentOperation = 'analysis';
try {
const report = await repairController.runAnalysisOnly();
updateResults(report);
log('✅ Analyse erfolgreich abgeschlossen', 'success');
} catch (error) {
log(`❌ Analyse fehlgeschlagen: ${error.message}`, 'error');
connectionStatus.innerHTML = `
<strong>❌ Analyse fehlgeschlagen</strong><br>
${error.message}
`;
connectionStatus.className = 'status-card status-error';
} finally {
setButtonStates(false, false);
currentOperation = null;
}
}
// Start repair
async function startRepair() {
showConfirmation(
'Reparatur bestätigen',
'Sind Sie sicher, dass Sie die vollständige Reparatur starten möchten? Dies wird Änderungen an Ihren AppWrite-Sammlungen vornehmen.',
async (confirmed) => {
if (!confirmed) {
log('🚫 Reparatur vom Benutzer abgebrochen', 'warning');
return;
}
log('🔧 Starte vollständige Reparatur...', 'info');
setButtonStates(false, true);
currentOperation = 'repair';
try {
const report = await repairController.runFullRepair();
updateResults(report);
log('✅ Reparatur erfolgreich abgeschlossen', 'success');
} catch (error) {
log(`❌ Reparatur fehlgeschlagen: ${error.message}`, 'error');
connectionStatus.innerHTML = `
<strong>❌ Reparatur fehlgeschlagen</strong><br>
${error.message}
`;
connectionStatus.className = 'status-card status-error';
} finally {
setButtonStates(false, false);
currentOperation = null;
}
}
);
}
// Cancel operation
function cancelOperation() {
if (currentOperation) {
log(`🚫 ${currentOperation === 'analysis' ? 'Analyse' : 'Reparatur'} abgebrochen`, 'warning');
setButtonStates(false, false);
currentOperation = null;
// Hide progress section
progressSection.style.display = 'none';
}
}
// Export report
function exportReport() {
if (repairInterface && repairInterface.currentState.report) {
repairInterface.downloadReport();
log('📄 Bericht exportiert', 'success');
} else {
log('❌ Kein Bericht zum Exportieren verfügbar', 'error');
}
}
// Event listeners
startAnalysisBtn.addEventListener('click', startAnalysis);
startRepairBtn.addEventListener('click', startRepair);
cancelBtn.addEventListener('click', cancelOperation);
clearLogBtn.addEventListener('click', clearLog);
downloadLogBtn.addEventListener('click', downloadLog);
exportReportBtn.addEventListener('click', exportReport);
// Close modal when clicking outside
confirmationModal.addEventListener('click', (e) => {
if (e.target === confirmationModal) {
confirmationModal.classList.remove('show');
}
});
// Make toggleCollectionDetails available globally
window.toggleCollectionDetails = toggleCollectionDetails;
// Initialize when page loads
window.addEventListener('load', () => {
log('🚀 AppWrite Reparatur-Tool geladen', 'info');
// Initialize after a short delay to ensure extension is loaded
setTimeout(initializeRepairInterface, 1000);
});
</script>
</body>
</html>