diff --git a/webapp/src/app/modules/keywords-search/keywords-search.component.html b/webapp/src/app/modules/keywords-search/keywords-search.component.html index 8e50afb9..a8f41190 100644 --- a/webapp/src/app/modules/keywords-search/keywords-search.component.html +++ b/webapp/src/app/modules/keywords-search/keywords-search.component.html @@ -58,17 +58,14 @@
+ +
-
- - Topic Mapping - +
+ + Topic Mapping + +
@@ -276,36 +273,48 @@
- + @if (isExtracting() && broadKeywords().length === 0) { + + } @else { + + }
- + @if (isExtracting() && coarseKeywords().length === 0) { + + } @else { + + }
- + @if (isExtracting() && fineKeywords().length === 0) { + + } @else { + + }
@@ -322,14 +331,18 @@ {{ broadKeywords().length }}
- + @if (isExtracting() && broadKeywords().length === 0) { + + } @else { + + }
@@ -339,14 +352,18 @@ {{ coarseKeywords().length }}
- + @if (isExtracting() && coarseKeywords().length === 0) { + + } @else { + + }
@@ -356,14 +373,18 @@ {{ fineKeywords().length }}
- + @if (isExtracting() && fineKeywords().length === 0) { + + } @else { + + }
@@ -378,30 +399,27 @@ } - - - @if (sourceContent().length > 0) { - - - - Quellentext: {{ sourceUrl() }} - -
-
- } - @if (isExtracting() && !keywordsExist()) { + + + @if (sourceContent().length > 0) { + + + + Quellentext: {{ sourceUrl() }} + +
+
} - @if (isExtracting() && keywordsExist()) { + @if (isExtracting()) {
{{ statusMessage() }}
}
diff --git a/webapp/src/app/modules/keywords-search/keywords-search.component.scss b/webapp/src/app/modules/keywords-search/keywords-search.component.scss index 5aa71fe2..b9692f90 100644 --- a/webapp/src/app/modules/keywords-search/keywords-search.component.scss +++ b/webapp/src/app/modules/keywords-search/keywords-search.component.scss @@ -22,7 +22,9 @@ $touch-target: 44px; margin-top: 0.5rem; gap: 0.5rem; align-items: top; - justify-content: center; + app-file-upload { + width: 100%; + } } .full-width { @@ -87,7 +89,6 @@ $touch-target: 44px; gap: auto; ::ng-deep .mdc-switch { - position: relative; width: 100%; } ::ng-deep .mdc-form-field { @@ -564,7 +565,7 @@ mat-button-toggle-group { SOURCE EXPANSION PANEL ============================================================ */ .source-expansion { - margin: 0.75rem 0; + margin: 0.5rem 1rem; background: var(--sg-background-muted, #f5f5f5); border-radius: 4px; //border-left: 4px solid var(--sg-primary, #1976d2); diff --git a/webapp/src/app/modules/keywords-search/keywords-search.component.ts b/webapp/src/app/modules/keywords-search/keywords-search.component.ts index 5987992e..3bf8947e 100644 --- a/webapp/src/app/modules/keywords-search/keywords-search.component.ts +++ b/webapp/src/app/modules/keywords-search/keywords-search.component.ts @@ -152,39 +152,58 @@ export class KeywordsSearchComponent { let highlightedContent = content; - // replace the keyword with highlighted spans + const normalizeText = (text: string): string => { + return text + .trim() + .toLowerCase() + .replace(/[\u2010-\u2015\u2026—–]/g, '-') + .replace(/[\u2018\u2019\u201b\u201c\u201d\u201f]/g, "'") + .replace(/[\s\n\r\t]+/g, ' ') + .replace(/[^a-zA-Z0-9\s\-]/g, ''); + }; + + // Normalize keyword for matching + const normalizeKeyword = (keyword: string): string => { + return keyword + .trim() + .toLowerCase() + .replace(/[\s\-]+/g, '') + .replace(/[^a-zA-Z0-9]/g, ''); + }; + for (const keyword of selectedKeywords) { - const normalizedKeyword = this.normalizeKeyword(keyword); + const normalizedKeyword = normalizeKeyword(keyword); - // Find the first keyword entry that matches this normalized keyword - const entry = this.allKeywordEntries().find( - (e) => - this.normalizeKeyword(this.getKeywordLabel(e)) === normalizedKeyword, - ); + const entry = this.allKeywordEntries().find((e) => { + const label = this.getKeywordLabel(e); + return normalizeKeyword(label) === normalizedKeyword; + }); - if (entry) { - const topic = this.getTopic(entry); - if (topic) { - const color = this.getTopicColor(topic); - // Escape HTML special characters in the keyword before using it in HTML - const escapedKeyword = keyword - .replace(/&/g, '&') - .replace(//g, '>'); + if (!entry) continue; - // Create the replacement span HTML - const replacement = `${escapedKeyword}`; + const topic = this.getTopic(entry); + if (!topic) continue; - const escapedRegexKeyword = keyword.replace( - /[.*+?^${}()|[\]\\]/g, - '\\$&', - ); - const regex = new RegExp(escapedRegexKeyword, 'g'); + const color = this.getTopicColor(topic); - highlightedContent = highlightedContent.replace(regex, replacement); - } - } + const escapedKeyword = keyword + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); + + const escapedRegexKeyword = keyword + .replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + .replace(/\s+/g, '\\s*'); + + const regex = new RegExp(escapedRegexKeyword, 'gi'); + + const replacement = `${escapedKeyword}`; + + highlightedContent = highlightedContent.replace(regex, replacement); } + return this.sanitizer.bypassSecurityTrustHtml(highlightedContent); }); @@ -378,13 +397,6 @@ export class KeywordsSearchComponent { this.uploadedFiles.set(files); } - // Helper: Update progress bar - private updateProgress(processed: number, total: number) { - const progress = Math.round((processed / total) * 100); - this.progress.set(progress); - this.statusMessage.set(`Reading ${processed}/${total} files...`); - } - // Helper: Send files to WebSocket for server-side extraction private sendFilesToWebSocket(files: FileUpload[]) { const keywordsRequest: KeywordsRequest = { @@ -407,17 +419,6 @@ export class KeywordsSearchComponent { this.isExtracting.set(false); }); } - - onUploadProgress(event: { id: string; progress: number }) { - console.log('Upload progress:', event.progress + '%'); - this.progress.set(event.progress); - } - - onUploadError(error: { id: string; error: string }) { - console.error('Upload error:', error); - this.statusMessage.set('Upload failed: ' + error.error); - this.isExtracting.set(false); - } // --- Keyword selection & manual entry ------------------------------------ private keywordExists(keyword: string): boolean { @@ -589,6 +590,7 @@ export class KeywordsSearchComponent { } onExtractKeywordsClick(): void { + this.clearKeywords(); if (this.isExtracting()) { this.cancelKeywordExtraction(); return; @@ -626,7 +628,6 @@ export class KeywordsSearchComponent { }; processedFiles++; - this.updateProgress(processedFiles, totalFiles); if (processedFiles === totalFiles) { this.sendFilesToWebSocket(fileUploads); @@ -642,7 +643,6 @@ export class KeywordsSearchComponent { }; processedFiles++; - this.updateProgress(processedFiles, totalFiles); if (processedFiles === totalFiles) { this.sendFilesToWebSocket(fileUploads);