recipe links

This commit is contained in:
Joren de Graaf
2026-10-23 14:30:58 +02:00
parent 5b986134be
commit 4d76a2bc9c
52 changed files with 2698 additions and 19 deletions
@@ -0,0 +1,17 @@
{% extends 'planner/base.html' %}
{% block title %}Preview grocery sync · TasksNest{% endblock %}
{% block content %}
<section class="settings-page">
<p class="eyebrow">Home Assistant</p><h1>Preview grocery sync</h1>
<p><a href="{% url 'home_assistant:settings' %}">← Home Assistant settings</a></p>
<section class="settings-card">
<h2>{% if first_sync %}First sync review{% else %}Changes to sync{% endif %}</h2>
<p>Review these changes before anything is written. This preview expires after 10 minutes and is checked again when you confirm. At most 20 changes run at once.</p>
{% if plan.operations %}<ul>{% for action in plan.operations %}<li><strong>{% if action.kind == 'export' %}Add to Home Assistant{% elif action.kind == 'import' %}Add to TasksNest{% elif action.kind == 'push' %}Update Home Assistant{% elif action.kind == 'pull' %}Update TasksNest{% elif action.kind == 'reconcile' %}Reconnect by UID{% else %}Record matching state{% endif %}:</strong> {{ action.label }}</li>{% endfor %}</ul>{% else %}<p>No changes are ready to sync.</p>{% endif %}
{% if plan.limited %}<p>Only the first 20 changes will run. Preview again for the rest.</p>{% endif %}
{% if plan.issues %}<h3>Needs review</h3><ul>{% for issue in plan.issues %}<li>{{ issue }}</li>{% endfor %}</ul>{% endif %}
{% if plan.pending_recoveries %}<h3>Uncertain additions</h3><p>Check the Home Assistant list first. Reset only if the item is absent; if it appears, preview again so it can be matched.</p>{% for recovery in plan.pending_recoveries %}<form method="post">{% csrf_token %}<input type="hidden" name="preview_token" value="{{ preview_token }}"><input type="hidden" name="action" value="reset-pending"><input type="hidden" name="mapping_id" value="{{ recovery.mapping_id }}"><label><input type="checkbox" name="checked_absent" value="yes" required> I checked Home Assistant; “{{ recovery.label }}” is not there.</label> <button class="button button--secondary" type="submit">Reset pending addition</button></form>{% endfor %}{% endif %}
{% if plan.operations or first_sync %}<form method="post">{% csrf_token %}<input type="hidden" name="preview_token" value="{{ preview_token }}"><button class="button" type="submit">{% if first_sync %}Confirm first sync{% else %}Sync these changes{% endif %}</button></form>{% endif %}
</section>
</section>
{% endblock %}
@@ -0,0 +1,47 @@
{% extends 'planner/base.html' %}
{% block title %}Home Assistant · TasksNest{% endblock %}
{% block content %}
<section class="settings-page">
<p class="eyebrow">Integrations</p><h1>Home Assistant</h1>
<p><a href="{% url 'planner:user-settings' %}">← Settings</a></p>
<section class="settings-card" aria-labelledby="ha-connect-title">
<h2 id="ha-connect-title">Connection</h2>
<p>In Home Assistant, open your profile → Security → Long-Lived Access Tokens. Create a token and paste it here. For private network addresses, HTTP is allowed; use HTTPS for public servers.</p>
<form method="post">{% csrf_token %}<input type="hidden" name="action" value="save"><input type="hidden" name="username" autocomplete="username" value="{{ request.user.username }}">
<div class="form-field"><label for="ha-url">Instance URL</label><input id="ha-url" name="base_url" type="url" maxlength="500" required value="{% if connection %}{{ connection.base_url }}{% endif %}" placeholder="https://home.example.nl"></div>
<div class="form-field"><label for="ha-token">Long-lived access token</label><input id="ha-token" name="token" type="password" maxlength="4096" autocomplete="new-password" {% if not connection %}required{% endif %} aria-describedby="ha-token-help"><small id="ha-token-help">{% if connection %}A token is saved. Leave blank to keep it; enter a new one to replace it.{% else %}The token is stored encrypted and is never shown again.{% endif %}</small></div>
<button class="button" type="submit">Save connection</button>
</form>
{% if connection %}<p>Connection: {% if connection.last_tested_at %}Tested {{ connection.last_tested_at }} · Home Assistant {{ connection.version }}{% else %}Not tested{% endif %}</p>
{% if connection.last_error %}<p role="alert">Last test: {{ connection.last_error }}</p>{% endif %}
<form method="post">{% csrf_token %}<button class="button button--secondary" name="action" value="test">Test connection</button> <button class="button button--secondary" name="action" value="discover">Discover to-do lists</button></form>
<form method="post">{% csrf_token %}<button class="button button--secondary" type="submit" name="action" value="disconnect">Disconnect and remove token</button></form>
{% endif %}
</section>
{% if connection and connection.entities %}<section class="settings-card" aria-labelledby="ha-lists-title">
<h2 id="ha-lists-title">Grocery list</h2><p>Choose the Home Assistant to-do entity for your TasksNest groceries. Selecting a list does not sync or change any items.</p>
<form method="post">{% csrf_token %}<div class="form-field"><label for="ha-grocery-list">Home Assistant list</label><select id="ha-grocery-list" name="grocery_entity_id" required><option value="">Choose a list</option>{% for entity in connection.entities %}<option value="{{ entity.id }}" {% if entity.id == connection.grocery_entity_id %}selected{% endif %} {% if entity.available == False %}disabled{% endif %}>{{ entity.name }} ({{ entity.id }}){% if entity.available == False %} — unavailable{% endif %}</option>{% endfor %}</select></div><button class="button" name="action" value="select">Save list</button></form>
</section>{% endif %}
{% if connection and connection.entities %}<section class="settings-card" aria-labelledby="ha-task-list-title">
<h2 id="ha-task-list-title">Optional task list</h2>
<p>Syncs only top-level, active, non-recurring tasks. Titles, completion, descriptions, and scheduled dates are shared when the selected Home Assistant list supports those fields. Recurrence, subtasks, priority, weather rules, and deferrals stay in TasksNest. If you also use Apple Reminders through the Home Assistant Companion app, set its list sync direction to “Beide kanten op” and its conflict preference to Home Assistant; iOS background sync may be delayed.</p>
<form method="post">{% csrf_token %}<div class="form-field"><label for="ha-task-list">Home Assistant task list</label><select id="ha-task-list" name="task_entity_id"><option value="">Not connected</option>{% for entity in connection.entities %}{% if entity.id != connection.grocery_entity_id %}<option value="{{ entity.id }}" {% if entity.id == connection.task_entity_id %}selected{% endif %} {% if entity.available == False %}disabled{% endif %}>{{ entity.name }} ({{ entity.id }}){% if entity.available == False %} — unavailable{% endif %}</option>{% endif %}{% endfor %}</select></div><button class="button button--secondary" name="action" value="select-task">Save task list</button></form>
{% if connection.task_entity_id %}<p>{% if connection.task_initial_sync_confirmed %}Task sync is enabled.{% else %}First task sync needs review and confirmation.{% endif %}</p><a class="button" href="{% url 'home_assistant:task-preview' %}">Preview task changes</a>{% endif %}
</section>{% endif %}
{% if connection and connection.grocery_entity_id %}<section class="settings-card" aria-labelledby="ha-sync-title">
<h2 id="ha-sync-title">Grocery sync</h2>
<p>TasksNest syncs item names and purchased status. Quantities, units, categories, product links, and inventory stay in TasksNest. Items absent from either list are never deleted automatically.</p>
<form method="post">{% csrf_token %}<input type="hidden" name="action" value="sync-options">
<div class="form-field"><label for="ha-direction">Direction</label><select id="ha-direction" name="direction"><option value="both" {% if connection.direction == 'both' %}selected{% endif %}>Two-way (recommended)</option><option value="from_ha" {% if connection.direction == 'from_ha' %}selected{% endif %}>Home Assistant → TasksNest</option><option value="to_ha" {% if connection.direction == 'to_ha' %}selected{% endif %}>TasksNest → Home Assistant</option></select></div>
<div class="form-field"><label for="ha-winner">If both sides changed</label><select id="ha-winner" name="conflict_winner"><option value="ha" {% if connection.conflict_winner == 'ha' %}selected{% endif %}>Home Assistant wins (recommended)</option><option value="tasksnest" {% if connection.conflict_winner == 'tasksnest' %}selected{% endif %}>TasksNest wins</option></select></div>
<div class="form-field"><label for="ha-interval">Automatic sync</label><select id="ha-interval" name="sync_interval_minutes"><option value="manual" {% if connection.sync_interval_minutes == 'manual' %}selected{% endif %}>Manual only</option><option value="5" {% if connection.sync_interval_minutes == '5' %}selected{% endif %}>Every 5 minutes</option><option value="15" {% if connection.sync_interval_minutes == '15' %}selected{% endif %}>Every 15 minutes</option><option value="30" {% if connection.sync_interval_minutes == '30' %}selected{% endif %}>Every 30 minutes</option></select></div>
<div class="form-field"><label><input type="checkbox" name="auto_sync_enabled" {% if connection.auto_sync_enabled %}checked{% endif %} {% if not connection.initial_sync_confirmed %}disabled{% endif %}> Enable automatic sync</label>{% if not connection.initial_sync_confirmed %}<small>Confirm the first sync before enabling automatic sync.</small>{% endif %}</div>
<button class="button button--secondary" type="submit">Save sync preferences</button>
</form>
<p>{% if connection.last_synced_at %}Last successful sync: {{ connection.last_synced_at }}{% else %}No sync has run yet.{% endif %}</p>
{% if connection.last_sync_error %}<p role="alert">Last sync: {{ connection.last_sync_error }}</p>{% endif %}
{% if history %}<h3>Recent sync activity</h3><ul>{% for run in history %}<li>{{ run.created_at }} · {% if run.succeeded %}Succeeded{% else %}Failed{% endif %}{% if run.automatic %} (automatic){% else %} (manual){% endif %} · {{ run.summary }}{% if run.error %}: {{ run.error }}{% endif %}</li>{% endfor %}</ul>{% endif %}
<a class="button" href="{% url 'home_assistant:preview' %}">Preview changes</a>
</section>{% endif %}
</section>
{% endblock %}
@@ -0,0 +1,17 @@
{% extends 'planner/base.html' %}
{% block title %}Preview task sync · TasksNest{% endblock %}
{% block content %}
<section class="settings-page">
<p class="eyebrow">Home Assistant</p><h1>Preview task sync</h1>
<p><a href="{% url 'home_assistant:settings' %}">← Home Assistant settings</a></p>
<section class="settings-card">
<h2>{% if first_sync %}First task sync review{% else %}Task changes to sync{% endif %}</h2>
<p>Review changes before writing. The preview expires after 10 minutes and is checked again at confirmation. At most 20 changes run at once.</p>
{% if plan.operations %}<ul>{% for action in plan.operations %}<li><strong>{% if action.kind == 'task_export' %}Add to Home Assistant{% elif action.kind == 'task_import' %}Add to TasksNest{% elif action.kind == 'task_push' %}Update Home Assistant{% elif action.kind == 'task_pull' %}Update TasksNest{% elif action.kind == 'task_reconcile' %}Reconnect by UID{% else %}Record matching state{% endif %}:</strong> {{ action.label }}</li>{% endfor %}</ul>{% else %}<p>No changes are ready to sync.</p>{% endif %}
{% if plan.limited %}<p>Only the first 20 changes will run. Preview again for the rest.</p>{% endif %}
{% if plan.issues %}<h3>Needs review</h3><ul>{% for issue in plan.issues %}<li>{{ issue }}</li>{% endfor %}</ul>{% endif %}
{% if plan.pending_recoveries %}<h3>Uncertain additions</h3><p>Check the Home Assistant list first. Reset only if the task is absent; if it appears, preview again so it can be matched.</p>{% for recovery in plan.pending_recoveries %}<form method="post">{% csrf_token %}<input type="hidden" name="preview_token" value="{{ preview_token }}"><input type="hidden" name="action" value="reset-pending"><input type="hidden" name="mapping_id" value="{{ recovery.mapping_id }}"><label><input type="checkbox" name="checked_absent" value="yes" required> I checked Home Assistant; “{{ recovery.label }}” is not there.</label> <button class="button button--secondary" type="submit">Reset pending task addition</button></form>{% endfor %}{% endif %}
{% if plan.operations or first_sync %}<form method="post">{% csrf_token %}<input type="hidden" name="preview_token" value="{{ preview_token }}"><button class="button" type="submit">{% if first_sync %}Confirm first task sync{% else %}Sync these task changes{% endif %}</button></form>{% endif %}
</section>
</section>
{% endblock %}