Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
90933b06
Commit
90933b06
authored
Jan 31, 2018
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: refactor logic for retrieving url for folder/dashboard
parent
c19f4a86
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
20 deletions
+18
-20
pkg/api/dashboard.go
+3
-13
pkg/models/dashboards.go
+14
-0
pkg/services/sqlstore/dashboard.go
+1
-7
No files found.
pkg/api/dashboard.go
View file @
90933b06
...
...
@@ -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
()
,
})
}
...
...
pkg/models/dashboards.go
View file @
90933b06
...
...
@@ -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
)
...
...
pkg/services/sqlstore/dashboard.go
View file @
90933b06
...
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment