New route to test routine
continuous-integration/drone/tag Build is passing Details

This commit is contained in:
nemunaire 2022-12-08 19:33:51 +01:00
parent e1f5fbcd6c
commit d202cdfee8
3 changed files with 28 additions and 0 deletions

View File

@ -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)
})
}

View File

@ -37,6 +37,14 @@
>
<Icon name="pencil" />
</Button>
<Button
color="outline-success"
size="sm"
class="float-end ms-1"
on:click={() => routine.launch()}
>
<Icon name="play-fill" />
</Button>
{routine.name}
</CardHeader>
{#if routine.steps}

View File

@ -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',