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 {
IsFolder: dash.IsFolder,
FolderId: dash.FolderId,
FolderTitle: "Root",
Url: dash.GetUrl(),
}
// lookup folder title
......@@ -101,12 +102,6 @@ func GetDashboard(c *middleware.Context) Response {
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
dash.Data.Set("version", dash.Version)
......@@ -238,12 +233,7 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
return ApiError(500, "Invalid alert data. Cannot save dashboard", err)
}
var url string
if dash.IsFolder {
url = m.GetFolderUrl(dashboard.Uid, dashboard.Slug)
} else {
url = m.GetDashboardUrl(dashboard.Uid, dashboard.Slug)
}
dashboard.IsFolder = dash.IsFolder
c.TimeRequest(metrics.M_Api_Dashboard_Save)
return Json(200, util.DynMap{
......@@ -252,7 +242,7 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
"version": dashboard.Version,
"id": dashboard.Id,
"uid": dashboard.Uid,
"url": url,
"url": dashboard.GetUrl(),
})
}
......
......@@ -158,6 +158,20 @@ func SlugifyTitle(title string) string {
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
func GetDashboardUrl(uid string, slug string) string {
return fmt.Sprintf("%s/d/%s/%s", setting.AppSubUrl, uid, slug)
......
......@@ -258,17 +258,11 @@ func makeQueryResult(query *search.FindPersistedDashboardsQuery, res []Dashboard
for _, item := range res {
hit, exists := hits[item.Id]
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{
Id: item.Id,
Title: item.Title,
Uri: "db/" + item.Slug,
Url: url,
Url: m.GetDashboardFolderUrl(item.IsFolder, item.Uid, item.Slug),
Slug: item.Slug,
Type: getHitType(item),
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