feat(console): sort the monitor list and put monitors in an order of one's own
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 10m49s
ci / test (pull_request) Successful in 14m39s
ci / build (pull_request) Canceled after 14m22s
ci / image (pull_request) Canceled after 0s
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 10m49s
ci / test (pull_request) Successful in 14m39s
ci / build (pull_request) Canceled after 14m22s
ci / image (pull_request) Canceled after 0s
The monitor list gets a sort switcher: the organization's own order, by default, or by name, status (problems first), uptime (worst first) or latency (slowest first). The choice is remembered in a cookie; paging follows it. "Arrange monitors" shows the whole tree with each group's monitors to drag, or move with up and down, into the order wanted; every change is saved at once through PUT /api/v1/org/monitors/order, which needs write access to every monitor given and is audited. Monitors without a position follow the positioned ones, by name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
ca852c8299
commit
b0d4bcc002
16 files changed
+3389
-2653
No files matched your search
@@ -0,0 +1,66 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
|
||||
)
|
||||
|
||||
type monitorOrderRequest struct {
|
||||
// MonitorIDs in the order wanted; usually the monitors of one group.
|
||||
MonitorIDs []uuid.UUID `json:"monitor_ids" binding:"required,min=1,max=1000"`
|
||||
}
|
||||
|
||||
// orderMonitors stores the organization's own order of the monitors given,
|
||||
// which the monitor list follows when sorted by its own order. It needs
|
||||
// write access to every one of them.
|
||||
func (s *Server) orderMonitors(c *gin.Context) {
|
||||
var req monitorOrderRequest
|
||||
if !bind(c, &req) {
|
||||
return
|
||||
}
|
||||
p := current(c)
|
||||
ctx := c.Request.Context()
|
||||
t, err := s.loadGroupTree(ctx, p.scope())
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
errDenied := errors.New("denied")
|
||||
seen := map[uuid.UUID]bool{}
|
||||
err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||
for i, id := range req.MonitorIDs {
|
||||
if seen[id] {
|
||||
return pgx.ErrNoRows
|
||||
}
|
||||
seen[id] = true
|
||||
m, err := q.GetMonitor(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !canInGroup(p, authz.MonitorsWrite, t, m.GroupID) {
|
||||
return errDenied
|
||||
}
|
||||
if _, err := q.SetMonitorPosition(ctx, store.SetMonitorPositionParams{ID: id, Position: new(int32(i))}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
switch {
|
||||
case errors.Is(err, errDenied):
|
||||
fail(c, http.StatusForbidden, "forbidden")
|
||||
case errors.Is(err, pgx.ErrNoRows):
|
||||
fail(c, http.StatusUnprocessableEntity, "invalid_monitor")
|
||||
case err != nil:
|
||||
internalError(c, err)
|
||||
default:
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user