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
076905d1
Commit
076905d1
authored
Feb 05, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added isStarred to search result hit, very inefficient loading right now but can be cached later on
parent
69e7279c
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
40 additions
and
25 deletions
+40
-25
grafana
+1
-1
pkg/api/api.go
+0
-1
pkg/api/search.go
+29
-0
pkg/api/stars.go
+0
-20
pkg/models/search.go
+1
-0
pkg/models/star.go
+1
-1
pkg/services/sqlstore/star.go
+8
-2
No files found.
grafana
@
d5471c15
Subproject commit
ff47eccf4b119b348a7838a96b558cb2d6a36b0f
Subproject commit
d5471c153ab8ab0d4be57154300d28a75af1d363
pkg/api/api.go
View file @
076905d1
...
@@ -45,7 +45,6 @@ func Register(r *macaron.Macaron) {
...
@@ -45,7 +45,6 @@ func Register(r *macaron.Macaron) {
r
.
Put
(
"/"
,
bind
(
m
.
UpdateUserCommand
{}),
UpdateUser
)
r
.
Put
(
"/"
,
bind
(
m
.
UpdateUserCommand
{}),
UpdateUser
)
r
.
Post
(
"/using/:id"
,
SetUsingAccount
)
r
.
Post
(
"/using/:id"
,
SetUsingAccount
)
r
.
Get
(
"/accounts"
,
GetUserAccounts
)
r
.
Get
(
"/accounts"
,
GetUserAccounts
)
r
.
Get
(
"/stars/"
,
GetUserStars
)
r
.
Post
(
"/stars/dashboard/:id"
,
StarDashboard
)
r
.
Post
(
"/stars/dashboard/:id"
,
StarDashboard
)
r
.
Delete
(
"/stars/dashboard/:id"
,
UnstarDashboard
)
r
.
Delete
(
"/stars/dashboard/:id"
,
UnstarDashboard
)
})
})
...
...
pkg/api/search.go
View file @
076905d1
...
@@ -10,6 +10,26 @@ import (
...
@@ -10,6 +10,26 @@ import (
"github.com/torkelo/grafana-pro/pkg/setting"
"github.com/torkelo/grafana-pro/pkg/setting"
)
)
// 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
)
{
func
Search
(
c
*
middleware
.
Context
)
{
queryText
:=
c
.
Query
(
"q"
)
queryText
:=
c
.
Query
(
"q"
)
starred
:=
c
.
Query
(
"starred"
)
starred
:=
c
.
Query
(
"starred"
)
...
@@ -20,6 +40,7 @@ func Search(c *middleware.Context) {
...
@@ -20,6 +40,7 @@ func Search(c *middleware.Context) {
}
}
if
strings
.
HasPrefix
(
queryText
,
"tags!:"
)
{
if
strings
.
HasPrefix
(
queryText
,
"tags!:"
)
{
query
:=
m
.
GetDashboardTagsQuery
{
AccountId
:
c
.
AccountId
}
query
:=
m
.
GetDashboardTagsQuery
{
AccountId
:
c
.
AccountId
}
err
:=
bus
.
Dispatch
(
&
query
)
err
:=
bus
.
Dispatch
(
&
query
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -28,7 +49,9 @@ func Search(c *middleware.Context) {
...
@@ -28,7 +49,9 @@ func Search(c *middleware.Context) {
}
}
result
.
Tags
=
query
.
Result
result
.
Tags
=
query
.
Result
result
.
TagsOnly
=
true
result
.
TagsOnly
=
true
}
else
{
}
else
{
searchQueryRegEx
,
_
:=
regexp
.
Compile
(
`(tags:(\w*)\sAND\s)?(?:title:)?(.*)?`
)
searchQueryRegEx
,
_
:=
regexp
.
Compile
(
`(tags:(\w*)\sAND\s)?(?:title:)?(.*)?`
)
matches
:=
searchQueryRegEx
.
FindStringSubmatch
(
queryText
)
matches
:=
searchQueryRegEx
.
FindStringSubmatch
(
queryText
)
query
:=
m
.
SearchDashboardsQuery
{
query
:=
m
.
SearchDashboardsQuery
{
...
@@ -38,12 +61,18 @@ func Search(c *middleware.Context) {
...
@@ -38,12 +61,18 @@ func Search(c *middleware.Context) {
IsStarred
:
starred
==
"1"
,
IsStarred
:
starred
==
"1"
,
AccountId
:
c
.
AccountId
,
AccountId
:
c
.
AccountId
,
}
}
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
}
}
if
err
:=
setIsStarredFlagOnSearchResults
(
c
,
query
.
Result
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to get user stars"
,
err
)
return
}
result
.
Dashboards
=
query
.
Result
result
.
Dashboards
=
query
.
Result
for
_
,
dash
:=
range
result
.
Dashboards
{
for
_
,
dash
:=
range
result
.
Dashboards
{
dash
.
Url
=
setting
.
AbsUrlTo
(
"dashboard/db/"
+
dash
.
Slug
)
dash
.
Url
=
setting
.
AbsUrlTo
(
"dashboard/db/"
+
dash
.
Slug
)
...
...
pkg/api/stars.go
View file @
076905d1
package
api
package
api
import
(
import
(
"strconv"
"github.com/torkelo/grafana-pro/pkg/api/dtos"
"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,20 +43,3 @@ func UnstarDashboard(c *middleware.Context) {
...
@@ -46,20 +43,3 @@ func UnstarDashboard(c *middleware.Context) {
c
.
JsonOK
(
"Dashboard unstarred"
)
c
.
JsonOK
(
"Dashboard unstarred"
)
}
}
func
GetUserStars
(
c
*
middleware
.
Context
)
{
query
:=
m
.
GetUserStarsQuery
{
UserId
:
c
.
UserId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to get user stars"
,
err
)
return
}
var
result
dtos
.
UserStars
result
.
DashboardIds
=
make
(
map
[
string
]
bool
)
for
_
,
star
:=
range
query
.
Result
{
result
.
DashboardIds
[
strconv
.
FormatInt
(
star
.
DashboardId
,
10
)]
=
true
}
c
.
JSON
(
200
,
&
result
)
}
pkg/models/search.go
View file @
076905d1
...
@@ -12,6 +12,7 @@ type DashboardSearchHit struct {
...
@@ -12,6 +12,7 @@ type DashboardSearchHit struct {
Slug
string
`json:"slug"`
Slug
string
`json:"slug"`
Tags
[]
string
`json:"tags"`
Tags
[]
string
`json:"tags"`
Url
string
`json:"url"`
Url
string
`json:"url"`
IsStarred
bool
`json:"isStarred"`
}
}
type
DashboardTagCloudItem
struct
{
type
DashboardTagCloudItem
struct
{
...
...
pkg/models/star.go
View file @
076905d1
...
@@ -29,7 +29,7 @@ type UnstarDashboardCommand struct {
...
@@ -29,7 +29,7 @@ type UnstarDashboardCommand struct {
type
GetUserStarsQuery
struct
{
type
GetUserStarsQuery
struct
{
UserId
int64
UserId
int64
Result
[]
Star
Result
map
[
int64
]
bool
// dashboard ids
}
}
type
IsStarredByUserQuery
struct
{
type
IsStarredByUserQuery
struct
{
...
...
pkg/services/sqlstore/star.go
View file @
076905d1
...
@@ -61,7 +61,13 @@ func UnstarDashboard(cmd *m.UnstarDashboardCommand) error {
...
@@ -61,7 +61,13 @@ func UnstarDashboard(cmd *m.UnstarDashboardCommand) error {
}
}
func
GetUserStars
(
query
*
m
.
GetUserStarsQuery
)
error
{
func
GetUserStars
(
query
*
m
.
GetUserStarsQuery
)
error
{
query
.
Result
=
make
([]
m
.
Star
,
0
)
var
stars
=
make
([]
m
.
Star
,
0
)
err
:=
x
.
Where
(
"user_id=?"
,
query
.
UserId
)
.
Find
(
&
query
.
Result
)
err
:=
x
.
Where
(
"user_id=?"
,
query
.
UserId
)
.
Find
(
&
stars
)
query
.
Result
=
make
(
map
[
int64
]
bool
)
for
_
,
star
:=
range
stars
{
query
.
Result
[
star
.
DashboardId
]
=
true
}
return
err
return
err
}
}
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