-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
490 lines (425 loc) Β· 15.1 KB
/
index.html
File metadata and controls
490 lines (425 loc) Β· 15.1 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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fresh Cart - Inventory Dashboard</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1400px;
margin: 0 auto;
}
header {
background: white;
padding: 30px;
border-radius: 15px;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
margin-bottom: 30px;
text-align: center;
}
h1 {
color: #667eea;
font-size: 2.5em;
margin-bottom: 10px;
}
.subtitle {
color: #666;
font-size: 1.1em;
}
.dashboard {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.card {
background: white;
padding: 25px;
border-radius: 15px;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.card h2 {
color: #667eea;
margin-bottom: 15px;
font-size: 1.5em;
border-bottom: 2px solid #667eea;
padding-bottom: 10px;
}
.stat {
display: flex;
justify-content: space-between;
padding: 10px 0;
border-bottom: 1px solid #eee;
}
.stat:last-child {
border-bottom: none;
}
.stat-label {
color: #666;
font-weight: 500;
}
.stat-value {
color: #333;
font-weight: bold;
}
.status-live {
color: #22c55e;
font-weight: bold;
}
.status-dead {
color: #ef4444;
font-weight: bold;
}
.controls {
background: white;
padding: 20px;
border-radius: 15px;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
margin-bottom: 30px;
display: flex;
gap: 15px;
flex-wrap: wrap;
align-items: center;
}
.controls input, .controls select, .controls button {
padding: 12px 20px;
border: 2px solid #667eea;
border-radius: 8px;
font-size: 1em;
}
.controls input, .controls select {
flex: 1;
min-width: 200px;
}
.controls button {
background: #667eea;
color: white;
cursor: pointer;
font-weight: bold;
transition: all 0.3s;
}
.controls button:hover {
background: #764ba2;
transform: translateY(-2px);
}
.products-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.product-card {
background: white;
border-radius: 15px;
padding: 20px;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
transition: transform 0.3s, box-shadow 0.3s;
}
.product-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}
.product-name {
font-weight: bold;
color: #333;
margin-bottom: 10px;
font-size: 1.1em;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.product-info {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
font-size: 0.9em;
margin-top: 10px;
}
.product-info div {
padding: 5px;
background: #f8f9fa;
border-radius: 5px;
}
.price {
color: #22c55e;
font-weight: bold;
font-size: 1.3em;
}
.stock {
color: #667eea;
font-weight: bold;
}
.loading {
text-align: center;
padding: 50px;
font-size: 1.2em;
color: white;
}
.error {
background: #fee;
color: #c00;
padding: 15px;
border-radius: 8px;
margin: 20px 0;
border: 2px solid #c00;
}
.pagination {
display: flex;
justify-content: center;
gap: 10px;
margin: 30px 0;
}
.pagination button {
padding: 10px 20px;
background: white;
border: 2px solid #667eea;
border-radius: 8px;
color: #667eea;
cursor: pointer;
font-weight: bold;
transition: all 0.3s;
}
.pagination button:hover:not(:disabled) {
background: #667eea;
color: white;
}
.pagination button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.analytics-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
}
.analytics-card {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 25px;
border-radius: 15px;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.analytics-card h3 {
font-size: 2.5em;
margin-bottom: 10px;
}
.analytics-card p {
font-size: 1.1em;
opacity: 0.9;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>π Fresh Cart</h1>
<p class="subtitle">Distributed Inventory Management System</p>
</header>
<div class="dashboard">
<div class="card">
<h2>π₯οΈ Cluster Status</h2>
<div id="clusterStatus">
<div class="loading">Loading...</div>
</div>
</div>
<div class="card">
<h2>π System Stats</h2>
<div id="systemStats">
<div class="loading">Loading...</div>
</div>
</div>
<div class="card">
<h2>π° Inventory Value</h2>
<div id="inventoryValue">
<div class="loading">Loading...</div>
</div>
</div>
</div>
<div class="card" style="margin-bottom: 30px;">
<h2>π Regional Analytics</h2>
<div id="analytics" class="analytics-grid">
<div class="loading">Loading...</div>
</div>
</div>
<div class="controls">
<input type="text" id="searchInput" placeholder="Search products...">
<select id="regionFilter">
<option value="">All Regions</option>
<option value="North">North</option>
<option value="South">South</option>
<option value="East">East</option>
<option value="West">West</option>
</select>
<select id="warehouseFilter">
<option value="">All Warehouses</option>
<option value="WH-1">WH-1</option>
<option value="WH-2">WH-2</option>
<option value="WH-3">WH-3</option>
<option value="WH-4">WH-4</option>
<option value="WH-5">WH-5</option>
<option value="WH-6">WH-6</option>
</select>
<button onclick="loadProducts()">π Search</button>
<button onclick="resetFilters()">π Reset</button>
</div>
<div class="products-grid" id="productsGrid">
<div class="loading">Loading products...</div>
</div>
<div class="pagination" id="pagination"></div>
</div>
<script>
const API_URL = 'http://localhost:5000';
let current_page = 1;
const limit = 12;
async function loadClusterStatus() {
try {
const response = await fetch(`${API_URL}/api/cluster/status`);
const data = await response.json();
let html = '';
data.cluster.nodes.forEach(node => {
const status = node.is_live ?
'<span class="status-live">β LIVE</span>' :
'<span class="status-dead">β DEAD</span>';
html += `
<div class="stat">
<span class="stat-label">Node ${node.node_id}</span>
<span class="stat-value">${status}</span>
</div>
`;
});
document.getElementById('clusterStatus').innerHTML = html;
} catch (error) {
document.getElementById('clusterStatus').innerHTML =
'<div class="error">Failed to load cluster status</div>';
}
}
async function loadSystemStats() {
try {
const response = await fetch(`${API_URL}/api/products?limit=1`);
const data = await response.json();
const html = `
<div class="stat">
<span class="stat-label">Total Products</span>
<span class="stat-value">${data.pagination.total.toLocaleString()}</span>
</div>
<div class="stat">
<span class="stat-label">Total Pages</span>
<span class="stat-value">${data.pagination.total_pages.toLocaleString()}</span>
</div>
<div class="stat">
<span class="stat-label">Query Time</span>
<span class="stat-value">${data.query_time_ms}ms</span>
</div>
`;
document.getElementById('systemStats').innerHTML = html;
} catch (error) {
document.getElementById('systemStats').innerHTML =
'<div class="error">Failed to load stats</div>';
}
}
async function loadAnalytics() {
try {
const response = await fetch(`${API_URL}/api/analytics/inventory`);
const data = await response.json();
let html = '';
let total_value = 0;
data.data.forEach(region => {
total_value += parseFloat(region.inventory_value);
html += `
<div class="analytics-card">
<h3>${region.region}</h3>
<p>${region.product_count} products</p>
<p>${parseInt(region.total_stock).toLocaleString()} units</p>
<p>$${parseFloat(region.inventory_value).toLocaleString()}</p>
</div>
`;
});
document.getElementById('analytics').innerHTML = html;
document.getElementById('inventoryValue').innerHTML = `
<div class="stat">
<span class="stat-label">Total Value</span>
<span class="stat-value">$${total_value.toLocaleString()}</span>
</div>
<div class="stat">
<span class="stat-label">Regions</span>
<span class="stat-value">${data.data.length}</span>
</div>
`;
} catch (error) {
document.getElementById('analytics').innerHTML =
'<div class="error">Failed to load analytics</div>';
}
}
async function loadProducts(page = 1) {
current_page = page;
const region = document.getElementById('regionFilter').value;
const warehouse = document.getElementById('warehouseFilter').value;
const search = document.getElementById('searchInput').value.trim();
let url = `${API_URL}/api/products?page=${page}&limit=${limit}`;
if (region) url += `®ion=${region}`;
if (warehouse) url += `&warehouse=${warehouse}`;
if (search) url += `&search=${encodeURIComponent(search)}`;
try {
const response = await fetch(url);
const data = await response.json();
let html = '';
data.data.forEach(product => {
html += `
<div class="product-card">
<div class="product-name">${product.name}</div>
<div class="price">$${parseFloat(product.price).toFixed(2)}</div>
<div class="product-info">
<div>π ${product.region}</div>
<div>π ${product.warehouse}</div>
<div class="stock">π¦ ${product.stock} units</div>
<div>π·οΈ ${product.category?.substring(0, 20) || 'General'}</div>
</div>
</div>
`;
});
document.getElementById('productsGrid').innerHTML = html;
const pagination_html = `
<button onclick="loadProducts(${page - 1})" ${!data.pagination.has_prev ? 'disabled' : ''}>
β Previous
</button>
<button disabled>
Page ${page} of ${data.pagination.total_pages}
</button>
<button onclick="loadProducts(${page + 1})" ${!data.pagination.has_next ? 'disabled' : ''}>
Next β
</button>
`;
document.getElementById('pagination').innerHTML = pagination_html;
} catch (error) {
document.getElementById('productsGrid').innerHTML =
'<div class="error">Failed to load products</div>';
}
}
function resetFilters() {
document.getElementById('searchInput').value = '';
document.getElementById('regionFilter').value = '';
document.getElementById('warehouseFilter').value = '';
loadProducts(1);
}
window.onload = function() {
loadClusterStatus();
loadSystemStats();
loadAnalytics();
loadProducts();
setInterval(loadClusterStatus, 10000);
};
</script>
</body>
</html>