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
1a9f6307
Commit
1a9f6307
authored
May 11, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Began work on adding json files to search, #960
parent
48ddd721
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
26 deletions
+83
-26
conf/defaults.ini
+8
-0
main.go
+2
-0
pkg/api/search.go
+2
-26
pkg/services/search/jsonfiles.go
+12
-0
pkg/services/search/search.go
+59
-0
No files found.
conf/defaults.ini
View file @
1a9f6307
...
...
@@ -212,3 +212,11 @@ max_days = 7
enabled
=
false
rabbitmq_url
=
amqp://localhost/
exchange
=
grafana_events
#################################### Dashboard JSON files ##########################
[dashboards.json]
enabled
=
false
path
=
dashboards
orgs
=
*
main.go
View file @
1a9f6307
...
...
@@ -15,6 +15,7 @@ import (
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/services/eventpublisher"
"github.com/grafana/grafana/pkg/services/search"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/social"
...
...
@@ -51,6 +52,7 @@ func main() {
initRuntime
()
writePIDFile
()
search
.
Init
()
social
.
NewOAuthService
()
eventpublisher
.
Init
()
plugins
.
Init
()
...
...
pkg/api/search.go
View file @
1a9f6307
...
...
@@ -4,28 +4,9 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/middleware"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/search"
)
// TODO: this needs to be cached or improved somehow
func
setIsStarredFlagOnSearchResults
(
c
*
middleware
.
Context
,
hits
[]
*
m
.
DashboardSearchHit
)
error
{
if
!
c
.
IsSignedIn
{
return
nil
}
query
:=
m
.
GetUserStarsQuery
{
UserId
:
c
.
UserId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
err
}
for
_
,
dash
:=
range
hits
{
if
_
,
exists
:=
query
.
Result
[
dash
.
Id
];
exists
{
dash
.
IsStarred
=
true
}
}
return
nil
}
func
Search
(
c
*
middleware
.
Context
)
{
query
:=
c
.
Query
(
"query"
)
tag
:=
c
.
Query
(
"tag"
)
...
...
@@ -54,7 +35,7 @@ func Search(c *middleware.Context) {
result
.
TagsOnly
=
true
}
else
{
query
:=
m
.
SearchDashboards
Query
{
query
:=
search
.
Query
{
Title
:
query
,
Tag
:
tag
,
UserId
:
c
.
UserId
,
...
...
@@ -69,11 +50,6 @@ func Search(c *middleware.Context) {
return
}
if
err
:=
setIsStarredFlagOnSearchResults
(
c
,
query
.
Result
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to get user stars"
,
err
)
return
}
result
.
Dashboards
=
query
.
Result
}
...
...
pkg/services/search/jsonfiles.go
0 → 100644
View file @
1a9f6307
package
search
var
(
// settings
DashboardsJsonEnabled
bool
DashboardsJsonPath
string
DashboardJsonOrgs
string
)
func
initJsonFileIndex
()
{
}
pkg/services/search/search.go
0 → 100644
View file @
1a9f6307
package
search
import
(
"github.com/grafana/grafana/pkg/bus"
m
"github.com/grafana/grafana/pkg/models"
)
type
Query
struct
{
Title
string
Tag
string
OrgId
int64
UserId
int64
Limit
int
IsStarred
bool
Result
[]
*
m
.
DashboardSearchHit
}
func
Init
()
{
bus
.
AddHandler
(
"search"
,
searchHandler
)
initJsonFileIndex
()
}
func
searchHandler
(
query
*
Query
)
error
{
dashQuery
:=
m
.
SearchDashboardsQuery
{
Title
:
query
.
Title
,
Tag
:
query
.
Tag
,
UserId
:
query
.
UserId
,
Limit
:
query
.
Limit
,
IsStarred
:
query
.
IsStarred
,
OrgId
:
query
.
OrgId
,
}
if
err
:=
bus
.
Dispatch
(
&
dashQuery
);
err
!=
nil
{
return
err
}
if
err
:=
setIsStarredFlagOnSearchResults
(
query
.
UserId
,
query
.
Result
);
err
!=
nil
{
return
err
}
query
.
Result
=
dashQuery
.
Result
return
nil
}
func
setIsStarredFlagOnSearchResults
(
userId
int64
,
hits
[]
*
m
.
DashboardSearchHit
)
error
{
query
:=
m
.
GetUserStarsQuery
{
UserId
:
userId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
err
}
for
_
,
dash
:=
range
hits
{
if
_
,
exists
:=
query
.
Result
[
dash
.
Id
];
exists
{
dash
.
IsStarred
=
true
}
}
return
nil
}
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