Commit 90933b06 by Marcus Efraimsson

dashboard: refactor logic for retrieving url for folder/dashboard

parent c19f4a86
...@@ -90,6 +90,7 @@ func GetDashboard(c *middleware.Context) Response { ...@@ -90,6 +90,7 @@ func GetDashboard(c *middleware.Context) Response {
IsFolder: dash.IsFolder, IsFolder: dash.IsFolder,
FolderId: dash.FolderId, FolderId: dash.FolderId,
FolderTitle: "Root", FolderTitle: "Root",
Url: dash.GetUrl(),
} }
// lookup folder title // lookup folder title
...@@ -101,12 +102,6 @@ func GetDashboard(c *middleware.Context) Response { ...@@ -101,12 +102,6 @@ func GetDashboard(c *middleware.Context) Response {
meta.FolderTitle = query.Result.Title meta.FolderTitle = query.Result.Title
} }
if dash.IsFolder {
meta.Url = m.GetFolderUrl(dash.Uid, dash.Slug)
} else {
meta.Url = m.GetDashboardUrl(dash.Uid, dash.Slug)
}
// make sure db version is in sync with json model version // make sure db version is in sync with json model version
dash.Data.Set("version", dash.Version) dash.Data.Set("version", dash.Version)
...@@ -238,12 +233,7 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response { ...@@ -238,12 +233,7 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
return ApiError(500, "Invalid alert data. Cannot save dashboard", err) return ApiError(500, "Invalid alert data. Cannot save dashboard", err)
} }
var url string dashboard.IsFolder = dash.IsFolder
if dash.IsFolder {
url = m.GetFolderUrl(dashboard.Uid, dashboard.Slug)
} else {
url = m.GetDashboardUrl(dashboard.Uid, dashboard.Slug)
}
c.TimeRequest(metrics.M_Api_Dashboard_Save) c.TimeRequest(metrics.M_Api_Dashboard_Save)
return Json(200, util.DynMap{ return Json(200, util.DynMap{
...@@ -252,7 +242,7 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response { ...@@ -252,7 +242,7 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
"version": dashboard.Version, "version": dashboard.Version,
"id": dashboard.Id, "id": dashboard.Id,
"uid": dashboard.Uid, "uid": dashboard.Uid,
"url": url, "url": dashboard.GetUrl(),
}) })
} }
......
...@@ -158,6 +158,20 @@ func SlugifyTitle(title string) string { ...@@ -158,6 +158,20 @@ func SlugifyTitle(title string) string {
return slug.Make(strings.ToLower(title)) return slug.Make(strings.ToLower(title))
} }
// GetUrl return the html url for a folder if it's folder, otherwise for a dashboard
func (dash *Dashboard) GetUrl() string {
return GetDashboardFolderUrl(dash.IsFolder, dash.Uid, dash.Slug)
}
// GetDashboardFolderUrl return the html url for a folder if it's folder, otherwise for a dashboard
func GetDashboardFolderUrl(isFolder bool, uid string, slug string) string {
if isFolder {
return GetFolderUrl(uid, slug)
}
return GetDashboardUrl(uid, slug)
}
// GetDashboardUrl return the html url for a dashboard // GetDashboardUrl return the html url for a dashboard
func GetDashboardUrl(uid string, slug string) string { func GetDashboardUrl(uid string, slug string) string {
return fmt.Sprintf("%s/d/%s/%s", setting.AppSubUrl, uid, slug) return fmt.Sprintf("%s/d/%s/%s", setting.AppSubUrl, uid, slug)
......
...@@ -258,17 +258,11 @@ func makeQueryResult(query *search.FindPersistedDashboardsQuery, res []Dashboard ...@@ -258,17 +258,11 @@ func makeQueryResult(query *search.FindPersistedDashboardsQuery, res []Dashboard
for _, item := range res { for _, item := range res {
hit, exists := hits[item.Id] hit, exists := hits[item.Id]
if !exists { if !exists {
var url string
if item.IsFolder {
url = m.GetFolderUrl(item.Uid, item.Slug)
} else {
url = m.GetDashboardUrl(item.Uid, item.Slug)
}
hit = &search.Hit{ hit = &search.Hit{
Id: item.Id, Id: item.Id,
Title: item.Title, Title: item.Title,
Uri: "db/" + item.Slug, Uri: "db/" + item.Slug,
Url: url, Url: m.GetDashboardFolderUrl(item.IsFolder, item.Uid, item.Slug),
Slug: item.Slug, Slug: item.Slug,
Type: getHitType(item), Type: getHitType(item),
FolderId: item.FolderId, FolderId: item.FolderId,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment