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

Ingredient Amount in Text #218

Closed
vabene1111 opened this issue Nov 4, 2020 · 10 comments
Closed

Ingredient Amount in Text #218

vabene1111 opened this issue Nov 4, 2020 · 10 comments
Labels
enhancement New feature or request

Comments

@vabene1111
Copy link
Collaborator

Automatically show the amount for an ingredient in the instruction text when its mentioned.

This requires some kind of reference system between ingredients and text, maybe ingredients are stored to the DB the moment they are added to receive a unique ID or maybe something like the temp and final ID system from the importer.

Might also be the step were the move to client side markdown rendering is done 🤔 or some other solution needs to be found in order to be able to scale recipes

@vabene1111 vabene1111 added the enhancement New feature or request label Nov 4, 2020
@tourn
Copy link
Contributor

tourn commented Dec 18, 2020

If it's just about scaling, i might have a simpler idea. Do we really need references to the ingredients in the recipe text, or is it enough to just have numbers in the text scale based on the multiplier/serving count?
Let's say you write the following into your recipe step: (just bear with me in the example and feel free to substitute "eggs" with any other ingredient)

Bake $2$ eggs at 180º C for 15 minutes. 

We could then just parse these $xxx$ placeholders and scale them according to the multiplier.

Sure, if you ever update the count of eggs in your ingredient list you will have to manually adjust it in the text, but in some cases you're not using all the eggs in the same step. Doing it this way wouldn't require any changes in the data model at all, either.

@vabene1111
Copy link
Collaborator Author

hmm thats a very interesting idea. I am a very big fan of not having any redundant data anywhere but you are right, this would make it much simpler to implement.

On the other hand i need to implement the adding of elements on the client side with direct updates on the server anyways at some point since i currently have some very hacky solutions so this might be just the motivator to do so ...

I currently dont have the time for this feature but it would be one that i really like to have so we will see .. of course if you want to give it a shot feel free to play around a little ..

@aarondoet
Copy link
Contributor

I would prefer the option with Bake $2$ eggs at 180°C for 15 minutes. because sometimes you only need to add half of something. Currently the best option would be to write add half of the butter but with this feature you could just write add $20$g butter even when in the ingredients it says 50g butter because you need 30g for something else. Referencing the ingredient and then even adding a multiplier (like 0.5 or 0.4) would probably make it too overcomplicated.

@vabene1111
Copy link
Collaborator Author

interesting take. I tend to add two ingredients if i need some butter here and some there but you definitely have a point here.

@vabene1111
Copy link
Collaborator Author

vabene1111 commented Jan 5, 2021

ok so i have added this feature using jinja2 templating

2021-01-05_22-26

The syntax is

Take {{ ingredients[0] }} and mix it with {{ ingredients[1] }} 

This is not super intuitive as changing the order of the ingredients would break the text but i think its better than nothing. Also the alternative would be to use IDs in the text which is even more confusing.

The only way to really do this in a good way would be to use a WYSIWYG editor but i dont like those. Maybe someone has a better idea ?

TODO

  • add documentation
  • add some kind of button to insert reference into text

@vabene1111 vabene1111 pinned this issue Jan 5, 2021
@tourn
Copy link
Contributor

tourn commented Jan 5, 2021 via email

@vabene1111
Copy link
Collaborator Author

First: It also breaks if you have the same ingredient twice (e.g. bread baking with multiple sets of flour or water in one step), thats why i did not go this way (although it would not be to difficult)

Second: What would the multiplier be needed for ? The ingredient can already be scaled with the "global" multiplier.
Is this because you want to have an ingredient (e.g. flour) only once in the ingredient list and then in the text differentiate between the different times you use it ?

If this is the case, do you think that an option to "combine" ingredients of the same unit for the top most ingredient list would be a better feature ?

@tourn
Copy link
Contributor

tourn commented Jan 12, 2021

First: It also breaks if you have the same ingredient twice (e.g. bread baking with multiple sets of flour or water in one step), thats why i did not go this way (although it would not be to difficult)

Yup, you're right. Probably not the best idea.

Is this because you want to have an ingredient (e.g. flour) only once in the ingredient list and then in the text differentiate between the different times you use it ?

Yeah, for having the option to have scaling numbers without referencing any ingredient. I myself (and many people, I expect) don't expect to tweak around the ingredients too often, so not having to mess around with any ingredient references sounds appealing to me. This would cover my previous idea.


If we really want to go super fancy, we can add an autocomplete that opens when you type # to pick ingredients. We could format ingredient references like {{ ingredient(1285, 'Dinkelmehl') }} where the first paramater is the primary key of the ingredient table. The second parameter is ignored and just there so you have some idea what ingredient is referenced by this call. This would both be human readable and renaming resistant.
image

@vabene1111
Copy link
Collaborator Author

Yes, the primary key would be great. The problem is that, at least currently, i do not insert ingredients into the database whenever one is added on the client. This means that while adding many entries will not yet have primary keys.

One option would be to only allow templating after one has saved the recipe with all the ingredients once but that felt bad (but now that i am thinking about it actually sounds reasonable) ...

autocomplete would be awesome but is definitely something that will not be in the first version as i have no idea on how to do it (but i guess its probably not tooo hard)

@vabene1111
Copy link
Collaborator Author

Ok so i have decided not to go with primary keys but add comments to the tag when using the "copy template tag" function from the ingredient context menu e.g. {{ ingredients[0] }}{# Tomato #}

Autocompletion will be something that i add after the edit recipe page is migrated to the new vue.js build system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants