3
0
mirror of https://github.com/grafana/grafana.git synced 2025-02-25 18:55:37 -06:00

Fixed small issue when using 'Save As', dashboard version was not reset

This commit is contained in:
Torkel Ödegaard 2015-03-19 10:32:47 -04:00
parent 30047e6a9f
commit 94c3a07115

View File

@ -14,6 +14,7 @@ var (
ErrDashboardVersionMismatch = errors.New("The dashboard has been changed by someone else")
)
// Dashboard model
type Dashboard struct {
Id int64
Slug string
@ -27,6 +28,7 @@ type Dashboard struct {
Data map[string]interface{}
}
// NewDashboard creates a new dashboard
func NewDashboard(title string) *Dashboard {
dash := &Dashboard{}
dash.Data = make(map[string]interface{})
@ -36,6 +38,7 @@ func NewDashboard(title string) *Dashboard {
return dash
}
// GetTags turns the tags in data json into go string array
func (dash *Dashboard) GetTags() []string {
jsonTags := dash.Data["tags"]
if jsonTags == nil {
@ -50,6 +53,7 @@ func (dash *Dashboard) GetTags() []string {
return b
}
// GetDashboardModel turns the command into the savable model
func (cmd *SaveDashboardCommand) GetDashboardModel() *Dashboard {
dash := &Dashboard{}
dash.Data = cmd.Dashboard
@ -63,15 +67,19 @@ func (cmd *SaveDashboardCommand) GetDashboardModel() *Dashboard {
if dash.Data["version"] != nil {
dash.Version = int(dash.Data["version"].(float64))
}
} else {
dash.Data["version"] = 0
}
return dash
}
// GetString a
func (dash *Dashboard) GetString(prop string) string {
return dash.Data[prop].(string)
}
// UpdateSlug updates the slug
func (dash *Dashboard) UpdateSlug() {
title := strings.ToLower(dash.Data["title"].(string))
re := regexp.MustCompile("[^\\w ]+")