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
9fb7b887
Commit
9fb7b887
authored
Jan 30, 2018
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboards: add url property to dashboard meta and search api responses
#7883
parent
7ee691dc
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
0 deletions
+33
-0
pkg/api/dashboard.go
+6
-0
pkg/api/dtos/dashboard.go
+1
-0
pkg/models/dashboards.go
+12
-0
pkg/services/search/models.go
+1
-0
pkg/services/sqlstore/dashboard.go
+9
-0
pkg/services/sqlstore/dashboard_test.go
+3
-0
pkg/services/sqlstore/search_builder.go
+1
-0
No files found.
pkg/api/dashboard.go
View file @
9fb7b887
...
...
@@ -101,6 +101,12 @@ 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
)
...
...
pkg/api/dtos/dashboard.go
View file @
9fb7b887
...
...
@@ -16,6 +16,7 @@ type DashboardMeta struct {
CanAdmin
bool
`json:"canAdmin"`
CanStar
bool
`json:"canStar"`
Slug
string
`json:"slug"`
Url
string
`json:"url"`
Expires
time
.
Time
`json:"expires"`
Created
time
.
Time
`json:"created"`
Updated
time
.
Time
`json:"updated"`
...
...
pkg/models/dashboards.go
View file @
9fb7b887
...
...
@@ -2,11 +2,13 @@ package models
import
(
"errors"
"fmt"
"strings"
"time"
"github.com/gosimple/slug"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
)
...
...
@@ -156,6 +158,16 @@ func SlugifyTitle(title string) string {
return
slug
.
Make
(
strings
.
ToLower
(
title
))
}
// 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
)
}
// GetFolderUrl return the html url for a folder
func
GetFolderUrl
(
folderUid
string
,
slug
string
)
string
{
return
fmt
.
Sprintf
(
"%s/f/%v/%s"
,
setting
.
AppSubUrl
,
folderUid
,
slug
)
}
//
// COMMANDS
//
...
...
pkg/services/search/models.go
View file @
9fb7b887
...
...
@@ -15,6 +15,7 @@ type Hit struct {
Id
int64
`json:"id"`
Title
string
`json:"title"`
Uri
string
`json:"uri"`
Url
string
`json:"url"`
Slug
string
`json:"slug"`
Type
HitType
`json:"type"`
Tags
[]
string
`json:"tags"`
...
...
pkg/services/sqlstore/dashboard.go
View file @
9fb7b887
...
...
@@ -182,6 +182,7 @@ func GetDashboard(query *m.GetDashboardQuery) error {
type
DashboardSearchProjection
struct
{
Id
int64
Uid
string
Title
string
Slug
string
Term
string
...
...
@@ -257,10 +258,17 @@ 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
,
Slug
:
item
.
Slug
,
Type
:
getHitType
(
item
),
FolderId
:
item
.
FolderId
,
...
...
@@ -268,6 +276,7 @@ func makeQueryResult(query *search.FindPersistedDashboardsQuery, res []Dashboard
FolderSlug
:
item
.
FolderSlug
,
Tags
:
[]
string
{},
}
query
.
Result
=
append
(
query
.
Result
,
hit
)
hits
[
item
.
Id
]
=
hit
}
...
...
pkg/services/sqlstore/dashboard_test.go
View file @
9fb7b887
package
sqlstore
import
(
"fmt"
"testing"
"github.com/go-xorm/xorm"
...
...
@@ -145,6 +146,7 @@ func TestDashboardDataAccess(t *testing.T) {
So
(
len
(
query
.
Result
),
ShouldEqual
,
1
)
hit
:=
query
.
Result
[
0
]
So
(
hit
.
Type
,
ShouldEqual
,
search
.
DashHitFolder
)
So
(
hit
.
Url
,
ShouldEqual
,
fmt
.
Sprintf
(
"/f/%s/%s"
,
savedFolder
.
Uid
,
savedFolder
.
Slug
))
})
Convey
(
"Should be able to search for a dashboard folder's children"
,
func
()
{
...
...
@@ -160,6 +162,7 @@ func TestDashboardDataAccess(t *testing.T) {
So
(
len
(
query
.
Result
),
ShouldEqual
,
2
)
hit
:=
query
.
Result
[
0
]
So
(
hit
.
Id
,
ShouldEqual
,
savedDash
.
Id
)
So
(
hit
.
Url
,
ShouldEqual
,
fmt
.
Sprintf
(
"/d/%s/%s"
,
savedDash
.
Uid
,
savedDash
.
Slug
))
})
Convey
(
"Should be able to search for dashboard by dashboard ids"
,
func
()
{
...
...
pkg/services/sqlstore/search_builder.go
View file @
9fb7b887
...
...
@@ -101,6 +101,7 @@ func (sb *SearchBuilder) buildSelect() {
sb
.
sql
.
WriteString
(
`SELECT
dashboard.id,
dashboard.uid,
dashboard.title,
dashboard.slug,
dashboard_tag.term,
...
...
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