The view shown in the zone list and on the zone page now links to that
view. The zone page and changeset page get breadcrumbs, and the zone list
keeps its filters in the address so going back restores them. Views can
be given a colour (Views > Edit, `jarl view color`, PUT /views/{id}/color)
so zones of the same view are easy to spot; the colour is UI-only, kept
outside changesets, and needs no deploy.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"strconv"
|
|
)
|
|
|
|
// View colours only change how the web UI shows a view, so they are kept
|
|
// outside the configuration: setting one needs no changeset or deploy.
|
|
const viewColorsKey = "view_colors"
|
|
|
|
// ViewColors returns the colour of each view that has one, by view ID.
|
|
func (s *Store) ViewColors(ctx context.Context) (map[int64]string, error) {
|
|
out := map[int64]string{}
|
|
raw, err := s.GetMeta(ctx, viewColorsKey)
|
|
if errors.Is(err, ErrNotFound) {
|
|
return out, nil
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var m map[string]string
|
|
if err := json.Unmarshal([]byte(raw), &m); err != nil {
|
|
return nil, err
|
|
}
|
|
for k, v := range m {
|
|
if id, err := strconv.ParseInt(k, 10, 64); err == nil {
|
|
out[id] = v
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// SetViewColor sets a view's colour; "" removes it. View IDs are never
|
|
// reused, so the colour of a deleted view is harmless and is left alone
|
|
// (the view may still exist in a changeset).
|
|
func (s *Store) SetViewColor(ctx context.Context, id int64, color string) error {
|
|
m, err := s.ViewColors(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if color == "" {
|
|
delete(m, id)
|
|
} else {
|
|
m[id] = color
|
|
}
|
|
out := map[string]string{}
|
|
for k, v := range m {
|
|
out[strconv.FormatInt(k, 10)] = v
|
|
}
|
|
b, _ := json.Marshal(out)
|
|
return s.SetMeta(ctx, viewColorsKey, string(b))
|
|
}
|