From c144db3f13eda08dbdc6526bb19cee4d1d3770dd Mon Sep 17 00:00:00 2001 From: s8613 Date: Tue, 17 Jun 2025 11:29:49 +0200 Subject: [PATCH 1/8] Updated KennzahlenTabel --- .../src/components/KennzahlenTable.tsx | 217 +++++++++++++++--- 1 file changed, 184 insertions(+), 33 deletions(-) diff --git a/project/frontend/src/components/KennzahlenTable.tsx b/project/frontend/src/components/KennzahlenTable.tsx index b6a19bb..5cfbad3 100644 --- a/project/frontend/src/components/KennzahlenTable.tsx +++ b/project/frontend/src/components/KennzahlenTable.tsx @@ -38,29 +38,47 @@ interface KennzahlenTableProps { } export default function KennzahlenTable({ - onPageClick, - data, - pdfId, - settings, - from -}: KennzahlenTableProps) { + onPageClick, + data, + pdfId, + settings, + from + }: KennzahlenTableProps) { const [editingIndex, setEditingIndex] = useState(""); const [editValue, setEditValue] = useState(""); + const [editingPageIndex, setEditingPageIndex] = useState(""); + const [editPageValue, setEditPageValue] = useState(""); + const [hoveredPageIndex, setHoveredPageIndex] = useState(""); const navigate = useNavigate(); const queryClient = useQueryClient(); const { mutate } = useMutation({ - mutationFn: (id: string) => { + mutationFn: (params: { id: string; newValue?: string; newPage?: number }) => { + const { id, newValue, newPage } = params; const key = id.toUpperCase(); const updatedData = { ...data }; - updatedData[key] = data[key]?.map((item) => ({ - ...item, - entity: editValue, - })) || [{ label: key, entity: editValue }]; + + if (data[key] && data[key].length > 0) { + updatedData[key] = data[key].map((item) => ({ + ...item, + ...(newValue !== undefined && { entity: newValue }), + ...(newPage !== undefined && { page: newPage }), + })); + } else { + updatedData[key] = [{ + label: key, + entity: newValue || "", + page: newPage || 0, + status: "single-source", + source: "manual" + }]; + } + return fetchPutKPI(Number(pdfId), updatedData); }, - onMutate: async (id: string) => { + onMutate: async (params: { id: string; newValue?: string; newPage?: number }) => { + const { id, newValue, newPage } = params; await queryClient.cancelQueries({ queryKey: ["pitchBookKPI", pdfId], }); @@ -71,10 +89,23 @@ export default function KennzahlenTable({ queryClient.setQueryData(["pitchBookKPI", pdfId], () => { const updatedData = { ...data }; - updatedData[key] = data[key]?.map((item) => ({ - ...item, - entity: editValue, - })) || [{ label: key, entity: editValue }]; + + if (data[key] && data[key].length > 0) { + updatedData[key] = data[key].map((item) => ({ + ...item, + ...(newValue !== undefined && { entity: newValue }), + ...(newPage !== undefined && { page: newPage }), + })); + } else { + updatedData[key] = [{ + label: key, + entity: newValue || "", + page: newPage || 0, + status: "single-source", + source: "manual" + }]; + } + return updatedData; }); @@ -99,19 +130,39 @@ export default function KennzahlenTable({ setEditValue(value); }; + const startPageEditing = (value: number, index: string) => { + setEditingPageIndex(index); + setEditPageValue(value.toString()); + }; + // Bearbeitung beenden und Wert speichern const handleSave = async (index: string) => { - // await updateKennzahl(rows[index].label, editValue); - mutate(index); + mutate({ id: index, newValue: editValue }); setEditingIndex(""); }; + const handlePageSave = async (index: string) => { + const pageNumber = parseInt(editPageValue); + if (!isNaN(pageNumber) && pageNumber > 0) { + mutate({ id: index, newPage: pageNumber }); + } + setEditingPageIndex(""); + }; + // Tastatureingaben verarbeiten const handleKeyPress = (e: KeyboardEvent, index: string) => { if (e.key === "Enter") { handleSave(index); } else if (e.key === "Escape") { - setEditingIndex("null"); + setEditingIndex(""); + } + }; + + const handlePageKeyPress = (e: KeyboardEvent, index: string) => { + if (e.key === "Enter") { + handlePageSave(index); + } else if (e.key === "Escape") { + setEditingPageIndex(""); } }; @@ -138,7 +189,9 @@ export default function KennzahlenTable({ Wert - Seite + + Seite + @@ -165,6 +218,10 @@ export default function KennzahlenTable({ borderColor = "#f6ed48"; } + const currentPage = row.extractedValues.at(0)?.page ?? 0; + const isPageHovered = hoveredPageIndex === row.setting.name; + const canEditPage = !hasMultipleValues; + return ( {row.setting.name} @@ -300,21 +357,115 @@ export default function KennzahlenTable({ )} - {(row.extractedValues.at(0)?.page ?? 0) > 0 ? ( - { - const extractedValue = row.extractedValues.at(0); - if (extractedValue?.page && extractedValue.page > 0) { - onPageClick?.(Number(extractedValue.page), extractedValue.entity || ""); + {editingPageIndex === row.setting.name ? ( + { + const value = e.target.value; + if (value === '' || /^\d+$/.test(value) && parseInt(value) > 0) { + setEditPageValue(value); } }} - sx={{ cursor: "pointer" }} - > - {row.extractedValues.at(0)?.page} - + onKeyDown={(e) => handlePageKeyPress(e, row.setting.name)} + onBlur={() => handlePageSave(row.setting.name)} + autoFocus + size="small" + variant="standard" + sx={{ + width: "60px", + "& .MuiInput-input": { + textAlign: "center" + } + }} + inputProps={{ + min: 0, + style: { textAlign: 'center' } + }} + /> ) : ( - "" + <> + {currentPage > 0 ? ( + canEditPage && setHoveredPageIndex(row.setting.name)} + onMouseLeave={() => setHoveredPageIndex("")} + onClick={() => { + if (canEditPage) { + startPageEditing(currentPage, row.setting.name); + } + }} + > + { + e.stopPropagation(); + const extractedValue = row.extractedValues.at(0); + if (extractedValue?.page && extractedValue.page > 0) { + onPageClick?.(Number(extractedValue.page), extractedValue.entity || ""); + } + }} + sx={{ cursor: "pointer" }} + > + {currentPage} + + + {isPageHovered && canEditPage && ( + + )} + + ) : canEditPage ? ( + setHoveredPageIndex(row.setting.name)} + onMouseLeave={() => setHoveredPageIndex("")} + onClick={() => startPageEditing(0, row.setting.name)} + > + ... + + + ) : ( + "" + )} + )} @@ -324,4 +475,4 @@ export default function KennzahlenTable({ ); -} +} \ No newline at end of file From ac8cf2f7c2f0debaae9ea78083c5e1fdba564e08 Mon Sep 17 00:00:00 2001 From: s8613 Date: Tue, 17 Jun 2025 11:43:20 +0200 Subject: [PATCH 2/8] Updated extractedResult_.$pitchBook.$kpi.tsx for page number editing --- .../extractedResult_.$pitchBook.$kpi.tsx | 96 ++++++++++++++++++- 1 file changed, 93 insertions(+), 3 deletions(-) diff --git a/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx b/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx index 22ec938..a2cda4d 100644 --- a/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx +++ b/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx @@ -1,4 +1,5 @@ import ArrowBackIcon from "@mui/icons-material/ArrowBack"; +import EditIcon from "@mui/icons-material/Edit"; import { Box, Button, @@ -27,6 +28,7 @@ import { } from "@tanstack/react-query"; import { createFileRoute, useNavigate } from "@tanstack/react-router"; import { useEffect, useState } from "react"; +import type { KeyboardEvent } from "react"; import PDFViewer from "../components/pdfViewer"; import { fetchPutKPI } from "../util/api"; import { kpiQueryOptions } from "../util/query"; @@ -65,13 +67,23 @@ function ExtractedResultsPage() { const [showConfirmDialog, setShowConfirmDialog] = useState(false); const [hasChanges, setHasChanges] = useState(false); const [customValue, setCustomValue] = useState(""); + const [customPage, setCustomPage] = useState(""); + const [editingCustomPage, setEditingCustomPage] = useState(false); + const originalValue = kpiValues[0]?.entity || ""; + const originalPage = kpiValues[0]?.page || 0; const selectedValue = selectedIndex === -1 ? customValue : kpiValues[selectedIndex]?.entity || ""; + const selectedPage = + selectedIndex === -1 + ? (parseInt(customPage) > 0 ? parseInt(customPage) : 1) + : kpiValues[selectedIndex]?.page || 1; useEffect(() => { - setHasChanges(selectedValue !== originalValue); - }, [selectedValue, originalValue]); + const valueChanged = selectedValue !== originalValue; + const pageChanged = selectedPage !== originalPage; + setHasChanges(valueChanged || pageChanged); + }, [selectedValue, selectedPage, originalValue, originalPage]); const { mutate: updateKPI } = useMutation({ mutationFn: () => { @@ -83,7 +95,7 @@ function ExtractedResultsPage() { baseObject = { label: kpi.toUpperCase(), entity: selectedValue, - page: 0, + page: selectedPage, status: "single-source", source: "manual", }; @@ -92,6 +104,7 @@ function ExtractedResultsPage() { { ...baseObject, entity: selectedValue, + page: selectedPage, }, ]; return fetchPutKPI(Number(pitchBook), updatedData); @@ -120,6 +133,7 @@ function ExtractedResultsPage() { setSelectedIndex(index); setCurrentPage(kpiValues[index].page); setCustomValue(""); + setCustomPage(""); } }; @@ -131,10 +145,21 @@ function ExtractedResultsPage() { setSelectedIndex(-1); }; + const handleCustomPageChange = ( + event: React.ChangeEvent, + ) => { + const value = event.target.value; + // Allow empty string or positive numbers only (no 0) + if (value === '' || (/^\d+$/.test(value) && parseInt(value) > 0)) { + setCustomPage(value); + } + }; + const handleRowClick = (index: number) => { setCurrentPage(kpiValues[index].page); setSelectedIndex(index); setCustomValue(""); + setCustomPage(""); }; const handleBackClick = () => { @@ -166,6 +191,18 @@ function ExtractedResultsPage() { updateKPI(); }; + const startCustomPageEditing = () => { + setEditingCustomPage(true); + }; + + const handleCustomPageKeyPress = (e: KeyboardEvent) => { + if (e.key === "Enter") { + setEditingCustomPage(false); + } else if (e.key === "Escape") { + setEditingCustomPage(false); + } + }; + return ( @@ -318,6 +355,59 @@ function ExtractedResultsPage() { /> + + {editingCustomPage ? ( + setEditingCustomPage(false)} + autoFocus + size="small" + variant="standard" + sx={{ + width: "60px", + "& .MuiInput-input": { + textAlign: "center" + } + }} + inputProps={{ + min: 0, + style: { textAlign: 'center' } + }} + /> + ) : ( + { + e.stopPropagation(); + startCustomPageEditing(); + }} + > + {customPage || "..."} + { + e.stopPropagation(); + startCustomPageEditing(); + }} + /> + + )} + From 615007b437060b6f9cf0a2ad794ea78d3a9b64f2 Mon Sep 17 00:00:00 2001 From: s8613 Date: Tue, 17 Jun 2025 11:45:30 +0200 Subject: [PATCH 3/8] Fixed change of tabs --- project/frontend/src/components/KennzahlenTable.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/project/frontend/src/components/KennzahlenTable.tsx b/project/frontend/src/components/KennzahlenTable.tsx index 5cfbad3..4e8f565 100644 --- a/project/frontend/src/components/KennzahlenTable.tsx +++ b/project/frontend/src/components/KennzahlenTable.tsx @@ -38,12 +38,12 @@ interface KennzahlenTableProps { } export default function KennzahlenTable({ - onPageClick, - data, - pdfId, - settings, - from - }: KennzahlenTableProps) { + onPageClick, + data, + pdfId, + settings, + from + }: KennzahlenTableProps) { const [editingIndex, setEditingIndex] = useState(""); const [editValue, setEditValue] = useState(""); const [editingPageIndex, setEditingPageIndex] = useState(""); From 26224671bb5ec068cec8abf3aebaff10ed473aad Mon Sep 17 00:00:00 2001 From: s8613 Date: Tue, 17 Jun 2025 11:45:54 +0200 Subject: [PATCH 4/8] Fixed change of tabs --- project/frontend/src/components/KennzahlenTable.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/project/frontend/src/components/KennzahlenTable.tsx b/project/frontend/src/components/KennzahlenTable.tsx index 4e8f565..784c976 100644 --- a/project/frontend/src/components/KennzahlenTable.tsx +++ b/project/frontend/src/components/KennzahlenTable.tsx @@ -38,12 +38,12 @@ interface KennzahlenTableProps { } export default function KennzahlenTable({ - onPageClick, - data, - pdfId, - settings, - from - }: KennzahlenTableProps) { + onPageClick, + data, + pdfId, + settings, + from +}: KennzahlenTableProps) { const [editingIndex, setEditingIndex] = useState(""); const [editValue, setEditValue] = useState(""); const [editingPageIndex, setEditingPageIndex] = useState(""); From 6816e1a2d753821ee16ffcc3dab996df61df2808 Mon Sep 17 00:00:00 2001 From: s8613 Date: Tue, 17 Jun 2025 12:12:33 +0200 Subject: [PATCH 5/8] fixed small styling issue --- .../frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx b/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx index a2cda4d..1802d34 100644 --- a/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx +++ b/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx @@ -384,7 +384,9 @@ function ExtractedResultsPage() { justifyContent: "center", gap: 1, cursor: "pointer", - minHeight: "24px" + minHeight: "24px", + minWidth: "100px", + margin: "0 auto", }} onClick={(e: React.MouseEvent) => { e.stopPropagation(); @@ -398,7 +400,6 @@ function ExtractedResultsPage() { color: "#666", opacity: 0.7, transition: "opacity 0.2s ease", - ml: 1 // margin-left instead of absolute positioning }} onClick={(e) => { e.stopPropagation(); From eea2d015b28ad875e6c7ce7bd2d77bdee8522b64 Mon Sep 17 00:00:00 2001 From: s8613 Date: Tue, 17 Jun 2025 12:22:17 +0200 Subject: [PATCH 6/8] fixed small styling issue --- project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx b/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx index 1802d34..ca2fa6f 100644 --- a/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx +++ b/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx @@ -400,6 +400,7 @@ function ExtractedResultsPage() { color: "#666", opacity: 0.7, transition: "opacity 0.2s ease", + ml: 1 }} onClick={(e) => { e.stopPropagation(); From f20516535042d6094d02629792634db46c82aa90 Mon Sep 17 00:00:00 2001 From: s8613 Date: Tue, 17 Jun 2025 13:05:13 +0200 Subject: [PATCH 7/8] Fixed table columns sizing always changing widths --- project/frontend/src/components/KennzahlenTable.tsx | 6 +++--- .../src/routes/extractedResult_.$pitchBook.$kpi.tsx | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/project/frontend/src/components/KennzahlenTable.tsx b/project/frontend/src/components/KennzahlenTable.tsx index 784c976..9615208 100644 --- a/project/frontend/src/components/KennzahlenTable.tsx +++ b/project/frontend/src/components/KennzahlenTable.tsx @@ -182,13 +182,13 @@ export default function KennzahlenTable({ - + Kennzahl - + Wert - + Seite diff --git a/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx b/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx index ca2fa6f..1e98430 100644 --- a/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx +++ b/project/frontend/src/routes/extractedResult_.$pitchBook.$kpi.tsx @@ -240,10 +240,10 @@ function ExtractedResultsPage() {
- + Gefundene Werte - + Seite From 017670f95e3716c0820441b472490da94cbc6eec Mon Sep 17 00:00:00 2001 From: Jaronim Pracht Date: Wed, 18 Jun 2025 16:38:11 +0200 Subject: [PATCH 8/8] Add progress on pitch-books table --- project/backend/coordinator/app.py | 4 - .../coordinator/controller/kennzahlen.py | 61 -- .../controller/kpi_setting_controller.py | 13 +- .../controller/progress_controller.py | 2 +- project/backend/coordinator/model/database.py | 1 + project/backend/coordinator/model/kennzahl.py | 26 - .../coordinator/model/kpi_setting_model.py | 6 +- .../coordinator/model/pitch_book_model.py | 9 +- .../backend/coordinator/model/seed_data.py | 41 +- .../src/components/KennzahlenTable.tsx | 29 +- .../src/components/PitchBooksTable.tsx | 542 ++++++++++++------ .../frontend/src/components/UploadPage.tsx | 6 +- project/frontend/src/util/api.ts | 25 +- 13 files changed, 455 insertions(+), 310 deletions(-) delete mode 100644 project/backend/coordinator/controller/kennzahlen.py delete mode 100644 project/backend/coordinator/model/kennzahl.py diff --git a/project/backend/coordinator/app.py b/project/backend/coordinator/app.py index 702abb9..2603f42 100644 --- a/project/backend/coordinator/app.py +++ b/project/backend/coordinator/app.py @@ -5,7 +5,6 @@ from dotenv import load_dotenv from controller import register_routes from model.database import init_db from controller.socketIO import socketio -from controller.kennzahlen import kennzahlen_bp app = Flask(__name__) CORS(app) @@ -22,9 +21,6 @@ init_db(app) register_routes(app) -# Register blueprints -app.register_blueprint(kennzahlen_bp) - @app.route("/health") def health_check(): return "OK" diff --git a/project/backend/coordinator/controller/kennzahlen.py b/project/backend/coordinator/controller/kennzahlen.py deleted file mode 100644 index f01f72c..0000000 --- a/project/backend/coordinator/controller/kennzahlen.py +++ /dev/null @@ -1,61 +0,0 @@ -from flask import Blueprint, jsonify, request -from model.kennzahl import Kennzahl -from model.database import db - -kennzahlen_bp = Blueprint('kennzahlen', __name__) - -# Beispieldaten -EXAMPLE_DATA = [ - {"pdf_id": "example", "label": "Fondsname", "value": "Fund Real Estate Prime Europe", "page": 1, "status": "ok"}, - {"pdf_id": "example", "label": "Fondsmanager", "value": "", "page": 1, "status": "error"}, - {"pdf_id": "example", "label": "Risikoprofil", "value": "Core/Core+", "page": 10, "status": "warning"}, - {"pdf_id": "example", "label": "LTV", "value": "30-35 %", "page": 8, "status": "ok"}, - {"pdf_id": "example", "label": "Ausschüttungsrendite", "value": "4%", "page": 34, "status": "ok"} -] - - -@kennzahlen_bp.route('/api/kennzahlen/init', methods=['POST']) -def init_kennzahlen(): - try: - # Lösche existierende Beispieldaten - Kennzahl.query.filter_by(pdf_id='example').delete() - - # Füge Beispieldaten ein - for data in EXAMPLE_DATA: - kennzahl = Kennzahl( - pdf_id=data['pdf_id'], - label=data['label'], - value=data['value'], - page=data['page'], - status=data['status'] - ) - db.session.add(kennzahl) - - db.session.commit() - return jsonify({"message": "Kennzahlen erfolgreich initialisiert"}) - - except Exception as e: - db.session.rollback() - return jsonify({"error": str(e)}), 500 - - -@kennzahlen_bp.route('/api/kennzahlen', methods=['GET']) -def get_kennzahlen(): - pdf_id = request.args.get('pdf_id', 'example') # Default zu 'example' für Beispieldaten - kennzahlen = Kennzahl.query.filter_by(pdf_id=pdf_id).all() - return jsonify([k.to_dict() for k in kennzahlen]) - - -@kennzahlen_bp.route('/api/kennzahlen/
- - - - Fondsname - Fondsmanager - Dateiname - Status - - - - {pitchBooks.map((pitchBook: PitchBook) => { - const status = getStatus(pitchBook); - const fundName = getKPIValue(pitchBook, 'FONDSNAME') || - getKPIValue(pitchBook, 'FUND_NAME') || - getKPIValue(pitchBook, 'NAME'); + fetchPitchBooksById(progress.id) + .then((res) => { + setLoadingPitchBooks((prev) => [ + ...prev.filter((item) => item.id !== progress.id), + { + id: progress.id, + progress: progress.progress, + filename: res.filename, + buffer: 0, + intervalId, + }, + ]); + }) + .catch((err) => { + console.error(err); + }); + } + return [ + ...prev.filter((item) => item.id !== progress.id), + { + id: progress.id, + progress: progress.progress, + filename: oldItem?.filename, + buffer: 0, + intervalId, + }, + ]; + }); + } + }, + [queryClient], + ); - const manager = getKPIValue(pitchBook, 'FONDSMANAGER') || - getKPIValue(pitchBook, 'MANAGER') || - getKPIValue(pitchBook, 'PORTFOLIO_MANAGER'); + useEffect(() => { + socket.on("connect", onConnection); + socket.on("progress", onProgress); + return () => { + socket.off("connect", onConnection); + socket.off("progress", onProgress); + }; + }, [onConnection, onProgress]); - return ( - handleRowClick(pitchBook.id)} - sx={{ - cursor: "pointer", - "&:hover": { - backgroundColor: "#f9f9f9", - }, - }} - > - - - - - - - - {fundName} - - - {manager} - - - {pitchBook.filename} - - - - {status === 'completed' ? ( - } - label="Abgeschlossen" - size="small" - sx={{ - backgroundColor: "#e8f5e9", - color: "#2e7d32", - "& .MuiChip-icon": { - color: "#2e7d32", - }, - }} - /> - ) : ( - } - label="In Bearbeitung" - size="small" - sx={{ - backgroundColor: "#fff3e0", - color: "#e65100", - "& .MuiChip-icon": { - color: "#e65100", - }, - }} - /> - )} - - - ); - })} - -
- {pitchBooks.length === 0 && ( - - - Keine Pitch Books vorhanden - - - )} - - ); -} \ No newline at end of file + const getKPIValue = (pitchBook: PitchBook, fieldName: string): string => { + if (!pitchBook.kpi || typeof pitchBook.kpi === "string") { + try { + const parsedKPI = JSON.parse(pitchBook.kpi as string); + // Convert array to object format if needed + const kpiObj = Array.isArray(parsedKPI) + ? parsedKPI.reduce((acc, item) => { + if (!acc[item.label]) acc[item.label] = []; + acc[item.label].push(item); + return acc; + }, {}) + : parsedKPI; + + return kpiObj[fieldName]?.[0]?.entity || "N/A"; + } catch { + return "N/A"; + } + } + + return pitchBook.kpi[fieldName]?.[0]?.entity || "N/A"; + }; + + const getStatus = (pitchBook: PitchBook) => { + if ( + pitchBook.kpi && + ((typeof pitchBook.kpi === "string" && pitchBook.kpi !== "{}") || + (typeof pitchBook.kpi === "object" && + Object.keys(pitchBook.kpi).length > 0)) + ) { + return "completed"; + } + return "processing"; + }; + + if (isLoading) { + return ( + + + + ); + } + + return ( + + + + + + Fondsname + Fondsmanager + Dateiname + + Status + + + + + {pitchBooks + .filter( + (pitchbook: PitchBook) => + !loadingPitchBooks.some((e) => e.id === pitchbook.id), + ) + .sort( + (a: PitchBook, b: PitchBook) => + new Date(a.created_at).getTime() - + new Date(b.created_at).getTime(), + ) + .map((pitchBook: PitchBook) => { + const status = getStatus(pitchBook); + const fundName = + getKPIValue(pitchBook, "FONDSNAME") || + getKPIValue(pitchBook, "FUND_NAME") || + getKPIValue(pitchBook, "NAME"); + + const manager = + getKPIValue(pitchBook, "FONDSMANAGER") || + getKPIValue(pitchBook, "MANAGER") || + getKPIValue(pitchBook, "PORTFOLIO_MANAGER"); + + return ( + handleRowClick(pitchBook.id)} + sx={{ + cursor: "pointer", + "&:hover": { + backgroundColor: "#f9f9f9", + }, + }} + > + + + + + + + + {fundName} + + + {manager} + + + {pitchBook.filename} + + + + {status === "completed" ? ( + } + label="Abgeschlossen" + size="small" + sx={{ + backgroundColor: "#e8f5e9", + color: "#2e7d32", + "& .MuiChip-icon": { + color: "#2e7d32", + }, + }} + /> + ) : ( + } + label="In Bearbeitung" + size="small" + sx={{ + backgroundColor: "#fff3e0", + color: "#e65100", + "& .MuiChip-icon": { + color: "#e65100", + }, + }} + /> + )} + + + ); + })} + {loadingPitchBooks + .sort((a, b) => a.id - b.id) + .map((pitchBook) => ( + + + + + + + + + + + {" "} + + {pitchBook.filename} + + + + } + label="In Bearbeitung" + size="small" + sx={{ + backgroundColor: "#fff3e0", + color: "#e65100", + "& .MuiChip-icon": { + color: "#e65100", + }, + }} + /> + + + ))} + +
+ {pitchBooks.length === 0 && ( + + + Keine Pitch Books vorhanden + + + )} +
+ ); +} diff --git a/project/frontend/src/components/UploadPage.tsx b/project/frontend/src/components/UploadPage.tsx index 6de8a62..e72c9da 100644 --- a/project/frontend/src/components/UploadPage.tsx +++ b/project/frontend/src/components/UploadPage.tsx @@ -1,11 +1,11 @@ import SettingsIcon from "@mui/icons-material/Settings"; import { Backdrop, Box, Button, IconButton, Paper } from "@mui/material"; -import { useNavigate } from "@tanstack/react-router"; +import { useNavigate, useRouter } from "@tanstack/react-router"; import { useCallback, useEffect, useState } from "react"; import FileUpload from "react-material-file-upload"; import { socket } from "../socket"; -import { CircularProgressWithLabel } from "./CircularProgressWithLabel"; import { API_HOST } from "../util/api"; +import { CircularProgressWithLabel } from "./CircularProgressWithLabel"; export default function UploadPage() { const [files, setFiles] = useState([]); @@ -13,6 +13,7 @@ export default function UploadPage() { const [loadingState, setLoadingState] = useState(null); const fileTypes = ["pdf"]; const navigate = useNavigate(); + const router = useRouter(); const uploadFile = useCallback(async () => { const formData = new FormData(); @@ -178,6 +179,7 @@ export default function UploadPage() { backgroundColor: "#383838", "&:hover": { backgroundColor: "#2e2e2e" }, }} + onMouseEnter={() => router.preloadRoute({ to: "/pitchbooks" })} onClick={() => navigate({ to: "/pitchbooks" })} > Alle Pitch Books anzeigen diff --git a/project/frontend/src/util/api.ts b/project/frontend/src/util/api.ts index 65d3b2e..ca066c1 100644 --- a/project/frontend/src/util/api.ts +++ b/project/frontend/src/util/api.ts @@ -1,6 +1,6 @@ import type { Kennzahl } from "@/types/kpi"; -const API_HOST = import.meta.env.VITE_API_HOST || 'http://localhost:5050'; +const API_HOST = import.meta.env.VITE_API_HOST || "http://localhost:5050"; export { API_HOST }; @@ -15,9 +15,7 @@ export const fetchKPI = async ( source: string; }[]; }> => { - const response = await fetch( - `${API_HOST}/api/pitch_book/${pitchBookId}`, - ); + const response = await fetch(`${API_HOST}/api/pitch_book/${pitchBookId}`); const data = await response.json(); return data.kpi ? getKPI(data.kpi) : {}; @@ -46,13 +44,10 @@ export const fetchPutKPI = async ( const formData = new FormData(); formData.append("kpi", JSON.stringify(flattenKPIArray(kpi))); - const response = await fetch( - `${API_HOST}/api/pitch_book/${pitchBookId}`, - { - method: "PUT", - body: formData, - }, - ); + const response = await fetch(`${API_HOST}/api/pitch_book/${pitchBookId}`, { + method: "PUT", + body: formData, + }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } @@ -119,3 +114,11 @@ export async function fetchPitchBooks() { } return response.json(); } + +export async function fetchPitchBooksById(id: number) { + const response = await fetch(`${API_HOST}/api/pitch_book/${id}`); + if (!response.ok) { + throw new Error("Failed to fetch pitch books"); + } + return response.json(); +}