Spaces:
Running
Running
can you add lastly the filter for Dates range, another for Area and Another for Hazard Type - Initial Deployment
278d806 verified Download index.html from froilan1262/version-2-tracker: direct link, hf CLI and curl.
- Browser
- Download file 37.3 kB
-
https://huggingface.co/spaces/froilan1262/version-2-tracker/resolve/main/index.html
- Command line
-
hf download hf://spaces/froilan1262/version-2-tracker/index.html
-
curl -L -o index.html https://huggingface.co/spaces/froilan1262/version-2-tracker/resolve/main/index.html
37.3 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>MDC Warehouse Hazard Tracker</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script> | |
| <style> | |
| .logo-container { | |
| height: 150px; | |
| overflow: hidden; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| background-color: #f3f4f6; | |
| border: 1px dashed #ccc; | |
| } | |
| .logo-container img { | |
| width: 100%; | |
| height: 100%; | |
| object-fit: contain; | |
| } | |
| .hazard-table { | |
| width: 100%; | |
| border-collapse: collapse; | |
| } | |
| .hazard-table th, .hazard-table td { | |
| border: 1px solid #ddd; | |
| padding: 8px; | |
| text-align: left; | |
| } | |
| .hazard-table th { | |
| background-color: #f2f2f2; | |
| } | |
| .hazard-table tr:nth-child(even) { | |
| background-color: #f9f9f9; | |
| } | |
| .hazard-table tr:hover { | |
| background-color: #f1f1f1; | |
| } | |
| .chart-container { | |
| position: relative; | |
| margin: auto; | |
| height: 300px; | |
| width: 100%; | |
| } | |
| .status-open { | |
| background-color: #fef3c7; | |
| color: #92400e; | |
| } | |
| .status-closed { | |
| background-color: #d1fae5; | |
| color: #065f46; | |
| } | |
| .status-pending { | |
| background-color: #e0e7ff; | |
| color: #3730a3; | |
| } | |
| .status-ongoing { | |
| background-color: #fee2e2; | |
| color: #991b1b; | |
| } | |
| .big-text { | |
| font-size: 1.2rem; | |
| font-weight: bold; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50 p-4"> | |
| <div class="max-w-7xl mx-auto bg-white rounded-lg shadow-md p-6"> | |
| <div class="flex justify-between items-center mb-6"> | |
| <div class="flex items-center"> | |
| <div class="logo-container w-48 mr-4" id="logoContainer"> | |
| <img id="logoPreview" src="" alt="Logo" class="hidden"> | |
| </div> | |
| <h1 class="text-3xl font-bold text-green-800">MDC Warehouse Hazard Tracker</h1> | |
| </div> | |
| <div> | |
| <input type="file" id="logoUpload" accept="image/*" class="hidden"> | |
| <button onclick="document.getElementById('logoUpload').click()" class="bg-gray-200 hover:bg-gray-300 text-gray-800 font-bold py-2 px-4 rounded inline-flex items-center"> | |
| <svg class="w-4 h-4 mr-2" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> | |
| <path fill-rule="evenodd" d="M4 3a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V5a2 2 0 00-2-2H4zm12 12H4l4-8 3 6 2-4 3 6z" clip-rule="evenodd"></path> | |
| </svg> | |
| Upload Logo | |
| </button> | |
| </div> | |
| </div> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8"> | |
| <div class="bg-white p-4 rounded-lg shadow"> | |
| <h2 class="text-xl font-semibold mb-4">Top 3 Most Reported Hazards</h2> | |
| <div class="chart-container"> | |
| <canvas id="topHazardsChart"></canvas> | |
| </div> | |
| </div> | |
| <div class="bg-white p-4 rounded-lg shadow"> | |
| <h2 class="text-xl font-semibold mb-4">Hazard Status by Area</h2> | |
| <div class="chart-container"> | |
| <canvas id="areaStatusChart"></canvas> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8"> | |
| <div class="bg-white p-4 rounded-lg shadow"> | |
| <h2 class="text-xl font-semibold mb-4">Areas with Most Reports</h2> | |
| <div class="chart-container"> | |
| <canvas id="areaReportsChart"></canvas> | |
| </div> | |
| </div> | |
| <div class="bg-white p-4 rounded-lg shadow"> | |
| <h2 class="text-xl font-semibold mb-4">Areas with Most Corrected Hazards</h2> | |
| <div class="chart-container"> | |
| <canvas id="areaCorrectedChart"></canvas> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="mb-8"> | |
| <h2 class="text-2xl font-bold mb-4 text-green-800">Hazard Report Summary</h2> | |
| <div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-6"> | |
| <div class="bg-gray-100 p-4 rounded-lg"> | |
| <h3 class="font-semibold mb-2">Total Reports</h3> | |
| <p class="big-text" id="totalReports">0</p> | |
| </div> | |
| <div class="bg-gray-100 p-4 rounded-lg"> | |
| <h3 class="font-semibold mb-2">Open</h3> | |
| <p class="big-text" id="openReports">0</p> | |
| </div> | |
| <div class="bg-gray-100 p-4 rounded-lg"> | |
| <h3 class="font-semibold mb-2">Closed</h3> | |
| <p class="big-text" id="closedReports">0</p> | |
| </div> | |
| <div class="bg-gray-100 p-4 rounded-lg"> | |
| <h3 class="font-semibold mb-2">Pending/Ongoing</h3> | |
| <p class="big-text" id="pendingReports">0</p> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="mb-8"> | |
| <h2 class="text-2xl font-bold mb-4 text-green-800">Add New Hazard Report</h2> | |
| <form id="hazardForm" class="grid grid-cols-1 md:grid-cols-2 gap-4"> | |
| <div> | |
| <label class="block text-gray-700 font-medium mb-2" for="reportDate">Date of Report</label> | |
| <input type="date" id="reportDate" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-green-500" required> | |
| </div> | |
| <div> | |
| <label class="block text-gray-700 font-medium mb-2" for="hazardType">Hazard/Issue Observed</label> | |
| <select id="hazardType" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-green-500" required> | |
| <option value="">Select Hazard Type</option> | |
| <option value="MHE Related">MHE Related</option> | |
| <option value="Fire Hazard">Fire Hazard</option> | |
| <option value="WEM Related">WEM Related</option> | |
| <option value="GWP Related">GWP Related</option> | |
| <option value="Not wearing PPE">Not wearing Personal protective Equipment</option> | |
| <option value="Specialized activity without permit">Performing Specialized activity without work permit</option> | |
| <option value="Dilapidated Pallet">Dilapidated Pallet</option> | |
| <option value="Kissing Product">Kissing Product</option> | |
| <option value="Over-extended stacks">Over-extended stacks</option> | |
| <option value="Unauthorized Operation of MHE">Unauthorized Operation of MHE</option> | |
| <option value="Unsecured Stacks">Unsecured Stacks</option> | |
| <option value="Push-Pull Spotter without tool">Push-Pull Spotter without tool</option> | |
| <option value="Improper placement/Unattended Jack pallet">Improper placement / Unattended Jack pallet</option> | |
| <option value="Uncleared Rack Guards">Uncleared Rack Guards</option> | |
| <option value="Maximum Pallet Stacking">Maximum Pallet Stacking</option> | |
| <option value="Emergency Preparedness (EPRT) Related">Emergency Preparedness (EPRT) Related</option> | |
| <option value="Spillage/Leakage">Spillage / Leakage</option> | |
| <option value="Others">Others</option> | |
| <option value="Put away without Stretch film">Put away without Stretch film</option> | |
| <option value="Electrocution Hazard">Electrocution Hazard</option> | |
| <option value="Unattended Safety Tools and Equipment">Unattended Safety Tools and Equipment</option> | |
| </select> | |
| </div> | |
| <div class="md:col-span-2"> | |
| <label class="block text-gray-700 font-medium mb-2" for="hazardDetails">Complete Details of Hazard</label> | |
| <textarea id="hazardDetails" rows="3" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-green-500" required></textarea> | |
| </div> | |
| <div> | |
| <label class="block text-gray-700 font-medium mb-2" for="status">Status</label> | |
| <select id="status" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-green-500" required> | |
| <option value="">Select Status</option> | |
| <option value="Open">Open</option> | |
| <option value="Closed">Closed</option> | |
| <option value="Pending">Pending</option> | |
| <option value="Ongoing">Ongoing</option> | |
| </select> | |
| </div> | |
| <div> | |
| <label class="block text-gray-700 font-medium mb-2" for="area">Area</label> | |
| <select id="area" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-green-500" required> | |
| <option value="">Select Area</option> | |
| <option value="Domestic">Domestic</option> | |
| <option value="Export">Export</option> | |
| <option value="QMS">QMS</option> | |
| <option value="Security">Security</option> | |
| <option value="PMD">PMD</option> | |
| <option value="Others">Others</option> | |
| </select> | |
| </div> | |
| <div class="md:col-span-2 flex justify-end space-x-4"> | |
| <button type="submit" class="bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-6 rounded"> | |
| Add Report | |
| </button> | |
| <button type="reset" class="bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-6 rounded"> | |
| Clear | |
| </button> | |
| </div> | |
| </form> | |
| </div> | |
| <div class="mb-8"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h2 class="text-2xl font-bold text-green-800">Hazard Reports</h2> | |
| <div class="flex space-x-2"> | |
| <button id="resetFilters" class="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded inline-flex items-center"> | |
| <svg class="w-4 h-4 mr-2" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> | |
| <path fill-rule="evenodd" d="M4 2a1 1 0 011 1v2.101a7.002 7.002 0 0111.601 2.566 1 1 0 11-1.885.666A5.002 5.002 0 005.999 7H9a1 1 0 010 2H4a1 1 0 01-1-1V3a1 1 0 011-1zm.008 9.057a1 1 0 011.276.61A5.002 5.002 0 0014.001 13H11a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0v-2.101a7.002 7.002 0 01-11.601-2.566 1 1 0 01.61-1.276z" clip-rule="evenodd"></path> | |
| </svg> | |
| Reset Filters | |
| </button> | |
| <button id="exportExcel" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded inline-flex items-center"> | |
| <svg class="w-4 h-4 mr-2" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> | |
| <path fill-rule="evenodd" d="M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm3.293-7.707a1 1 0 011.414 0L9 10.586V3a1 1 0 112 0v7.586l1.293-1.293a1 1 0 111.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z" clip-rule="evenodd"></path> | |
| </svg> | |
| Export to Excel | |
| </button> | |
| <button id="exportPDF" class="bg-red-600 hover:bg-red-700 text-white font-bold py-2 px-4 rounded inline-flex items-center"> | |
| <svg class="w-4 h-4 mr-2" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> | |
| <path fill-rule="evenodd" d="M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm3.293-7.707a1 1 0 011.414 0L9 10.586V3a1 1 0 112 0v7.586l1.293-1.293a1 1 0 111.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z" clip-rule="evenodd"></path> | |
| </svg> | |
| Export to PDF | |
| </button> | |
| </div> | |
| </div> | |
| <div class="overflow-x-auto"> | |
| <table class="hazard-table w-full"> | |
| <thead> | |
| <tr> | |
| <th>Date</th> | |
| <th>Hazard Type</th> | |
| <th>Details</th> | |
| <th>Area</th> | |
| <th>Status</th> | |
| <th>Aging Days</th> | |
| <th>Actions</th> | |
| </tr> | |
| </thead> | |
| <tbody id="hazardTableBody"> | |
| <!-- Reports will be added here dynamically --> | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| // Initialize data from localStorage if available | |
| let hazardReports = JSON.parse(localStorage.getItem('hazardReports')) || []; | |
| let logoData = localStorage.getItem('logoData'); | |
| // DOM elements | |
| const hazardForm = document.getElementById('hazardForm'); | |
| const hazardTableBody = document.getElementById('hazardTableBody'); | |
| const logoUpload = document.getElementById('logoUpload'); | |
| const logoPreview = document.getElementById('logoPreview'); | |
| const logoContainer = document.getElementById('logoContainer'); | |
| const exportExcelBtn = document.getElementById('exportExcel'); | |
| const exportPDFBtn = document.getElementById('exportPDF'); | |
| // Summary elements | |
| const totalReportsEl = document.getElementById('totalReports'); | |
| const openReportsEl = document.getElementById('openReports'); | |
| const closedReportsEl = document.getElementById('closedReports'); | |
| const pendingReportsEl = document.getElementById('pendingReports'); | |
| // Charts | |
| let topHazardsChart, areaStatusChart, areaReportsChart, areaCorrectedChart; | |
| // Initialize the page | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Load logo if exists | |
| if (logoData) { | |
| logoPreview.src = logoData; | |
| logoPreview.classList.remove('hidden'); | |
| } | |
| // Render existing reports | |
| renderHazardReports(); | |
| updateSummary(); | |
| renderCharts(); | |
| // Set today's date as default | |
| document.getElementById('reportDate').valueAsDate = new Date(); | |
| }); | |
| // Handle form submission | |
| hazardForm.addEventListener('submit', function(e) { | |
| e.preventDefault(); | |
| const reportDate = document.getElementById('reportDate').value; | |
| const hazardType = document.getElementById('hazardType').value; | |
| const hazardDetails = document.getElementById('hazardDetails').value; | |
| const status = document.getElementById('status').value; | |
| const area = document.getElementById('area').value; | |
| // Create new report | |
| const newReport = { | |
| id: Date.now(), | |
| date: reportDate, | |
| hazardType: hazardType, | |
| details: hazardDetails, | |
| status: status, | |
| area: area, | |
| createdAt: new Date().toISOString() | |
| }; | |
| // Add to reports array | |
| hazardReports.push(newReport); | |
| // Save to localStorage | |
| saveData(); | |
| // Render the new report | |
| renderHazardReports(); | |
| updateSummary(); | |
| renderCharts(); | |
| // Reset form | |
| hazardForm.reset(); | |
| document.getElementById('reportDate').valueAsDate = new Date(); | |
| }); | |
| // Handle logo upload | |
| logoUpload.addEventListener('change', function(e) { | |
| const file = e.target.files[0]; | |
| if (file) { | |
| const reader = new FileReader(); | |
| reader.onload = function(event) { | |
| logoPreview.src = event.target.result; | |
| logoPreview.classList.remove('hidden'); | |
| logoData = event.target.result; | |
| localStorage.setItem('logoData', logoData); | |
| }; | |
| reader.readAsDataURL(file); | |
| } | |
| }); | |
| // Handle export to Excel | |
| exportExcelBtn.addEventListener('click', function() { | |
| exportToExcel(); | |
| }); | |
| // Handle export to PDF | |
| exportPDFBtn.addEventListener('click', function() { | |
| exportToPDF(); | |
| }); | |
| // Filter elements | |
| const startDateFilter = document.getElementById('startDate'); | |
| const endDateFilter = document.getElementById('endDate'); | |
| const areaFilter = document.getElementById('areaFilter'); | |
| const hazardFilter = document.getElementById('hazardFilter'); | |
| const resetFiltersBtn = document.getElementById('resetFilters'); | |
| // Set default date range (last 30 days) | |
| const defaultEndDate = new Date(); | |
| const defaultStartDate = new Date(); | |
| defaultStartDate.setDate(defaultStartDate.getDate() - 30); | |
| startDateFilter.valueAsDate = defaultStartDate; | |
| endDateFilter.valueAsDate = defaultEndDate; | |
| // Add event listeners for filters | |
| startDateFilter.addEventListener('change', applyFilters); | |
| endDateFilter.addEventListener('change', applyFilters); | |
| areaFilter.addEventListener('change', applyFilters); | |
| hazardFilter.addEventListener('change', applyFilters); | |
| resetFiltersBtn.addEventListener('click', resetFilters); | |
| // Function to apply filters | |
| function applyFilters() { | |
| renderHazardReports(); | |
| updateSummary(); | |
| renderCharts(); | |
| } | |
| // Function to reset all filters | |
| function resetFilters() { | |
| startDateFilter.valueAsDate = defaultStartDate; | |
| endDateFilter.valueAsDate = defaultEndDate; | |
| areaFilter.value = ''; | |
| hazardFilter.value = ''; | |
| applyFilters(); | |
| } | |
| // Function to get filtered reports | |
| function getFilteredReports() { | |
| const startDate = startDateFilter.value ? new Date(startDateFilter.value) : null; | |
| const endDate = endDateFilter.value ? new Date(endDateFilter.value) : null; | |
| const area = areaFilter.value; | |
| const hazardType = hazardFilter.value; | |
| return hazardReports.filter(report => { | |
| const reportDate = new Date(report.date); | |
| // Date filter | |
| if (startDate && reportDate < startDate) return false; | |
| if (endDate && reportDate > endDate) return false; | |
| // Area filter | |
| if (area && report.area !== area) return false; | |
| // Hazard type filter | |
| if (hazardType && report.hazardType !== hazardType) return false; | |
| return true; | |
| }); | |
| } | |
| // Function to render hazard reports in the table | |
| function renderHazardReports() { | |
| const filteredReports = getFilteredReports(); | |
| hazardTableBody.innerHTML = ''; | |
| if (hazardReports.length === 0) { | |
| hazardTableBody.innerHTML = '<tr><td colspan="7" class="text-center py-4">No hazard reports found</td></tr>'; | |
| return; | |
| } | |
| filteredReports.forEach(report => { | |
| const row = document.createElement('tr'); | |
| // Calculate aging days | |
| const reportDate = new Date(report.date); | |
| const today = new Date(); | |
| const diffTime = Math.abs(today - reportDate); | |
| const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); | |
| // Status class | |
| let statusClass = ''; | |
| if (report.status === 'Open') statusClass = 'status-open'; | |
| else if (report.status === 'Closed') statusClass = 'status-closed'; | |
| else if (report.status === 'Pending') statusClass = 'status-pending'; | |
| else if (report.status === 'Ongoing') statusClass = 'status-ongoing'; | |
| row.innerHTML = ` | |
| <td>${report.date}</td> | |
| <td>${report.hazardType}</td> | |
| <td>${report.details}</td> | |
| <td>${report.area}</td> | |
| <td class="${statusClass}">${report.status}</td> | |
| <td>${diffDays}</td> | |
| <td> | |
| <button onclick="editReport(${report.id})" class="text-blue-600 hover:text-blue-800 mr-2">Edit</button> | |
| <button onclick="deleteReport(${report.id})" class="text-red-600 hover:text-red-800">Delete</button> | |
| </td> | |
| `; | |
| hazardTableBody.appendChild(row); | |
| }); | |
| } | |
| // Function to edit a report | |
| function editReport(id) { | |
| const report = hazardReports.find(r => r.id === id); | |
| if (!report) return; | |
| document.getElementById('reportDate').value = report.date; | |
| document.getElementById('hazardType').value = report.hazardType; | |
| document.getElementById('hazardDetails').value = report.details; | |
| document.getElementById('status').value = report.status; | |
| document.getElementById('area').value = report.area; | |
| // Remove the report from the array | |
| hazardReports = hazardReports.filter(r => r.id !== id); | |
| // Save changes | |
| saveData(); | |
| renderHazardReports(); | |
| updateSummary(); | |
| renderCharts(); | |
| } | |
| // Function to delete a report | |
| function deleteReport(id) { | |
| if (confirm('Are you sure you want to delete this report?')) { | |
| hazardReports = hazardReports.filter(r => r.id !== id); | |
| saveData(); | |
| renderHazardReports(); | |
| updateSummary(); | |
| renderCharts(); | |
| } | |
| } | |
| // Function to save data to localStorage | |
| function saveData() { | |
| localStorage.setItem('hazardReports', JSON.stringify(hazardReports)); | |
| } | |
| // Function to update summary statistics | |
| function updateSummary() { | |
| const filteredReports = getFilteredReports(); | |
| totalReportsEl.textContent = filteredReports.length; | |
| openReportsEl.textContent = filteredReports.filter(r => r.status === 'Open').length; | |
| closedReportsEl.textContent = filteredReports.filter(r => r.status === 'Closed').length; | |
| pendingReportsEl.textContent = filteredReports.filter(r => r.status === 'Pending' || r.status === 'Ongoing').length; | |
| } | |
| // Function to render charts | |
| function renderCharts() { | |
| // Destroy existing charts if they exist | |
| if (topHazardsChart) topHazardsChart.destroy(); | |
| if (areaStatusChart) areaStatusChart.destroy(); | |
| if (areaReportsChart) areaReportsChart.destroy(); | |
| if (areaCorrectedChart) areaCorrectedChart.destroy(); | |
| // Get data for charts | |
| const filteredReports = getFilteredReports(); | |
| const hazardCounts = {}; | |
| const areaCounts = {}; | |
| const areaStatusCounts = {}; | |
| const areaCorrectedCounts = {}; | |
| filteredReports.forEach(report => { | |
| // Count hazards for top hazards chart | |
| hazardCounts[report.hazardType] = (hazardCounts[report.hazardType] || 0) + 1; | |
| // Count reports per area | |
| areaCounts[report.area] = (areaCounts[report.area] || 0) + 1; | |
| // Count corrected (closed) reports per area | |
| if (report.status === 'Closed') { | |
| areaCorrectedCounts[report.area] = (areaCorrectedCounts[report.area] || 0) + 1; | |
| } | |
| // Initialize area status counts if not exists | |
| if (!areaStatusCounts[report.area]) { | |
| areaStatusCounts[report.area] = { | |
| Open: 0, | |
| Closed: 0, | |
| Pending: 0, | |
| Ongoing: 0 | |
| }; | |
| } | |
| // Increment status count for the area | |
| areaStatusCounts[report.area][report.status]++; | |
| }); | |
| // Prepare data for top hazards chart (top 3) | |
| const sortedHazards = Object.entries(hazardCounts) | |
| .sort((a, b) => b[1] - a[1]) | |
| .slice(0, 3); | |
| const topHazardLabels = sortedHazards.map(item => item[0]); | |
| const topHazardData = sortedHazards.map(item => item[1]); | |
| // Prepare data for area reports chart | |
| const areaLabels = Object.keys(areaCounts); | |
| const areaReportData = areaLabels.map(area => areaCounts[area]); | |
| // Prepare data for area corrected chart | |
| const areaCorrectedData = areaLabels.map(area => areaCorrectedCounts[area] || 0); | |
| // Prepare data for area status chart (stacked bar chart) | |
| const areaStatusLabels = Object.keys(areaStatusCounts); | |
| const statusTypes = ['Open', 'Closed', 'Pending', 'Ongoing']; | |
| const statusColors = { | |
| 'Open': 'rgba(234, 179, 8, 0.7)', | |
| 'Closed': 'rgba(16, 185, 129, 0.7)', | |
| 'Pending': 'rgba(99, 102, 241, 0.7)', | |
| 'Ongoing': 'rgba(239, 68, 68, 0.7)' | |
| }; | |
| const statusDatasets = statusTypes.map(status => ({ | |
| label: status, | |
| data: areaStatusLabels.map(area => areaStatusCounts[area][status]), | |
| backgroundColor: statusColors[status], | |
| borderColor: statusColors[status].replace('0.7', '1'), | |
| borderWidth: 1 | |
| })); | |
| // Create charts | |
| const ctx1 = document.getElementById('topHazardsChart').getContext('2d'); | |
| topHazardsChart = new Chart(ctx1, { | |
| type: 'line', | |
| data: { | |
| labels: topHazardLabels, | |
| datasets: [{ | |
| label: 'Number of Reports', | |
| data: topHazardData, | |
| backgroundColor: 'rgba(22, 163, 74, 0.2)', | |
| borderColor: 'rgba(22, 163, 74, 1)', | |
| borderWidth: 2, | |
| tension: 0.1, | |
| fill: true | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| plugins: { | |
| title: { | |
| display: true, | |
| text: 'Top 3 Most Reported Hazards' | |
| }, | |
| legend: { | |
| display: false | |
| } | |
| }, | |
| scales: { | |
| y: { | |
| beginAtZero: true, | |
| ticks: { | |
| stepSize: 1 | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| const ctx2 = document.getElementById('areaStatusChart').getContext('2d'); | |
| areaStatusChart = new Chart(ctx2, { | |
| type: 'bar', | |
| data: { | |
| labels: areaStatusLabels, | |
| datasets: statusDatasets | |
| }, | |
| options: { | |
| responsive: true, | |
| plugins: { | |
| title: { | |
| display: true, | |
| text: 'Hazard Status by Area' | |
| }, | |
| tooltip: { | |
| mode: 'index', | |
| intersect: false | |
| } | |
| }, | |
| scales: { | |
| x: { | |
| stacked: true, | |
| }, | |
| y: { | |
| stacked: true, | |
| beginAtZero: true, | |
| ticks: { | |
| stepSize: 1 | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| const ctx3 = document.getElementById('areaReportsChart').getContext('2d'); | |
| areaReportsChart = new Chart(ctx3, { | |
| type: 'bar', | |
| data: { | |
| labels: areaLabels, | |
| datasets: [{ | |
| label: 'Reports', | |
| data: areaReportData, | |
| backgroundColor: 'rgba(59, 130, 246, 0.7)', | |
| borderColor: 'rgba(59, 130, 246, 1)', | |
| borderWidth: 1 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| plugins: { | |
| title: { | |
| display: true, | |
| text: 'Areas with Most Reports' | |
| }, | |
| legend: { | |
| display: false | |
| } | |
| }, | |
| scales: { | |
| y: { | |
| beginAtZero: true, | |
| ticks: { | |
| stepSize: 1 | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| const ctx4 = document.getElementById('areaCorrectedChart').getContext('2d'); | |
| areaCorrectedChart = new Chart(ctx4, { | |
| type: 'bar', | |
| data: { | |
| labels: areaLabels, | |
| datasets: [{ | |
| label: 'Corrected Hazards', | |
| data: areaCorrectedData, | |
| backgroundColor: 'rgba(16, 185, 129, 0.7)', | |
| borderColor: 'rgba(16, 185, 129, 1)', | |
| borderWidth: 1 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| plugins: { | |
| title: { | |
| display: true, | |
| text: 'Areas with Most Corrected Hazards' | |
| }, | |
| legend: { | |
| display: false | |
| } | |
| }, | |
| scales: { | |
| y: { | |
| beginAtZero: true, | |
| ticks: { | |
| stepSize: 1 | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| // Function to export to Excel | |
| function exportToExcel() { | |
| // Prepare data | |
| const data = [ | |
| ['Date', 'Hazard Type', 'Details', 'Area', 'Status', 'Aging Days'] | |
| ]; | |
| filteredReports.forEach(report => { | |
| const reportDate = new Date(report.date); | |
| const today = new Date(); | |
| const diffTime = Math.abs(today - reportDate); | |
| const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); | |
| data.push([ | |
| report.date, | |
| report.hazardType, | |
| report.details, | |
| report.area, | |
| report.status, | |
| diffDays | |
| ]); | |
| }); | |
| // Create workbook | |
| const wb = XLSX.utils.book_new(); | |
| const ws = XLSX.utils.aoa_to_sheet(data); | |
| XLSX.utils.book_append_sheet(wb, ws, 'Hazard Reports'); | |
| // Export | |
| XLSX.writeFile(wb, 'MDC_Warehouse_Hazard_Reports.xlsx'); | |
| } | |
| // Function to export to PDF | |
| function exportToPDF() { | |
| const { jsPDF } = window.jspdf; | |
| const doc = new jsPDF({ | |
| orientation: 'landscape' | |
| }); | |
| // Add title | |
| doc.setFontSize(18); | |
| doc.setTextColor(22, 101, 52); // Dark green | |
| doc.text('MDC Warehouse Hazard Report', 15, 15); | |
| // Add date | |
| doc.setFontSize(10); | |
| doc.setTextColor(0, 0, 0); | |
| doc.text(`Generated on: ${new Date().toLocaleDateString()}`, 250, 15); | |
| // Add summary | |
| doc.setFontSize(12); | |
| doc.text('Summary:', 15, 30); | |
| doc.text(`Total Reports: ${hazardReports.length}`, 15, 40); | |
| doc.text(`Open: ${hazardReports.filter(r => r.status === 'Open').length}`, 15, 50); | |
| doc.text(`Closed: ${hazardReports.filter(r => r.status === 'Closed').length}`, 15, 60); | |
| doc.text(`Pending/Ongoing: ${hazardReports.filter(r => r.status === 'Pending' || r.status === 'Ongoing').length}`, 15, 70); | |
| // Add charts (as images - simplified for this example) | |
| // In a real implementation, you might need to use canvas.toDataURL() and addImage() | |
| // Add table | |
| doc.setFontSize(10); | |
| const headers = ['Date', 'Hazard Type', 'Details', 'Area', 'Status', 'Aging Days']; | |
| const rows = []; | |
| filteredReports.forEach(report => { | |
| const reportDate = new Date(report.date); | |
| const today = new Date(); | |
| const diffTime = Math.abs(today - reportDate); | |
| const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); | |
| rows.push([ | |
| report.date, | |
| report.hazardType, | |
| report.details.substring(0, 50) + (report.details.length > 50 ? '...' : ''), | |
| report.area, | |
| report.status, | |
| diffDays.toString() | |
| ]); | |
| }); | |
| // AutoTable plugin would be better here, but using basic text for this example | |
| doc.text('Hazard Reports:', 15, 85); | |
| let y = 95; | |
| // Add headers | |
| doc.setFontStyle('bold'); | |
| let x = 15; | |
| headers.forEach((header, i) => { | |
| doc.text(header, x, y); | |
| x += i === 2 ? 60 : 40; // Wider column for details | |
| }); | |
| // Add rows | |
| doc.setFontStyle('normal'); | |
| rows.forEach(row => { | |
| y += 7; | |
| x = 15; | |
| row.forEach((cell, i) => { | |
| doc.text(cell, x, y); | |
| x += i === 2 ? 60 : 40; | |
| }); | |
| // Add new page if needed | |
| if (y > 270) { | |
| doc.addPage('landscape'); | |
| y = 20; | |
| } | |
| }); | |
| // Save the PDF | |
| doc.save('MDC_Warehouse_Hazard_Report.pdf'); | |
| } | |
| </script> | |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=froilan1262/version-2-tracker" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |