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
d66932a8
Commit
d66932a8
authored
Jan 28, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore(playlist): extract playlist start into new file
parent
3ccf7c80
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
39 deletions
+91
-39
pkg/api/playlist.go
+3
-39
pkg/api/playlist_play.go
+88
-0
No files found.
pkg/api/playlist.go
View file @
d66932a8
package
api
package
api
import
(
import
(
"errors"
"strconv"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
_
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/middleware"
m
"github.com/grafana/grafana/pkg/models"
m
"github.com/grafana/grafana/pkg/models"
)
)
...
@@ -101,39 +98,6 @@ func LoadPlaylistItems(id int64) ([]m.PlaylistItem, error) {
...
@@ -101,39 +98,6 @@ func LoadPlaylistItems(id int64) ([]m.PlaylistItem, error) {
return
*
itemQuery
.
Result
,
nil
return
*
itemQuery
.
Result
,
nil
}
}
func
LoadPlaylistDashboards
(
id
int64
)
([]
m
.
PlaylistDashboardDto
,
error
)
{
playlistItems
,
_
:=
LoadPlaylistItems
(
id
)
dashboardIds
:=
make
([]
int64
,
0
)
for
_
,
i
:=
range
playlistItems
{
dashboardId
,
_
:=
strconv
.
ParseInt
(
i
.
Value
,
10
,
64
)
dashboardIds
=
append
(
dashboardIds
,
dashboardId
)
}
if
len
(
dashboardIds
)
==
0
{
return
make
([]
m
.
PlaylistDashboardDto
,
0
),
nil
}
dashboardQuery
:=
m
.
GetPlaylistDashboardsQuery
{
DashboardIds
:
dashboardIds
}
if
err
:=
bus
.
Dispatch
(
&
dashboardQuery
);
err
!=
nil
{
log
.
Warn
(
"dashboardquery failed: %v"
,
err
)
return
nil
,
errors
.
New
(
"Playlist not found"
)
}
dtos
:=
make
([]
m
.
PlaylistDashboardDto
,
0
)
for
_
,
item
:=
range
*
dashboardQuery
.
Result
{
dtos
=
append
(
dtos
,
m
.
PlaylistDashboardDto
{
Id
:
item
.
Id
,
Slug
:
item
.
Slug
,
Title
:
item
.
Title
,
Uri
:
"db/"
+
item
.
Slug
,
})
}
return
dtos
,
nil
}
func
GetPlaylistItems
(
c
*
middleware
.
Context
)
Response
{
func
GetPlaylistItems
(
c
*
middleware
.
Context
)
Response
{
id
:=
c
.
ParamsInt64
(
":id"
)
id
:=
c
.
ParamsInt64
(
":id"
)
...
@@ -147,9 +111,9 @@ func GetPlaylistItems(c *middleware.Context) Response {
...
@@ -147,9 +111,9 @@ func GetPlaylistItems(c *middleware.Context) Response {
}
}
func
GetPlaylistDashboards
(
c
*
middleware
.
Context
)
Response
{
func
GetPlaylistDashboards
(
c
*
middleware
.
Context
)
Response
{
i
d
:=
c
.
ParamsInt64
(
":id"
)
playlistI
d
:=
c
.
ParamsInt64
(
":id"
)
playlists
,
err
:=
LoadPlaylistDashboards
(
i
d
)
playlists
,
err
:=
LoadPlaylistDashboards
(
c
.
OrgId
,
c
.
UserId
,
playlistI
d
)
if
err
!=
nil
{
if
err
!=
nil
{
return
ApiError
(
500
,
"Could not load dashboards"
,
err
)
return
ApiError
(
500
,
"Could not load dashboards"
,
err
)
}
}
...
...
pkg/api/playlist_play.go
0 → 100644
View file @
d66932a8
package
api
import
(
"errors"
"strconv"
"github.com/grafana/grafana/pkg/bus"
_
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/search"
)
func
populateDashboardsById
(
dashboardByIds
[]
int64
)
([]
m
.
PlaylistDashboardDto
,
error
)
{
result
:=
make
([]
m
.
PlaylistDashboardDto
,
0
)
if
len
(
dashboardByIds
)
>
0
{
dashboardQuery
:=
m
.
GetPlaylistDashboardsQuery
{
DashboardIds
:
dashboardByIds
}
if
err
:=
bus
.
Dispatch
(
&
dashboardQuery
);
err
!=
nil
{
return
result
,
errors
.
New
(
"Playlist not found"
)
//TODO: dont swallow error
}
for
_
,
item
:=
range
*
dashboardQuery
.
Result
{
result
=
append
(
result
,
m
.
PlaylistDashboardDto
{
Id
:
item
.
Id
,
Slug
:
item
.
Slug
,
Title
:
item
.
Title
,
Uri
:
"db/"
+
item
.
Slug
,
})
}
}
return
result
,
nil
}
func
populateDashboardsByTag
(
orgId
,
userId
int64
,
dashboardByTag
[]
string
)
[]
m
.
PlaylistDashboardDto
{
result
:=
make
([]
m
.
PlaylistDashboardDto
,
0
)
if
len
(
dashboardByTag
)
>
0
{
for
_
,
tag
:=
range
dashboardByTag
{
searchQuery
:=
search
.
Query
{
Title
:
""
,
Tags
:
[]
string
{
tag
},
UserId
:
userId
,
Limit
:
100
,
IsStarred
:
false
,
OrgId
:
orgId
,
}
if
err
:=
bus
.
Dispatch
(
&
searchQuery
);
err
==
nil
{
for
_
,
item
:=
range
searchQuery
.
Result
{
result
=
append
(
result
,
m
.
PlaylistDashboardDto
{
Id
:
item
.
Id
,
Title
:
item
.
Title
,
Uri
:
item
.
Uri
,
})
}
}
}
}
return
result
}
func
LoadPlaylistDashboards
(
orgId
,
userId
,
playlistId
int64
)
([]
m
.
PlaylistDashboardDto
,
error
)
{
playlistItems
,
_
:=
LoadPlaylistItems
(
playlistId
)
dashboardByIds
:=
make
([]
int64
,
0
)
dashboardByTag
:=
make
([]
string
,
0
)
for
_
,
i
:=
range
playlistItems
{
if
i
.
Type
==
"dashboard_by_id"
{
dashboardId
,
_
:=
strconv
.
ParseInt
(
i
.
Value
,
10
,
64
)
dashboardByIds
=
append
(
dashboardByIds
,
dashboardId
)
}
if
i
.
Type
==
"dashboard_by_tag"
{
dashboardByTag
=
append
(
dashboardByTag
,
i
.
Value
)
}
}
result
:=
make
([]
m
.
PlaylistDashboardDto
,
0
)
var
k
,
_
=
populateDashboardsById
(
dashboardByIds
)
result
=
append
(
result
,
k
...
)
result
=
append
(
result
,
populateDashboardsByTag
(
orgId
,
userId
,
dashboardByTag
)
...
)
return
result
,
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