Skip to content

Commit

Permalink
Merge pull request #37 from ivoxavier/store_scanned_product_in_userfo…
Browse files Browse the repository at this point in the history
…odslist

Store scanned product
  • Loading branch information
ivoxavier authored Dec 27, 2022
2 parents 1c52234 + 6ef268b commit 0886ce1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 38 deletions.
36 changes: 0 additions & 36 deletions js/ControlBarCodeInfo.js

This file was deleted.

21 changes: 21 additions & 0 deletions qml/SetFoodPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import "../js/Chart.js" as Charts
import "../js/QChartJsTypes.js" as ChartTypes
import "../js/UserTable.js" as UserTable
import "../js/IngestionsTable.js" as IngestionsTable
import "../js/UserFoodsListTable.js" as UserFoodsListTable


Page{
Expand Down Expand Up @@ -258,12 +259,32 @@ Page{
anchors.fill: parent
onClicked:{
try{
if(UserFoodsListTable.isUnique(product_name_set_food_page) >= 1){
/* REGISTER INGESTION */
//item already on DB
IngestionsTable.saveIngestion(product_name_set_food_page,
nutriscore_set_food_page, cal_ingested,
fat_ingested, carbo_ingested,
protein_ingested, meal_set_food_page)
root.initDB()
PopupUtils.open(sucess_dialog)
} else{
/* CREATE NEW ENTRY */
//new item
UserFoodsListTable.saveIngestion(product_name_set_food_page,
nutriscore_set_food_page, cal_set_food_page,
fat_set_food_page, carbo_set_food_page,
protein_set_food_page)
root.initDB()

/* REGISTER INGESTION */
IngestionsTable.saveIngestion(product_name_set_food_page,
nutriscore_set_food_page, cal_ingested,
fat_ingested, carbo_ingested,
protein_ingested, meal_set_food_page)
root.initDB()
PopupUtils.open(sucess_dialog)
}
} catch (err){
PopupUtils.open(error_dialog)
}
Expand Down
22 changes: 20 additions & 2 deletions qml/components/IsProductFoundDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Lomiri.Components 1.3
import Lomiri.Components.Popups 1.3
import Lomiri.Components.Pickers 1.3
import QtQuick.LocalStorage 2.12
import "../../js/ControlBarCodeInfo.js" as ControlBarCodeInfo


Dialog {
id: is_product_found_dialog
Expand All @@ -40,7 +40,25 @@ Dialog {
id: openFoodFactJSON
source: "https://world.openfoodfacts.org/api/v0/product/" + barcode + ".json";
query: "$[*]"
onJsonChanged: ControlBarCodeInfo.getData()
onJsonChanged: {
var _json = openFoodFactJSON.model.get(0);
if (typeof _json !== "undefined" && typeof _json.product_name !== "undefined" ) {
product_name = _json.product_name
nutriscore_grade = (typeof _json.nutriscore_grade == "undefined") ? "a" : _json.nutriscore_grade
energy_kcal_100g = (typeof _json.nutriments.energy_value == "undefined") ? 0 : _json.nutriments.energy_value
fat_100g = (typeof _json.nutriments.fat_100g == "undefined") ? 0.0 : _json.nutriments.fat_100g
protein_100g = (typeof _json.nutriments.proteins_100g == "undefined") ? 0.0 : _json.nutriments.proteins_100g
carbohydrates_100g = (typeof _json.nutriments.carbohydrates_100g == "undefined") ? 0.0 : _json.nutriments.carbohydrates_100g
next_button.enabled = true
loading_circle.running = false
loading_circle.visible = false
}else{
loading_circle.running = false
loading_circle.visible = false
enter_manually.visible = true
is_code_empty = true
}
}
}

title: is_code_empty ? i18n.tr("BarCode Not Found") : i18n.tr("BarCode Found")
Expand Down

0 comments on commit 0886ce1

Please sign in to comment.