Download script.js from cslhasan/routeranger-time-tracker: direct link, hf CLI and curl.
- Browser
- Download file 6.26 kB
-
https://huggingface.co/spaces/cslhasan/routeranger-time-tracker/resolve/main/script.js
- Command line
-
hf download hf://spaces/cslhasan/routeranger-time-tracker/script.js
-
curl -L -o script.js https://huggingface.co/spaces/cslhasan/routeranger-time-tracker/resolve/main/script.js
6.26 kB
| // Update current time every second | |
| function updateClock() { | |
| const now = new Date(); | |
| document.getElementById('current-date').textContent = now.toLocaleDateString('en-US', { | |
| weekday: 'long', | |
| year: 'numeric', | |
| month: 'long', | |
| day: 'numeric' | |
| }); | |
| document.getElementById('current-time').textContent = now.toLocaleTimeString('en-US', { | |
| hour: '2-digit', | |
| minute: '2-digit' | |
| }); | |
| } | |
| setInterval(updateClock, 1000); | |
| updateClock(); | |
| // Mock data for demonstration | |
| const mockDrivers = [ | |
| { id: 1, name: "John Smith" }, | |
| { id: 2, name: "Sarah Johnson" }, | |
| { id: 3, name: "Michael Brown" } | |
| ]; | |
| const mockRecords = [ | |
| { | |
| driverId: 1, | |
| driverName: "John Smith", | |
| clockIn: "2023-05-15T08:00:00", | |
| clockOut: "2023-05-15T16:30:00", | |
| location: "Warehouse A" | |
| }, | |
| { | |
| driverId: 2, | |
| driverName: "Sarah Johnson", | |
| clockIn: "2023-05-15T08:15:00", | |
| clockOut: "2023-05-15T17:00:00", | |
| location: "Main Office" | |
| }, | |
| { | |
| driverId: 3, | |
| driverName: "Michael Brown", | |
| clockIn: "2023-05-15T07:45:00", | |
| clockOut: "2023-05-15T16:15:00", | |
| location: "Distribution Center" | |
| } | |
| ]; | |
| // Populate driver filter dropdown | |
| const driverFilter = document.getElementById('driver-filter'); | |
| mockDrivers.forEach(driver => { | |
| const option = document.createElement('option'); | |
| option.value = driver.id; | |
| option.textContent = driver.name; | |
| driverFilter.appendChild(option); | |
| }); | |
| // Display records in admin view | |
| function displayRecords(records) { | |
| const tableBody = document.getElementById('records-table'); | |
| tableBody.innerHTML = ''; | |
| records.forEach(record => { | |
| const row = document.createElement('tr'); | |
| row.className = 'hover:bg-gray-50'; | |
| const clockInTime = new Date(record.clockIn); | |
| const clockOutTime = record.clockOut ? new Date(record.clockOut) : null; | |
| const hoursWorked = clockOutTime | |
| ? `${Math.floor((clockOutTime - clockInTime) / 3600000)}h ${Math.floor(((clockOutTime - clockInTime) % 3600000) / 60000)}m` | |
| : 'In Progress'; | |
| row.innerHTML = ` | |
| <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${record.driverName}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${clockInTime.toLocaleTimeString()}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${clockOutTime ? clockOutTime.toLocaleTimeString() : '--'}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${hoursWorked}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${record.location}</td> | |
| `; | |
| tableBody.appendChild(row); | |
| }); | |
| document.getElementById('record-count').textContent = records.length; | |
| } | |
| // Initial display | |
| displayRecords(mockRecords); | |
| // Clock in/out functionality | |
| let clockedIn = false; | |
| let clockInTime = null; | |
| document.getElementById('clock-in-btn').addEventListener('click', () => { | |
| clockedIn = true; | |
| clockInTime = new Date(); | |
| document.getElementById('clock-in-btn').disabled = true; | |
| document.getElementById('clock-out-btn').disabled = false; | |
| document.getElementById('clock-in-time').textContent = clockInTime.toLocaleTimeString(); | |
| // Update hours worked every minute | |
| setInterval(updateHoursWorked, 60000); | |
| updateHoursWorked(); | |
| }); | |
| document.getElementById('clock-out-btn').addEventListener('click', () => { | |
| clockedIn = false; | |
| const clockOutTime = new Date(); | |
| document.getElementById('clock-in-btn').disabled = false; | |
| document.getElementById('clock-out-btn').disabled = true; | |
| // Calculate total hours worked | |
| updateHoursWorked(); | |
| }); | |
| function updateHoursWorked() { | |
| if (clockedIn && clockInTime) { | |
| const now = new Date(); | |
| const diffMs = now - clockInTime; | |
| const hours = Math.floor(diffMs / 3600000); | |
| const minutes = Math.floor((diffMs % 3600000) / 60000); | |
| document.getElementById('hours-worked').textContent = `${hours}h ${minutes}m`; | |
| } | |
| } | |
| // Filter functionality | |
| document.getElementById('date-filter').addEventListener('change', (e) => { | |
| filterRecords(); | |
| }); | |
| document.getElementById('driver-filter').addEventListener('change', (e) => { | |
| filterRecords(); | |
| }); | |
| function filterRecords() { | |
| const dateFilter = document.getElementById('date-filter').value; | |
| const driverFilter = document.getElementById('driver-filter').value; | |
| let filteredRecords = [...mockRecords]; | |
| if (dateFilter) { | |
| filteredRecords = filteredRecords.filter(record => { | |
| return new Date(record.clockIn).toISOString().split('T')[0] === dateFilter; | |
| }); | |
| } | |
| if (driverFilter) { | |
| filteredRecords = filteredRecords.filter(record => { | |
| return record.driverId.toString() === driverFilter; | |
| }); | |
| } | |
| displayRecords(filteredRecords); | |
| } | |
| // Export to CSV | |
| document.getElementById('export-btn').addEventListener('click', () => { | |
| alert('Export functionality would be implemented here in a real application'); | |
| }); | |
| // Toggle between driver and admin views (for demo purposes) | |
| function toggleAdminView() { | |
| const driverView = document.getElementById('driver-view'); | |
| const adminView = document.getElementById('admin-view'); | |
| if (driverView.classList.contains('hidden')) { | |
| driverView.classList.remove('hidden'); | |
| adminView.classList.add('hidden'); | |
| } else { | |
| driverView.classList.add('hidden'); | |
| adminView.classList.remove('hidden'); | |
| } | |
| } | |
| // For demo - add a button to toggle views in the navbar | |
| document.addEventListener('DOMContentLoaded', () => { | |
| const adminToggleBtn = document.createElement('button'); | |
| adminToggleBtn.className = 'ml-4 px-3 py-1 bg-gray-200 hover:bg-gray-300 rounded text-sm'; | |
| adminToggleBtn.textContent = 'Toggle Admin View'; | |
| adminToggleBtn.addEventListener('click', toggleAdminView); | |
| document.querySelector('custom-navbar').shadowRoot.querySelector('.navbar-content').appendChild(adminToggleBtn); | |
| }); |