Fix FG quality page: Display OK for quality code 0, export CSV with 0 value

This commit is contained in:
ske087
2025-11-13 04:26:46 +02:00
parent 0d98c527c6
commit 5de2584b27

View File

@@ -354,12 +354,20 @@ window.addEventListener('DOMContentLoaded', function() {
thead.innerHTML = '';
tbody.innerHTML = '';
// Find the index of the quality code column
let qualityCodeIndex = -1;
// Add headers
if (data.headers) {
data.headers.forEach(header => {
data.headers.forEach((header, index) => {
const th = document.createElement('th');
th.textContent = header;
thead.appendChild(th);
// Track the quality code column
if (header === 'Defect Code' || header === 'Quality Code') {
qualityCodeIndex = index;
}
});
}
@@ -367,9 +375,20 @@ window.addEventListener('DOMContentLoaded', function() {
if (data.rows && data.rows.length > 0) {
data.rows.forEach(row => {
const tr = document.createElement('tr');
row.forEach(cell => {
row.forEach((cell, index) => {
const td = document.createElement('td');
td.textContent = cell || '';
// Special handling for quality code column
if (index === qualityCodeIndex && (cell === 0 || cell === '0' || cell === '' || cell === null)) {
td.textContent = 'OK';
td.style.color = '#28a745'; // Green color for OK
td.style.fontWeight = '600';
td.setAttribute('data-csv-value', '0'); // Store original value for CSV
} else {
td.textContent = cell || '';
td.setAttribute('data-csv-value', cell || ''); // Store original value
}
tr.appendChild(td);
});
tbody.appendChild(tr);
@@ -420,11 +439,69 @@ window.addEventListener('DOMContentLoaded', function() {
.then(response => response.json())
.then(data => {
console.log('📊 FG Range data received:', data);
// Handle response similar to above
document.getElementById('report-title').textContent = `FG Date Range Report (${startDate} to ${endDate})`;
const table = document.getElementById('report-table');
const thead = table.querySelector('thead tr');
const tbody = table.querySelector('tbody');
// Clear existing content
thead.innerHTML = '';
tbody.innerHTML = '';
// Find the index of the quality code column
let qualityCodeIndex = -1;
// Add headers
if (data.headers) {
data.headers.forEach((header, index) => {
const th = document.createElement('th');
th.textContent = header;
thead.appendChild(th);
// Track the quality code column
if (header === 'Defect Code' || header === 'Quality Code') {
qualityCodeIndex = index;
}
});
}
// Add rows
if (data.rows && data.rows.length > 0) {
data.rows.forEach(row => {
const tr = document.createElement('tr');
row.forEach((cell, index) => {
const td = document.createElement('td');
// Special handling for quality code column
if (index === qualityCodeIndex && (cell === 0 || cell === '0' || cell === '' || cell === null)) {
td.textContent = 'OK';
td.style.color = '#28a745'; // Green color for OK
td.style.fontWeight = '600';
td.setAttribute('data-csv-value', '0'); // Store original value for CSV
} else {
td.textContent = cell || '';
td.setAttribute('data-csv-value', cell || ''); // Store original value
}
tr.appendChild(td);
});
tbody.appendChild(tr);
});
document.getElementById('report-title').textContent = `FG Date Range Report (${startDate} to ${endDate}) - ${data.rows.length} records`;
} else {
const tr = document.createElement('tr');
const td = document.createElement('td');
td.colSpan = data.headers ? data.headers.length : 1;
td.textContent = data.message || 'No FG data found';
td.style.textAlign = 'center';
tr.appendChild(td);
tbody.appendChild(tr);
document.getElementById('report-title').textContent = `FG Date Range Report (${startDate} to ${endDate}) - No data`;
}
})
.catch(error => {
console.error('❌ Error fetching FG range data:', error);
document.getElementById('report-title').textContent = 'Error loading FG data';
});
// Hide modal