Add manual run button for backups in dashboard

This commit is contained in:
Luis Eduardo Jeréz Girón
2024-07-24 10:14:42 -06:00
parent 76d8562855
commit 8e5a804a41
3 changed files with 40 additions and 0 deletions

View File

@@ -76,6 +76,7 @@ func listBackups(
lucide.List(),
),
),
manualRunbutton(backup.ID),
editBackupButton(backup),
deleteBackupButton(backup.ID),
),

View File

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

View File

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