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

Add thumbnail images to autocomplete ingredients #1043

Conversation

ImTheTom
Copy link
Contributor

@ImTheTom ImTheTom commented May 13, 2022

Proposed Changes

  • Finishing off Add images to ingredients #653
  • Adds the thumbnail image to ingredient results if provided
  • Also added the media folder to gitignore. I can revert it, if not wanted.

Please check that the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features) - Planning on leaving this feature untested.
  • Added yourself to AUTHORS.rst

Other questions

None

Showcase

Query http://127.0.0.1:8000/api/v2/ingredient/search?term=whole grain oats
Returns

{
    "suggestions": [
        {
            "value": "100% whole grain oats quick 1-minute oats",
            "data": {
                "id": 9754,
                "name": "100% whole grain oats quick 1-minute oats",
                "image": "/media/ingredients/ab1abca2-d55f-4da7-b2ce-c759aa86f3f5/1d684f01-31f2-40d6-ad47-277abfb4a3a2.jpg",
                "image_thumbnail": "/media/ingredients/ab1abca2-d55f-4da7-b2ce-c759aa86f3f5/1d684f01-31f2-40d6-ad47-277abfb4a3a2.jpg.30x30_q85_crop-smart.jpg"
            }
        },
        {
            "value": "Old fashioned 100% whole grain oats, old fashioned",
            "data": {
                "id": 9749,
                "name": "Old fashioned 100% whole grain oats, old fashioned",
                "image": null,
                "image_thumbnail": null
            }
        }
    ]
}

Front end
Screenshot from 2022-05-14 07-51-13
And
Screenshot from 2022-05-14 19-23-12

if (suggestion.data.image_thumbnail) {
return '<div><img src="' + suggestion.data.image_thumbnail + '" /> ' + suggestion.value + '</div>';
}
return '<div>' + suggestion.value + '</div>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the same format result to wgerInitIngredientAutocompleter() as well? Then it'll be shown on the nutritional plan form as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sure 👍

@rolandgeider
Copy link
Member

Sure, leave the media folder in gitignore

@rolandgeider rolandgeider linked an issue May 14, 2022 that may be closed by this pull request
@rolandgeider rolandgeider merged commit 5682090 into wger-project:feature/ingredient-images May 14, 2022
@ImTheTom ImTheTom deleted the ingredient-images-autocompleter branch May 19, 2022 10:07
@ImTheTom ImTheTom restored the ingredient-images-autocompleter branch May 19, 2022 10:07
@ImTheTom ImTheTom deleted the ingredient-images-autocompleter branch May 19, 2022 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add images to ingredients
2 participants