added websocket implementation to frontend
This commit is contained in:
@@ -59,17 +59,7 @@
|
||||
(click)="extractKeywords()"
|
||||
[disabled]="isExtracting()">
|
||||
<mat-icon>troubleshoot</mat-icon>
|
||||
@switch (loadingState()) {
|
||||
@case ('extracting-url') {
|
||||
URL wird abgerufen...
|
||||
}
|
||||
@case ('extracting-text') {
|
||||
Text wird analysiert...
|
||||
}
|
||||
@default {
|
||||
Keywords extrahieren
|
||||
}
|
||||
}
|
||||
Keywords extrahieren
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
@@ -112,137 +102,121 @@
|
||||
}
|
||||
<mat-divider></mat-divider>
|
||||
<!-- Extracted Keywords Section -->
|
||||
@if (!isExtracting()) {
|
||||
<div class="extracted-section">
|
||||
<mat-card-title class="section-title"
|
||||
>Extrahierte Keywords</mat-card-title
|
||||
>
|
||||
@if (extractedKeywordsExist()) {
|
||||
<div class="category-grid">
|
||||
<!-- Broad -->
|
||||
@if (broadKeywords().length > 0) {
|
||||
<div class="category-section">
|
||||
<h4>Breite Keywords</h4>
|
||||
<mat-chip-listbox
|
||||
multiple
|
||||
[value]="selectedBroadKeywords()"
|
||||
(change)="onCategoryChange('broad', $event)">
|
||||
@for (keyword of broadKeywords(); track keyword) {
|
||||
<mat-chip-option
|
||||
[value]="keyword"
|
||||
class="compact-chip broad-chip"
|
||||
>{{ keyword }}</mat-chip-option
|
||||
>
|
||||
}
|
||||
</mat-chip-listbox>
|
||||
</div>
|
||||
}
|
||||
<!-- Coarse -->
|
||||
@if (coarseKeywords().length > 0) {
|
||||
<div class="category-section">
|
||||
<h4>Coarse Keywords</h4>
|
||||
<mat-chip-listbox
|
||||
multiple
|
||||
dense
|
||||
[value]="selectedCoarseKeywords()"
|
||||
(change)="onCategoryChange('coarse', $event)">
|
||||
@for (keyword of coarseKeywords(); track keyword) {
|
||||
<mat-chip-option
|
||||
[value]="keyword"
|
||||
class="compact-chip coarse-chip"
|
||||
>{{ keyword }}</mat-chip-option
|
||||
>
|
||||
}
|
||||
</mat-chip-listbox>
|
||||
</div>
|
||||
}
|
||||
<!-- Fine -->
|
||||
@if (fineKeywords().length > 0) {
|
||||
<div class="category-section">
|
||||
<h4>Fine Keywords</h4>
|
||||
<mat-chip-listbox
|
||||
multiple
|
||||
dense
|
||||
[value]="selectedFineKeywords()"
|
||||
(change)="onCategoryChange('fine', $event)">
|
||||
@for (keyword of fineKeywords(); track keyword) {
|
||||
<mat-chip-option
|
||||
[value]="keyword"
|
||||
class="compact-chip fine-chip"
|
||||
>{{ keyword }}</mat-chip-option
|
||||
>
|
||||
}
|
||||
</mat-chip-listbox>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="extracted-section">
|
||||
<mat-card-title class="section-title"
|
||||
>Extrahierte Keywords</mat-card-title
|
||||
>
|
||||
@if (extractedKeywordsExist()) {
|
||||
<div class="category-grid">
|
||||
<!-- Broad -->
|
||||
@if (broadKeywords().length > 0) {
|
||||
<div class="category-section">
|
||||
<h4>Breite Keywords</h4>
|
||||
<mat-chip-listbox
|
||||
multiple
|
||||
[value]="selectedBroadKeywords()"
|
||||
(change)="onCategoryChange('broad', $event)">
|
||||
@for (keyword of broadKeywords(); track keyword) {
|
||||
<mat-chip-option
|
||||
[value]="keyword"
|
||||
class="compact-chip broad-chip"
|
||||
>{{ keyword }}</mat-chip-option
|
||||
>
|
||||
}
|
||||
</mat-chip-listbox>
|
||||
</div>
|
||||
}
|
||||
<!-- Coarse -->
|
||||
@if (coarseKeywords().length > 0) {
|
||||
<div class="category-section">
|
||||
<h4>Coarse Keywords</h4>
|
||||
<mat-chip-listbox
|
||||
multiple
|
||||
dense
|
||||
[value]="selectedCoarseKeywords()"
|
||||
(change)="onCategoryChange('coarse', $event)">
|
||||
@for (keyword of coarseKeywords(); track keyword) {
|
||||
<mat-chip-option
|
||||
[value]="keyword"
|
||||
class="compact-chip coarse-chip"
|
||||
>{{ keyword }}</mat-chip-option
|
||||
>
|
||||
}
|
||||
</mat-chip-listbox>
|
||||
</div>
|
||||
}
|
||||
<!-- Fine -->
|
||||
@if (fineKeywords().length > 0) {
|
||||
<div class="category-section">
|
||||
<h4>Fine Keywords</h4>
|
||||
<mat-chip-listbox
|
||||
multiple
|
||||
dense
|
||||
[value]="selectedFineKeywords()"
|
||||
(change)="onCategoryChange('fine', $event)">
|
||||
@for (keyword of fineKeywords(); track keyword) {
|
||||
<mat-chip-option
|
||||
[value]="keyword"
|
||||
class="compact-chip fine-chip"
|
||||
>{{ keyword }}</mat-chip-option
|
||||
>
|
||||
}
|
||||
</mat-chip-listbox>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Select/Deselect All Extracted -->
|
||||
<div class="select-all-container">
|
||||
<!-- Existing select/deselect buttons -->
|
||||
@if (areAllExtractedSelected()) {
|
||||
<button
|
||||
mat-stroked-button
|
||||
color="primary"
|
||||
size="small"
|
||||
(click)="deselectAllExtracted()">
|
||||
<mat-icon>select_all</mat-icon> Alle extrahierten Keywords
|
||||
abwählen
|
||||
</button>
|
||||
} @else {
|
||||
<button
|
||||
mat-stroked-button
|
||||
color="primary"
|
||||
size="small"
|
||||
(click)="selectAllExtracted()">
|
||||
<mat-icon>select_all</mat-icon> Alle extrahierten Keywords
|
||||
auswählen
|
||||
</button>
|
||||
}
|
||||
|
||||
<!-- Clear extracted keywords button -->
|
||||
<!-- Select/Deselect All Extracted -->
|
||||
<div class="select-all-container">
|
||||
<!-- Existing select/deselect buttons -->
|
||||
@if (areAllExtractedSelected()) {
|
||||
<button
|
||||
mat-stroked-button
|
||||
color="warn"
|
||||
color="primary"
|
||||
size="small"
|
||||
(click)="clearExtractedKeywords()">
|
||||
<mat-icon>delete_outline</mat-icon> Lösche alle extrahierten
|
||||
Keywords
|
||||
(click)="deselectAllExtracted()">
|
||||
<mat-icon>select_all</mat-icon> Alle extrahierten Keywords
|
||||
abwählen
|
||||
</button>
|
||||
</div>
|
||||
} @else {
|
||||
<p class="empty-state">
|
||||
Keine extrahierten Keywords vorhanden. Extrahiere Keywords, um
|
||||
sie hier zu sehen oder füge sie manuell hinzu.
|
||||
</p>
|
||||
}
|
||||
} @else {
|
||||
<button
|
||||
mat-stroked-button
|
||||
color="primary"
|
||||
size="small"
|
||||
[disabled]="isExtracting()"
|
||||
(click)="selectAllExtracted()">
|
||||
<mat-icon>select_all</mat-icon> Alle extrahierten Keywords
|
||||
auswählen
|
||||
</button>
|
||||
}
|
||||
|
||||
<!-- Clear extracted keywords button -->
|
||||
<button
|
||||
mat-stroked-button
|
||||
color="warn"
|
||||
size="small"
|
||||
(click)="clearExtractedKeywords()">
|
||||
<mat-icon>delete_outline</mat-icon> Lösche alle extrahierten
|
||||
Keywords
|
||||
</button>
|
||||
</div>
|
||||
} @else {
|
||||
<p class="empty-state">
|
||||
Keine extrahierten Keywords vorhanden. Extrahiere Keywords, um sie
|
||||
hier zu sehen oder füge sie manuell hinzu.
|
||||
</p>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (isExtracting()) {
|
||||
<div class="progress-container">
|
||||
<mat-progress-bar
|
||||
mode="determinate"
|
||||
[value]="progress()"
|
||||
color="primary">
|
||||
</mat-progress-bar>
|
||||
<div class="status-message">{{ statusMessage() }}</div>
|
||||
</div>
|
||||
} @else {
|
||||
<span class="loading-hint">
|
||||
@switch (loadingState()) {
|
||||
@case ('extracting-url') {
|
||||
<app-loading
|
||||
text="Seite wird geladen und analysiert..."
|
||||
icon="language"
|
||||
[size]="50"
|
||||
[diameter]="50" />
|
||||
}
|
||||
@case ('extracting-text') {
|
||||
<app-loading
|
||||
text="Text wird verarbeitet..."
|
||||
icon="article"
|
||||
[size]="50"
|
||||
[diameter]="50" />
|
||||
}
|
||||
@default {
|
||||
<app-loading
|
||||
text="Keywords werden extrahiert..."
|
||||
icon="manage_search"
|
||||
[size]="50"
|
||||
[diameter]="50" />
|
||||
}
|
||||
}
|
||||
</span>
|
||||
}
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
||||
@@ -242,3 +242,20 @@
|
||||
background: rgba(0, 0, 0, 0.03);
|
||||
}
|
||||
}
|
||||
.progress-container {
|
||||
margin-top: 1rem;
|
||||
padding: 0.5rem 0;
|
||||
|
||||
mat-progress-bar {
|
||||
height: 8px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.status-message {
|
||||
margin-top: 0.5rem;
|
||||
font-size: 0.9rem;
|
||||
color: var(--sg-text-secondary);
|
||||
text-align: center;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,16 @@ import { MatInputModule } from '@angular/material/input';
|
||||
import { MatTabsModule } from '@angular/material/tabs';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { debounceTime, distinctUntilChanged } from 'rxjs';
|
||||
import { KeywordsService } from '../../api/api/keywords.service';
|
||||
import { KeywordsRequest } from '../../api/model/keywordsRequest';
|
||||
import { MatExpansionModule } from '@angular/material/expansion';
|
||||
import { ExtractedKeywords } from '../../api/model/extractedKeywords';
|
||||
import { ExtractedKeywordsResponse } from '../../api/model/extractedKeywordsResponse';
|
||||
import { DestroyRef } from '@angular/core';
|
||||
import { LoadingComponent } from '../../shared/ui/loading/loading.component';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import {
|
||||
KeywordWebSocketService,
|
||||
WsEvent,
|
||||
} from '../../shared/services/websocket.service';
|
||||
type InputMode = 'url' | 'text' | 'keywords';
|
||||
|
||||
@Component({
|
||||
@@ -31,7 +36,7 @@ type InputMode = 'url' | 'text' | 'keywords';
|
||||
MatDividerModule,
|
||||
MatCardModule,
|
||||
MatExpansionModule,
|
||||
LoadingComponent,
|
||||
MatProgressBarModule,
|
||||
],
|
||||
templateUrl: './keywords-search.component.html',
|
||||
styleUrl: './keywords-search.component.scss',
|
||||
@@ -80,22 +85,17 @@ export class KeywordsSearchComponent {
|
||||
|
||||
private isRestoringState = false;
|
||||
|
||||
readonly loadingState = computed(() => {
|
||||
if (!this.isExtracting()) return 'idle' as const;
|
||||
|
||||
const mode = this.form.controls.selectedInputType.value;
|
||||
if (mode === 'url') return 'extracting-url' as const;
|
||||
if (mode === 'text') return 'extracting-text' as const;
|
||||
return 'extracting-keywords' as const;
|
||||
});
|
||||
readonly progress = signal(0);
|
||||
readonly statusMessage = signal('');
|
||||
constructor(
|
||||
private readonly formBuilder: FormBuilder,
|
||||
private readonly route: ActivatedRoute,
|
||||
private readonly router: Router,
|
||||
private readonly keywordsService: KeywordsService,
|
||||
private readonly destroyRef: DestroyRef,
|
||||
private readonly websocketService: KeywordWebSocketService,
|
||||
) {
|
||||
this.route.queryParamMap.pipe(takeUntilDestroyed()).subscribe(() => {
|
||||
this.route.queryParamMap.pipe(takeUntilDestroyed()).subscribe((event) => {
|
||||
console.log('Component received event:', event);
|
||||
this.restoreStateFromQueryParams();
|
||||
});
|
||||
|
||||
@@ -117,6 +117,64 @@ export class KeywordsSearchComponent {
|
||||
this.updateQueryParams();
|
||||
});
|
||||
|
||||
//get streamed data
|
||||
this.websocketService.getMessages().subscribe((event: WsEvent) => {
|
||||
switch (event.type) {
|
||||
case 'status':
|
||||
console.log('STATUS:', event.step, event.message);
|
||||
this.statusMessage.set(event.message || '');
|
||||
this.progress.set(this.getProgressForStep(event.step || ''));
|
||||
break;
|
||||
case 'keywords':
|
||||
console.log('KEYWORDS:', event.keywords);
|
||||
if (event.keywords) this.addExtractedKeyword(event.keywords);
|
||||
break;
|
||||
|
||||
// case 'result':
|
||||
// console.log('RESULT:', event.result);
|
||||
// this.processExtractedKeywords(
|
||||
// event.result as ExtractedKeywordsResponse,
|
||||
// );
|
||||
// this.isExtracting.set(false);
|
||||
// break;
|
||||
case 'completed':
|
||||
console.log('COMPLETED:', event.result);
|
||||
this.processExtractedKeywords(
|
||||
event.result as ExtractedKeywordsResponse,
|
||||
);
|
||||
this.isExtracting.set(false);
|
||||
this.progress.set(100);
|
||||
this.statusMessage.set('Fertig!');
|
||||
this.websocketService.close();
|
||||
this.isExtracting.set(false);
|
||||
break;
|
||||
|
||||
case 'error':
|
||||
console.error('ERROR:', event.message);
|
||||
this.progress.set(0);
|
||||
this.statusMessage.set('Fehler: ' + event.message);
|
||||
this.broadKeywords.set([]);
|
||||
this.coarseKeywords.set([]);
|
||||
this.fineKeywords.set([]);
|
||||
this.websocketService.close();
|
||||
this.isExtracting.set(false);
|
||||
// Keep manual, but remove selected that are not in manual
|
||||
this.selectedKeywords.set(
|
||||
this.selectedKeywords().filter((k) =>
|
||||
this.manualKeywords().includes(k),
|
||||
),
|
||||
);
|
||||
// extractionSource stays as it was (or reset? we keep it)
|
||||
this.updateQueryParams();
|
||||
break;
|
||||
default:
|
||||
console.warn('Unknown event type:', event);
|
||||
}
|
||||
this.destroyRef.onDestroy(() => {
|
||||
this.websocketService.close();
|
||||
});
|
||||
});
|
||||
|
||||
// Clear session storage on component destroy
|
||||
this.destroyRef.onDestroy(() => {
|
||||
const nav = this.router.lastSuccessfulNavigation;
|
||||
@@ -251,12 +309,62 @@ export class KeywordsSearchComponent {
|
||||
isSearchDisabled(): boolean {
|
||||
return this.selectedKeywords().length === 0 || this.isExtracting();
|
||||
}
|
||||
addExtractedKeyword(keywords: ExtractedKeywords): void {
|
||||
const broad = this.extractKeywordStrings(keywords.broad_keywords);
|
||||
const coarse = this.extractKeywordStrings(keywords.coarse_grained);
|
||||
const fine = this.extractKeywordStrings(keywords.fine_grained);
|
||||
|
||||
extractKeywords(): void {
|
||||
this.broadKeywords.set(broad);
|
||||
this.coarseKeywords.set(coarse);
|
||||
this.fineKeywords.set(fine);
|
||||
}
|
||||
processExtractedKeywords(result: ExtractedKeywordsResponse): void {
|
||||
if (result === undefined) {
|
||||
return;
|
||||
}
|
||||
console.log('Processing extracted keywords:', result);
|
||||
const { results, source, source_content, source_url } = result;
|
||||
|
||||
const broad = this.extractKeywordStrings(results.broad_keywords);
|
||||
const coarse = this.extractKeywordStrings(results.coarse_grained);
|
||||
const fine = this.extractKeywordStrings(results.fine_grained);
|
||||
|
||||
this.broadKeywords.set(broad);
|
||||
this.coarseKeywords.set(coarse);
|
||||
this.fineKeywords.set(fine);
|
||||
this.sourceContent.set(source_content);
|
||||
this.extractionSource.set(source as InputMode);
|
||||
this.sourceUrl.set(source_url ?? '');
|
||||
this.saveSourceToSession();
|
||||
|
||||
console.log('Extracted keywords:', {
|
||||
broad,
|
||||
coarse,
|
||||
fine,
|
||||
manual: this.manualKeywords(),
|
||||
});
|
||||
// Keep only selected keywords that still exist in any category (including manual)
|
||||
const allExtracted = [
|
||||
...broad,
|
||||
...coarse,
|
||||
...fine,
|
||||
...this.manualKeywords(),
|
||||
];
|
||||
this.selectedKeywords.set(
|
||||
this.selectedKeywords().filter((k) => allExtracted.includes(k)),
|
||||
);
|
||||
|
||||
this.updateQueryParams();
|
||||
}
|
||||
async extractKeywords(): Promise<void> {
|
||||
this.clearExtractedKeywords();
|
||||
const query = this.getCurrentExtractionQuery();
|
||||
if (!query) return;
|
||||
|
||||
// Reset progress and status
|
||||
this.progress.set(0);
|
||||
this.statusMessage.set('Starte Extraktion...');
|
||||
|
||||
const currentMode = this.form.controls.selectedInputType.value;
|
||||
const keywordsRequest: KeywordsRequest = {
|
||||
query: query,
|
||||
@@ -265,56 +373,15 @@ export class KeywordsSearchComponent {
|
||||
};
|
||||
|
||||
this.isExtracting.set(true);
|
||||
this.keywordsService.extractKeywords(keywordsRequest).subscribe({
|
||||
next: ({ results, source, source_content, source_url }) => {
|
||||
const broad = this.extractKeywordStrings(results.broad_keywords);
|
||||
const coarse = this.extractKeywordStrings(results.coarse_grained);
|
||||
const fine = this.extractKeywordStrings(results.fine_grained);
|
||||
|
||||
this.broadKeywords.set(broad);
|
||||
this.coarseKeywords.set(coarse);
|
||||
this.fineKeywords.set(fine);
|
||||
this.sourceContent.set(source_content);
|
||||
this.extractionSource.set(source as InputMode);
|
||||
this.sourceUrl.set(source_url ?? '');
|
||||
this.saveSourceToSession();
|
||||
|
||||
console.log('Extracted keywords:', {
|
||||
broad,
|
||||
coarse,
|
||||
fine,
|
||||
manual: this.manualKeywords(),
|
||||
});
|
||||
// Keep only selected keywords that still exist in any category (including manual)
|
||||
const allExtracted = [
|
||||
...broad,
|
||||
...coarse,
|
||||
...fine,
|
||||
...this.manualKeywords(),
|
||||
];
|
||||
this.selectedKeywords.set(
|
||||
this.selectedKeywords().filter((k) => allExtracted.includes(k)),
|
||||
);
|
||||
|
||||
this.updateQueryParams();
|
||||
},
|
||||
error: () => {
|
||||
this.broadKeywords.set([]);
|
||||
this.coarseKeywords.set([]);
|
||||
this.fineKeywords.set([]);
|
||||
// Keep manual, but remove selected that are not in manual
|
||||
this.selectedKeywords.set(
|
||||
this.selectedKeywords().filter((k) =>
|
||||
this.manualKeywords().includes(k),
|
||||
),
|
||||
);
|
||||
// extractionSource stays as it was (or reset? we keep it)
|
||||
this.updateQueryParams();
|
||||
},
|
||||
complete: () => {
|
||||
this.isExtracting.set(false);
|
||||
},
|
||||
});
|
||||
try {
|
||||
// sendRequest now waits internally for the connection to open
|
||||
await this.websocketService.sendRequest(keywordsRequest);
|
||||
} catch (error) {
|
||||
console.error('WebSocket send error:', error);
|
||||
this.isExtracting.set(false);
|
||||
this.statusMessage.set('Fehler beim Senden der Anfrage');
|
||||
}
|
||||
}
|
||||
|
||||
search(): void {
|
||||
@@ -390,6 +457,7 @@ export class KeywordsSearchComponent {
|
||||
sourceContent: this.sourceContent(),
|
||||
sourceUrl: this.sourceUrl(),
|
||||
};
|
||||
console.log(data);
|
||||
sessionStorage.setItem(this.SESSION_KEY, JSON.stringify(data));
|
||||
}
|
||||
|
||||
@@ -446,4 +514,18 @@ export class KeywordsSearchComponent {
|
||||
const normalized = value.trim();
|
||||
return normalized.length ? normalized : null;
|
||||
}
|
||||
private getProgressForStep(step: string): number {
|
||||
switch (step) {
|
||||
case 'started':
|
||||
return 10;
|
||||
case 'fetching_url':
|
||||
return 30;
|
||||
case 'content_extracted':
|
||||
return 60;
|
||||
case 'calling_llm':
|
||||
return 80;
|
||||
default:
|
||||
return 50; // fallback for unknown steps
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user