|
|
@@ -0,0 +1,82 @@
|
|
|
+import { Component, Inject, inject } from '@angular/core';
|
|
|
+import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
|
|
+import { HttpClient } from '@angular/common/http';
|
|
|
+import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
|
|
+import { CommonModule } from '@angular/common';
|
|
|
+import { MatFormFieldModule } from '@angular/material/form-field';
|
|
|
+import { MatInputModule } from '@angular/material/input';
|
|
|
+import { MatButtonModule } from '@angular/material/button';
|
|
|
+import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
|
|
+import { MatTableModule } from '@angular/material/table';
|
|
|
+import { webConfig } from '../../config';
|
|
|
+import { MatIconModule } from '@angular/material/icon';
|
|
|
+import { FFBProduction } from '../../ffb/ffb-production.interface';
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-ffb-vector-search-dialog',
|
|
|
+ templateUrl: './ffb-vector-search-dialog.component.html',
|
|
|
+ styleUrls: ['./ffb-vector-search-dialog.component.css'],
|
|
|
+ standalone: true,
|
|
|
+ imports: [
|
|
|
+ CommonModule,
|
|
|
+ ReactiveFormsModule,
|
|
|
+ MatFormFieldModule,
|
|
|
+ MatInputModule,
|
|
|
+ MatButtonModule,
|
|
|
+ MatProgressSpinnerModule,
|
|
|
+ MatTableModule,
|
|
|
+ MatIconModule
|
|
|
+ ],
|
|
|
+})
|
|
|
+export class FfbVectorSearchDialogComponent {
|
|
|
+ private http = inject(HttpClient);
|
|
|
+ dialogRef = inject(MatDialogRef<FfbVectorSearchDialogComponent>);
|
|
|
+
|
|
|
+ queryControl = new FormControl('');
|
|
|
+ kControl = new FormControl(5);
|
|
|
+
|
|
|
+ loading = false;
|
|
|
+ results: FFBProduction[] = [];
|
|
|
+
|
|
|
+ displayedColumns: string[] = ['productionDate', 'site', 'phase', 'block', 'weight', 'quantity', 'score'];
|
|
|
+
|
|
|
+ constructor(@Inject(MAT_DIALOG_DATA) public data: any) {}
|
|
|
+
|
|
|
+ search() {
|
|
|
+ const q = this.queryControl.value?.trim();
|
|
|
+ const k = this.kControl.value || 5;
|
|
|
+
|
|
|
+ if (!q) return;
|
|
|
+
|
|
|
+ this.loading = true;
|
|
|
+ this.results = [];
|
|
|
+
|
|
|
+ this.http.get<FFBProduction[]>(`${webConfig.exposedUrl}/api/ffb-production/search?q=${encodeURIComponent(q)}&k=${k}`)
|
|
|
+ .subscribe({
|
|
|
+ next: (data) => {
|
|
|
+ console.log(data)
|
|
|
+ // Strip vector to save memory/UI
|
|
|
+ this.results = data.map(h => ({ ...h, vector: undefined, productionDate: new Date(h.productionDate) }));
|
|
|
+ this.loading = false;
|
|
|
+ },
|
|
|
+ error: (err) => {
|
|
|
+ console.error(err);
|
|
|
+ this.loading = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ close() {
|
|
|
+ this.dialogRef.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ applyResults() {
|
|
|
+ // Return results to parent
|
|
|
+ this.dialogRef.close(this.results);
|
|
|
+ }
|
|
|
+
|
|
|
+ formatDate(date: Date | string) {
|
|
|
+ const d = new Date(date);
|
|
|
+ return d.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: '2-digit' });
|
|
|
+ }
|
|
|
+}
|