Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #495 - new "action" element for knowledge panels #496

Merged
merged 6 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Future<Product?> getProduct() async {
if (result.status == 1) {
return result.product;
} else {
throw Exception('product not found, please insert data for ' + barcode);
throw Exception('product not found, please insert data for $barcode');
}
}

Expand Down
43 changes: 41 additions & 2 deletions lib/model/KnowledgePanelElement.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,36 @@ class KnowledgePanelTableElement extends JsonObject {
Map<String, dynamic> toJson() => _$KnowledgePanelTableElementToJson(this);
}

/// "Contribute action" element of the Knowledge panel.
@JsonSerializable()
class KnowledgePanelActionElement extends JsonObject {
/// Possible needed contribute action: add categories.
static const String ACTION_ADD_CATEGORIES = 'add_categories';

/// Possible needed contribute action: add ingredients text.
static const String ACTION_ADD_INGREDIENTS_TEXT = 'add_ingredients_text';

/// Possible needed contribute action: add nutrition facts.
static const String ACTION_ADD_NUTRITION_FACTS = 'add_nutrition_facts';

/// HTML description.
final String html;

/// Needed contribute actions, e.g. [ACTION_ADD_CATEGORIES].
final List<String> actions;

const KnowledgePanelActionElement({
required this.html,
required this.actions,
});

factory KnowledgePanelActionElement.fromJson(Map<String, dynamic> json) =>
_$KnowledgePanelActionElementFromJson(json);

@override
Map<String, dynamic> toJson() => _$KnowledgePanelActionElementToJson(this);
}

/// The type of Knowledge panel.
enum KnowledgePanelElementType {
/// The description summarizes the knowledge panel.
Expand All @@ -315,6 +345,9 @@ enum KnowledgePanelElementType {
@JsonValue('table')
TABLE,

@JsonValue('action')
ACTION,

@JsonValue('map')
MAP,
UNKNOWN,
Expand All @@ -325,8 +358,9 @@ enum KnowledgePanelElementType {
/// An Element could be one of [{@code ]KnowledgePanelElementType].
@JsonSerializable()
class KnowledgePanelElement extends JsonObject {
/// Type of the text description, Client may choose to display the description
/// depending upon the type.
/// Type of the text description.
///
/// Client may choose to display the description depending upon the type.
@JsonKey(
name: 'element_type', unknownEnumValue: KnowledgePanelElementType.UNKNOWN)
final KnowledgePanelElementType elementType;
Expand Down Expand Up @@ -354,6 +388,10 @@ class KnowledgePanelElement extends JsonObject {
@JsonKey(name: 'map_element')
final KnowledgePanelWorldMapElement? mapElement;

/// "Contribute action" element.
@JsonKey(name: 'action_element')
final KnowledgePanelActionElement? actionElement;

const KnowledgePanelElement({
required this.elementType,
this.textElement,
Expand All @@ -362,6 +400,7 @@ class KnowledgePanelElement extends JsonObject {
this.panelGroupElement,
this.tableElement,
this.mapElement,
this.actionElement,
});

factory KnowledgePanelElement.fromJson(Map<String, dynamic> json) =>
Expand Down
21 changes: 21 additions & 0 deletions lib/model/KnowledgePanelElement.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.