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
bcdbec61
Commit
bcdbec61
authored
Jan 06, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dashboard search works better, tag cloud should be done soon
parent
3f266a3e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
6 deletions
+61
-6
README.md
+10
-0
grafana
+1
-1
pkg/api/dashboard.go
+20
-1
pkg/models/dashboards.go
+18
-1
pkg/stores/sqlstore/dashboards.go
+12
-3
No files found.
README.md
View file @
bcdbec61
...
@@ -24,3 +24,13 @@ npm install
...
@@ -24,3 +24,13 @@ npm install
npm install -g grunt-cli
npm install -g grunt-cli
grunt
grunt
```
```
To rebuild on source change:
```
go get github.com/Unknwon/bra
bra run
```
grafana
@
d03949a7
Subproject commit
a5c8bbfe1f04830507d981dff5a44248ffeab04c
Subproject commit
d03949a735fd6ee486e278feb3b87f252be5ce96
pkg/api/dashboard.go
View file @
bcdbec61
package
api
package
api
import
(
import
(
"strings"
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/middleware"
"github.com/torkelo/grafana-pro/pkg/middleware"
m
"github.com/torkelo/grafana-pro/pkg/models"
m
"github.com/torkelo/grafana-pro/pkg/models"
...
@@ -46,15 +48,32 @@ func DeleteDashboard(c *middleware.Context) {
...
@@ -46,15 +48,32 @@ func DeleteDashboard(c *middleware.Context) {
func
Search
(
c
*
middleware
.
Context
)
{
func
Search
(
c
*
middleware
.
Context
)
{
queryText
:=
c
.
Query
(
"q"
)
queryText
:=
c
.
Query
(
"q"
)
result
:=
m
.
SearchResult
{
Dashboards
:
[]
m
.
DashboardSearchHit
{},
Tags
:
[]
m
.
DashboardTagCloudItem
{},
}
if
strings
.
HasPrefix
(
queryText
,
"tags!:"
)
{
query
:=
m
.
GetDashboardTagsQuery
{}
err
:=
bus
.
Dispatch
(
&
query
)
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to get tags from database"
,
err
)
return
}
result
.
Tags
=
query
.
Result
result
.
TagsOnly
=
true
}
else
{
queryText
:=
strings
.
TrimPrefix
(
queryText
,
"title:"
)
query
:=
m
.
SearchDashboardsQuery
{
Query
:
queryText
,
AccountId
:
c
.
GetAccountId
()}
query
:=
m
.
SearchDashboardsQuery
{
Query
:
queryText
,
AccountId
:
c
.
GetAccountId
()}
err
:=
bus
.
Dispatch
(
&
query
)
err
:=
bus
.
Dispatch
(
&
query
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Search failed"
,
err
)
c
.
JsonApiErr
(
500
,
"Search failed"
,
err
)
return
return
}
}
result
.
Dashboards
=
query
.
Result
}
c
.
JSON
(
200
,
query
.
R
esult
)
c
.
JSON
(
200
,
r
esult
)
}
}
func
PostDashboard
(
c
*
middleware
.
Context
)
{
func
PostDashboard
(
c
*
middleware
.
Context
)
{
...
...
pkg/models/dashboards.go
View file @
bcdbec61
...
@@ -27,16 +27,33 @@ type Dashboard struct {
...
@@ -27,16 +27,33 @@ type Dashboard struct {
}
}
type
SearchResult
struct
{
type
SearchResult
struct
{
Dashboards
[]
DashboardSearchHit
`json:"dashboards"`
Tags
[]
DashboardTagCloudItem
`json:"tags"`
TagsOnly
bool
`json:"tagsOnly"`
}
type
DashboardSearchHit
struct
{
Id
string
`json:"id"`
Id
string
`json:"id"`
Title
string
`json:"title"`
Title
string
`json:"title"`
Slug
string
`json:"slug"`
Slug
string
`json:"slug"`
Tags
[]
string
`json:"tags"`
}
type
DashboardTagCloudItem
struct
{
Term
string
`json:"term"`
Count
int
`json:"count"`
}
}
type
SearchDashboardsQuery
struct
{
type
SearchDashboardsQuery
struct
{
Query
string
Query
string
AccountId
int64
AccountId
int64
Result
[]
*
SearchResult
Result
[]
DashboardSearchHit
}
type
GetDashboardTagsQuery
struct
{
AccountId
int64
Result
[]
DashboardTagCloudItem
}
}
type
SaveDashboardCommand
struct
{
type
SaveDashboardCommand
struct
{
...
...
pkg/stores/sqlstore/dashboards.go
View file @
bcdbec61
...
@@ -11,6 +11,7 @@ func init() {
...
@@ -11,6 +11,7 @@ func init() {
bus
.
AddHandler
(
"sql"
,
GetDashboard
)
bus
.
AddHandler
(
"sql"
,
GetDashboard
)
bus
.
AddHandler
(
"sql"
,
DeleteDashboard
)
bus
.
AddHandler
(
"sql"
,
DeleteDashboard
)
bus
.
AddHandler
(
"sql"
,
SearchDashboards
)
bus
.
AddHandler
(
"sql"
,
SearchDashboards
)
bus
.
AddHandler
(
"sql"
,
GetDashboardTags
)
}
}
func
SaveDashboard
(
cmd
*
m
.
SaveDashboardCommand
)
error
{
func
SaveDashboard
(
cmd
*
m
.
SaveDashboardCommand
)
error
{
...
@@ -55,17 +56,25 @@ func GetDashboard(query *m.GetDashboardQuery) error {
...
@@ -55,17 +56,25 @@ func GetDashboard(query *m.GetDashboardQuery) error {
}
}
func
SearchDashboards
(
query
*
m
.
SearchDashboardsQuery
)
error
{
func
SearchDashboards
(
query
*
m
.
SearchDashboardsQuery
)
error
{
title
Match
:=
"%"
+
query
.
Query
+
"%"
title
Query
:=
"%"
+
query
.
Query
+
"%"
sess
:=
x
.
Limit
(
100
,
0
)
.
Where
(
"account_id=? AND title LIKE ?"
,
query
.
AccountId
,
title
Match
)
sess
:=
x
.
Limit
(
100
,
0
)
.
Where
(
"account_id=? AND title LIKE ?"
,
query
.
AccountId
,
title
Query
)
sess
.
Table
(
"Dashboard"
)
sess
.
Table
(
"Dashboard"
)
query
.
Result
=
make
([]
*
m
.
SearchResul
t
,
0
)
query
.
Result
=
make
([]
m
.
DashboardSearchHi
t
,
0
)
err
:=
sess
.
Find
(
&
query
.
Result
)
err
:=
sess
.
Find
(
&
query
.
Result
)
return
err
return
err
}
}
func
GetDashboardTags
(
query
*
m
.
GetDashboardTagsQuery
)
error
{
query
.
Result
=
[]
m
.
DashboardTagCloudItem
{
m
.
DashboardTagCloudItem
{
Term
:
"test"
,
Count
:
10
},
m
.
DashboardTagCloudItem
{
Term
:
"prod"
,
Count
:
20
},
}
return
nil
}
func
DeleteDashboard
(
cmd
*
m
.
DeleteDashboardCommand
)
error
{
func
DeleteDashboard
(
cmd
*
m
.
DeleteDashboardCommand
)
error
{
sess
:=
x
.
NewSession
()
sess
:=
x
.
NewSession
()
defer
sess
.
Close
()
defer
sess
.
Close
()
...
...
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