Now uses svg's from API
This commit is contained in:
parent
47dc83fd55
commit
a47127b4fb
2 changed files with 83 additions and 18 deletions
66
index.html
66
index.html
|
|
@ -1,11 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html data-theme="light">
|
||||
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>
|
||||
Toddler Shop
|
||||
</title>
|
||||
<script src="/scripts/main.js"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1.0.2/css/bulma.min.css">
|
||||
</head>
|
||||
|
||||
<body onload="loadProducts()">
|
||||
|
|
@ -15,10 +17,64 @@
|
|||
</form>
|
||||
|
||||
<img class="product_image">
|
||||
<img class="product_image">
|
||||
<img class="product_image">
|
||||
<img class="product_image">
|
||||
<img class="product_image">
|
||||
|
||||
<div class="columns">
|
||||
|
||||
<div class="column is-one-fifth product_placeholder">
|
||||
<span class="icon-text">
|
||||
<i><svg width="90" height="90">
|
||||
<image class="product_image" xlink:href="" width="50" height="50"/>
|
||||
</svg></i>
|
||||
|
||||
</span>
|
||||
<span class="product_price">Home</span>
|
||||
</div>
|
||||
|
||||
<div class="column is-one-fifth product_placeholder">
|
||||
<span class="icon-text">
|
||||
<i><svg width="90" height="90">
|
||||
<image class="product_image" xlink:href="" width="50" height="50"/>
|
||||
</svg></i>
|
||||
|
||||
</span>
|
||||
<span class="product_price">Home</span>
|
||||
</div>
|
||||
|
||||
<div class="column is-one-fifth product_placeholder">
|
||||
<span class="icon-text">
|
||||
<i><svg width="90" height="90">
|
||||
<image class="product_image" xlink:href="" width="50" height="50"/>
|
||||
</svg></i>
|
||||
|
||||
</span>
|
||||
<span class="product_price">Home</span>
|
||||
</div>
|
||||
|
||||
<div class="column is-one-fifth product_placeholder">
|
||||
<span class="icon-text">
|
||||
<i><svg width="90" height="90">
|
||||
<image class="product_image" xlink:href="" width="50" height="50"/>
|
||||
</svg></i>
|
||||
|
||||
</span>
|
||||
<span class="product_price">Home</span>
|
||||
</div>
|
||||
|
||||
<div class="column is-one-fifth product_placeholder">
|
||||
<span class="icon-text">
|
||||
<i><svg width="90" height="90">
|
||||
<image class="product_image" xlink:href="" width="50" height="50"/>
|
||||
</svg></i>
|
||||
|
||||
</span>
|
||||
<span class="product_price">Home</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<button class="button is-success">Cash</button>
|
||||
<button class="button is-success">Card</button>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ var all_products
|
|||
|
||||
let barcodeForm
|
||||
|
||||
const api_url = "http://127.0.0.1:8000"
|
||||
|
||||
var to_fill_product_index = 0
|
||||
|
||||
async function makeAPIRequest(request) {
|
||||
try {
|
||||
const response = await fetch(request);
|
||||
|
|
@ -13,15 +17,15 @@ async function makeAPIRequest(request) {
|
|||
}
|
||||
|
||||
async function loadProducts() {
|
||||
const loadProductRequest = new Request("http://127.0.0.1:8000/products")
|
||||
const loadProductRequest = new Request(api_url + "/products")
|
||||
all_products = await makeAPIRequest(loadProductRequest)
|
||||
console.log("Loaded products:", all_products)
|
||||
|
||||
barcodeForm = document.getElementById("barcode_form");
|
||||
|
||||
barcodeForm.addEventListener("submit", (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
console.log('help')
|
||||
|
||||
const barcode = document.getElementById('barcode_input').value
|
||||
var chosen_product
|
||||
for (index = 0; index < all_products.length; index++) {
|
||||
|
|
@ -32,14 +36,19 @@ async function loadProducts() {
|
|||
|
||||
barcode_input.value = ""
|
||||
|
||||
const product_image_placeholders = document.getElementsByClassName('product_image')
|
||||
console.log(product_image_placeholders)
|
||||
for (index = 0; index < product_image_placeholders.length; index++) {
|
||||
console.log(product_image_placeholders[index].src)
|
||||
if (product_image_placeholders[index].src == "") {
|
||||
product_image_placeholders[index].src = chosen_product.image_url
|
||||
return false
|
||||
}
|
||||
}
|
||||
const product_placeholders = document.getElementsByClassName('product_placeholder')
|
||||
const chosen_product_placeholder = product_placeholders[to_fill_product_index]
|
||||
var image_product = chosen_product_placeholder.getElementsByClassName('product_image')[0]
|
||||
var price_product = chosen_product_placeholder.getElementsByClassName('product_price')[0]
|
||||
|
||||
console.log(chosen_product_placeholder)
|
||||
console.log(image_product)
|
||||
console.log(price_product)
|
||||
|
||||
image_product.setAttribute('href', api_url + "/icons/" + chosen_product.image_filename);
|
||||
price_product.textContent = "\u20AC " + chosen_product.price
|
||||
|
||||
to_fill_product_index += 1
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue