-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-sync.html
More file actions
859 lines (752 loc) · 33.4 KB
/
admin-sync.html
File metadata and controls
859 lines (752 loc) · 33.4 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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PacMac Mobile - Admin Sync</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 12px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
text-align: center;
}
.header h1 {
font-size: 2.5rem;
margin-bottom: 10px;
}
.header p {
opacity: 0.9;
font-size: 1.1rem;
}
.content {
padding: 30px;
}
.sync-section {
background: #f8f9fa;
border-radius: 8px;
padding: 25px;
margin-bottom: 25px;
}
.sync-section h2 {
color: #333;
margin-bottom: 15px;
font-size: 1.5rem;
}
.sync-section p {
color: #666;
margin-bottom: 20px;
line-height: 1.6;
}
.btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 12px 24px;
border-radius: 6px;
cursor: pointer;
font-size: 1rem;
font-weight: 600;
transition: all 0.3s ease;
margin-right: 10px;
margin-bottom: 10px;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
}
.btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.btn-secondary {
background: #6c757d;
}
.btn-success {
background: #28a745;
}
.btn-warning {
background: #ffc107;
color: #333;
}
.btn-info {
background: #17a2b8;
}
/* Form Input Styling */
input, textarea, select {
background: #ffffff !important;
color: #333333 !important;
border: 2px solid #e0e0e0 !important;
border-radius: 6px !important;
padding: 12px !important;
font-size: 14px !important;
font-family: inherit !important;
transition: all 0.3s ease !important;
width: 100% !important;
box-sizing: border-box !important;
}
input:focus, textarea:focus, select:focus {
border-color: #667eea !important;
outline: none !important;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
background: #ffffff !important;
}
input::placeholder, textarea::placeholder {
color: #999999 !important;
opacity: 1 !important;
}
/* Label styling */
label {
color: #333333 !important;
font-weight: 600 !important;
margin-bottom: 8px !important;
display: block !important;
}
/* Autofill styling */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
-webkit-box-shadow: 0 0 0 30px #ffffff inset !important;
-webkit-text-fill-color: #333333 !important;
background-color: #ffffff !important;
border: 2px solid #e0e0e0 !important;
}
/* Form container styling */
.form-container {
background: #ffffff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
/* Button improvements */
.btn {
font-weight: 600 !important;
text-transform: none !important;
letter-spacing: 0.5px !important;
}
/* Status message improvements */
.status {
font-weight: 500 !important;
border-radius: 8px !important;
}
.status {
padding: 15px;
border-radius: 6px;
margin: 15px 0;
font-weight: 500;
}
.status.success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.status.error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.status.info {
background: #d1ecf1;
color: #0c5460;
border: 1px solid #bee5eb;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
margin: 20px 0;
}
.stat-card {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
text-align: center;
}
.stat-card h3 {
color: #333;
margin-bottom: 10px;
}
.stat-card .number {
font-size: 2rem;
font-weight: bold;
color: #667eea;
margin-bottom: 5px;
}
.stat-card .label {
color: #666;
font-size: 0.9rem;
}
.log {
background: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 6px;
padding: 15px;
margin: 20px 0;
max-height: 300px;
overflow-y: auto;
font-family: 'Courier New', monospace;
font-size: 0.9rem;
}
.log-entry {
margin-bottom: 5px;
padding: 2px 0;
}
.log-entry.success {
color: #28a745;
}
.log-entry.error {
color: #dc3545;
}
.log-entry.info {
color: #17a2b8;
}
.log-entry.warning {
color: #ffc107;
}
.loading {
display: inline-block;
width: 20px;
height: 20px;
border: 3px solid #f3f3f3;
border-top: 3px solid #667eea;
border-radius: 50%;
animation: spin 1s linear infinite;
margin-right: 10px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.hidden {
display: none;
}
.connection-status {
display: flex;
align-items: center;
margin-bottom: 20px;
}
.status-indicator {
width: 12px;
height: 12px;
border-radius: 50%;
margin-right: 10px;
}
.status-indicator.connected {
background: #28a745;
}
.status-indicator.disconnected {
background: #dc3545;
}
.status-indicator.connecting {
background: #ffc107;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🔄 Admin Sync</h1>
<p>Sync inventory between frontend and backend systems</p>
</div>
<div class="content">
<!-- Connection Status -->
<div class="connection-status">
<div class="status-indicator" id="connection-status"></div>
<span id="connection-text">Checking connection...</span>
</div>
<!-- Sync Section -->
<div class="sync-section">
<h2>🔄 Inventory Sync</h2>
<p>Sync your inventory data between the frontend e-commerce site and the backend admin portal. This ensures that product information, stock levels, and pricing are consistent across both systems.</p>
<button class="btn" id="sync-btn" onclick="startSync()">
<span class="loading hidden" id="sync-loading"></span>
Sync with Backend
</button>
<button class="btn btn-secondary" onclick="refreshStats()">Refresh Stats</button>
<button class="btn btn-warning" onclick="exportData()">Export Data</button>
<div id="sync-status"></div>
</div>
<!-- Product Management Section -->
<div class="sync-section">
<h2>📦 Product Management</h2>
<p>Create, update, and manage products directly through the API. This allows you to add new products to your inventory system.</p>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 20px 0;">
<div class="form-container">
<h3 style="color: #333; margin-bottom: 20px;">Create New Product</h3>
<form id="product-form" onsubmit="createProduct(event)">
<div style="margin-bottom: 15px;">
<label style="display: block; margin-bottom: 5px; font-weight: 600; color: #333;">Product Name *</label>
<input type="text" id="product-name" required placeholder="e.g., iPhone 15 Pro Max" autocomplete="off">
</div>
<div style="margin-bottom: 15px;">
<label style="display: block; margin-bottom: 5px; font-weight: 600; color: #333;">Brand</label>
<input type="text" id="product-brand" placeholder="e.g., Apple, Samsung, Google" autocomplete="off">
</div>
<div style="margin-bottom: 15px;">
<label style="display: block; margin-bottom: 5px; font-weight: 600; color: #333;">Model</label>
<input type="text" id="product-model" placeholder="e.g., iPhone 15 Pro Max 256GB" autocomplete="off">
</div>
<div style="margin-bottom: 15px;">
<label style="display: block; margin-bottom: 5px; font-weight: 600; color: #333;">Price *</label>
<input type="number" id="product-price" step="0.01" required placeholder="0.00" autocomplete="off">
</div>
<div style="margin-bottom: 15px;">
<label style="display: block; margin-bottom: 5px; font-weight: 600; color: #333;">Description</label>
<textarea id="product-description" rows="3" placeholder="Enter product description..."></textarea>
</div>
<div style="margin-bottom: 15px;">
<label style="display: block; margin-bottom: 5px; font-weight: 600; color: #333;">Image URL</label>
<input type="url" id="product-image" placeholder="https://example.com/image.jpg" autocomplete="off">
</div>
<div style="margin-bottom: 15px;">
<label style="display: block; margin-bottom: 5px; font-weight: 600; color: #333;">Stock Count</label>
<input type="number" id="product-stock" value="0" min="0" placeholder="0" autocomplete="off">
</div>
<div style="margin-bottom: 15px;">
<label style="display: block; margin-bottom: 5px; font-weight: 600; color: #333;">Category</label>
<select id="product-category">
<option value="main">Main Product</option>
<option value="accessory">Accessory</option>
<option value="refurbished">Refurbished</option>
</select>
</div>
<div style="margin-bottom: 15px;">
<button type="button" class="btn btn-info" onclick="autofillProductInfo()">🔍 Autofill from Web</button>
<button type="button" class="btn btn-secondary" onclick="clearForm()">Clear Form</button>
</div>
<button type="submit" class="btn btn-success">Create Product</button>
</form>
</div>
<div class="form-container">
<h3 style="color: #333; margin-bottom: 20px;">Quick Test</h3>
<p style="color: #666; margin-bottom: 15px;">Test the product creation API with sample data:</p>
<button class="btn btn-secondary" onclick="testProductCreation()">Test Create Product</button>
<button class="btn btn-secondary" onclick="testProductUpdate()">Test Update Product</button>
<button class="btn btn-secondary" onclick="testProductDelete()">Test Delete Product</button>
<div id="test-results" style="margin-top: 15px; padding: 10px; background: #f8f9fa; border-radius: 4px; font-family: monospace; font-size: 0.9rem;"></div>
</div>
</div>
</div>
<!-- Statistics -->
<div class="sync-section">
<h2>📊 Inventory Statistics</h2>
<div class="stats-grid" id="stats-grid">
<div class="stat-card">
<div class="number" id="total-products">-</div>
<div class="label">Total Products</div>
</div>
<div class="stat-card">
<div class="number" id="in-stock">-</div>
<div class="label">In Stock</div>
</div>
<div class="stat-card">
<div class="number" id="out-of-stock">-</div>
<div class="label">Out of Stock</div>
</div>
<div class="stat-card">
<div class="number" id="total-value">-</div>
<div class="label">Total Value</div>
</div>
</div>
</div>
<!-- Activity Log -->
<div class="sync-section">
<h2>📝 Activity Log</h2>
<div class="log" id="activity-log">
<div class="log-entry info">System initialized. Ready to sync.</div>
</div>
<button class="btn btn-secondary" onclick="clearLog()">Clear Log</button>
</div>
</div>
</div>
<script src="admin-integration.js"></script>
<script>
let isConnected = false;
let syncInProgress = false;
// Initialize the admin sync interface
document.addEventListener('DOMContentLoaded', function() {
checkConnection();
loadStats();
});
// Check connection to backend
async function checkConnection() {
const statusIndicator = document.getElementById('connection-status');
const statusText = document.getElementById('connection-text');
statusIndicator.className = 'status-indicator connecting';
statusText.textContent = 'Checking connection...';
try {
// In production, this would check the actual backend connection
await new Promise(resolve => setTimeout(resolve, 1000)); // Simulate API call
isConnected = true;
statusIndicator.className = 'status-indicator connected';
statusText.textContent = 'Connected to backend admin portal';
addLogEntry('Connection established with backend admin portal', 'success');
} catch (error) {
isConnected = false;
statusIndicator.className = 'status-indicator disconnected';
statusText.textContent = 'Connection failed - using local data';
addLogEntry('Failed to connect to backend admin portal', 'error');
}
}
// Start sync process
async function startSync() {
if (syncInProgress) return;
syncInProgress = true;
const syncBtn = document.getElementById('sync-btn');
const syncLoading = document.getElementById('sync-loading');
const syncStatus = document.getElementById('sync-status');
syncBtn.disabled = true;
syncLoading.classList.remove('hidden');
syncBtn.textContent = 'Syncing...';
addLogEntry('Starting sync with backend admin portal...', 'info');
try {
const success = await window.adminIntegration.syncWithBackend();
if (success) {
syncStatus.innerHTML = '<div class="status success">✅ Sync completed successfully!</div>';
addLogEntry('Sync completed successfully', 'success');
await loadStats(); // Refresh statistics
} else {
syncStatus.innerHTML = '<div class="status error">❌ Sync failed. Check the log for details.</div>';
addLogEntry('Sync failed', 'error');
}
} catch (error) {
syncStatus.innerHTML = '<div class="status error">❌ Sync failed: ' + error.message + '</div>';
addLogEntry('Sync failed: ' + error.message, 'error');
} finally {
syncInProgress = false;
syncBtn.disabled = false;
syncLoading.classList.add('hidden');
syncBtn.innerHTML = '<span class="loading hidden" id="sync-loading"></span>Sync with Backend';
}
}
// Load and display statistics
async function loadStats() {
try {
const stats = await window.adminIntegration.getBackendStats();
document.getElementById('total-products').textContent = stats.totalProducts;
document.getElementById('in-stock').textContent = stats.inStockProducts;
document.getElementById('out-of-stock').textContent = stats.outOfStockProducts;
document.getElementById('total-value').textContent = '$' + stats.totalValue.toFixed(2);
addLogEntry('Statistics updated', 'info');
} catch (error) {
addLogEntry('Failed to load statistics: ' + error.message, 'error');
}
}
// Refresh statistics
async function refreshStats() {
addLogEntry('Refreshing statistics...', 'info');
await loadStats();
}
// Export data
async function exportData() {
try {
addLogEntry('Exporting inventory data...', 'info');
const exportData = await window.adminIntegration.exportInventory();
// Create and download file
const blob = new Blob([JSON.stringify(exportData, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `pacmac-inventory-export-${new Date().toISOString().split('T')[0]}.json`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
addLogEntry('Inventory data exported successfully', 'success');
} catch (error) {
addLogEntry('Export failed: ' + error.message, 'error');
}
}
// Add log entry
function addLogEntry(message, type = 'info') {
const log = document.getElementById('activity-log');
const entry = document.createElement('div');
entry.className = `log-entry ${type}`;
entry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
log.appendChild(entry);
log.scrollTop = log.scrollHeight;
}
// Clear log
function clearLog() {
const log = document.getElementById('activity-log');
log.innerHTML = '<div class="log-entry info">Log cleared.</div>';
}
// Auto-refresh stats every 30 seconds
setInterval(loadStats, 30000);
// Product Management Functions
async function createProduct(event) {
event.preventDefault();
const formData = {
name: document.getElementById('product-name').value,
brand: document.getElementById('product-brand').value,
model: document.getElementById('product-model').value || document.getElementById('product-name').value,
price: parseFloat(document.getElementById('product-price').value),
description: document.getElementById('product-description').value,
imageUrl: document.getElementById('product-image').value || 'products/placeholder.jpg',
specs: {
'Display': 'Standard Display',
'Storage': 'Standard Storage'
},
inStock: true,
stockCount: parseInt(document.getElementById('product-stock').value) || 0,
category: document.getElementById('product-category').value
};
try {
addLogEntry('Creating new product...', 'info');
const product = await window.inventoryAPI.createProduct(formData);
addLogEntry(`Product created successfully: ${product.name} (ID: ${product.id})`, 'success');
// Clear form
clearForm();
// Refresh stats
await loadStats();
// Show success message
document.getElementById('sync-status').innerHTML = '<div class="status success">✅ Product created successfully!</div>';
} catch (error) {
addLogEntry(`Failed to create product: ${error.message}`, 'error');
document.getElementById('sync-status').innerHTML = '<div class="status error">❌ Failed to create product: ' + error.message + '</div>';
}
}
// Clear form function
function clearForm() {
document.getElementById('product-form').reset();
document.getElementById('product-stock').value = '0';
}
// Autofill product information from web
async function autofillProductInfo() {
const productName = document.getElementById('product-name').value.trim();
if (!productName) {
alert('Please enter a product name first');
return;
}
try {
addLogEntry(`Searching for product information: ${productName}`, 'info');
// Show loading state
const autofillBtn = event.target;
const originalText = autofillBtn.textContent;
autofillBtn.textContent = '🔍 Searching...';
autofillBtn.disabled = true;
// Simulate web search and data extraction
const productInfo = await searchProductInfo(productName);
// Fill form with found information
if (productInfo.brand) {
document.getElementById('product-brand').value = productInfo.brand;
}
if (productInfo.model) {
document.getElementById('product-model').value = productInfo.model;
}
if (productInfo.price) {
document.getElementById('product-price').value = productInfo.price;
}
if (productInfo.description) {
document.getElementById('product-description').value = productInfo.description;
}
if (productInfo.imageUrl) {
document.getElementById('product-image').value = productInfo.imageUrl;
}
if (productInfo.category) {
document.getElementById('product-category').value = productInfo.category;
}
addLogEntry(`Product information autofilled for: ${productName}`, 'success');
} catch (error) {
addLogEntry(`Failed to autofill product info: ${error.message}`, 'error');
alert('Failed to autofill product information. Please fill manually.');
} finally {
// Reset button state
autofillBtn.textContent = originalText;
autofillBtn.disabled = false;
}
}
// Search product information (simulated web search)
async function searchProductInfo(productName) {
// Simulate API delay
await new Promise(resolve => setTimeout(resolve, 1500));
// Mock product database with common devices
const productDatabase = {
'iphone 15': {
brand: 'Apple',
model: 'iPhone 15',
price: 799.00,
description: 'Latest iPhone with USB-C, Dynamic Island, and 48MP camera system',
imageUrl: 'products/iPhone-15.jpg',
category: 'main'
},
'iphone 15 pro': {
brand: 'Apple',
model: 'iPhone 15 Pro',
price: 999.00,
description: 'Pro iPhone with titanium design, A17 Pro chip, and advanced camera system',
imageUrl: 'products/iPhone-15-Pro.jpg',
category: 'main'
},
'iphone 15 pro max': {
brand: 'Apple',
model: 'iPhone 15 Pro Max',
price: 1199.00,
description: 'Largest iPhone with titanium design, A17 Pro chip, and 5x telephoto camera',
imageUrl: 'products/iPhone-15-Pro-Max.jpg',
category: 'main'
},
'samsung galaxy s25': {
brand: 'Samsung',
model: 'Galaxy S25',
price: 799.99,
description: 'Latest Samsung flagship with AI-powered features and advanced camera system',
imageUrl: 'products/SamS25.jpg',
category: 'main'
},
'samsung galaxy s25 ultra': {
brand: 'Samsung',
model: 'Galaxy S25 Ultra',
price: 1299.99,
description: 'Ultimate Samsung flagship with S Pen, titanium design, and 200MP camera',
imageUrl: 'products/SamS25Ultra.jpg',
category: 'main'
},
'ipad air': {
brand: 'Apple',
model: 'iPad Air 11"',
price: 599.00,
description: 'Powerful iPad with M2 chip and Liquid Retina display',
imageUrl: 'products/iPadAir11.jpg',
category: 'main'
},
'apple watch': {
brand: 'Apple',
model: 'Apple Watch Series 10',
price: 399.00,
description: 'Latest Apple Watch with advanced health features and S10 chip',
imageUrl: 'products/AppleWatch10.jpg',
category: 'accessory'
}
};
// Search for matching product
const searchTerm = productName.toLowerCase();
for (const [key, product] of Object.entries(productDatabase)) {
if (searchTerm.includes(key) || key.includes(searchTerm)) {
return product;
}
}
// If no exact match, try partial matching
for (const [key, product] of Object.entries(productDatabase)) {
const keyWords = key.split(' ');
const searchWords = searchTerm.split(' ');
for (const searchWord of searchWords) {
if (keyWords.some(keyWord => keyWord.includes(searchWord) || searchWord.includes(keyWord))) {
return product;
}
}
}
// Default fallback
return {
brand: 'Unknown',
model: productName,
price: 299.99,
description: `High-quality ${productName} with modern features and specifications`,
imageUrl: 'products/placeholder.jpg',
category: 'main'
};
}
async function testProductCreation() {
const testProduct = {
name: 'Test Product ' + Date.now(),
brand: 'Test Brand',
model: 'Test Model',
price: 299.99,
description: 'A test product created via API',
imageUrl: 'products/test.jpg',
specs: {
'Display': '6.1 inch',
'Storage': '128GB',
'Camera': '12MP'
},
inStock: true,
stockCount: 5,
category: 'main'
};
try {
addLogEntry('Testing product creation...', 'info');
const product = await window.inventoryAPI.createProduct(testProduct);
addLogEntry(`Test product created: ${product.name}`, 'success');
document.getElementById('test-results').innerHTML = `✅ Created: ${product.name}<br>ID: ${product.id}`;
await loadStats();
} catch (error) {
addLogEntry(`Test product creation failed: ${error.message}`, 'error');
document.getElementById('test-results').innerHTML = `❌ Error: ${error.message}`;
}
}
async function testProductUpdate() {
try {
// First create a test product
const testProduct = {
name: 'Update Test Product ' + Date.now(),
brand: 'Test Brand',
price: 199.99,
stockCount: 10,
category: 'main'
};
addLogEntry('Testing product update...', 'info');
const created = await window.inventoryAPI.createProduct(testProduct);
// Then update it
const updateData = {
name: 'Updated ' + created.name,
price: 249.99,
stockCount: 15
};
const updated = await window.inventoryAPI.updateProduct(created.id, updateData);
addLogEntry(`Test product updated: ${updated.name}`, 'success');
document.getElementById('test-results').innerHTML = `✅ Updated: ${updated.name}<br>New Price: $${updated.price}`;
await loadStats();
} catch (error) {
addLogEntry(`Test product update failed: ${error.message}`, 'error');
document.getElementById('test-results').innerHTML = `❌ Error: ${error.message}`;
}
}
async function testProductDelete() {
try {
// First create a test product
const testProduct = {
name: 'Delete Test Product ' + Date.now(),
brand: 'Test Brand',
price: 99.99,
stockCount: 1,
category: 'main'
};
addLogEntry('Testing product deletion...', 'info');
const created = await window.inventoryAPI.createProduct(testProduct);
// Then delete it
const deleted = await window.inventoryAPI.deleteProduct(created.id);
if (deleted) {
addLogEntry(`Test product deleted: ${created.name}`, 'success');
document.getElementById('test-results').innerHTML = `✅ Deleted: ${created.name}`;
await loadStats();
}
} catch (error) {
addLogEntry(`Test product deletion failed: ${error.message}`, 'error');
document.getElementById('test-results').innerHTML = `❌ Error: ${error.message}`;
}
}
</script>
</body>
</html>