forked from openfoodfacts/openfoodfacts-dart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/openfoodfacts#193 - added ProductImprovements to 191's
- Loading branch information
1 parent
e20fa4d
commit d9806b2
Showing
1 changed file
with
61 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,39 @@ enum ProductImprovement { | |
/// or edit the product so that they can be taken into account. If it is not | ||
/// clear, you can contact the food producer.” | ||
ORIGINS_TO_BE_COMPLETED, | ||
|
||
/// We could not compute an Nutri-Score for this product. It might be that the | ||
/// category is an exception. If you believe this is an error, | ||
/// you can email [email protected] | ||
/// List of exceptions: | ||
/// https://www.santepubliquefrance.fr/content/download/150262/file/QR_scientifique_technique_150421.pdf | ||
/// You can get states with | ||
/// https://world.openfoodfacts.org/api/v0/product/3414280980209.json?fields=ecoscore_grade,states_tags | ||
/// Add a message if we have a category but no nutrition | ||
CATEGORIES_BUT_NO_NUTRISCORE, | ||
|
||
/// Possible message: “Add nutrition facts to compute the Nutri-Score” | ||
/// Add a one-click option to indicate no nutrition facts on the packaging | ||
/// This product doesn't have nutrition facts | ||
/// Add a message if we have nutrition but no category | ||
ADD_NUTRITION_FACTS, | ||
|
||
/// Possible message: “Add a category to compute the Nutri-Score” | ||
/// Help the user add the category if it is missing | ||
/// You can use our Robotoff API to get your users to validate a prediction | ||
/// Robotoff Questions | ||
/// Add a message if we have no category and no nutrition | ||
ADD_CATEGORY, | ||
|
||
/// Prompt: “Add nutrition facts and a category to compute the Nutri-Score” | ||
/// Add a one-click option to indicate no nutrition facts on the packaging | ||
/// This product doesn't have nutrition facts | ||
/// Add a message if the nutrition image is missing | ||
ADD_NUTRITION_FACTS_AND_CATEGORY, | ||
|
||
/// Add a message if the nutrition image is obsolete using the image refresh API | ||
/// https://github.com/openfoodfacts/api-documentation/issues/15 | ||
OBSOLETE_NUTRITION_IMAGE, | ||
} | ||
|
||
/// This class contains most of the data about a specific product. | ||
|
@@ -488,14 +521,37 @@ class Product extends JsonObject { | |
/// when displaying a [Product]. | ||
Set<ProductImprovement> getProductImprovements() { | ||
final Set<ProductImprovement> result = {}; | ||
if (statesTags != null) { | ||
if (statesTags!.contains('en:labels-to-be-completed')) { | ||
result.add(ProductImprovement.LABELS_TO_BE_COMPLETED); | ||
if (statesTags == null) { | ||
return result; | ||
} | ||
if (statesTags!.contains('en:labels-to-be-completed')) { | ||
result.add(ProductImprovement.LABELS_TO_BE_COMPLETED); | ||
} | ||
if (statesTags!.contains('en:origins-to-be-completed')) { | ||
result.add(ProductImprovement.ORIGINS_TO_BE_COMPLETED); | ||
} | ||
if (statesTags!.contains('en:categories-completed')) { | ||
if (nutriscore == null) { | ||
result.add(ProductImprovement.CATEGORIES_BUT_NO_NUTRISCORE); | ||
} | ||
if (statesTags!.contains('en:origins-to-be-completed')) { | ||
result.add(ProductImprovement.ORIGINS_TO_BE_COMPLETED); | ||
if (statesTags!.contains('en:nutrition-facts-to-be-completed')) { | ||
result.add(ProductImprovement.ADD_NUTRITION_FACTS); | ||
} | ||
} | ||
if (statesTags!.contains('en:categories-to-be-completed')) { | ||
if (statesTags!.contains('en:nutrition-facts-completed')) { | ||
result.add(ProductImprovement.ADD_CATEGORY); | ||
} | ||
if (statesTags!.contains('en:nutrition-facts-to-be-completed')) { | ||
result.add(ProductImprovement.ADD_NUTRITION_FACTS_AND_CATEGORY); | ||
} | ||
} | ||
if (statesTags!.contains('en:nutrition-photo-to-be-selected') || | ||
statesTags!.contains('en:photos-to-be-uploaded')) { | ||
result.add(ProductImprovement.OBSOLETE_NUTRITION_IMAGE); | ||
} | ||
|
||
// TODO (Optional) Add Nutri-Score disclaimers cf. https://github.com/openfoodfacts/openfoodfacts-dart/issues/193 | ||
return result; | ||
} | ||
} |