-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
454 lines (402 loc) · 14 KB
/
admin.html
File metadata and controls
454 lines (402 loc) · 14 KB
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CW Admin Dashboard | Inventory Control</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
<style>
/* Admin specific overrides */
.admin-table {
width: 100%;
border-collapse: separate;
border-spacing: 0 8px;
margin-top: 16px;
}
.admin-table th {
padding: 12px 16px;
text-align: left;
font-size: 11px;
text-transform: uppercase;
color: var(--muted);
letter-spacing: 1px;
}
.admin-table td {
background: rgba(30, 41, 59, 0.4);
padding: 16px;
border-top: 1px solid var(--border);
border-bottom: 1px solid var(--border);
}
.admin-table td:first-child {
border-left: 1px solid var(--border);
border-radius: 12px 0 0 12px;
}
.admin-table td:last-child {
border-right: 1px solid var(--border);
border-radius: 0 12px 12px 0;
}
.tab-btn {
background: transparent;
border: 1px solid var(--border);
color: var(--muted);
padding: 8px 20px;
border-radius: 10px;
cursor: pointer;
transition: var(--transition);
}
.tab-btn.active {
background: var(--primary);
color: white;
border-color: var(--primary);
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.stat-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.stat-card {
background: rgba(255, 255, 255, 0.03);
border: 1px solid var(--border);
padding: 24px;
border-radius: 20px;
text-align: center;
}
.stat-value {
font-size: 32px;
font-weight: 700;
color: var(--primary);
display: block;
}
.stat-label {
font-size: 12px;
text-transform: uppercase;
color: var(--muted);
letter-spacing: 1px;
margin-top: 4px;
display: block;
}
</style>
</head>
<body>
<!-- LOGIN SCREEN -->
<div id="loginBox" class="login-screen animate-fade">
<div class="card login-card">
<h2 style="justify-content: center">🔐 Admin Access</h2>
<p style="color: var(--muted); margin-bottom: 24px; font-size: 14px;">Please enter your credentials to manage
inventory.</p>
<div class="input-group" style="text-align: left">
<label>Master Password</label>
<input type="password" id="pass" placeholder="••••••••">
</div>
<button class="btn btn-primary" onclick="login()" style="width: 100%; margin-top: 24px;">
Enter Dashboard
</button>
<div id="error" style="color: var(--danger); font-size: 13px; margin-top: 16px; font-weight: 500;"></div>
</div>
</div>
<!-- DASHBOARD -->
<div id="appBox" class="container animate-fade" style="display: none">
<header>
<div>
<h1>⚡ Admin<span>Panel</span></h1>
<div class="subtitle">Management Console</div>
</div>
<button class="btn btn-danger" onclick="logout()" style="padding: 8px 16px; font-size: 13px;">
Logout
</button>
</header>
<div style="display: flex; gap: 12px; margin-bottom: 32px;">
<button class="tab-btn active" onclick="openTab(1, this)">📦 Products</button>
<button class="tab-btn" onclick="openTab(2, this)">👤 Submissions</button>
</div>
<!-- PRODUCTS TAB -->
<div id="tab1" class="tab-content active">
<div class="card">
<h2>Add New Product</h2>
<div class="form-grid">
<div class="input-group">
<label>Product Name</label>
<input id="pName" placeholder="e.g. Arduino Uno">
</div>
<div class="input-group">
<label>Category</label>
<select id="pCat">
<option value="Microcontrollers">Microcontrollers</option>
<option value="Sensors">Sensors</option>
<option value="Actuators">Actuators</option>
<option value="Power">Power</option>
<option value="Mechanical">Mechanical</option>
<option value="Other">Other</option>
</select>
</div>
<div class="input-group">
<label>Initial Stock</label>
<input id="pStock" type="number" placeholder="0">
</div>
</div>
<div style="text-align: right">
<button class="btn btn-primary" onclick="addProduct()">➕ Register Product</button>
</div>
</div>
<div class="card">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2 style="margin: 0">Inventory Status</h2>
<button class="btn btn-primary" style="padding: 6px 12px; font-size: 12px;" onclick="loadProducts()">🔄
Refresh</button>
</div>
<div style="overflow-x: auto">
<table class="admin-table" id="prodTable">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Category</th>
<th>Stock</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<!-- Rows added by JS -->
</tbody>
</table>
</div>
</div>
</div>
<!-- SUBMISSIONS TAB -->
<div id="tab2" class="tab-content">
<div class="stat-grid">
<div class="stat-card">
<span class="stat-value" id="stat-active">0</span>
<span class="stat-label">Active Issues</span>
</div>
<div class="stat-card">
<span class="stat-value" id="stat-overdue" style="color: var(--danger)">0</span>
<span class="stat-label">Overdue Items</span>
</div>
<div class="stat-card">
<span class="stat-value" id="stat-popular">---</span>
<span class="stat-label">Popular Item</span>
</div>
</div>
<div class="card">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2 style="margin: 0">Usage History</h2>
<div style="display: flex; gap: 12px;">
<input type="text" id="subSearch" placeholder="Search students..."
style="padding: 6px 12px; font-size: 13px;" oninput="filterSubs()">
<button class="btn btn-primary" style="padding: 6px 12px; font-size: 12px;" onclick="loadSubs()">🔄
Refresh</button>
</div>
</div>
<div style="overflow-x: auto">
<table class="admin-table" id="subTable">
<thead>
<tr>
<th>Timestamp</th>
<th>Name</th>
<th>Contact</th>
<th>Items</th>
<th>Return Date</th>
</tr>
</thead>
<tbody>
<!-- Rows added by JS -->
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
const API = "https://script.google.com/macros/s/AKfycbwd_xE9NtNjLAjfYWZLjygRijPxFm090e2zYNNlkvJk8X-m-NbKu5AbREWR-sdJr0YQTw/exec";
const PASSWORD = "cwstock";
let allSubs = [];
/* AUTH */
function login() {
const pass = document.getElementById("pass").value;
const error = document.getElementById("error");
if (pass === PASSWORD) {
document.getElementById("loginBox").style.display = "none";
document.getElementById("appBox").style.display = "block";
loadProducts();
loadSubs();
} else {
error.innerText = "Invalid master password. Please try again.";
}
}
function logout() {
location.reload();
}
/* NAVIGATION */
function openTab(id, btn) {
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
document.getElementById('tab' + id).classList.add('active');
btn.classList.add('active');
}
/* PRODUCTS */
async function loadProducts() {
try {
const r = await fetch(API + "?action=getProducts");
const data = await r.json();
const tbody = document.querySelector("#prodTable tbody");
tbody.innerHTML = "";
data.forEach(p => {
const tr = document.createElement("tr");
tr.innerHTML = `
<td style="font-weight: 600; color: var(--primary)">#${p[0]}</td>
<td><b>${p[1]}</b></td>
<td><span style="font-size: 12px; background: rgba(255,255,255,0.05); padding: 4px 8px; border-radius: 6px;">${p[2]}</span></td>
<td>
<div style="display: flex; align-items: center; gap: 10px;">
<input id="s${p[0]}" type="number" value="${p[3]}" style="width: 80px; padding: 6px 10px; ${p[3] < 3 ? 'border-color: var(--danger)' : ''}">
${p[3] < 3 ? '<span class="badge badge-low">Low</span>' : ''}
</div>
</td>
<td style="display: flex; gap: 8px;">
<button class="btn btn-success" style="padding: 6px 10px; font-size: 12px;" onclick="updateProduct(${p[0]})">Save</button>
<button class="btn btn-danger" style="padding: 6px 10px; font-size: 12px;" onclick="deleteProduct(${p[0]})">Delete</button>
</td>
`;
tbody.appendChild(tr);
});
} catch (e) {
alert("Error loading products");
}
}
async function addProduct() {
const name = document.getElementById("pName").value;
const cat = document.getElementById("pCat").value;
const stock = document.getElementById("pStock").value;
if (!name || !stock) return alert("Please fill all fields");
try {
await fetch(API, {
method: "POST",
mode: "no-cors",
body: JSON.stringify({
action: "addProduct",
name, category: cat, stock
})
});
alert("Product added successfully");
document.getElementById("pName").value = "";
document.getElementById("pStock").value = "";
loadProducts();
} catch (e) {
alert("Error adding product");
}
}
async function updateProduct(id) {
const stock = document.getElementById("s" + id).value;
try {
await fetch(API, {
method: "POST",
mode: "no-cors",
body: JSON.stringify({
action: "updateStock",
id, stock
})
});
alert("Product updated");
loadProducts();
} catch (e) {
alert("Error updating product");
}
}
async function deleteProduct(id) {
if (!confirm("Are you sure you want to delete this product?")) return;
try {
await fetch(API, {
method: "POST",
mode: "no-cors",
body: JSON.stringify({
action: "deleteProduct",
id
})
});
alert("Product deleted");
loadProducts();
} catch (e) {
alert("Error deleting product");
}
}
/* SUBMISSIONS */
async function loadSubs() {
try {
const r = await fetch(API + "?action=getSubs");
allSubs = await r.json();
updateStats(allSubs);
renderSubs(allSubs);
} catch (e) {
alert("Error loading submissions");
}
}
function renderSubs(subs) {
const tbody = document.querySelector("#subTable tbody");
tbody.innerHTML = "";
const today = new Date();
today.setHours(0, 0, 0, 0);
subs.forEach(row => {
const returnDate = new Date(row[9]);
const isOverdue = returnDate < today;
const tr = document.createElement("tr");
tr.innerHTML = `
<td style="font-size: 12px; color: var(--muted)">${row[0]}</td>
<td><b>${row[1]}</b><br><small style="color: var(--muted)">${row[2]}</small></td>
<td>${row[3]}<br><small style="color: var(--muted)">${row[4]}</small></td>
<td style="max-width: 200px; font-size: 13px;">${row[5]}</td>
<td style="color: ${isOverdue ? 'var(--danger)' : 'var(--primary)'}; font-weight: 500;">
${row[9]}
${isOverdue ? '<span class="badge badge-overdue" style="display:block; margin-top:4px; max-width:80px">Overdue</span>' : ''}
</td>
`;
tbody.appendChild(tr);
});
}
function filterSubs() {
const term = document.getElementById('subSearch').value.toLowerCase();
const filtered = allSubs.filter(s =>
s[1].toLowerCase().includes(term) ||
s[3].toLowerCase().includes(term) ||
s[5].toLowerCase().includes(term)
);
renderSubs(filtered);
}
function updateStats(subs) {
const today = new Date();
today.setHours(0, 0, 0, 0);
let overdue = 0;
let itemCounts = {};
subs.forEach(s => {
const d = new Date(s[9]);
if (d < today) overdue++;
// Basic popularity logic (count mentions in items string)
// Note: This is a proxy since items are stored as strings
const items = s[5].split('•').filter(i => i.trim());
items.forEach(i => {
const name = i.split('x')[0].trim();
itemCounts[name] = (itemCounts[name] || 0) + 1;
});
});
document.getElementById('stat-active').innerText = subs.length;
document.getElementById('stat-overdue').innerText = overdue;
let popular = "---";
let max = 0;
for (let name in itemCounts) {
if (itemCounts[name] > max) {
max = itemCounts[name];
popular = name;
}
}
document.getElementById('stat-popular').innerText = popular;
}
</script>
</body>
</html>