diff --git a/internal/view/web/dashboard/backups/list_backups.go b/internal/view/web/dashboard/backups/list_backups.go index 7224154..466c9e0 100644 --- a/internal/view/web/dashboard/backups/list_backups.go +++ b/internal/view/web/dashboard/backups/list_backups.go @@ -76,6 +76,7 @@ func listBackups( lucide.List(), ), ), + manualRunbutton(backup.ID), editBackupButton(backup), deleteBackupButton(backup.ID), ), diff --git a/internal/view/web/dashboard/backups/manual_run.go b/internal/view/web/dashboard/backups/manual_run.go new file mode 100644 index 0000000..ecaba94 --- /dev/null +++ b/internal/view/web/dashboard/backups/manual_run.go @@ -0,0 +1,38 @@ +package backups + +import ( + lucide "github.com/eduardolat/gomponents-lucide" + "github.com/eduardolat/pgbackweb/internal/view/web/htmx" + "github.com/google/uuid" + "github.com/labstack/echo/v4" + "github.com/maragudk/gomponents" + "github.com/maragudk/gomponents/html" +) + +func (h *handlers) manualRunHandler(c echo.Context) error { + ctx := c.Request().Context() + + backupID, err := uuid.Parse(c.Param("backupID")) + if err != nil { + return htmx.RespondToastError(c, err.Error()) + } + + if err := h.servs.ExecutionsService.RunExecution(ctx, backupID); err != nil { + return htmx.RespondToastError(c, err.Error()) + } + + return htmx.RespondToastSuccess(c, "Backup run successfully, check the backup executions for more details") +} + +func manualRunbutton(backupID uuid.UUID) gomponents.Node { + return html.Div( + html.Class("inline-block tooltip tooltip-right"), + html.Data("tip", "Run backup now"), + html.Button( + htmx.HxPost("/dashboard/backups/"+backupID.String()+"/run"), + htmx.HxDisabledELT("this"), + html.Class("btn btn-sm btn-ghost btn-square"), + lucide.Zap(), + ), + ) +} diff --git a/internal/view/web/dashboard/backups/router.go b/internal/view/web/dashboard/backups/router.go index 424c5b3..2ad0960 100644 --- a/internal/view/web/dashboard/backups/router.go +++ b/internal/view/web/dashboard/backups/router.go @@ -25,4 +25,5 @@ func MountRouter( parent.POST("", h.createBackupHandler) parent.DELETE("/:backupID", h.deleteBackupHandler) parent.POST("/:backupID/edit", h.editBackupHandler) + parent.POST("/:backupID/run", h.manualRunHandler) }