Add height parameter to dashboard data model #36

This commit is contained in:
Sonja Happ 2020-06-26 09:44:25 +02:00
parent 9649967187
commit 1fa7444c66
7 changed files with 60 additions and 658 deletions

View file

@ -145,6 +145,8 @@ type Dashboard struct {
Name string `json:"name" gorm:"not null"`
// Grid of dashboard
Grid int `json:"grid" gorm:"default:15"`
// Height of dashboard
Height int `json:"height"`
// ID of scenario to which dashboard belongs
ScenarioID uint `json:"scenarioID"`
// Widgets that belong to dashboard

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -72,6 +72,7 @@ func (d *Dashboard) update(modifiedDab Dashboard) error {
err := db.Model(d).Updates(map[string]interface{}{
"Name": modifiedDab.Name,
"Grid": modifiedDab.Grid,
"Height": modifiedDab.Height,
}).Error
return err

View file

@ -41,6 +41,7 @@ var router *gin.Engine
type DashboardRequest struct {
Name string `json:"name,omitempty"`
Grid int `json:"grid,omitempty"`
Height int `json:"height,omitempty"`
ScenarioID uint `json:"scenarioID,omitempty"`
}

View file

@ -30,11 +30,13 @@ var validate *validator.Validate
type validNewDashboard struct {
Name string `form:"Name" validate:"required"`
Grid int `form:"Grid" validate:"required"`
Height int `form:"Height" validate:"omitempty"`
ScenarioID uint `form:"ScenarioID" validate:"required"`
}
type validUpdatedDashboard struct {
Name string `form:"Name" validate:"omitempty" json:"name"`
Height int `form:"Height" validate:"omitempty" json:"height"`
Grid int `form:"Grid" validate:"omitempty" json:"grid"`
}
@ -63,6 +65,7 @@ func (r *addDashboardRequest) createDashboard() Dashboard {
s.Name = r.Dashboard.Name
s.Grid = r.Dashboard.Grid
s.Height = r.Dashboard.Height
s.ScenarioID = r.Dashboard.ScenarioID
return s
@ -80,5 +83,9 @@ func (r *updateDashboardRequest) updatedDashboard(oldDashboard Dashboard) Dashbo
s.Grid = r.Dashboard.Grid
}
if r.Dashboard.Height > 0 {
s.Height = r.Dashboard.Height
}
return s
}