Download app.js from Carsonogen/deepsite-project-fln2p: direct link, hf CLI and curl.
- Browser
- Download file 15.4 kB
-
https://huggingface.co/spaces/Carsonogen/deepsite-project-fln2p/resolve/main/app.js
- Command line
-
hf download hf://spaces/Carsonogen/deepsite-project-fln2p/app.js
-
curl -L -o app.js https://huggingface.co/spaces/Carsonogen/deepsite-project-fln2p/resolve/main/app.js
15.4 kB
| let employees = []; | |
| let qaMetrics = []; | |
| let filteredEmployees = []; | |
| let currentPage = 1; | |
| let itemsPerPage = 12; | |
| let isGridView = true; | |
| async function loadData() { | |
| try { | |
| const [employeesRes, qaRes] = await Promise.all([ | |
| fetch("./data/employees.json"), | |
| fetch("./data/qa.json") | |
| ]); | |
| if (!employeesRes.ok) { | |
| throw new Error(`Failed to load employees.json (${employeesRes.status})`); | |
| } | |
| if (!qaRes.ok) { | |
| throw new Error(`Failed to load qa.json (${qaRes.status})`); | |
| } | |
| employees = await employeesRes.json(); | |
| qaMetrics = await qaRes.json(); | |
| filteredEmployees = [...employees]; | |
| currentPage = 1; | |
| return true; | |
| } catch (error) { | |
| console.error(error); | |
| return false; | |
| } | |
| } | |
| function toggleMobileMenu() { | |
| const menu = document.getElementById("mobile-menu"); | |
| if (!menu) return; | |
| menu.classList.toggle("hidden"); | |
| } | |
| function getInitials(name) { | |
| if (!name) return ""; | |
| return name | |
| .split(" ") | |
| .filter(Boolean) | |
| .slice(0, 2) | |
| .map(part => part[0].toUpperCase()) | |
| .join(""); | |
| } | |
| function getDepartmentColor(department) { | |
| const colors = { | |
| "Support": "bg-blue-100 text-blue-700", | |
| "Sales": "bg-green-100 text-green-700", | |
| "Trust and Safety": "bg-orange-100 text-orange-700" | |
| }; | |
| return colors[department] || "bg-gray-100 text-gray-700"; | |
| } | |
| function getShiftColor(shiftStartTime) { | |
| const hour = Number.parseInt(String(shiftStartTime).split(":")[0], 10); | |
| if (Number.isNaN(hour)) return "bg-gray-100 text-gray-700"; | |
| if (hour < 10) return "bg-emerald-100 text-emerald-700"; | |
| if (hour < 14) return "bg-amber-100 text-amber-700"; | |
| return "bg-indigo-100 text-indigo-700"; | |
| } | |
| function getScoreClass(score) { | |
| if (score >= 90) return "bg-score-excellent"; | |
| if (score >= 80) return "bg-score-good"; | |
| if (score >= 70) return "bg-score-average"; | |
| return "bg-score-poor"; | |
| } | |
| function getScoreColor(score) { | |
| if (score >= 90) return "score-excellent"; | |
| if (score >= 80) return "score-good"; | |
| if (score >= 70) return "score-average"; | |
| return "score-poor"; | |
| } | |
| function getEmployeeQAStats(agentName) { | |
| const entries = qaMetrics.filter(item => item.agentName === agentName); | |
| if (!entries.length) return null; | |
| const reviewCount = entries.length; | |
| const avgScore = Math.round(entries.reduce((sum, entry) => sum + entry.qaScore, 0) / reviewCount); | |
| const latestEntry = entries | |
| .slice() | |
| .sort((a, b) => new Date(b.scoredDate) - new Date(a.scoredDate))[0]; | |
| return { | |
| avgScore, | |
| latestScore: latestEntry.qaScore, | |
| reviewCount | |
| }; | |
| } | |
| function openModal(employeeNumber) { | |
| const emp = employees.find(e => e.employeeNumber === employeeNumber); | |
| if (!emp) return; | |
| const modal = document.getElementById("detail-modal"); | |
| if (!modal) return; | |
| const setText = (id, value) => { | |
| const el = document.getElementById(id); | |
| if (el) el.textContent = value; | |
| }; | |
| setText("modal-avatar", getInitials(emp.fullName)); | |
| setText("modal-name", emp.fullName); | |
| setText("modal-id", emp.employeeNumber); | |
| setText("modal-leader", emp.teamLeader); | |
| setText("modal-shift", emp.shiftStartTime); | |
| setText("modal-days", emp.daysOff); | |
| const deptEl = document.getElementById("modal-dept"); | |
| if (deptEl) { | |
| deptEl.textContent = emp.department; | |
| deptEl.className = `inline-block mt-2 px-3 py-1 rounded-full text-sm font-medium ${getDepartmentColor(emp.department)}`; | |
| } | |
| const emailEl = document.getElementById("modal-email"); | |
| if (emailEl) { | |
| emailEl.textContent = emp.email; | |
| emailEl.href = `mailto:${emp.email}`; | |
| } | |
| const phoneEl = document.getElementById("modal-phone"); | |
| if (phoneEl) { | |
| phoneEl.textContent = emp.phoneNumber; | |
| phoneEl.href = `tel:${emp.phoneNumber}`; | |
| } | |
| const emailBtn = document.getElementById("modal-email-btn"); | |
| if (emailBtn) emailBtn.href = `mailto:${emp.email}`; | |
| const callBtn = document.getElementById("modal-call-btn"); | |
| if (callBtn) callBtn.href = `tel:${emp.phoneNumber}`; | |
| const qaStats = getEmployeeQAStats(emp.fullName); | |
| const qaSection = document.getElementById("modal-qa-stats"); | |
| if (qaSection) { | |
| if (qaStats) { | |
| qaSection.innerHTML = ` | |
| <div class="text-center p-4 bg-gray-50 rounded-lg"> | |
| <p class="text-2xl font-bold ${getScoreColor(qaStats.avgScore)}">${qaStats.avgScore}%</p> | |
| <p class="text-sm text-gray-500">Average Score</p> | |
| </div> | |
| <div class="text-center p-4 bg-gray-50 rounded-lg"> | |
| <p class="text-2xl font-bold text-gray-800">${qaStats.reviewCount}</p> | |
| <p class="text-sm text-gray-500">Total Reviews</p> | |
| </div> | |
| <div class="text-center p-4 bg-gray-50 rounded-lg"> | |
| <p class="text-2xl font-bold ${getScoreColor(qaStats.latestScore)}">${qaStats.latestScore}%</p> | |
| <p class="text-sm text-gray-500">Latest Score</p> | |
| </div> | |
| `; | |
| } else { | |
| qaSection.innerHTML = '<p class="col-span-3 text-center text-gray-400 py-4">No QA data available</p>'; | |
| } | |
| } | |
| modal.classList.remove("hidden"); | |
| modal.classList.add("flex"); | |
| if (window.lucide) { | |
| window.lucide.createIcons(); | |
| } | |
| } | |
| function closeModal() { | |
| const modal = document.getElementById("detail-modal"); | |
| if (!modal) return; | |
| modal.classList.remove("flex"); | |
| modal.classList.add("hidden"); | |
| } | |
| function exportData() { | |
| const dataToExport = filteredEmployees.map(emp => { | |
| const stats = getEmployeeQAStats(emp.fullName); | |
| return { | |
| employeeNumber: emp.employeeNumber, | |
| fullName: emp.fullName, | |
| department: emp.department, | |
| teamLeader: emp.teamLeader, | |
| shiftStartTime: emp.shiftStartTime, | |
| daysOff: emp.daysOff, | |
| qaAverageScore: stats ? stats.avgScore : null, | |
| qaReviewCount: stats ? stats.reviewCount : 0 | |
| }; | |
| }); | |
| const blob = new Blob([JSON.stringify(dataToExport, null, 2)], { type: "application/json" }); | |
| const url = URL.createObjectURL(blob); | |
| const link = document.createElement("a"); | |
| link.href = url; | |
| link.download = "employees_export.json"; | |
| document.body.appendChild(link); | |
| link.click(); | |
| link.remove(); | |
| URL.revokeObjectURL(url); | |
| } | |
| function populateFilters() { | |
| const deptSelect = document.getElementById("dept-filter"); | |
| const shiftSelect = document.getElementById("shift-filter"); | |
| if (!deptSelect || !shiftSelect) return; | |
| const depts = [...new Set(employees.map(e => e.department))].sort(); | |
| const shifts = [...new Set(employees.map(e => e.shiftStartTime))].sort(); | |
| deptSelect.innerHTML = '<option value="">All Departments</option>'; | |
| shiftSelect.innerHTML = '<option value="">All Shifts</option>'; | |
| depts.forEach(d => { | |
| deptSelect.innerHTML += `<option value="${d}">${d}</option>`; | |
| }); | |
| shifts.forEach(s => { | |
| shiftSelect.innerHTML += `<option value="${s}">${s}</option>`; | |
| }); | |
| } | |
| function updateStats() { | |
| const totalEmployeesEl = document.getElementById("total-employees"); | |
| const totalDepartmentsEl = document.getElementById("total-departments"); | |
| const totalLeadersEl = document.getElementById("total-leaders"); | |
| const avgQaEl = document.getElementById("avg-qa-score"); | |
| if (!totalEmployeesEl || !totalDepartmentsEl || !totalLeadersEl || !avgQaEl) return; | |
| totalEmployeesEl.textContent = employees.length; | |
| totalDepartmentsEl.textContent = new Set(employees.map(e => e.department)).size; | |
| totalLeadersEl.textContent = new Set(employees.map(e => e.teamLeader)).size; | |
| const avgScore = qaMetrics.length | |
| ? Math.round(qaMetrics.reduce((sum, row) => sum + row.qaScore, 0) / qaMetrics.length) | |
| : 0; | |
| avgQaEl.textContent = `${avgScore}%`; | |
| } | |
| function filterEmployees() { | |
| const dept = document.getElementById("dept-filter")?.value || ""; | |
| const shift = document.getElementById("shift-filter")?.value || ""; | |
| const search = (document.getElementById("search-input")?.value || "").toLowerCase(); | |
| filteredEmployees = employees.filter(e => { | |
| const matchDept = !dept || e.department === dept; | |
| const matchShift = !shift || e.shiftStartTime === shift; | |
| const matchSearch = !search | |
| || e.fullName.toLowerCase().includes(search) | |
| || e.employeeNumber.toLowerCase().includes(search) | |
| || e.teamLeader.toLowerCase().includes(search); | |
| return matchDept && matchShift && matchSearch; | |
| }); | |
| currentPage = 1; | |
| renderEmployees(); | |
| } | |
| function setView(grid) { | |
| isGridView = grid; | |
| const gridBtn = document.getElementById("grid-btn"); | |
| const listBtn = document.getElementById("list-btn"); | |
| if (gridBtn && listBtn) { | |
| gridBtn.className = grid ? "p-2 rounded-lg bg-indigo-600 text-white" : "p-2 rounded-lg bg-gray-200 text-gray-600"; | |
| listBtn.className = grid ? "p-2 rounded-lg bg-gray-200 text-gray-600" : "p-2 rounded-lg bg-indigo-600 text-white"; | |
| } | |
| renderEmployees(); | |
| } | |
| function renderEmployees() { | |
| const container = document.getElementById("employee-container"); | |
| if (!container) return; | |
| const start = (currentPage - 1) * itemsPerPage; | |
| const pageItems = filteredEmployees.slice(start, start + itemsPerPage); | |
| container.className = isGridView | |
| ? "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6" | |
| : "flex flex-col gap-4"; | |
| container.innerHTML = pageItems.map(emp => { | |
| const qaStats = getEmployeeQAStats(emp.fullName); | |
| const scoreClass = qaStats ? getScoreClass(qaStats.avgScore) : "bg-gray-100 text-gray-600"; | |
| if (isGridView) { | |
| return ` | |
| <div onclick="openModal('${emp.employeeNumber}')" class="bg-white rounded-xl shadow-sm border border-gray-200 p-6 card-hover cursor-pointer"> | |
| <div class="flex items-center gap-4 mb-4"> | |
| <div class="w-14 h-14 rounded-full bg-indigo-600 text-white text-lg font-bold flex items-center justify-center"> | |
| ${getInitials(emp.fullName)} | |
| </div> | |
| <div class="flex-1 min-w-0"> | |
| <h3 class="font-bold text-gray-800 truncate">${emp.fullName}</h3> | |
| <p class="text-sm text-gray-500">${emp.employeeNumber}</p> | |
| </div> | |
| </div> | |
| <div class="space-y-2"> | |
| <span class="inline-block px-3 py-1 rounded-full text-xs font-medium ${getDepartmentColor(emp.department)}"> | |
| ${emp.department} | |
| </span> | |
| <div class="flex items-center gap-2 text-sm text-gray-600"> | |
| <i data-lucide="clock" class="w-4 h-4"></i> | |
| <span>${emp.shiftStartTime}</span> | |
| <span class="px-2 py-0.5 rounded text-xs ${getShiftColor(emp.shiftStartTime)}">${emp.shiftStartTime}</span> | |
| </div> | |
| <div class="flex items-center gap-2 text-sm text-gray-600"> | |
| <i data-lucide="calendar" class="w-4 h-4"></i> | |
| <span>Off: ${emp.daysOff}</span> | |
| </div> | |
| </div> | |
| ${qaStats ? ` | |
| <div class="mt-4 pt-4 border-t border-gray-100"> | |
| <div class="flex items-center justify-between"> | |
| <span class="text-sm text-gray-500">QA Score</span> | |
| <span class="px-3 py-1 rounded-full text-sm font-bold ${scoreClass}">${qaStats.avgScore}%</span> | |
| </div> | |
| <p class="text-xs text-gray-400 mt-1">${qaStats.reviewCount} reviews</p> | |
| </div> | |
| ` : '<div class="mt-4 pt-4 border-t border-gray-100 text-sm text-gray-400">No QA data</div>'} | |
| </div> | |
| `; | |
| } | |
| return ` | |
| <div onclick="openModal('${emp.employeeNumber}')" class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 card-hover cursor-pointer flex items-center gap-4"> | |
| <div class="w-12 h-12 rounded-full bg-indigo-600 text-white font-bold flex items-center justify-center flex-shrink-0"> | |
| ${getInitials(emp.fullName)} | |
| </div> | |
| <div class="flex-1 min-w-0 grid grid-cols-4 gap-4 items-center"> | |
| <div> | |
| <h3 class="font-bold text-gray-800 truncate">${emp.fullName}</h3> | |
| <p class="text-sm text-gray-500">${emp.employeeNumber}</p> | |
| </div> | |
| <div> | |
| <span class="inline-block px-3 py-1 rounded-full text-xs font-medium ${getDepartmentColor(emp.department)}"> | |
| ${emp.department} | |
| </span> | |
| <p class="text-sm text-gray-500 mt-1">Leader: ${emp.teamLeader}</p> | |
| </div> | |
| <div class="text-sm text-gray-600"> | |
| <p><i data-lucide="clock" class="w-4 h-4 inline mr-1"></i>${emp.shiftStartTime}</p> | |
| <p class="mt-1"><i data-lucide="calendar" class="w-4 h-4 inline mr-1"></i>${emp.daysOff}</p> | |
| </div> | |
| <div class="text-right"> | |
| ${qaStats ? ` | |
| <span class="px-3 py-1 rounded-full text-sm font-bold ${scoreClass}">${qaStats.avgScore}%</span> | |
| <p class="text-xs text-gray-400 mt-1">${qaStats.reviewCount} reviews</p> | |
| ` : '<span class="text-sm text-gray-400">No QA data</span>'} | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| }).join(""); | |
| const totalPages = Math.ceil(filteredEmployees.length / itemsPerPage); | |
| const pageInfoEl = document.getElementById("page-info"); | |
| const prevBtn = document.getElementById("prev-btn"); | |
| const nextBtn = document.getElementById("next-btn"); | |
| if (pageInfoEl) pageInfoEl.textContent = `Page ${currentPage} of ${totalPages || 1}`; | |
| if (prevBtn) prevBtn.disabled = currentPage === 1; | |
| if (nextBtn) nextBtn.disabled = currentPage >= totalPages; | |
| if (window.lucide) { | |
| window.lucide.createIcons(); | |
| } | |
| } | |
| function changePage(delta) { | |
| currentPage += delta; | |
| renderEmployees(); | |
| } | |
| async function initDashboard() { | |
| if (!document.getElementById("employee-container")) return; | |
| const loaded = await loadData(); | |
| if (!loaded) return; | |
| populateFilters(); | |
| updateStats(); | |
| renderEmployees(); | |
| if (window.lucide) { | |
| window.lucide.createIcons(); | |
| } | |
| } | |
| document.addEventListener("keydown", event => { | |
| if (event.key === "Escape") { | |
| closeModal(); | |
| } | |
| }); | |
| document.addEventListener("DOMContentLoaded", () => { | |
| initDashboard(); | |
| }); | |