Skip to content

Commit

Permalink
feat: openfoodfacts#2169 - added emb codes and countries (openfoodfac…
Browse files Browse the repository at this point in the history
…ts#2363)

* feat: openfoodfacts#2169 - added emb codes and countries

Impacted files:
* `app_en.arb`: added emb codes and countries translations
* `app_fr.arb`: added emb codes and countries translations
* `edit_product_page.dart`: added emb codes and countries editors
* `Podfile.lock`: wtf
* `product_query.dart`: added emb codes and countries product fields
* `product_refresher.dart`: now using language and country parameters for `saveProduct`
* `pubspec.lock`: wtf
* `pubspec.yaml`: upgraded versions of off-dart and sentry
* `simple_input_page.dart`: added an optional explanation field
* `simple_input_page_helpers.dart`: added emb codes and countries helpers; added an optional explanation field; refactored

* Update packages/smooth_app/lib/l10n/app_en.arb

Co-authored-by: Pierre Slamich <pierre.slamich@gmail.com>

* Update packages/smooth_app/lib/l10n/app_en.arb

Co-authored-by: Pierre Slamich <pierre.slamich@gmail.com>

* Update packages/smooth_app/lib/l10n/app_en.arb

Co-authored-by: Pierre Slamich <pierre.slamich@gmail.com>

* Update packages/smooth_app/lib/l10n/app_en.arb

Co-authored-by: Pierre Slamich <pierre.slamich@gmail.com>

Co-authored-by: Pierre Slamich <pierre.slamich@gmail.com>
  • Loading branch information
monsieurtanuki and teolemon authored Jun 23, 2022
1 parent b2fcd14 commit 3999967
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 22 deletions.
12 changes: 6 additions & 6 deletions packages/smooth_app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ PODS:
- Realm/Headers (10.25.2)
- RealmSwift (10.25.2):
- Realm (= 10.25.2)
- Sentry (7.11.0):
- Sentry/Core (= 7.11.0)
- Sentry/Core (7.11.0)
- Sentry (7.18.0):
- Sentry/Core (= 7.18.0)
- Sentry/Core (7.18.0)
- sentry_flutter (0.0.1):
- Flutter
- FlutterMacOS
- Sentry (~> 7.11.0)
- Sentry (~> 7.18.0)
- share_plus (0.0.1):
- Flutter
- shared_preferences_ios (0.0.1):
Expand Down Expand Up @@ -249,8 +249,8 @@ SPEC CHECKSUMS:
Protobuf: 235750e4696ff59fb07d949a9dbbc92b3c0700fe
Realm: 978303663d0509166498f423d112e5ee97d4c91b
RealmSwift: a0c30c1efc49e928a0a6f8fb141bb2629616d79b
Sentry: 0c5cd63d714187b4a39c331c1f0eb04ba7868341
sentry_flutter: efb3df2c203cd03aad255892a8d628a458656d14
Sentry: aff6fb3785973436f0bf25748f6b3bcb3e825e09
sentry_flutter: b635e75d735415172e54bf3b72c39ce69882b4ca
share_plus: 056a1e8ac890df3e33cb503afffaf1e9b4fbae68
shared_preferences_ios: 548a61f8053b9b8a49ac19c1ffbc8b92c50d68ad
sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904
Expand Down
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/database/product_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ abstract class ProductQuery {
ProductField.ECOSCORE_GRADE,
ProductField.ECOSCORE_SCORE,
ProductField.KNOWLEDGE_PANELS,
ProductField.COUNTRIES,
ProductField.COUNTRIES_TAGS,
ProductField.COUNTRIES_TAGS_IN_LANGUAGES,
ProductField.EMB_CODES,
];

