Spaces:
Running
Running
Update templates/menu_page.html
Browse files- templates/menu_page.html +90 -3
templates/menu_page.html
CHANGED
@@ -39,22 +39,71 @@
|
|
39 |
margin: 5px 0;
|
40 |
color: #555;
|
41 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
</style>
|
43 |
</head>
|
44 |
<body>
|
45 |
-
<h1>Menu</h1>
|
46 |
<div class="menu-container" id="menu-list">
|
47 |
<p>Loading menu...</p>
|
48 |
</div>
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
<script>
|
|
|
|
|
51 |
function fetchMenu() {
|
52 |
fetch("/menu") // Fetch from Flask API
|
53 |
.then(response => response.json())
|
54 |
.then(data => {
|
55 |
if (data.success) {
|
56 |
let menuContainer = document.getElementById("menu-list");
|
57 |
-
menuContainer.innerHTML = "";
|
58 |
|
59 |
data.menu.forEach(item => {
|
60 |
let menuItem = document.createElement("div");
|
@@ -63,8 +112,9 @@
|
|
63 |
menuItem.innerHTML = `
|
64 |
<h3>${item.name}</h3>
|
65 |
<p><strong>Category:</strong> ${item.category}</p>
|
66 |
-
<p><strong>Price:</strong> $${item.price}</p>
|
67 |
<p><strong>Ingredients:</strong> ${item.ingredients}</p>
|
|
|
68 |
`;
|
69 |
|
70 |
menuContainer.appendChild(menuItem);
|
@@ -79,6 +129,43 @@
|
|
79 |
});
|
80 |
}
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
window.onload = fetchMenu;
|
83 |
</script>
|
84 |
</body>
|
|
|
39 |
margin: 5px 0;
|
40 |
color: #555;
|
41 |
}
|
42 |
+
.menu-item button {
|
43 |
+
background-color: #ff5722;
|
44 |
+
color: white;
|
45 |
+
border: none;
|
46 |
+
padding: 8px;
|
47 |
+
cursor: pointer;
|
48 |
+
width: 100%;
|
49 |
+
border-radius: 5px;
|
50 |
+
}
|
51 |
+
.menu-item button:hover {
|
52 |
+
background-color: #e64a19;
|
53 |
+
}
|
54 |
+
.cart-container {
|
55 |
+
margin-top: 30px;
|
56 |
+
padding: 15px;
|
57 |
+
background: white;
|
58 |
+
border-radius: 8px;
|
59 |
+
width: 50%;
|
60 |
+
margin-left: auto;
|
61 |
+
margin-right: auto;
|
62 |
+
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);
|
63 |
+
text-align: left;
|
64 |
+
}
|
65 |
+
.cart-container h2 {
|
66 |
+
text-align: center;
|
67 |
+
color: #ff5722;
|
68 |
+
}
|
69 |
+
.cart-item {
|
70 |
+
display: flex;
|
71 |
+
justify-content: space-between;
|
72 |
+
border-bottom: 1px solid #ddd;
|
73 |
+
padding: 5px 0;
|
74 |
+
}
|
75 |
+
.cart-total {
|
76 |
+
font-size: 18px;
|
77 |
+
font-weight: bold;
|
78 |
+
text-align: right;
|
79 |
+
margin-top: 10px;
|
80 |
+
}
|
81 |
</style>
|
82 |
</head>
|
83 |
<body>
|
84 |
+
<h1>Restaurant Menu</h1>
|
85 |
<div class="menu-container" id="menu-list">
|
86 |
<p>Loading menu...</p>
|
87 |
</div>
|
88 |
|
89 |
+
<div class="cart-container">
|
90 |
+
<h2>Your Cart</h2>
|
91 |
+
<div id="cart-list">
|
92 |
+
<p>No items in cart.</p>
|
93 |
+
</div>
|
94 |
+
<p class="cart-total" id="cart-total">Total: $0.00</p>
|
95 |
+
</div>
|
96 |
+
|
97 |
<script>
|
98 |
+
let cart = [];
|
99 |
+
|
100 |
function fetchMenu() {
|
101 |
fetch("/menu") // Fetch from Flask API
|
102 |
.then(response => response.json())
|
103 |
.then(data => {
|
104 |
if (data.success) {
|
105 |
let menuContainer = document.getElementById("menu-list");
|
106 |
+
menuContainer.innerHTML = "";
|
107 |
|
108 |
data.menu.forEach(item => {
|
109 |
let menuItem = document.createElement("div");
|
|
|
112 |
menuItem.innerHTML = `
|
113 |
<h3>${item.name}</h3>
|
114 |
<p><strong>Category:</strong> ${item.category}</p>
|
115 |
+
<p><strong>Price:</strong> $${item.price.toFixed(2)}</p>
|
116 |
<p><strong>Ingredients:</strong> ${item.ingredients}</p>
|
117 |
+
<button onclick="addToCart('${item.name}', ${item.price})">Add to Cart</button>
|
118 |
`;
|
119 |
|
120 |
menuContainer.appendChild(menuItem);
|
|
|
129 |
});
|
130 |
}
|
131 |
|
132 |
+
function addToCart(name, price) {
|
133 |
+
cart.push({ name, price });
|
134 |
+
updateCart();
|
135 |
+
}
|
136 |
+
|
137 |
+
function updateCart() {
|
138 |
+
let cartContainer = document.getElementById("cart-list");
|
139 |
+
let totalContainer = document.getElementById("cart-total");
|
140 |
+
|
141 |
+
if (cart.length === 0) {
|
142 |
+
cartContainer.innerHTML = "<p>No items in cart.</p>";
|
143 |
+
totalContainer.innerText = "Total: $0.00";
|
144 |
+
return;
|
145 |
+
}
|
146 |
+
|
147 |
+
cartContainer.innerHTML = "";
|
148 |
+
let total = 0;
|
149 |
+
|
150 |
+
cart.forEach((item, index) => {
|
151 |
+
total += item.price;
|
152 |
+
let cartItem = document.createElement("div");
|
153 |
+
cartItem.classList.add("cart-item");
|
154 |
+
cartItem.innerHTML = `
|
155 |
+
<span>${item.name} - $${item.price.toFixed(2)}</span>
|
156 |
+
<button onclick="removeFromCart(${index})" style="background-color: red; padding: 4px; font-size: 12px;">Remove</button>
|
157 |
+
`;
|
158 |
+
cartContainer.appendChild(cartItem);
|
159 |
+
});
|
160 |
+
|
161 |
+
totalContainer.innerText = `Total: $${total.toFixed(2)}`;
|
162 |
+
}
|
163 |
+
|
164 |
+
function removeFromCart(index) {
|
165 |
+
cart.splice(index, 1);
|
166 |
+
updateCart();
|
167 |
+
}
|
168 |
+
|
169 |
window.onload = fetchMenu;
|
170 |
</script>
|
171 |
</body>
|