snapshot of https://github.com/traggo/server.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
build / build (push) Failing after 3s
Some checks failed
build / build (push) Failing after 3s
This commit is contained in:
59
dashboard/convert/entry.go
Normal file
59
dashboard/convert/entry.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/traggo/server/generated/gqlmodel"
|
||||
"github.com/traggo/server/model"
|
||||
)
|
||||
|
||||
func toExternalEntries(entries []model.DashboardEntry) ([]*gqlmodel.DashboardEntry, error) {
|
||||
result := []*gqlmodel.DashboardEntry{}
|
||||
for _, entry := range entries {
|
||||
converted, err := ToExternalEntry(entry)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result = append(result, converted)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ToExternalEntry converts entries.
|
||||
func ToExternalEntry(entry model.DashboardEntry) (*gqlmodel.DashboardEntry, error) {
|
||||
mobilePosition, err := toExternalPosition(entry.MobilePosition)
|
||||
if err != nil {
|
||||
return &gqlmodel.DashboardEntry{}, err
|
||||
}
|
||||
desktopPos, err := toExternalPosition(entry.DesktopPosition)
|
||||
if err != nil {
|
||||
return &gqlmodel.DashboardEntry{}, err
|
||||
}
|
||||
pos := gqlmodel.ResponsiveDashboardEntryPos{
|
||||
Mobile: enhancePos(mobilePosition, "mobile"),
|
||||
Desktop: enhancePos(desktopPos, "desktop"),
|
||||
}
|
||||
dateRange := &gqlmodel.RelativeOrStaticRange{
|
||||
From: entry.RangeFrom,
|
||||
To: entry.RangeTo,
|
||||
}
|
||||
stats := &gqlmodel.StatsSelection{
|
||||
Interval: ExternalInterval(entry.Interval),
|
||||
Tags: strings.Split(entry.Keys, ","),
|
||||
Range: dateRange,
|
||||
ExcludeTags: tagFiltersToExternal(entry.TagFilters, false),
|
||||
IncludeTags: tagFiltersToExternal(entry.TagFilters, true),
|
||||
}
|
||||
if entry.RangeID != model.NoRangeIDDefined {
|
||||
stats.RangeID = &entry.RangeID
|
||||
stats.Range = nil
|
||||
}
|
||||
return &gqlmodel.DashboardEntry{
|
||||
ID: entry.ID,
|
||||
Title: entry.Title,
|
||||
Total: entry.Total,
|
||||
Pos: &pos,
|
||||
StatsSelection: stats,
|
||||
EntryType: ExternalEntryType(entry.Type),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user