`;
}
function createAssetReport() {
const rows = dashboardData.vehicles.map(v => `
| ${v.name} |
${v.type} |
${v.status} |
${v.lat}, ${v.lon} |
${v.details.driver} |
`).join('');
return `
| Name | Type | Status | Coordinates | Driver |
${rows}
`;
}
function createDataConfiguration() {
const vehicleRows = dashboardData.vehicles.map(v => `
|
|
|
|
|
|
|
`).join('');
return `
Asset Configuration
| Name | Type | Status | Latitude | Longitude | Driver | Del |
${vehicleRows}
`;
}
// --- HELPER & UTILITY ---
function renderMap() {
const container = document.getElementById('map-container');
if (!container) return;
container.innerHTML = ''; // Clear previous points
// Bounding box for sample data (North America)
const latMin = 25, latMax = 50, lonMin = -125, lonMax = -65;
const icons = {
Truck: '
',
Van: '
',
Car: '
'
};
dashboardData.vehicles.forEach(v => {
const x = ((v.lon - lonMin) / (lonMax - lonMin)) * 100;
const y = ((latMax - v.lat) / (latMax - latMin)) * 100;
if (x >= 0 && x <= 100 && y >= 0 && y <= 100) {
const pointEl = document.createElement('div');
pointEl.id = `map-point-${v.id}`;
pointEl.className = `map-point status-${v.status.toLowerCase()}`;
pointEl.dataset.id = v.id;
pointEl.style.left = `${x}%`;
pointEl.style.top = `${y}%`;
pointEl.innerHTML = icons[v.type] || icons['Car'];
pointEl.addEventListener('click', () => selectAsset(v.id));
container.appendChild(pointEl);
}
});
}
function selectAsset(id) {
id = parseInt(id);
const asset = dashboardData.vehicles.find(v => v.id === id);
if (!asset) return;
// Update map points
document.querySelectorAll('.map-point').forEach(p => p.classList.remove('selected'));
document.getElementById(`map-point-${id}`)?.classList.add('selected');
// Update list items
document.querySelectorAll('.list-item').forEach(i => i.classList.remove('selected'));
document.getElementById(`list-item-${id}`)?.classList.add('selected');
// Update details panel
const detailsPanel = document.getElementById('details-panel');
detailsPanel.innerHTML = `
${asset.name}
- Status: ${asset.status}
- Type: ${asset.type}
- Driver: ${asset.details.driver}
- Speed: ${asset.details.speed}
- Cargo: ${asset.details.cargo}
`;
}
function createKPICard(title, value, color) {
return `
`;
}
function addTableRow(tableId) {
const table = document.getElementById(tableId);
const newRow = table.tBodies[0].insertRow();
newRow.innerHTML = `
|
|
|
|
|
|
|
`;
newRow.querySelector('.delete-row-btn').addEventListener('click', (e) => e.target.closest('tr').remove());
}
function filterAppointments() {
const filter = document.getElementById('appointment-search').value.toLowerCase();
document.querySelectorAll('.appointment-row').forEach(row => {
row.style.display = row.textContent.toLowerCase().includes(filter) ? "" : "none";
});
}
function navigateTabs(direction) {
const newIndex = currentTabIndex + direction;
if (newIndex >= 0 && newIndex < tabs.length) showTab(newIndex);
}
function updateNavButtons() {
prevTabBtn.disabled = currentTabIndex === 0;
nextTabBtn.disabled = currentTabIndex === tabs.length - 1;
}
async function generatePDF() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF('p', 'pt', 'a4');
const activeTab = tabs[currentTabIndex];
const addHeader = (title) => {
doc.setFontSize(18); doc.text('ArcGIS Dashboard Report', 40, 60);
doc.setFontSize(12); doc.setTextColor(100); doc.text(`Section: ${title}`, 40, 80);
doc.setLineWidth(0.5); doc.line(40, 90, 555, 90);
};
addHeader(activeTab.name);
if (activeTab.id === 'dashboard-overview') {
const overviewEl = document.getElementById('dashboard-overview');
const canvas = await html2canvas(overviewEl, { backgroundColor: '#ffffff', scale: 2 });
const imgData = canvas.toDataURL('image/png');
const pdfWidth = doc.internal.pageSize.getWidth() - 80;
const pdfHeight = (canvas.height * pdfWidth) / canvas.width;
doc.addImage(imgData, 'PNG', 40, 110, pdfWidth, pdfHeight);
} else {
const table = document.querySelector(`#${activeTab.id} table`);
if (table) doc.autoTable({ html: table, startY: 110 });
}
doc.save(`ArcGIS_Report_${activeTab.name.replace(/\s/g, '_')}.pdf`);
}
init();
});