Future<SearchResult> getSearchResult();
Expand Down
24 changes: 24 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,30 @@
"@edit_product_form_item_stores_hint": {
"description": "Product edition - Stores - input textfield hint"
},
"edit_product_form_item_countries_title": "Countries where sold",
"@edit_product_form_item_countries_title": {
"description": "Product edition - Countries - Title"
},
"edit_product_form_item_countries_hint": "Spain",
"@edit_product_form_item_countries_hint": {
"description": "Product edition - Countries - input textfield hint"
},
"edit_product_form_item_countries_explanations": "Countries where the product is widely available (not including stores specialising in foreign products).",
"@edit_product_form_item_countries_explanations": {
"description": "Product edition - Countries - explanations"
},
"edit_product_form_item_emb_codes_title": "Traceability codes",
"@edit_product_form_item_emb_codes_title": {
"description": "Product edition - Traceability codes - Title"
},
"edit_product_form_item_emb_codes_hint": "EMB 53062, FR 62.448.034 CE, 84 R 20, 33 RECOLTANT 522",
"@edit_product_form_item_emb_codes_hint": {
"description": "Product edition - Traceability Codes - input textfield hint"
},
"edit_product_form_item_emb_codes_explanations": "In Europe, code in an ellipse with the 2 country initials followed by a number and CE.\nExamples: EMB 53062, FR 62.448.034 CE, 84 R 20, 33 RECOLTANT 522",
"@edit_product_form_item_emb_codes_examples": {
"description": "Product edition - EMB Codes - explanations"
},
"edit_product_form_item_categories_title": "Categories",
"@edit_product_form_item_categories_title": {
"description": "Product edition - Categories - Title"
Expand Down
24 changes: 24 additions & 0 deletions packages/smooth_app/lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,30 @@
"@edit_product_form_item_stores_hint": {
"description": "Product edition - Stores - input textfield hint"
},
"edit_product_form_item_countries_title": "Pays de vente",
"@edit_product_form_item_countries_title": {
"description": "Product edition - Countries - Title"
},
"edit_product_form_item_countries_hint": "Espagne",
"@edit_product_form_item_countries_hint": {
"description": "Product edition - Countries - input textfield hint"
},
"edit_product_form_item_countries_explanations": "Pays dans lesquels le produit est largement distribué (hors magasins spécialisés dans l'import).",
"@edit_product_form_item_countries_examples": {
"description": "Product edition - Countries - explanations"
},
"edit_product_form_item_emb_codes_title": "Code de traçabilité",
"@edit_product_form_item_emb_codes_title": {
"description": "Product edition - EMB Codes - Title"
},
"edit_product_form_item_emb_codes_hint": "EMB 53062",
"@edit_product_form_item_emb_codes_hint": {
"description": "Product edition - EMB Codes - input textfield hint"
},
"edit_product_form_item_emb_codes_explanations": "En Europe, le code est une ellipse contenant les deux initiales du pays suivies par un nombre et CE.\nExemples : EMB 53062, FR 62.448.034 CE, 84 R 20, 33 RECOLTANT 522",
"@edit_product_form_item_emb_codes_examples": {
"description": "Product edition - EMB Codes - explanations"
},
"edit_product_form_item_categories_title": "Catégories",
"@edit_product_form_item_categories_title": {
"description": "Product edition - Categories - Title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class ProductRefresher {
final Status status = await OpenFoodAPIClient.saveProduct(
ProductQuery.getUser(),
inputProduct,
language: ProductQuery.getLanguage(),
country: ProductQuery.getCountry(),
);
if (status.error != null) {
return _MetaProductRefresher.error(status.error);
Expand Down
6 changes: 6 additions & 0 deletions packages/smooth_app/lib/pages/product/edit_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ class _EditProductPageState extends State<EditProductPage> {
_getSimpleListTileItem(
SimpleInputPageStoreHelper(_product, appLocalizations),
),
_getSimpleListTileItem(
SimpleInputPageEmbCodeHelper(_product, appLocalizations),
),
_getSimpleListTileItem(
SimpleInputPageCountryHelper(_product, appLocalizations),
),
_getSimpleListTileItem(
SimpleInputPageCategoryHelper(_product, appLocalizations),
),
Expand Down
2 changes: 2 additions & 0 deletions packages/smooth_app/lib/pages/product/simple_input_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class _SimpleInputPageState extends State<SimpleInputPage> {
),
],
),
if (widget.helper.getAddExplanations() != null)
Text(widget.helper.getAddExplanations()!),
Divider(color: themeData.colorScheme.onBackground),
Wrap(
direction: Axis.horizontal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ abstract class AbstractSimpleInputPageHelper {
/// "Have the terms been changed?"
bool _changed = false;

final String _separator = ',';

/// Returns the terms as they were initially in the product.
@protected
List<String> initTerms();
Expand Down Expand Up @@ -69,6 +71,9 @@ abstract class AbstractSimpleInputPageHelper {
/// Returns the hint of the "add" text field.
String getAddHint();

/// Returns additional examples about the "add" text field.
String? getAddExplanations() => null;

/// Impacts a product in order to take the changes into account.
@protected
void changeProduct(final Product changedProduct);
Expand All @@ -82,6 +87,18 @@ abstract class AbstractSimpleInputPageHelper {
changeProduct(changedProduct);
return changedProduct;
}

@protected
List<String> splitString(String? input) {
if (input == null) {
return <String>[];
}
input = input.trim();
if (input.isEmpty) {
return <String>[];
}
return input.split(_separator);
}
}

/// Implementation for "Stores" of an [AbstractSimpleInputPageHelper].
Expand All @@ -95,28 +112,45 @@ class SimpleInputPageStoreHelper extends AbstractSimpleInputPageHelper {
);

@override
List<String> initTerms() => _splitString(product.stores);
List<String> initTerms() => splitString(product.stores);

@override
void changeProduct(final Product changedProduct) =>
changedProduct.stores = terms.join(', ');
changedProduct.stores = terms.join(_separator);

@override
String getTitle() => appLocalizations.edit_product_form_item_stores_title;

@override
String getAddHint() => appLocalizations.edit_product_form_item_stores_hint;
}

List<String> _splitString(String? input) {
if (input == null) {
return <String>[];
}
input = input.trim();
if (input.isEmpty) {
return <String>[];
}
return input.split(',');
}
/// Implementation for "Emb Code" of an [AbstractSimpleInputPageHelper].
class SimpleInputPageEmbCodeHelper extends AbstractSimpleInputPageHelper {
SimpleInputPageEmbCodeHelper(
final Product product,
final AppLocalizations appLocalizations,
) : super(
product,
appLocalizations,
);

@override
List<String> initTerms() => splitString(product.embCodes);

@override
void changeProduct(final Product changedProduct) =>
changedProduct.embCodes = terms.join(_separator);

@override
String getTitle() => appLocalizations.edit_product_form_item_emb_codes_title;

@override
String getAddHint() => appLocalizations.edit_product_form_item_emb_codes_hint;

@override
String getAddExplanations() =>
appLocalizations.edit_product_form_item_emb_codes_explanations;
}

/// Abstraction, for "in language" field, of an [AbstractSimpleInputPageHelper].
Expand Down Expand Up @@ -175,7 +209,7 @@ abstract class AbstractSimpleInputPageInLanguageHelper
String? tag = _termToTags[term];
tag ??= '${_language.code}:$term';
if (i > 0) {
result.write(', ');
result.write(_separator);
}
result.write(tag);
}
Expand Down Expand Up @@ -245,3 +279,36 @@ class SimpleInputPageCategoryHelper
String getAddHint() =>
appLocalizations.edit_product_form_item_categories_hint;
}

/// Implementation for "Countries" of an [AbstractSimpleInputPageHelper].
class SimpleInputPageCountryHelper
extends AbstractSimpleInputPageInLanguageHelper {
SimpleInputPageCountryHelper(
final Product product,
final AppLocalizations appLocalizations,
) : super(
product,
appLocalizations,
);

@override
List<String>? getTags() => product.countriesTags;

@override
Map<OpenFoodFactsLanguage, List<String>>? getInLanguages() =>
product.countriesTagsInLanguages;

@override
void setValue(final Product changedProduct, final String value) =>
changedProduct.countries = value;

@override
String getTitle() => appLocalizations.edit_product_form_item_countries_title;

@override
String getAddHint() => appLocalizations.edit_product_form_item_countries_hint;

@override
String getAddExplanations() =>
appLocalizations.edit_product_form_item_countries_explanations;
}
16 changes: 15 additions & 1 deletion packages/smooth_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.3"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
flutter_localizations:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -651,6 +658,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
lints:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
lists:
dependency: transitive
description:
Expand Down Expand Up @@ -736,7 +750,7 @@ packages:
name: openfoodfacts
url: "https://pub.dartlang.org"
source: hosted
version: "1.18.2"
version: "1.19.0"
openfoodfacts_flutter_lints:
dependency: "direct dev"
description:
Expand Down
4 changes: 2 additions & 2 deletions packages/smooth_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies:
url: 'https://github.com/M123-dev/matomo-tracker.git'
ref: 'fix-event-sending'
modal_bottom_sheet: ^2.0.1
openfoodfacts: ^1.18.2
openfoodfacts: ^1.19.0
# openfoodfacts:
# path: ../../../openfoodfacts-dart
package_info_plus: ^1.4.2
Expand All @@ -42,7 +42,7 @@ dependencies:
photo_view: ^0.14.0
uuid: ^3.0.6
provider: ^6.0.3
sentry_flutter: ^6.5.1 # careful with upgrading cf: https://github.com/openfoodfacts/smooth-app/issues/1300
sentry_flutter: ^6.6.0 # careful with upgrading cf: https://github.com/openfoodfacts/smooth-app/issues/1300
sqflite: ^2.0.2+1
url_launcher: ^6.1.3
visibility_detector: ^0.3.3
Expand Down

0 comments on commit 3999967

Please sign in to comment.