New route to test routine
All checks were successful
continuous-integration/drone/tag Build is passing
All checks were successful
continuous-integration/drone/tag Build is passing
This commit is contained in:
parent
e1f5fbcd6c
commit
d202cdfee8
@ -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)
|
||||
})
|
||||
}
|
||||
|
@ -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}
|
||||
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user