diff --git a/api/routines.go b/api/routines.go
index 16d7c0a..82c5b53 100644
--- a/api/routines.go
+++ b/api/routines.go
@@ -78,4 +78,12 @@ func declareRoutinesRoutes(cfg *config.Config, router *gin.RouterGroup) {
c.JSON(http.StatusOK, nil)
})
+
+ routinesRoutes.POST("/run", func(c *gin.Context) {
+ routine := c.MustGet("routine").(*reveil.Routine)
+
+ go routine.Launch(cfg)
+
+ c.JSON(http.StatusOK, true)
+ })
}
diff --git a/ui/src/lib/components/CardRoutine.svelte b/ui/src/lib/components/CardRoutine.svelte
index cc63566..4ca9b1b 100644
--- a/ui/src/lib/components/CardRoutine.svelte
+++ b/ui/src/lib/components/CardRoutine.svelte
@@ -37,6 +37,14 @@
>
+
{routine.name}
{#if routine.steps}
diff --git a/ui/src/lib/routine.js b/ui/src/lib/routine.js
index 95e6691..f08b2c2 100644
--- a/ui/src/lib/routine.js
+++ b/ui/src/lib/routine.js
@@ -26,6 +26,18 @@ export class Routine {
}
}
+ async launch() {
+ const res = await fetch(`api/routines/${this.id}/run`, {
+ method: 'POST',
+ headers: {'Accept': 'application/json'}
+ });
+ if (res.status == 200) {
+ return true;
+ } else {
+ throw new Error((await res.json()).errmsg);
+ }
+ }
+
async save() {
const res = await fetch(this.id?`api/routines/${this.id}`:'api/routines', {
method: this.id?'PUT':'POST',