-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaggregator.html
183 lines (167 loc) · 6.39 KB
/
aggregator.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Order Tracking System</title>
<!-- Bootstrap for styling -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
<style>
body {
background-color: #f8f9fa;
font-family: Arial, sans-serif;
}
.container {
margin-top: 50px;
max-width: 900px;
}
.card {
margin-bottom: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
transform: perspective(1000px) rotateX(3deg);
transition: transform 0.3s ease-in-out;
}
.card:hover {
transform: perspective(1000px) rotateX(0deg) scale(1.02);
}
.spinner {
display: none;
text-align: center;
margin-top: 20px;
}
.progress {
height: 20px;
}
.tracking-icon {
font-size: 22px;
margin-right: 10px;
}
.search-container {
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
margin-bottom: 20px;
}
.form-control {
width: 50%;
}
.btn {
width: 15%;
}
.details-container {
display: flex;
justify-content: space-between;
gap: 15px;
}
.card {
flex: 1;
background: #ffffff;
}
/* Dark Mode Styling */
body.dark-mode {
background-color: #121212;
color: white;
}
.card.dark-mode {
background-color: #1e1e1e;
color: white;
}
.dark-mode-toggle {
position: absolute;
top: 20px;
right: 20px;
cursor: pointer;
font-size: 24px;
}
</style>
</head>
<body>
<div class="container text-center">
<i class="fas fa-moon dark-mode-toggle" onclick="toggleDarkMode()"></i>
<h2 class="text-primary mb-3">Real-Time Order Tracking</h2>
<div class="search-container">
<input type="text" id="orderId" class="form-control" placeholder="Enter Order ID">
<button class="btn btn-primary" onclick="fetchOrderDetails()">Track</button>
</div>
<div class="spinner" id="loadingSpinner">
<div class="spinner-border text-primary"></div>
<p>Fetching Order Details...</p>
</div>
<div id="orderDetails" class="mt-4 details-container"></div>
</div>
<script>
function toggleDarkMode() {
document.body.classList.toggle("dark-mode");
document.querySelectorAll(".card").forEach(card => card.classList.toggle("dark-mode"));
}
function fetchOrderDetails() {
let orderId = document.getElementById("orderId").value;
if (!orderId) {
alert("Please enter a valid Order ID");
return;
}
document.getElementById("loadingSpinner").style.display = "block";
document.getElementById("orderDetails").innerHTML = "";
const apiUrl = `http://localhost:9090/order-aggregator/${orderId}`; // ✅ Use single API
fetch(apiUrl)
.then(response => response.json())
.then(data => {
displayOrderDetails(data.order, data.shipping, data.payment); // ✅ Extract from single response
})
.catch(error => {
console.error("Error fetching data:", error);
alert("Failed to fetch order details. Please check if backend service is running.");
})
.finally(() => {
document.getElementById("loadingSpinner").style.display = "none";
});
}
function displayOrderDetails(order, shipping, payment) {
let trackingIcon = shipping.status === "In Transit" ? "fa-truck-moving" : "fa-box-open";
let progressPercentage = shipping.status === "Delivered" ? 100 : shipping.status === "In Transit" ? 60 : 20;
let html = `
<div class="card">
<div class="card-header bg-primary text-white">
<i class="fa fa-shopping-cart tracking-icon"></i> Order Details
</div>
<div class="card-body">
<p><strong>Order ID:</strong> ${order.orderId}</p>
<p><strong>Items:</strong> ${order.items}</p>
<p><strong>Status:</strong> ${order.status}</p>
<p><strong>Order Date:</strong> ${order.date}</p>
</div>
</div>
<div class="card">
<div class="card-header bg-success text-white">
<i class="fa ${trackingIcon} tracking-icon"></i> Shipping Details
</div>
<div class="card-body">
<p><strong>Status:</strong> ${shipping.status}</p>
<p><strong>Current Location:</strong> ${shipping.currentLocation}</p>
<p><strong>Estimated Arrival:</strong> ${shipping.eta}</p>
<div class="progress">
<div class="progress-bar bg-info" role="progressbar" style="width: ${progressPercentage}%;">
${progressPercentage}%
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header bg-warning text-white">
<i class="fa fa-credit-card tracking-icon"></i> Payment Details
</div>
<div class="card-body">
<p><strong>Status:</strong> ${payment.status}</p>
<p><strong>Method:</strong> ${payment.method}</p>
</div>
</div>
`;
document.getElementById("orderDetails").innerHTML = html;
}
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>