mirror of
https://github.com/StefBuwalda/cal_counter.git
synced 2025-10-30 11:19:59 +00:00
Refactor food item flow and barcode handling
Updated routes and templates to improve the process of adding and logging food items by barcode. The add_food_item route now accepts a barcode parameter, and barcode lookups redirect to item creation if not found. The log_food flow now uses session variables for item and meal selection, and the get_item.html template uses fetch to handle barcode lookups and redirects accordingly.
This commit is contained in:
@@ -49,8 +49,22 @@
|
||||
if (result) {
|
||||
// Result found, this should post the barcode
|
||||
const codeText = result.getText();
|
||||
const baseURL = "{{url_for('user.food_item', barcode='0')}}"
|
||||
window.location.href = baseURL.replace("0", encodeURIComponent(codeText))
|
||||
const baseURL = "{{url_for('user.foodId_from_barcode', barcode='!')}}"
|
||||
fetch(baseURL.replace("!", encodeURIComponent(codeText)))
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not OK');
|
||||
}
|
||||
return response.json(); // or response.text(), response.blob(), etc.
|
||||
})
|
||||
.then(data => {
|
||||
const baseURL2 = "{{url_for('user.select_item', item_id='0')}}"
|
||||
window.location.href = baseURL2.replace("0", encodeURIComponent(data["item_id"]))
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Fetch error:', error);
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user