Compare commits

...

10 commits

Author SHA1 Message Date
Arnaud Vergnet
bfa1319b27 Add dialog loading while fetching openFoodFacts data 2020-09-09 12:44:49 +02:00
docjyJ
6ba1459848 Update Api 2020-08-29 09:15:30 +02:00
docjyJ
83cee48d36 Update Code 2020-08-29 09:08:08 +02:00
docjyJ
2786d17e5d Update Data Stop API 2020-08-23 13:29:51 +02:00
docjyJ
88aada72b1 Update Api Data Sock 2020-08-23 13:01:19 +02:00
docjyJ
384328739e Remove OpenFoodFact client 2020-08-23 13:00:20 +02:00
docjyJ
862b6a4741 Merge V3 to V2 2020-08-23 11:38:13 +02:00
docjyJ
72b5fae35f Add Add new information fr/en 2020-08-22 11:59:33 +02:00
docjyJ
5b37c48d36 Add OpenFoodFacts 0.2.3 lib 2020-08-22 11:34:59 +02:00
docjyJ
01581a61d7 Add V3 api Export
This is an experimental feature
2020-08-22 11:31:15 +02:00
2 changed files with 55 additions and 27 deletions

View file

@ -1,38 +1,41 @@
async function sendRequest() {
let response = await $.ajax({
type: "POST",
url: "write_json.php",
});
response = JSON.parse(response);
console.log(response);
return response["status"];
}
$('#uploadButton').on('click', function () {
$.confirm({
title: 'Confirmer',
content: "Voulez vous vraiment mettre en ligne le stock actuel du Proximo ? Il sera visible depuis l'application CAMPUS.",
content: "Voulez vous vraiment mettre en ligne le stock actuel du Proximo ? Il sera visible depuis l'application CAMPUS." +
"<br/><br/><strong>NOUVEAUTÉ !</strong><br/>Le site va maintenant récupérer les informations nutritionelles sur le site OpenFoodFacts !" +
"<br><strong>La mise en ligne va donc prendre plus longtemps</strong>",
type: "orange",
buttons: {
formSubmit: {
text: 'Confirmer',
btnClass: "btn-warning",
action: async function () {
let result = await sendRequest();
if (result !== 0) {
$.alert({
title: "Erreur",
content: "Une erreur est survenue, merci de réessayer plus tard.",
type: "red",
})
} else {
$.alert({
title: "Succès",
content: "Le stock a bien été mis à jour.",
type: "green",
})
}
action: function () {
$.confirm({
columnClass: "small",
content: function () {
let self = this;
return $.ajax({
type: "POST",
url: "write_json.php",
}).done((data) => {
const response = JSON.parse(data);
if (response["status"] === 0) {
self.setTitle("Succès");
self.setContent('Le stock a bien été mis à jour.');
self.setType("green");
} else {
self.setTitle("Erreur");
self.setContent('Une erreur est survenue, merci de réessayer plus tard.');
self.setType("red");
}
}).fail(() => {
self.setTitle("Erreur");
self.setContent('Une erreur est survenue, merci de réessayer plus tard.');
self.setType("red");
});
},
type: "orange",
})
}
},
cancel: {

View file

@ -83,12 +83,37 @@ class PostHandler
foreach ($articles as $article) {
$article["type"] = $this->dao->get_categories_of_article($article["id"]);
$article["image"] = $this->imageBaseUrl . $article["id"] . ".jpg";
//EXPERIMENTAL
$product = $this->get_openfoodfacts_product($article["code"]);
if($product != null){
$article["nutri-score"] = $product["nutrition_grade_fr"];
if(!empty($product["ingredients_text_fr"])) $article["ingredients"] = $product["ingredients_text_fr"];
else $article["ingredients"] = $product["ingredients_text"];
if(!empty($product["generic_name_fr"])) $article["generic"] = $product["generic_name_fr"];
else $article["generic"] = $product["generic_name"];
}
else {
$article["nutri-score"] = null;
$article["generic"] = null;
$article["ingredients"] = null;
}
array_push($formatted_articles, $article);
}
return $formatted_articles;
}
private function get_openfoodfacts_product($barcode)
{
$country = 'fr';
$productSlug = 'produit';
$url = 'https://{country}.openfoodfacts.org/api/v0/{product}/{scan}.json';
$url = str_replace(['{country}','{product}','{scan}'],[$country,$productSlug,$barcode],$url);
$result = json_decode(file_get_contents($url), true);
if ($result["status"] == 1) return $result["product"];
else return null;
}
private function save_image()
{
$success = true;