Recipe edit (WIP): add API to set some recipe values

This commit is contained in:
Greg Burri 2024-12-23 01:37:01 +01:00
parent c6dfff065c
commit dd05a673d9
20 changed files with 690 additions and 2189 deletions

View file

@ -1,38 +1,6 @@
{% extends "base_with_header.html" %}
{% macro recipe_item(id, title, class) %}
<a href="/recipe/view/{{ id }}" class="{{ class }}">
{% if title == "" %}
{# TODO: Translation #}
No title defined
{% else %}
{{ title }}
{% endif %}
</a>
{% endmacro %}
{% block main_container %}
<nav class="recipes-list">
<ul>
{% for (id, title) in recipes.list %}
<li>
{% match recipes.current_id %}
{# Don't know how to avoid
repetition: comparing (using '==' or .eq()) recipes.current_recipe_id.unwrap() and id doesn't work.
Guards for match don't exist.
See: https://github.com/djc/askama/issues/752 #}
{% when Some(current_id) %}
{% if current_id == id %}
{% call recipe_item(id, title, "recipe-item-current") %}
{% else %}
{% call recipe_item(id, title, "recipe-item") %}
{% endif %}
{% when None %}
{% call recipe_item(id, title, "recipe-item") %}
{% endmatch %}
</li>
{% endfor %}
</ul>
</nav>
{% include "recipes_list_fragment.html" %}
{% block content %}{% endblock %}
{% endblock %}

View file

@ -42,10 +42,10 @@
<label for="select-difficulty">Difficulty</label>
<select id="select-difficulty" name="difficulty">
<option value="0" {%+ call is_difficulty(crate::data::model::Difficulty::Unknown) %}> - </option>
<option value="1" {%+ call is_difficulty(crate::data::model::Difficulty::Easy) %}>Easy</option>
<option value="2" {%+ call is_difficulty(crate::data::model::Difficulty::Medium) %}>Medium</option>
<option value="3" {%+ call is_difficulty(crate::data::model::Difficulty::Hard) %}>Hard</option>
<option value="0" {%+ call is_difficulty(common::ron_api::Difficulty::Unknown) %}> - </option>
<option value="1" {%+ call is_difficulty(common::ron_api::Difficulty::Easy) %}>Easy</option>
<option value="2" {%+ call is_difficulty(common::ron_api::Difficulty::Medium) %}>Medium</option>
<option value="3" {%+ call is_difficulty(common::ron_api::Difficulty::Hard) %}>Hard</option>
</select>
<label for="select-language">Language</label>
@ -59,7 +59,10 @@
id="input-is-published"
type="checkbox"
name="is-published"
value="{{ recipe.is_published }}" />
{%+ if recipe.is_published %}
checked
{% endif %}
>
<label for="input-is-published">Is published</label>
<div id="groups-container">

View file

@ -0,0 +1,50 @@
{% macro recipe_item(id, title, class) %}
<a href="/recipe/view/{{ id }}" class="{{ class }}" id="recipe-{{ id }}">
{% if title == "" %}
{# TODO: Translation #}
Untitled recipe
{% else %}
{{ title }}
{% endif %}
</a>
{% endmacro %}
<div id="recipes-list">
{% if !recipes.unpublished.is_empty() %}
Unpublished recipes
{% endif %}
<nav class="recipes-list-unpublished">
<ul>
{% for (id, title) in recipes.unpublished %}
<li>
{% if recipes.is_current(id) %}
{% call recipe_item(id, title, "recipe-item-current") %}
{% else %}
{% call recipe_item(id, title, "recipe-item") %}
{% endif %}
</li>
{% endfor %}
</ul>
</nav>
{% if !recipes.unpublished.is_empty() %}
<hr />
{% endif %}
<nav class="recipes-list-published">
<ul>
{% for (id, title) in recipes.published %}
<li>
{% if recipes.is_current(id) %}
{% call recipe_item(id, title, "recipe-item-current") %}
{% else %}
{% call recipe_item(id, title, "recipe-item") %}
{% endif %}
</li>
{% endfor %}
</ul>
</nav>
</div>