-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbarcode.html
384 lines (328 loc) · 10.8 KB
/
barcode.html
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title> Admin dashboard </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/barcode.css">
<link rel="stylesheet" href="css/color.css">
<!-- Boxicons CDN Link -->
<link href='https://unpkg.com/boxicons@2.0.7/css/boxicons.min.css' rel='stylesheet'>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<!--sidebar begins here-->
<div class="sidebar">
<div class="logo-details">
<i class='bx bxl-t-plus-plus'></i>
<!--type of icon-->
<span class="logo_name">TrackMe</span>
</div>
<ul class="nav-links">
<li>
<a href="index.html">
<i class='bx bx-grid-alt'></i>
<span class="links_name">Dashboard</span>
</a>
</li>
<li>
<a href="report.html">
<i class='bx bx-edit'></i>
<span class="links_name">Info Reports</span>
</a>
</li>
<li>
<a href="#" class="active">
<i class='bx bx-barcode'></i>
<span class="links_name">Generate QR</span>
</a>
</li>
<li>
<a href="scan.html">
<i class='bx bx-scan'></i>
<span class="links_name">Scan QR</span>
</a>
</li>
<li>
<a href="workers.html">
<i class='bx bx-user'></i>
<span class="links_name">Employees</span>
</a>
</li>
<li class="log_out">
<a href="#">
<i class='bx bx-log-out'></i>
<span class="links_name">Log out</span>
</a>
</li>
</ul>
</div>
<!-- sidebar ends here -->
<section class="home-section">
<!-- navbar starts here -->
<nav>
<div class="sidebar-button">
<i class='bx bx-menu sidebarBtn'></i>
<span class="dashboard">Dashboard</span>
</div>
<!-- <div class="profile-details"> -->
<!-- <img src="images/profile.jpg" alt="">
<span class="admin_name">Admin</span>
<i class='bx bx-chevron-down'></i>
</div> -->
</nav>
<!-- navbar ends here -->
<div id="loader" class="loader show">
<div class="loader-body">
<img alt="loader-img" src="./assets/images/loader.gif" />
<p>Loading your data...</p>
</div>
</div>
<div class="code-content-body">
<div class="barcode-table-header">
<div class="title">
QR code
<span id="today-date" class="small-text">- (generated on </span>
</div>
<div class="right-container">
<div class="button">
<a class="trigger" href="#">Generate</a>
</div>
<div class="button">
<a class="trigger" id="print-barcodes-table" href="#">Print</a>
</div>
<select name="filter" id="filter-barcodes">
<option value="">Filter</option>
<option value="today">Today</option>
<option value="week">This week</option>
</select>
</div>
</div>
<table id="barcodes-main-table">
<thead>
<tr>
<th class="topic print">Code</th>
<th class="topic print">Checked In</th>
<th class="topic print">Checked Out</th>
<th class="topic print">QR</th>
</tr>
</thead>
<tbody id="barcode-table-data"></tbody>
</table>
<div class="modal">
<div class="modal-content">
<span class="close-button"><i class="bx bx-x"></i></span>
<h1>Generate barcodes for today</h1>
<hr />
<div class="input-section">
<div>
<label>Set how many codes you want to generate for today</label>
</div>
<div>
<input type="number" id="max_num" name="max_num" value="25">
</div>
</div>
<div class="btn-section">
<button id="submit-btn" class="submit-btn">Generate</button>
</div>
</div>
</div>
</div>
</section>
<script src="./js/date.js"></script>
<script src="./js/generate_dashboard_table.js"></script>
<script src="./js/utils.js"></script>
<script src="./js/firebase.js"></script>
<script src="./js/print.min.js"></script>
<!-- Firebase sdk setup -->
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp, } from "https://www.gstatic.com/firebasejs/9.6.10/firebase-app.js";
import {
getFirestore,
getDocs,
collection,
addDoc,
setDoc,
updateDoc,
deleteDoc,
doc,
query,
where,
} from "https://www.gstatic.com/firebasejs/9.6.10/firebase-firestore.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: config.apiKey,
authDomain: config.authDomain,
projectId: config.projectId,
storageBucket: config.storageBucket,
messagingSenderId: config.messagingSenderId,
appId: config.appId
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
//Firestore connection
const database = getFirestore();
const getBarcodesQuery = () => {
const q = query(collection(database, BARCODE), where("date", "==", getTodayDate()));
return getDocs(q);
};
// This function runs the query and resolves the result
const getBarcodes = async () => {
const querySnapshot = await getBarcodesQuery();
let barcodes = [];
querySnapshot.forEach((doc) => {
barcodes.push({ ...doc.data() });
});
return barcodes;
}
const getFilterBarcodesQuery = (filterData) => {
const q = query(collection(database, BARCODE), where("date", "in", filterData));
return getDocs(q);
};
const getFilterBarcodes = async (filterData) => {
const querySnapshot = await getFilterBarcodesQuery(filterData);
console.log(querySnapshot);
let barcodes = [];
querySnapshot.forEach((doc) => {
barcodes.push({ ...doc.data() });
});
return barcodes;
}
//function to save input
const addBarcodeQuery = async (codeData) => {
const newIdRef = await doc(collection(database, BARCODE));
codeData.id = newIdRef.id;
return setDoc(newIdRef, codeData);
};
const addBarcode = async (codeData) => {
try {
const querySnapshot = await addBarcodeQuery(codeData);
console.log("Barcode added");
} catch (error) {
console.log("Opps! could not fetch barcode");
}
}
// Get all data when page loads
let [
barcodes,
] = await Promise.all(
[
getBarcodes(),
]
);
// hide loader when the data arrives
let loaderElement = document.getElementById("loader");
if (typeof barcodes == "object") {
loaderElement.classList.remove("show");
loaderElement.classList.add("hide");
}
let tableBody = document.getElementById("barcode-table-data").innerHTML + generate_barcode(barcodes);
document.getElementById("barcode-table-data").innerHTML = tableBody;
const saveCode = async () => {
//Close the modal
document.querySelector(".close-button").click();
//toggle loader
loaderElement.classList.add("show");
loaderElement.classList.remove("hide");
const maxCodes = document.getElementById("max_num").value;
const codes = generate_unique_code(parseInt(maxCodes));
try {
codes.forEach((code) => {
let barcode = {
code: code,
date: getTodayDate(),
checked_out: false,
checked_in: false,
created_by: "jsnjsnnfjh"
}
addBarcode(barcode);
});
// get new barcodes and add to table
let newBarcodes = await getBarcodes();
document.getElementById("barcode-table-data").innerHTML = generate_barcode(newBarcodes);
//toggle loader
loaderElement.classList.remove("show");
loaderElement.classList.add("hide");
} catch (error) {
console.error(error)
}
}
let codeBtn = document.getElementById("submit-btn");
codeBtn.addEventListener("click", saveCode);
// Filter barcode in table
let filterSelect = document.getElementById("filter-barcodes");
filterSelect.addEventListener("change", async (event) => {
let value = event.srcElement.value;
switch (value) {
case "today":
let todayBarcodes = await getBarcodes();
document.getElementById("barcode-table-data").innerHTML = generate_barcode(todayBarcodes);
break;
case "week":
let weekBarcodes = await getFilterBarcodes(getThisWeekDate());
document.getElementById("barcode-table-data").innerHTML = generate_barcode(weekBarcodes);
break;
default:
break;
}
});
</script>
<script>
// Print button functionality
let focuser = setInterval(() => window.dispatchEvent(new Event('focus')), 500);
let printBtn = document.getElementById("print-barcodes-table");
printBtn.addEventListener('click', (e) => {
let printables = document.querySelectorAll(".print");
printables.forEach(printEl => {
printEl.classList.remove("print");
printEl.classList.add("no-print");
});
printJS({
printable: 'barcodes-main-table',
type: 'html',
onPrintDialogClose: () => {
clearInterval(focuser);
printables.forEach(printEl => {
printEl.classList.add("print");
printEl.classList.remove("no-print");
});
}
});
});
</script>
<script>
// modal functionality
const modal = document.querySelector(".modal");
const trigger = document.querySelector(".trigger");
const closeButton = document.querySelector(".close-button");
const toggleModal = () => {
modal.classList.toggle("show-modal");
}
function windowOnClick(event) {
if (event.target === modal) {
toggleModal(modal);
}
}
trigger.addEventListener("click", toggleModal);
closeButton.addEventListener("click", toggleModal);
window.addEventListener("click", windowOnClick);
</script>
<script>
let sidebar = document.querySelector(".sidebar");
let sidebarBtn = document.querySelector(".sidebarBtn");
sidebarBtn.onclick = function () {
sidebar.classList.toggle("active");
if (sidebar.classList.contains("active")) {
sidebarBtn.classList.replace("bx-menu", "bx-menu-alt-right");
} else
sidebarBtn.classList.replace("bx-menu-alt-right", "bx-menu");
}
let tableTitle = document.getElementById("today-date");
tableTitle.innerText = tableTitle.innerText + getTodayDate() + ")";
</script>
</body>
</html>