TandoorRecipes / recipes

Application for managing recipes, planning meals, building shopping lists and much much more!
https://docs.tandoor.dev
Other
5.44k stars 577 forks source link

Ingredient Amount in Text #218

Closed vabene1111 closed 3 years ago

vabene1111 commented 3 years ago

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

tourn commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

tourn commented 3 years ago

I suppose you could use the ingredient name (perhaps in a normalized form) as a dict key in ingredients as well, so you could use {{ingredients ['Dinkelmehl'] }} which would of course break when you go batch renaming your ingredients.

Could you also provide a multiplier variable so we could use {{ 200 * multiplier }} grams?

On Tue, Jan 5, 2021, 10:37 PM vabene1111 notifications@github.com wrote:

ok so i have added this feature using jinja2 templating

[image: 2021-01-05_22-26] https://user-images.githubusercontent.com/6819595/103701386-3e1a2b80-4fa6-11eb-93d1-6257e65bb5b1.gif

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/vabene1111/recipes/issues/218#issuecomment-754917207, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQNERSLNEQRI3KFWY5T4DLSYOBBRANCNFSM4TKDHUOA .

vabene1111 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.