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:
106
model/dashboard.go
Normal file
106
model/dashboard.go
Normal file
@@ -0,0 +1,106 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// DashboardRange a named range of a dashboard.
|
||||
type DashboardRange struct {
|
||||
ID int `gorm:"primary_key;unique_index;AUTO_INCREMENT"`
|
||||
Name string
|
||||
DashboardID int `gorm:"type:int REFERENCES dashboards(id) ON DELETE CASCADE"`
|
||||
Editable bool
|
||||
From string
|
||||
To string
|
||||
}
|
||||
|
||||
// Dashboard a dashboard
|
||||
type Dashboard struct {
|
||||
ID int `gorm:"primary_key;unique_index;AUTO_INCREMENT"`
|
||||
UserID int `gorm:"type:int REFERENCES users(id) ON DELETE CASCADE"`
|
||||
Name string
|
||||
Entries []DashboardEntry
|
||||
Ranges []DashboardRange
|
||||
}
|
||||
|
||||
// DashboardEntry an entry which represents a diagram in a dashboard.
|
||||
type DashboardEntry struct {
|
||||
ID int `gorm:"primary_key;unique_index;AUTO_INCREMENT"`
|
||||
DashboardID int `gorm:"type:int REFERENCES dashboards(id) ON DELETE CASCADE"`
|
||||
Title string
|
||||
Total bool `gorm:"default:false"`
|
||||
Type DashboardType
|
||||
Keys string
|
||||
Interval Interval
|
||||
RangeID int
|
||||
RangeFrom string
|
||||
RangeTo string
|
||||
TagFilters []DashboardTagFilter
|
||||
|
||||
MobilePosition string
|
||||
DesktopPosition string
|
||||
}
|
||||
|
||||
// DashboardTagFilter a tag for filtering timespans
|
||||
type DashboardTagFilter struct {
|
||||
DashboardEntryID int `gorm:"type:int REFERENCES dashboard_entries(id) ON DELETE CASCADE"`
|
||||
Key string
|
||||
StringValue string
|
||||
Include bool
|
||||
}
|
||||
|
||||
// DashboardType the dashboard type
|
||||
type DashboardType string
|
||||
|
||||
// Value for db
|
||||
func (t DashboardType) Value() (driver.Value, error) {
|
||||
return string(t), nil
|
||||
}
|
||||
|
||||
// Scan for db
|
||||
func (t *DashboardType) Scan(value interface{}) error {
|
||||
s, ok := value.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("expected string but was %#v", value)
|
||||
}
|
||||
*t = DashboardType(s)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Interval the interval in which the diagram data should be grouped.
|
||||
type Interval string
|
||||
|
||||
// Value for db
|
||||
func (t Interval) Value() (driver.Value, error) {
|
||||
return string(t), nil
|
||||
}
|
||||
|
||||
// Scan for db
|
||||
func (t *Interval) Scan(value interface{}) error {
|
||||
s, ok := value.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("expected string but was %#v", value)
|
||||
}
|
||||
*t = Interval(s)
|
||||
return nil
|
||||
}
|
||||
|
||||
// No lint errors please.
|
||||
const (
|
||||
TypePieChart DashboardType = "piechart"
|
||||
TypeBarChart DashboardType = "barchart"
|
||||
TypeLineChart DashboardType = "linechart"
|
||||
HorizontalTable DashboardType = "horizontaltable"
|
||||
VerticalTable DashboardType = "verticaltable"
|
||||
TypeStackedBarChart DashboardType = "stackedbarchart"
|
||||
|
||||
IntervalHourly Interval = "hourly"
|
||||
IntervalDaily Interval = "daily"
|
||||
IntervalWeekly Interval = "weekly"
|
||||
IntervalMonthly Interval = "monthly"
|
||||
IntervalYearly Interval = "yearly"
|
||||
IntervalSingle Interval = "single"
|
||||
|
||||
NoRangeIDDefined = -1
|
||||
)
|
||||
Reference in New Issue
Block a user