diff --git a/apps/manacore/apps/web/src/lib/modules/automations/ListView.svelte b/apps/manacore/apps/web/src/lib/modules/automations/ListView.svelte index 358d5eb98..e0b561650 100644 --- a/apps/manacore/apps/web/src/lib/modules/automations/ListView.svelte +++ b/apps/manacore/apps/web/src/lib/modules/automations/ListView.svelte @@ -34,7 +34,6 @@ return () => sub.unsubscribe(); }); - // Load habits for the select dropdown $effect(() => { const sub = liveQuery(async () => { const all = await db.table('habits').toArray(); @@ -51,7 +50,7 @@ return () => sub.unsubscribe(); }); - // Load suggestions + // ─── Suggestions ───────────────────────────────────────── async function refreshSuggestions() { const all = await generateSuggestions(); suggestions = all.filter((s) => !isSuggestionDismissed(s.id)); @@ -61,9 +60,8 @@ refreshSuggestions(); }); - // Refresh suggestions when automations change $effect(() => { - automations; // track + automations; refreshSuggestions(); }); @@ -121,9 +119,7 @@ async function handleCreate(e: Event) { e.preventDefault(); if (!selectedSource || !selectedAction) return; - const name = newName.trim() || `${selectedSource.appLabel} → ${selectedAction.appLabel}`; - await automationsStore.create({ name, sourceApp: selectedSource.app, @@ -139,239 +135,335 @@ resetForm(); } + // ─── Helpers ───────────────────────────────────────────── function sourceLabel(a: LocalAutomation): string { const src = SOURCE_OPTIONS.find( (s) => s.app === a.sourceApp && s.collection === a.sourceCollection ); - return src - ? `${src.appLabel} / ${src.collectionLabel}` - : `${a.sourceApp}.${a.sourceCollection}`; + return src ? src.appLabel : a.sourceApp; + } + + function sourceDetail(a: LocalAutomation): string { + const src = SOURCE_OPTIONS.find( + (s) => s.app === a.sourceApp && s.collection === a.sourceCollection + ); + const opLabel = a.sourceOp === 'insert' ? 'erstellt' : 'geaendert'; + return src ? `${src.collectionLabel} ${opLabel}` : `${a.sourceCollection} ${opLabel}`; } function actionLabel(a: LocalAutomation): string { const act = ACTION_OPTIONS.find((o) => o.app === a.targetApp && o.action === a.targetAction); - return act ? `${act.appLabel}: ${act.actionLabel}` : `${a.targetApp}.${a.targetAction}`; + return act ? act.appLabel : a.targetApp; + } + + function actionDetail(a: LocalAutomation): string { + const act = ACTION_OPTIONS.find((o) => o.app === a.targetApp && o.action === a.targetAction); + if (!act) return a.targetAction; + if (a.targetAction === 'logHabit' && a.targetParams?.habitId) { + const habit = habits.find((h) => h.id === a.targetParams?.habitId); + return habit ? `${act.actionLabel}: ${habit.title}` : act.actionLabel; + } + return act.actionLabel; } function conditionLabel(a: LocalAutomation): string { - if (!a.conditionField) return 'immer'; + if (!a.conditionField || !a.conditionValue) return ''; const opLabel = CONDITION_OPS.find((o) => o.value === a.conditionOp)?.label ?? a.conditionOp; return `${a.conditionField} ${opLabel} "${a.conditionValue}"`; }
- -
- Automations - {#if !showCreate} - - {/if} -
- {#if suggestions.length > 0} -
+
{#each suggestions as sug (sug.id)} -
-
- {sug.name} - {sug.description} +
+
+
-
- - +
+ {sug.name} + {sug.description} +
+
+ +
{/each}
{/if} - - {#if showCreate} -
- + +
+
+ + {#if !showCreate} + + {/if} +
- -
- WENN - + {#if showCreate} + + - {#if selectedSource} -
- -
- {/if} -
- - - {#if selectedSource} -
- BEDINGUNG (optional) -
- + + {#each SOURCE_OPTIONS as src} + {/each} - {#if newConditionField} - + + - {/if}
- {/if} - -
- DANN - - - {#if selectedAction} - {#each selectedAction.params as param} -
- {param.label} - {#if param.key === 'habitId'} - + + {#each selectedSource.fields as field} + + {/each} + + {#if newConditionField} + - {:else} { - newParams = { ...newParams, [param.key]: (e.target as HTMLInputElement).value }; - }} + placeholder="Wert..." + bind:value={newConditionValue} /> {/if}
- {/each} +
{/if} -
- -
- - -
-
- {/if} - - -
- {#each automations as auto (auto.id)} -
- -
- {auto.name} - - {sourceLabel(auto)} - - {conditionLabel(auto)} - - {actionLabel(auto)} - +
+ DANN +
+ + {#if selectedAction} + {#each selectedAction.params as param} + {#if param.key === 'habitId'} + + {:else} + { + newParams = { + ...newParams, + [param.key]: (e.target as HTMLInputElement).value, + }; + }} + /> + {/if} + {/each} + {/if} +
+
+ + + + {/if} + + + {#each automations as auto (auto.id)} +
+
+ + {auto.name} + +
+
+ {sourceLabel(auto)} + {sourceDetail(auto)} + {#if conditionLabel(auto)} + + wenn + {conditionLabel(auto)} + {/if} + + {actionLabel(auto)} + {actionDetail(auto)}
-
{/each} -
- {#if automations.length === 0 && !showCreate} -
-

Keine Automations angelegt.

-

Erstelle Regeln die Module miteinander verbinden.

- -
- {/if} + {#if automations.length === 0 && !showCreate} +
+

Keine Automations

+

Verbinde Module mit Regeln: "Wenn X passiert, mache Y"

+ +
+ {/if} +