From fd8897aaca73b14e0dbf8e6c8d88ea751692a575 Mon Sep 17 00:00:00 2001 From: Scheianu Ionut Date: Thu, 24 Apr 2025 06:39:24 +0300 Subject: [PATCH] first qyality report --- py_app/app/__pycache__/routes.cpython-312.pyc | Bin 13781 -> 15220 bytes py_app/app/routes.py | 47 +++++++-- py_app/app/static/script.js | 90 ++++++++++++++++-- py_app/app/static/style.css | 28 ++++++ py_app/app/templates/quality.html | 34 +++++-- 5 files changed, 175 insertions(+), 24 deletions(-) diff --git a/py_app/app/__pycache__/routes.cpython-312.pyc b/py_app/app/__pycache__/routes.cpython-312.pyc index 0604142cc773ab5a4318eb25bd013394d154a674..1b03b809916f20406969981438a6f4fa125e679a 100644 GIT binary patch delta 4055 zcma)9Yfu!~74FCMyk}sT;W+~|4}}2%QAF1Wt~$88Mn%z$%S0Vpx`DxY;GISmG6a9@ z4@fMLYPZ;AO@&HQDU4RKDN>bGDyi(lt)wbH0wvkCTC3uZ&5!*RR?TD0kK~-&&M+9Z zvRyS_pL@@_=YIFx)AyeF^Mxmu+<$br>)YK#rmev08g8sv1V zEUAhbjVrnhQC4EA^utFS&$_k8LYK1`%yiRWGNqDIEo2s1r>2Q9n5$-^$;;)p`VbX$KkrYa4cXt&?ZZ%!ShLp$YeisHfuYbEo|rFfO8ASwrkhjt%W<$){EdnC`52;y1R9f z`lbxmCct%)-2gf-#bTrao0SM6f)k+%p&FqUVH3h;1iDTOIf(L02n`5Z5SkF05n2FJ zIGsK#SA1+o!)WI*;I zWFtflVH4qH?bn_V+o}D>b92r8I|Vy-QTOgqi711~k(5FwAYa|U)e-DN=!RcvkM=uH zp|;K22=PAaZ5Gy?UN31h)39$}{IFz<3vNUebBydlcmY7?2NadGY6JepGj-S&x(G=U z-P*6HeS^3YG`LQ33`ZPC=s`Gva1!BFgs%bUroLn%L3&YiMiVK8s1YM?S%sX^{^l<% z#FQhr1`0SRb(quM_4pQ>0%iO@KWbC%w8X5-3$qw98rk^BWAU! z%AF9DcPmG^9_l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oXk5U!NTLLyM*g*;bCc~SP7@5T4ZAx`^6)f?cK(5ZAN@QmNyN<}wh?y_=DH=VY6aTJj@cr_#Xhht)b_%% z6Mot)fH~ne7OoAI&f90imN+cX00M4}ii=~~%wn!rXYH`8+j2@Ft;)J(Or<&M!6oal zDTPk!&aq6kpwQ&uY27-Op>Qr&hKJEX1S^6K!GT}_h)U*DU_p}rB9RD7qVVby=W8@G5U~$|)^2ptHW2&)me zpLRNo;}L|l2pICBd-*b@ByiYQN&1;FGbA}s-y}E7tu6`K7^m7=>qfh^|5z5uYyaPSGS98 zOI@N0Dz&4+WJabzR(xjQsjWT$dn?}J2u-hAeRQb^Kgu$Lor;_(l+De8^eQrb0GJb4 zwCj8P09_BssuirIT=xX~C;Ig9<(Bf$+GHiGKqceR70bG~b=V$_V3tW`>r@c@h}K=^ z*4?pt&K|sBZ~4N0$;QHc5%%4><6!O9?nx=OlC=%6i#8%OAuN7QKf4`!|9@irq*|mq za;XUjAk}m`U_O;ocxBS9MVcunQ9FI&u||R770HPi1P_g|zj_<2MKE!p6&}~zD)>hzT;bc@xaAB zmv&zF#J=**d#}6q-hO=Pu2u58?rpQ$+_t&l2VTKle|qrbv)3(6y!1ySn|2^nd3WZSNU72^+ za+l)$g?9#CZm~}CB17@&QoJD)Q-{01tf4$|48h5*Q(0v@eH%FVCsO+w@UBD%SrD8H bg10ok= ? + ORDER BY date DESC, time DESC + """, (five_days_ago.strftime('%Y-%m-%d'),)) + rows = cursor.fetchall() + + # Debugging: Print fetched rows + print("Fetched rows for report 1:", rows) + + # Define headers based on database column names + data["headers"] = ["Id", "Operator Code", "CP Base Code", "OC1 Code", "OC2 Code", "Quality Code", "Date", "Time", "Approved Quantity", "Rejected Quantity"] + + # Convert rows to JSON serializable format + data["rows"] = [ + [str(cell) if isinstance(cell, (datetime, timedelta)) else cell for cell in row] + for row in rows + ] + + conn.close() + except mariadb.Error as e: + print(f"Error fetching report data: {e}") + data["error"] = "Error fetching report data." + + # Debugging: Print the final data being returned + print("Data being returned:", data) return jsonify(data) \ No newline at end of file diff --git a/py_app/app/static/script.js b/py_app/app/static/script.js index 2c18792..15d72c6 100644 --- a/py_app/app/static/script.js +++ b/py_app/app/static/script.js @@ -128,15 +128,23 @@ document.addEventListener('DOMContentLoaded', () => { // Handle report button clicks reportButtons.forEach((button) => { button.addEventListener('click', () => { +// Get the text label of the button + const reportLabel = button.textContent.trim(); + + // Update the title dynamically with the button's text label + reportTitle.textContent = `Data for "${reportLabel}"`; + + // Fetch data for the selected report const reportNumber = button.dataset.report; - - // Update the title dynamically - reportTitle.textContent = `Data for "Report ${reportNumber}"`; - - // Fetch data for the selected report (mocked for now) fetch(`/get_report_data?report=${reportNumber}`) - .then((response) => response.json()) + .then((response) => { + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + return response.json(); + }) .then((data) => { +console.log("Fetched data:", data); // Debugging populateTable(data); }) .catch((error) => { @@ -196,4 +204,74 @@ document.addEventListener('DOMContentLoaded', () => { alert('Exporting current report as PDF...'); // Add logic to export the current report as PDF }); +}); +document.addEventListener('DOMContentLoaded', () => { + const reportButtons = document.querySelectorAll('.report-btn'); + const reportTitle = document.getElementById('report-title'); + const reportTable = document.getElementById('report-table'); + + // Handle report button clicks + reportButtons.forEach((button) => { + button.addEventListener('click', () => { + const reportNumber = button.dataset.report; + // Get the text label of the button + const reportLabel = button.textContent.trim(); + // Update the title dynamically + reportTitle.textContent = `Date pentru "${reportLabel}"`; + + // Fetch data for the selected report + fetch(`/get_report_data?report=${reportNumber}`) + .then((response) => { + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + return response.json(); + }) + .then((data) => { + console.log("Fetched data:", data); // Debugging + populateTable(data); + }) + .catch((error) => { + console.error('Error fetching report data:', error); + }); + }); + }); + + // Populate the table with data + function populateTable(data) { + const tableHead = reportTable.querySelector('thead tr'); + const tableBody = reportTable.querySelector('tbody'); + + // Clear existing table content + tableHead.innerHTML = ''; + tableBody.innerHTML = ''; + + if (data.headers && data.rows) { + // Populate table headers + data.headers.forEach((header) => { + const th = document.createElement('th'); + th.textContent = header; + tableHead.appendChild(th); + }); + + // Populate table rows + data.rows.forEach((row) => { + const tr = document.createElement('tr'); + row.forEach((cell) => { + const td = document.createElement('td'); + td.textContent = cell; + tr.appendChild(td); + }); + tableBody.appendChild(tr); + }); + } else { + // No data available + const tr = document.createElement('tr'); + const td = document.createElement('td'); + td.textContent = 'No data available.'; + td.colSpan = data.headers ? data.headers.length : 1; + tr.appendChild(td); + tableBody.appendChild(tr); + } + } }); \ No newline at end of file diff --git a/py_app/app/static/style.css b/py_app/app/static/style.css index 38dc348..5d149d2 100644 --- a/py_app/app/static/style.css +++ b/py_app/app/static/style.css @@ -639,4 +639,32 @@ body.dark-mode .dashboard-full-width-card { .dashboard-full-width-card { flex: 1 1 100%; /* Ensure the full-width card spans the entire width */ } +} + +/* Style for the export description label */ +.export-description { + display: block; + margin-bottom: 10px; + font-size: 1em; + font-weight: bold; + color: #333; /* Default color for light mode */ +} + +/* Dark mode styles for the export description label */ +body.dark-mode .export-description { + color: #fefdfd; /* Light color for dark mode */ +} + +/* Style for the container holding the last two buttons */ +.form-centered.last-buttons .button-row { + display: flex; + justify-content: flex-start; /* Align buttons to the left */ + gap: 10px; /* Add spacing between the buttons */ +} + +/* Style for the buttons */ +.form-centered.last-buttons .btn { + padding: 5px 10px; /* Make the buttons smaller */ + font-size: 0.9em; /* Reduce the font size */ + border-radius: 3px; /* Slightly smaller border radius */ } \ No newline at end of file diff --git a/py_app/app/templates/quality.html b/py_app/app/templates/quality.html index 4cad439..5145061 100644 --- a/py_app/app/templates/quality.html +++ b/py_app/app/templates/quality.html @@ -3,23 +3,39 @@ {% block content %}
-
+

Rapoarte

- - - - - + +
- - + + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
-
+

No data to display, please select a report.