-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.js
123 lines (106 loc) · 3.82 KB
/
dashboard.js
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
// Simple visitor management system
let visitors = [];
let currentVisitors = 0;
let todayTotal = 0;
// DOM elements
const visitorForm = document.getElementById('visitor-form');
const visitorList = document.getElementById('visitor-list');
const currentVisitorsEl = document.getElementById('current-visitors');
const todayTotalEl = document.getElementById('today-total');
const lockAllBtn = document.getElementById('lock-all');
const unlockAllBtn = document.getElementById('unlock-all');
const generateReportBtn = document.getElementById('generate-report');
const reportOutput = document.getElementById('report-output');
// Event listeners
visitorForm.addEventListener('submit', checkInVisitor);
lockAllBtn.addEventListener('click', lockAllDoors);
unlockAllBtn.addEventListener('click', unlockAllDoors);
generateReportBtn.addEventListener('click', generateReport);
// Check-in visitor
function checkInVisitor(e) {
e.preventDefault();
const name = document.getElementById('visitor-name').value;
const email = document.getElementById('visitor-email').value;
const purpose = document.getElementById('visitor-purpose').value;
const visitor = {
name,
email,
purpose,
checkInTime: new Date()
};
visitors.push(visitor);
currentVisitors++;
todayTotal++;
updateStats();
displayVisitors();
visitorForm.reset();
}
// Display visitors
function displayVisitors() {
visitorList.innerHTML = '';
visitors.forEach((visitor, index) => {
const visitorEl = document.createElement('div');
visitorEl.classList.add('visitor-item');
visitorEl.innerHTML = `
<h3>${visitor.name}</h3>
<p>Email: ${visitor.email}</p>
<p>Purpose: ${visitor.purpose}</p>
<p>Check-in Time: ${visitor.checkInTime.toLocaleString()}</p>
<button onclick="checkOutVisitor(${index})">Check-Out</button>
`;
visitorList.appendChild(visitorEl);
});
}
// Check-out visitor
function checkOutVisitor(index) {
visitors.splice(index, 1);
currentVisitors--;
updateStats();
displayVisitors();
}
// Update stats
function updateStats() {
currentVisitorsEl.textContent = currentVisitors;
todayTotalEl.textContent = todayTotal;
}
// Lock all doors (simulated)
function lockAllDoors() {
alert('All doors have been locked.');
}
// Unlock all doors (simulated)
function unlockAllDoors() {
alert('All doors have been unlocked.');
}
// Generate simple report
function generateReport() {
const report = `
<h3>Visitor Report</h3>
<p>Current Visitors: ${currentVisitors}</p>
<p>Today's Total: ${todayTotal}</p>
<h4>Visitor List:</h4>
<ul>
${visitors.map(visitor => `<li>${visitor.name} - ${visitor.purpose}</li>`).join('')}
</ul>
`;
reportOutput.innerHTML = report;
}
// Initial display
updateStats();
// Add a search bar to the HTML
// const searchInput = document.getElementById('search-input');
// // Add an event listener to the search input
// searchInput.addEventListener('input', searchVisitors);
// // Define the searchVisitors function
// function searchVisitors() {
// const searchTerm = searchInput.value.toLowerCase();
// const filteredVisitors = visitors.filter(visitor => {
// return visitor.name.toLowerCase().includes(searchTerm) ||
// visitor.email.toLowerCase().includes(searchTerm) ||
// visitor.purpose.toLowerCase().includes(searchTerm);
// });
// displayVisitors(filteredVisitors);
// }
// // Update the displayVisitors function to accept an optional array of visitors
// function displayVisitors(visitorsArray = visitors) {
// visitorList.innerHTML = '';
// visitors}