diff --git a/src/components/AIQueryInterface.astro b/src/components/AIQueryInterface.astro
index 2cbf0c6..9007691 100644
--- a/src/components/AIQueryInterface.astro
+++ b/src/components/AIQueryInterface.astro
@@ -125,10 +125,39 @@ const domainAgnosticSoftware = data['domain-agnostic-software'] || [];
Datenschutzrichtlinien
+
+
+
+
+
+ Vorherige Analyse wiederherstellen:
+
+
+
+
+
+
+ Laden Sie eine zuvor heruntergeladene Analyse-Datei, um Ergebnisse und Audit-Trail anzuzeigen
+
+
-
-
@@ -345,6 +373,7 @@ class AIQueryInterface {
console.log('[AI Interface] Initializing...');
this.initializeElements();
this.setupEventListeners();
+ this.setupUnifiedUploadSystem();
this.updateModeUI();
console.log('[AI Interface] Initialized successfully');
}
@@ -421,6 +450,9 @@ class AIQueryInterface {
this.elements.dismissSuggestions?.addEventListener('click', () => this.hideSmartPrompting());
+ // CRITICAL: Setup upload for previous analysis (always available)
+ this.setupPreviousAnalysisUpload();
+
console.log('[AI Interface] Event listeners setup complete');
}
@@ -987,28 +1019,6 @@ class AIQueryInterface {
${this.renderPhaseGroups(rawAuditTrail, stats)}
-
-
-
-
- Analyse herunterladen
-
-
-
-
-
@@ -1023,9 +1033,6 @@ class AIQueryInterface {
`;
-
- // Setup download functionality
- this.setupDownloadUpload();
} catch (error) {
console.error('[AI Interface] Error rendering audit trail:', error);
@@ -1049,6 +1056,50 @@ class AIQueryInterface {
}
}
+ setupUnifiedUploadSystem() {
+ // Setup the always-available upload (previous analysis)
+ const previousUploadInput = document.getElementById('upload-previous-analysis');
+ if (previousUploadInput) {
+ previousUploadInput.addEventListener('change', (event) => {
+ const files = event.target.files;
+ const file = files ? files[0] : null;
+ if (file) {
+ this.handlePreviousAnalysisUpload(file);
+ }
+ event.target.value = ''; // Reset for reuse
+ });
+ console.log('[AI Interface] Previous analysis upload setup complete');
+ }
+
+ // Setup download buttons automatically when they appear
+ const setupDownloadBtn = () => {
+ const downloadBtn = document.getElementById('download-results-btn');
+ if (downloadBtn && !downloadBtn.hasAttribute('data-setup')) {
+ downloadBtn.setAttribute('data-setup', 'true');
+ downloadBtn.addEventListener('click', () => this.downloadResults());
+ console.log('[AI Interface] Download button setup complete');
+ }
+ };
+
+ // Try to setup immediately (if already present)
+ setupDownloadBtn();
+
+ // Watch for dynamically added download buttons
+ const observer = new MutationObserver(() => {
+ setupDownloadBtn();
+ });
+
+ observer.observe(document.body, {
+ childList: true,
+ subtree: true
+ });
+
+ // Store observer for cleanup
+ this.uploadObserver = observer;
+
+ console.log('[AI Interface] Unified upload system setup complete');
+ }
+
calculateAuditStats(auditTrail) {
if (!auditTrail || auditTrail.length === 0) {
return {
@@ -1270,26 +1321,6 @@ class AIQueryInterface {
return actions[action] || action;
}
- setupDownloadUpload() {
- const downloadBtn = document.getElementById('download-results-btn');
- const uploadInput = document.getElementById('upload-results');
-
- if (downloadBtn) {
- downloadBtn.addEventListener('click', () => this.downloadResults());
- }
-
- if (uploadInput) {
- uploadInput.addEventListener('change', (event) => {
- // FIXED: Remove TypeScript casting
- const files = event.target.files;
- const file = files ? files[0] : null;
- if (file) {
- this.handleFileUpload(file);
- }
- });
- }
- }
-
downloadResults() {
if (!this.currentRecommendation) {
alert('Keine Analyse zum Herunterladen verfügbar.');
@@ -1334,7 +1365,105 @@ class AIQueryInterface {
console.log('[AI Interface] Analysis downloaded');
}
- async handleFileUpload(file) {
+ validateUploadStructure(data) {
+ try {
+ return !!(
+ data &&
+ typeof data === 'object' &&
+ data.metadata &&
+ typeof data.metadata === 'object' &&
+ typeof data.metadata.timestamp === 'string' &&
+ data.recommendation &&
+ typeof data.recommendation === 'object' &&
+ Array.isArray(data.auditTrail)
+ );
+ } catch (error) {
+ console.error('[AI Interface] Structure validation error:', error);
+ return false;
+ }
+ }
+
+ displayUploadedResults(data) {
+ try {
+ console.log('[AI Interface] Displaying uploaded results');
+
+ // Show upload banner
+ this.showUploadedBanner(data.metadata);
+
+ // Restore interface state
+ this.currentRecommendation = data.recommendation;
+
+ // Display the uploaded analysis
+ this.showResults();
+
+ // Update the recommendation display based on mode
+ if (data.metadata.mode === 'workflow') {
+ this.displayWorkflowResults(data.recommendation, data.metadata.userQuery);
+ } else {
+ this.displayToolResults(data.recommendation, data.metadata.userQuery);
+ }
+
+ // Render the uploaded audit trail
+ setTimeout(() => {
+ try {
+ this.renderAuditTrail(data.auditTrail);
+ console.log('[AI Interface] Audit trail from upload rendered successfully');
+ } catch (error) {
+ console.error('[AI Interface] Failed to render uploaded audit trail:', error);
+ }
+ }, 200);
+
+ console.log('[AI Interface] Uploaded analysis displayed successfully');
+ } catch (error) {
+ console.error('[AI Interface] Error displaying uploaded results:', error);
+ this.showError('Fehler beim Anzeigen der hochgeladenen Analyse: ' + error.message);
+ }
+ }
+
+ showUploadedBanner(metadata) {
+ const banner = `
+
+
📁
+
+
Hochgeladene Analyse
+
+ Erstellt: ${new Date(metadata.timestamp).toLocaleString('de-DE')} |
+ Modus: ${metadata.mode} |
+ ${metadata.toolsDataHash ? `Hash: ${metadata.toolsDataHash.slice(0, 8)}...` : ''}
+
+
+
×
+
+ `;
+
+ if (this.elements && this.elements.results) {
+ this.elements.results.insertAdjacentHTML('afterbegin', banner);
+ }
+ }
+
+ setupPreviousAnalysisUpload() {
+ const uploadInput = document.getElementById('upload-previous-analysis');
+
+ if (uploadInput) {
+ uploadInput.addEventListener('change', (event) => {
+ const files = event.target.files;
+ const file = files ? files[0] : null;
+ if (file) {
+ this.handlePreviousAnalysisUpload(file);
+ }
+ // Reset the input so the same file can be uploaded again
+ event.target.value = '';
+ });
+
+ console.log('[AI Interface] Previous analysis upload setup complete');
+ } else {
+ console.warn('[AI Interface] Previous analysis upload input not found');
+ }
+ }
+
+ async handlePreviousAnalysisUpload(file) {
+ console.log('[AI Interface] Handling previous analysis upload:', file.name);
+
try {
// Security validation
if (file.size > 10 * 1024 * 1024) {
@@ -1358,82 +1487,30 @@ class AIQueryInterface {
throw new Error('Ungültiges Analyse-Dateiformat');
}
- console.log('[AI Interface] Valid analysis file uploaded');
- this.displayUploadedResults(data);
+ console.log('[AI Interface] Valid previous analysis file uploaded');
- } catch (error) {
- console.error('[AI Interface] Upload failed:', error);
- alert(`Upload fehlgeschlagen: ${error.message}`);
- }
- }
-
- validateUploadStructure(data) {
- try {
- return !!(
- data &&
- typeof data === 'object' &&
- data.metadata &&
- typeof data.metadata === 'object' &&
- typeof data.metadata.timestamp === 'string' &&
- data.recommendation &&
- typeof data.recommendation === 'object' &&
- Array.isArray(data.auditTrail)
- );
- } catch (error) {
- console.error('[AI Interface] Structure validation error:', error);
- return false;
- }
- }
-
- displayUploadedResults(data) {
- try {
- // Show upload banner
- this.showUploadedBanner(data.metadata);
-
- // Restore interface state
- this.currentRecommendation = data.recommendation;
+ // Hide any existing results or errors
+ this.hideResults();
+ this.hideError();
+ this.hideLoading();
// Display the uploaded analysis
- this.showResults();
+ this.displayUploadedResults(data);
- // Update the recommendation display
- if (data.metadata.mode === 'workflow') {
- this.displayWorkflowResults(data.recommendation, data.metadata.userQuery);
- } else {
- this.displayToolResults(data.recommendation, data.metadata.userQuery);
+ // Update mode if different
+ if (data.metadata.mode && data.metadata.mode !== this.currentMode) {
+ this.setMode(data.metadata.mode);
}
- // Render the uploaded audit trail
- setTimeout(() => {
- this.renderAuditTrail(data.auditTrail);
- }, 100);
+ // Optionally restore the query in the input field
+ if (data.metadata.userQuery && this.elements.input) {
+ this.elements.input.value = data.metadata.userQuery;
+ this.updateCharacterCount();
+ }
- console.log('[AI Interface] Uploaded analysis displayed successfully');
} catch (error) {
- console.error('[AI Interface] Error displaying uploaded results:', error);
- alert('Fehler beim Anzeigen der hochgeladenen Analyse');
- }
- }
-
- showUploadedBanner(metadata) {
- const banner = `
-
-
📁
-
-
Hochgeladene Analyse
-
- Erstellt: ${new Date(metadata.timestamp).toLocaleString('de-DE')} |
- Modus: ${metadata.mode} |
- ${metadata.toolsDataHash ? `Hash: ${metadata.toolsDataHash.slice(0, 8)}...` : ''}
-
-
-
×
-
- `;
-
- // FIXED: Add null checking
- if (this.elements && this.elements.results) {
- this.elements.results.insertAdjacentHTML('afterbegin', banner);
+ console.error('[AI Interface] Previous analysis upload failed:', error);
+ this.showError(`Upload fehlgeschlagen: ${error.message}`);
}
}