File size: 6,255 Bytes
c49553c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | // 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);
}); |