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
dd7e215e
Commit
dd7e215e
authored
Mar 05, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(dashslist): make sure dashbords exists in recently viewd dashboards
closes #4249
parent
fcd75422
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
77 additions
and
29 deletions
+77
-29
pkg/api/search.go
+10
-0
pkg/services/search/handlers.go
+1
-0
pkg/services/search/models.go
+2
-0
pkg/services/sqlstore/dashboard.go
+13
-0
pkg/services/sqlstore/dashboard_test.go
+34
-1
public/app/features/dashboard/dashboardLoaderSrv.js
+2
-7
public/app/features/dashboard/impression_store.ts
+5
-10
public/app/plugins/panel/dashlist/module.ts
+10
-11
No files found.
pkg/api/search.go
View file @
dd7e215e
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/services/search"
"github.com/grafana/grafana/pkg/services/search"
"strconv"
)
)
func
Search
(
c
*
middleware
.
Context
)
{
func
Search
(
c
*
middleware
.
Context
)
{
...
@@ -16,6 +17,14 @@ func Search(c *middleware.Context) {
...
@@ -16,6 +17,14 @@ func Search(c *middleware.Context) {
limit
=
1000
limit
=
1000
}
}
dbids
:=
make
([]
int
,
0
)
for
_
,
id
:=
range
c
.
QueryStrings
(
"dashboardIds"
)
{
dashboardId
,
err
:=
strconv
.
Atoi
(
id
)
if
err
==
nil
{
dbids
=
append
(
dbids
,
dashboardId
)
}
}
searchQuery
:=
search
.
Query
{
searchQuery
:=
search
.
Query
{
Title
:
query
,
Title
:
query
,
Tags
:
tags
,
Tags
:
tags
,
...
@@ -23,6 +32,7 @@ func Search(c *middleware.Context) {
...
@@ -23,6 +32,7 @@ func Search(c *middleware.Context) {
Limit
:
limit
,
Limit
:
limit
,
IsStarred
:
starred
==
"true"
,
IsStarred
:
starred
==
"true"
,
OrgId
:
c
.
OrgId
,
OrgId
:
c
.
OrgId
,
DashboardIds
:
dbids
,
}
}
err
:=
bus
.
Dispatch
(
&
searchQuery
)
err
:=
bus
.
Dispatch
(
&
searchQuery
)
...
...
pkg/services/search/handlers.go
View file @
dd7e215e
...
@@ -43,6 +43,7 @@ func searchHandler(query *Query) error {
...
@@ -43,6 +43,7 @@ func searchHandler(query *Query) error {
UserId
:
query
.
UserId
,
UserId
:
query
.
UserId
,
IsStarred
:
query
.
IsStarred
,
IsStarred
:
query
.
IsStarred
,
OrgId
:
query
.
OrgId
,
OrgId
:
query
.
OrgId
,
DashboardIds
:
query
.
DashboardIds
,
}
}
if
err
:=
bus
.
Dispatch
(
&
dashQuery
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
dashQuery
);
err
!=
nil
{
...
...
pkg/services/search/models.go
View file @
dd7e215e
...
@@ -31,6 +31,7 @@ type Query struct {
...
@@ -31,6 +31,7 @@ type Query struct {
UserId
int64
UserId
int64
Limit
int
Limit
int
IsStarred
bool
IsStarred
bool
DashboardIds
[]
int
Result
HitList
Result
HitList
}
}
...
@@ -40,6 +41,7 @@ type FindPersistedDashboardsQuery struct {
...
@@ -40,6 +41,7 @@ type FindPersistedDashboardsQuery struct {
OrgId
int64
OrgId
int64
UserId
int64
UserId
int64
IsStarred
bool
IsStarred
bool
DashboardIds
[]
int
Result
HitList
Result
HitList
}
}
pkg/services/sqlstore/dashboard.go
View file @
dd7e215e
...
@@ -146,6 +146,19 @@ func SearchDashboards(query *search.FindPersistedDashboardsQuery) error {
...
@@ -146,6 +146,19 @@ func SearchDashboards(query *search.FindPersistedDashboardsQuery) error {
params
=
append
(
params
,
query
.
UserId
)
params
=
append
(
params
,
query
.
UserId
)
}
}
if
len
(
query
.
DashboardIds
)
>
0
{
sql
.
WriteString
(
" AND ("
)
for
i
,
dashboardId
:=
range
query
.
DashboardIds
{
if
i
!=
0
{
sql
.
WriteString
(
"OR"
)
}
sql
.
WriteString
(
" dashboard.id = ?"
)
params
=
append
(
params
,
dashboardId
)
}
sql
.
WriteString
(
")"
)
}
if
len
(
query
.
Title
)
>
0
{
if
len
(
query
.
Title
)
>
0
{
sql
.
WriteString
(
" AND dashboard.title "
+
dialect
.
LikeStr
()
+
" ?"
)
sql
.
WriteString
(
" AND dashboard.title "
+
dialect
.
LikeStr
()
+
" ?"
)
params
=
append
(
params
,
"%"
+
query
.
Title
+
"%"
)
params
=
append
(
params
,
"%"
+
query
.
Title
+
"%"
)
...
...
pkg/services/sqlstore/dashboard_test.go
View file @
dd7e215e
...
@@ -32,6 +32,8 @@ func TestDashboardDataAccess(t *testing.T) {
...
@@ -32,6 +32,8 @@ func TestDashboardDataAccess(t *testing.T) {
Convey
(
"Given saved dashboard"
,
func
()
{
Convey
(
"Given saved dashboard"
,
func
()
{
savedDash
:=
insertTestDashboard
(
"test dash 23"
,
1
,
"prod"
,
"webapp"
)
savedDash
:=
insertTestDashboard
(
"test dash 23"
,
1
,
"prod"
,
"webapp"
)
insertTestDashboard
(
"test dash 45"
,
1
,
"prod"
)
insertTestDashboard
(
"test dash 67"
,
1
,
"prod"
,
"webapp"
)
Convey
(
"Should return dashboard model"
,
func
()
{
Convey
(
"Should return dashboard model"
,
func
()
{
So
(
savedDash
.
Title
,
ShouldEqual
,
"test dash 23"
)
So
(
savedDash
.
Title
,
ShouldEqual
,
"test dash 23"
)
...
@@ -87,7 +89,7 @@ func TestDashboardDataAccess(t *testing.T) {
...
@@ -87,7 +89,7 @@ func TestDashboardDataAccess(t *testing.T) {
Convey
(
"Should be able to search for dashboard"
,
func
()
{
Convey
(
"Should be able to search for dashboard"
,
func
()
{
query
:=
search
.
FindPersistedDashboardsQuery
{
query
:=
search
.
FindPersistedDashboardsQuery
{
Title
:
"test"
,
Title
:
"test
dash 23
"
,
OrgId
:
1
,
OrgId
:
1
,
}
}
...
@@ -99,6 +101,37 @@ func TestDashboardDataAccess(t *testing.T) {
...
@@ -99,6 +101,37 @@ func TestDashboardDataAccess(t *testing.T) {
So
(
len
(
hit
.
Tags
),
ShouldEqual
,
2
)
So
(
len
(
hit
.
Tags
),
ShouldEqual
,
2
)
})
})
Convey
(
"Should be able to search for dashboard by dashboard ids"
,
func
()
{
Convey
(
"should be able to find two dashboards by id"
,
func
()
{
query
:=
search
.
FindPersistedDashboardsQuery
{
DashboardIds
:
[]
int
{
1
,
2
},
OrgId
:
1
,
}
err
:=
SearchDashboards
(
&
query
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
2
)
hit
:=
query
.
Result
[
0
]
So
(
len
(
hit
.
Tags
),
ShouldEqual
,
2
)
hit2
:=
query
.
Result
[
1
]
So
(
len
(
hit2
.
Tags
),
ShouldEqual
,
1
)
})
Convey
(
"DashboardIds that does not exists should not cause errors"
,
func
()
{
query
:=
search
.
FindPersistedDashboardsQuery
{
DashboardIds
:
[]
int
{
1000
},
OrgId
:
1
,
}
err
:=
SearchDashboards
(
&
query
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
0
)
})
})
Convey
(
"Should not be able to save dashboard with same name"
,
func
()
{
Convey
(
"Should not be able to save dashboard with same name"
,
func
()
{
cmd
:=
m
.
SaveDashboardCommand
{
cmd
:=
m
.
SaveDashboardCommand
{
OrgId
:
1
,
OrgId
:
1
,
...
...
public/app/features/dashboard/dashboardLoaderSrv.js
View file @
dd7e215e
...
@@ -8,7 +8,7 @@ define([
...
@@ -8,7 +8,7 @@ define([
'./impression_store'
,
'./impression_store'
,
'app/core/config'
,
'app/core/config'
,
],
],
function
(
angular
,
moment
,
_
,
$
,
kbn
,
dateMath
,
impressionStore
,
config
)
{
function
(
angular
,
moment
,
_
,
$
,
kbn
,
dateMath
,
impressionStore
)
{
'use strict'
;
'use strict'
;
var
module
=
angular
.
module
(
'grafana.services'
);
var
module
=
angular
.
module
(
'grafana.services'
);
...
@@ -48,12 +48,7 @@ function (angular, moment, _, $, kbn, dateMath, impressionStore, config) {
...
@@ -48,12 +48,7 @@ function (angular, moment, _, $, kbn, dateMath, impressionStore, config) {
promise
.
then
(
function
(
result
)
{
promise
.
then
(
function
(
result
)
{
if
(
result
.
meta
.
dashboardNotFound
!==
true
)
{
if
(
result
.
meta
.
dashboardNotFound
!==
true
)
{
impressionStore
.
impressions
.
addDashboardImpression
({
impressionStore
.
impressions
.
addDashboardImpression
(
result
.
dashboard
.
id
);
type
:
type
,
slug
:
slug
,
title
:
result
.
dashboard
.
title
,
orgId
:
config
.
bootData
.
user
.
orgId
});
}
}
return
result
;
return
result
;
...
...
public/app/features/dashboard/impression_store.ts
View file @
dd7e215e
...
@@ -6,7 +6,7 @@ import _ from 'lodash';
...
@@ -6,7 +6,7 @@ import _ from 'lodash';
export
class
ImpressionsStore
{
export
class
ImpressionsStore
{
constructor
()
{}
constructor
()
{}
addDashboardImpression
(
impression
)
{
addDashboardImpression
(
dashboardId
)
{
var
impressions
=
[];
var
impressions
=
[];
if
(
store
.
exists
(
"dashboard_impressions"
))
{
if
(
store
.
exists
(
"dashboard_impressions"
))
{
impressions
=
JSON
.
parse
(
store
.
get
(
"dashboard_impressions"
));
impressions
=
JSON
.
parse
(
store
.
get
(
"dashboard_impressions"
));
...
@@ -16,18 +16,13 @@ export class ImpressionsStore {
...
@@ -16,18 +16,13 @@ export class ImpressionsStore {
}
}
impressions
=
impressions
.
filter
((
imp
)
=>
{
impressions
=
impressions
.
filter
((
imp
)
=>
{
return
impression
.
slug
!==
imp
.
slug
;
return
dashboardId
!==
imp
;
});
});
impressions
.
unshift
({
impressions
.
unshift
(
dashboardId
);
title
:
impression
.
title
,
slug
:
impression
.
slug
,
orgId
:
impression
.
orgId
,
type
:
impression
.
type
});
if
(
impressions
.
length
>
2
0
)
{
if
(
impressions
.
length
>
5
0
)
{
impressions
.
shift
();
impressions
.
pop
();
}
}
store
.
set
(
"dashboard_impressions"
,
JSON
.
stringify
(
impressions
));
store
.
set
(
"dashboard_impressions"
,
JSON
.
stringify
(
impressions
));
}
}
...
...
public/app/plugins/panel/dashlist/module.ts
View file @
dd7e215e
...
@@ -43,22 +43,21 @@ class DashListCtrl extends PanelCtrl {
...
@@ -43,22 +43,21 @@ class DashListCtrl extends PanelCtrl {
var
params
:
any
=
{
limit
:
this
.
panel
.
limit
};
var
params
:
any
=
{
limit
:
this
.
panel
.
limit
};
if
(
this
.
panel
.
mode
===
'recently viewed'
)
{
if
(
this
.
panel
.
mode
===
'recently viewed'
)
{
var
dashboardIds
=
impressions
.
getDashboardOpened
();
var
dashListNames
=
impressions
.
getDashboardOpened
().
filter
((
imp
)
=>
{
return
this
.
backendSrv
.
search
({
return
imp
.
orgId
===
config
.
bootData
.
user
.
orgId
;
dashboardIds
:
impressions
.
getDashboardOpened
(),
});
limit
:
this
.
panel
.
limit
}).
then
(
result
=>
{
dashListNames
=
_
.
first
(
dashListNames
,
params
.
limit
).
map
((
dashboard
)
=>
{
this
.
dashList
=
dashboardIds
.
map
(
e
=>
{
return
{
return
_
.
find
(
result
,
r
=>
{
title
:
dashboard
.
title
,
return
r
.
id
===
e
;
uri
:
dashboard
.
type
+
'/'
+
dashboard
.
slug
});
};
});
});
this
.
dashList
=
dashListNames
;
this
.
renderingCompleted
();
this
.
renderingCompleted
();
return
;
})
;
}
}
if
(
this
.
panel
.
mode
===
'starred'
)
{
if
(
this
.
panel
.
mode
===
'starred'
)
{
...
...
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