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
7e7d9457
Commit
7e7d9457
authored
Jan 12, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'playlist_relation_table' into playlist
parents
0ea01f24
07fdf649
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
294 additions
and
118 deletions
+294
-118
pkg/api/api.go
+2
-1
pkg/api/playlist.go
+115
-8
pkg/models/playlist.go
+40
-10
pkg/services/sqlstore/dashboard.go
+0
-20
pkg/services/sqlstore/migrations/playlist_mig.go
+14
-2
pkg/services/sqlstore/playlist.go
+75
-21
public/app/features/playlist/partials/playlist.html
+10
-14
public/app/features/playlist/playlist_edit_ctrl.js
+37
-41
public/app/features/playlist/playlist_routes.js
+1
-1
No files found.
pkg/api/api.go
View file @
7e7d9457
...
@@ -176,7 +176,8 @@ func Register(r *macaron.Macaron) {
...
@@ -176,7 +176,8 @@ func Register(r *macaron.Macaron) {
r
.
Group
(
"/playlists"
,
func
()
{
r
.
Group
(
"/playlists"
,
func
()
{
r
.
Get
(
"/"
,
wrap
(
SearchPlaylists
))
r
.
Get
(
"/"
,
wrap
(
SearchPlaylists
))
r
.
Get
(
"/:id"
,
ValidateOrgPlaylist
,
wrap
(
GetPlaylist
))
r
.
Get
(
"/:id"
,
ValidateOrgPlaylist
,
wrap
(
GetPlaylist
))
r
.
Get
(
"/:id/dashboards"
,
ValidateOrgPlaylist
,
wrap
(
GetPlaylistDashboards
))
r
.
Get
(
"/:id/playlistitems"
,
ValidateOrgPlaylist
,
wrap
(
GetPlaylistItems
))
r
.
Get
(
"/:id/playlistdashboards"
,
ValidateOrgPlaylist
,
wrap
(
GetPlaylistDashboards
))
r
.
Delete
(
"/:id"
,
reqEditorRole
,
ValidateOrgPlaylist
,
wrap
(
DeletePlaylist
))
r
.
Delete
(
"/:id"
,
reqEditorRole
,
ValidateOrgPlaylist
,
wrap
(
DeletePlaylist
))
r
.
Put
(
"/:id"
,
reqEditorRole
,
bind
(
m
.
UpdatePlaylistQuery
{}),
ValidateOrgPlaylist
,
wrap
(
UpdatePlaylist
))
r
.
Put
(
"/:id"
,
reqEditorRole
,
bind
(
m
.
UpdatePlaylistQuery
{}),
ValidateOrgPlaylist
,
wrap
(
UpdatePlaylist
))
r
.
Post
(
"/"
,
reqEditorRole
,
bind
(
m
.
CreatePlaylistQuery
{}),
wrap
(
CreatePlaylist
))
r
.
Post
(
"/"
,
reqEditorRole
,
bind
(
m
.
CreatePlaylistQuery
{}),
wrap
(
CreatePlaylist
))
...
...
pkg/api/playlist.go
View file @
7e7d9457
package
api
package
api
import
(
import
(
"errors"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/bus"
"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"
"strconv"
)
)
func
ValidateOrgPlaylist
(
c
*
middleware
.
Context
)
{
func
ValidateOrgPlaylist
(
c
*
middleware
.
Context
)
{
...
@@ -52,19 +55,67 @@ func GetPlaylist(c *middleware.Context) Response {
...
@@ -52,19 +55,67 @@ func GetPlaylist(c *middleware.Context) Response {
return
ApiError
(
500
,
"Playlist not found"
,
err
)
return
ApiError
(
500
,
"Playlist not found"
,
err
)
}
}
return
Json
(
200
,
cmd
.
Result
)
itemQuery
:=
m
.
GetPlaylistItemsByIdQuery
{
PlaylistId
:
id
}
if
err
:=
bus
.
Dispatch
(
&
itemQuery
);
err
!=
nil
{
log
.
Warn
(
"itemQuery failed: %v"
,
err
)
return
ApiError
(
500
,
"Playlist items not found"
,
err
)
}
playlistDTOs
:=
make
([]
m
.
PlaylistItemDTO
,
0
)
for
_
,
item
:=
range
*
itemQuery
.
Result
{
playlistDTOs
=
append
(
playlistDTOs
,
m
.
PlaylistItemDTO
{
Id
:
item
.
Id
,
PlaylistId
:
item
.
PlaylistId
,
Type
:
item
.
Type
,
Value
:
item
.
Value
,
Order
:
item
.
Order
,
})
}
dto
:=
&
m
.
PlaylistDTO
{
Id
:
cmd
.
Result
.
Id
,
Title
:
cmd
.
Result
.
Title
,
Timespan
:
cmd
.
Result
.
Timespan
,
OrgId
:
cmd
.
Result
.
OrgId
,
Items
:
playlistDTOs
,
}
return
Json
(
200
,
dto
)
}
}
func
GetPlaylistDashboards
(
c
*
middleware
.
Context
)
Response
{
func
LoadPlaylistItems
(
id
int64
)
([]
m
.
PlaylistItem
,
error
)
{
id
:=
c
.
ParamsInt64
(
":id"
)
itemQuery
:=
m
.
GetPlaylistItemsByIdQuery
{
PlaylistId
:
id
}
if
err
:=
bus
.
Dispatch
(
&
itemQuery
);
err
!=
nil
{
log
.
Warn
(
"itemQuery failed: %v"
,
err
)
return
nil
,
errors
.
New
(
"Playlist not found"
)
}
query
:=
m
.
GetPlaylistDashboardsQuery
{
Id
:
id
}
return
*
itemQuery
.
Result
,
nil
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
}
return
ApiError
(
500
,
"Playlist not found"
,
err
)
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
)
dtos
:=
make
([]
m
.
PlaylistDashboardDto
,
0
)
for
_
,
item
:=
range
*
q
uery
.
Result
{
for
_
,
item
:=
range
*
dashboardQ
uery
.
Result
{
dtos
=
append
(
dtos
,
m
.
PlaylistDashboardDto
{
dtos
=
append
(
dtos
,
m
.
PlaylistDashboardDto
{
Id
:
item
.
Id
,
Id
:
item
.
Id
,
Slug
:
item
.
Slug
,
Slug
:
item
.
Slug
,
...
@@ -73,7 +124,43 @@ func GetPlaylistDashboards(c *middleware.Context) Response {
...
@@ -73,7 +124,43 @@ func GetPlaylistDashboards(c *middleware.Context) Response {
})
})
}
}
return
Json
(
200
,
dtos
)
return
dtos
,
nil
}
func
GetPlaylistItems
(
c
*
middleware
.
Context
)
Response
{
id
:=
c
.
ParamsInt64
(
":id"
)
items
,
err
:=
LoadPlaylistItems
(
id
)
if
err
!=
nil
{
return
ApiError
(
500
,
"Could not load playlist items"
,
err
)
}
playlistDTOs
:=
make
([]
m
.
PlaylistItemDTO
,
0
)
for
_
,
item
:=
range
items
{
playlistDTOs
=
append
(
playlistDTOs
,
m
.
PlaylistItemDTO
{
Id
:
item
.
Id
,
PlaylistId
:
item
.
PlaylistId
,
Type
:
item
.
Type
,
Value
:
item
.
Value
,
Order
:
item
.
Order
,
Title
:
item
.
Title
,
})
}
return
Json
(
200
,
playlistDTOs
)
}
func
GetPlaylistDashboards
(
c
*
middleware
.
Context
)
Response
{
id
:=
c
.
ParamsInt64
(
":id"
)
playlists
,
err
:=
LoadPlaylistDashboards
(
id
)
if
err
!=
nil
{
return
ApiError
(
500
,
"Could not load dashboards"
,
err
)
}
return
Json
(
200
,
playlists
)
}
}
func
DeletePlaylist
(
c
*
middleware
.
Context
)
Response
{
func
DeletePlaylist
(
c
*
middleware
.
Context
)
Response
{
...
@@ -103,5 +190,25 @@ func UpdatePlaylist(c *middleware.Context, query m.UpdatePlaylistQuery) Response
...
@@ -103,5 +190,25 @@ func UpdatePlaylist(c *middleware.Context, query m.UpdatePlaylistQuery) Response
return
ApiError
(
500
,
"Failed to save playlist"
,
err
)
return
ApiError
(
500
,
"Failed to save playlist"
,
err
)
}
}
items
,
err
:=
LoadPlaylistItems
(
query
.
Id
)
playlistDTOs
:=
make
([]
m
.
PlaylistItemDTO
,
0
)
for
_
,
item
:=
range
items
{
playlistDTOs
=
append
(
playlistDTOs
,
m
.
PlaylistItemDTO
{
Id
:
item
.
Id
,
PlaylistId
:
item
.
PlaylistId
,
Type
:
item
.
Type
,
Value
:
item
.
Value
,
Order
:
item
.
Order
,
})
}
if
err
!=
nil
{
return
ApiError
(
500
,
"Failed to save playlist"
,
err
)
}
query
.
Result
.
Items
=
playlistDTOs
return
Json
(
200
,
query
.
Result
)
return
Json
(
200
,
query
.
Result
)
}
}
pkg/models/playlist.go
View file @
7e7d9457
...
@@ -12,12 +12,27 @@ var (
...
@@ -12,12 +12,27 @@ var (
// Playlist model
// Playlist model
type
Playlist
struct
{
type
Playlist
struct
{
Id
int64
`json:"id"`
Id
int64
`json:"id"`
Title
string
`json:"title"`
Title
string
`json:"title"`
Type
string
`json:"type"`
Timespan
string
`json:"timespan"`
Timespan
string
`json:"timespan"`
OrgId
int64
`json:"-"`
Data
[]
int64
`json:"data"`
}
OrgId
int64
`json:"-"`
type
PlaylistDTO
struct
{
Id
int64
`json:"id"`
Title
string
`json:"title"`
Timespan
string
`json:"timespan"`
OrgId
int64
`json:"-"`
Items
[]
PlaylistItemDTO
`json:"items"`
}
type
PlaylistItemDTO
struct
{
Id
int64
`json:"id"`
PlaylistId
int64
`json:"playlistid"`
Type
string
`json:"type"`
Title
string
`json:"title"`
Value
string
`json:"value"`
Order
int
`json:"order"`
}
}
type
PlaylistDashboard
struct
{
type
PlaylistDashboard
struct
{
...
@@ -26,6 +41,15 @@ type PlaylistDashboard struct {
...
@@ -26,6 +41,15 @@ type PlaylistDashboard struct {
Title
string
`json:"title"`
Title
string
`json:"title"`
}
}
type
PlaylistItem
struct
{
Id
int64
PlaylistId
int64
Type
string
Value
string
Order
int
Title
string
}
func
(
this
PlaylistDashboard
)
TableName
()
string
{
func
(
this
PlaylistDashboard
)
TableName
()
string
{
return
"dashboard"
return
"dashboard"
}
}
...
@@ -60,9 +84,9 @@ type UpdatePlaylistQuery struct {
...
@@ -60,9 +84,9 @@ type UpdatePlaylistQuery struct {
Title
string
Title
string
Type
string
Type
string
Timespan
string
Timespan
string
Data
[]
int64
Items
[]
PlaylistItemDTO
Result
*
Playlist
Result
*
Playlist
DTO
}
}
type
CreatePlaylistQuery
struct
{
type
CreatePlaylistQuery
struct
{
...
@@ -71,6 +95,7 @@ type CreatePlaylistQuery struct {
...
@@ -71,6 +95,7 @@ type CreatePlaylistQuery struct {
Timespan
string
Timespan
string
Data
[]
int64
Data
[]
int64
OrgId
int64
OrgId
int64
Items
[]
PlaylistItemDTO
Result
*
Playlist
Result
*
Playlist
}
}
...
@@ -80,9 +105,14 @@ type GetPlaylistByIdQuery struct {
...
@@ -80,9 +105,14 @@ type GetPlaylistByIdQuery struct {
Result
*
Playlist
Result
*
Playlist
}
}
type
GetPlaylistItemsByIdQuery
struct
{
PlaylistId
int64
Result
*
[]
PlaylistItem
}
type
GetPlaylistDashboardsQuery
struct
{
type
GetPlaylistDashboardsQuery
struct
{
Id
int64
DashboardIds
[]
int64
Result
*
PlaylistDashboards
Result
*
PlaylistDashboards
}
}
type
DeletePlaylistQuery
struct
{
type
DeletePlaylistQuery
struct
{
...
...
pkg/services/sqlstore/dashboard.go
View file @
7e7d9457
...
@@ -220,26 +220,6 @@ func DeleteDashboard(cmd *m.DeleteDashboardCommand) error {
...
@@ -220,26 +220,6 @@ func DeleteDashboard(cmd *m.DeleteDashboardCommand) error {
}
}
}
}
var
playlists
=
make
(
m
.
Playlists
,
0
)
err
=
sess
.
Where
(
"data LIKE ?"
,
fmt
.
Sprintf
(
"%%%v%%"
,
dashboard
.
Id
))
.
Find
(
&
playlists
)
if
err
!=
nil
{
return
err
}
for
_
,
playlist
:=
range
playlists
{
filteredData
:=
make
([]
int64
,
0
)
for
_
,
plDashboardId
:=
range
playlist
.
Data
{
if
plDashboardId
!=
dashboard
.
Id
{
filteredData
=
append
(
filteredData
,
plDashboardId
)
}
}
playlist
.
Data
=
filteredData
_
,
err
=
sess
.
Id
(
playlist
.
Id
)
.
Cols
(
"data"
)
.
Update
(
playlist
)
if
err
!=
nil
{
return
err
}
}
return
nil
return
nil
})
})
}
}
pkg/services/sqlstore/migrations/playlist_mig.go
View file @
7e7d9457
...
@@ -8,8 +8,6 @@ func addPlaylistMigrations(mg *Migrator) {
...
@@ -8,8 +8,6 @@ func addPlaylistMigrations(mg *Migrator) {
Columns
:
[]
*
Column
{
Columns
:
[]
*
Column
{
{
Name
:
"id"
,
Type
:
DB_BigInt
,
IsPrimaryKey
:
true
,
IsAutoIncrement
:
true
},
{
Name
:
"id"
,
Type
:
DB_BigInt
,
IsPrimaryKey
:
true
,
IsAutoIncrement
:
true
},
{
Name
:
"title"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
{
Name
:
"title"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
{
Name
:
"type"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
{
Name
:
"data"
,
Type
:
DB_Text
,
Nullable
:
false
},
{
Name
:
"timespan"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
{
Name
:
"timespan"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
{
Name
:
"org_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"org_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
},
},
...
@@ -17,4 +15,18 @@ func addPlaylistMigrations(mg *Migrator) {
...
@@ -17,4 +15,18 @@ func addPlaylistMigrations(mg *Migrator) {
// create table
// create table
mg
.
AddMigration
(
"create playlist table v1"
,
NewAddTableMigration
(
playlistV1
))
mg
.
AddMigration
(
"create playlist table v1"
,
NewAddTableMigration
(
playlistV1
))
playlistItemV1
:=
Table
{
Name
:
"playlist_item"
,
Columns
:
[]
*
Column
{
{
Name
:
"id"
,
Type
:
DB_BigInt
,
IsPrimaryKey
:
true
,
IsAutoIncrement
:
true
},
{
Name
:
"playlist_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"type"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
{
Name
:
"value"
,
Type
:
DB_Text
,
Nullable
:
false
},
{
Name
:
"title"
,
Type
:
DB_Text
,
Nullable
:
false
},
{
Name
:
"order"
,
Type
:
DB_Int
,
Nullable
:
false
},
},
}
mg
.
AddMigration
(
"create playlist item table v1"
,
NewAddTableMigration
(
playlistItemV1
))
}
}
pkg/services/sqlstore/playlist.go
View file @
7e7d9457
package
sqlstore
package
sqlstore
import
(
import
(
"fmt"
"github.com/go-xorm/xorm"
"github.com/go-xorm/xorm"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/bus"
...
@@ -14,6 +15,7 @@ func init() {
...
@@ -14,6 +15,7 @@ func init() {
bus
.
AddHandler
(
"sql"
,
SearchPlaylists
)
bus
.
AddHandler
(
"sql"
,
SearchPlaylists
)
bus
.
AddHandler
(
"sql"
,
GetPlaylist
)
bus
.
AddHandler
(
"sql"
,
GetPlaylist
)
bus
.
AddHandler
(
"sql"
,
GetPlaylistDashboards
)
bus
.
AddHandler
(
"sql"
,
GetPlaylistDashboards
)
bus
.
AddHandler
(
"sql"
,
GetPlaylistItem
)
}
}
func
CreatePlaylist
(
query
*
m
.
CreatePlaylistQuery
)
error
{
func
CreatePlaylist
(
query
*
m
.
CreatePlaylistQuery
)
error
{
...
@@ -21,14 +23,27 @@ func CreatePlaylist(query *m.CreatePlaylistQuery) error {
...
@@ -21,14 +23,27 @@ func CreatePlaylist(query *m.CreatePlaylistQuery) error {
playlist
:=
m
.
Playlist
{
playlist
:=
m
.
Playlist
{
Title
:
query
.
Title
,
Title
:
query
.
Title
,
Type
:
query
.
Type
,
Data
:
query
.
Data
,
Timespan
:
query
.
Timespan
,
Timespan
:
query
.
Timespan
,
OrgId
:
query
.
OrgId
,
OrgId
:
query
.
OrgId
,
}
}
_
,
err
=
x
.
Insert
(
&
playlist
)
_
,
err
=
x
.
Insert
(
&
playlist
)
fmt
.
Printf
(
"%v"
,
playlist
.
Id
)
playlistItems
:=
make
([]
m
.
PlaylistItem
,
0
)
for
_
,
item
:=
range
query
.
Items
{
playlistItems
=
append
(
playlistItems
,
m
.
PlaylistItem
{
PlaylistId
:
playlist
.
Id
,
Type
:
item
.
Type
,
Value
:
item
.
Value
,
Order
:
item
.
Order
,
Title
:
item
.
Title
,
})
}
_
,
err
=
x
.
Insert
(
&
playlistItems
)
query
.
Result
=
&
playlist
query
.
Result
=
&
playlist
return
err
return
err
}
}
...
@@ -39,8 +54,6 @@ func UpdatePlaylist(query *m.UpdatePlaylistQuery) error {
...
@@ -39,8 +54,6 @@ func UpdatePlaylist(query *m.UpdatePlaylistQuery) error {
playlist
:=
m
.
Playlist
{
playlist
:=
m
.
Playlist
{
Id
:
query
.
Id
,
Id
:
query
.
Id
,
Title
:
query
.
Title
,
Title
:
query
.
Title
,
Type
:
query
.
Type
,
Data
:
query
.
Data
,
Timespan
:
query
.
Timespan
,
Timespan
:
query
.
Timespan
,
}
}
...
@@ -50,9 +63,40 @@ func UpdatePlaylist(query *m.UpdatePlaylistQuery) error {
...
@@ -50,9 +63,40 @@ func UpdatePlaylist(query *m.UpdatePlaylistQuery) error {
return
m
.
ErrPlaylistNotFound
return
m
.
ErrPlaylistNotFound
}
}
_
,
err
=
x
.
Id
(
query
.
Id
)
.
Cols
(
"id"
,
"title"
,
"data"
,
"timespan"
)
.
Update
(
&
playlist
)
query
.
Result
=
&
m
.
PlaylistDTO
{
Id
:
playlist
.
Id
,
OrgId
:
playlist
.
OrgId
,
Title
:
playlist
.
Title
,
Timespan
:
playlist
.
Timespan
,
}
_
,
err
=
x
.
Id
(
query
.
Id
)
.
Cols
(
"id"
,
"title"
,
"timespan"
)
.
Update
(
&
playlist
)
if
err
!=
nil
{
return
err
}
rawSql
:=
"DELETE FROM playlist_item WHERE playlist_id = ?"
_
,
err
=
x
.
Exec
(
rawSql
,
query
.
Id
)
if
err
!=
nil
{
return
err
}
playlistItems
:=
make
([]
m
.
PlaylistItem
,
0
)
for
_
,
item
:=
range
query
.
Items
{
playlistItems
=
append
(
playlistItems
,
m
.
PlaylistItem
{
PlaylistId
:
playlist
.
Id
,
Type
:
item
.
Type
,
Value
:
item
.
Value
,
Order
:
item
.
Order
,
Title
:
item
.
Title
,
})
}
_
,
err
=
x
.
Insert
(
&
playlistItems
)
query
.
Result
=
&
playlist
return
err
return
err
}
}
...
@@ -63,6 +107,7 @@ func GetPlaylist(query *m.GetPlaylistByIdQuery) error {
...
@@ -63,6 +107,7 @@ func GetPlaylist(query *m.GetPlaylistByIdQuery) error {
playlist
:=
m
.
Playlist
{}
playlist
:=
m
.
Playlist
{}
_
,
err
:=
x
.
Id
(
query
.
Id
)
.
Get
(
&
playlist
)
_
,
err
:=
x
.
Id
(
query
.
Id
)
.
Get
(
&
playlist
)
query
.
Result
=
&
playlist
query
.
Result
=
&
playlist
return
err
return
err
...
@@ -74,9 +119,17 @@ func DeletePlaylist(query *m.DeletePlaylistQuery) error {
...
@@ -74,9 +119,17 @@ func DeletePlaylist(query *m.DeletePlaylistQuery) error {
}
}
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
var
rawSql
=
"DELETE FROM playlist WHERE id = ?"
var
rawPlaylistSql
=
"DELETE FROM playlist WHERE id = ?"
_
,
err
:=
sess
.
Exec
(
rawSql
,
query
.
Id
)
_
,
err
:=
sess
.
Exec
(
rawPlaylistSql
,
query
.
Id
)
return
err
if
err
!=
nil
{
return
err
}
var
rawItemSql
=
"DELETE FROM playlist_item WHERE playlist_id = ?"
_
,
err2
:=
sess
.
Exec
(
rawItemSql
,
query
.
Id
)
return
err2
})
})
}
}
...
@@ -96,27 +149,28 @@ func SearchPlaylists(query *m.PlaylistQuery) error {
...
@@ -96,27 +149,28 @@ func SearchPlaylists(query *m.PlaylistQuery) error {
return
err
return
err
}
}
func
GetPlaylist
Dashboards
(
query
*
m
.
GetPlaylistDashboards
Query
)
error
{
func
GetPlaylist
Item
(
query
*
m
.
GetPlaylistItemsById
Query
)
error
{
if
query
.
Id
==
0
{
if
query
.
Playlist
Id
==
0
{
return
m
.
ErrCommandValidationFailed
return
m
.
ErrCommandValidationFailed
}
}
var
dashboards
=
make
(
m
.
PlaylistDashboards
,
0
)
var
playlistItems
=
make
([]
m
.
PlaylistItem
,
0
)
var
playlist
=
m
.
Playlist
{}
err
:=
x
.
Where
(
"playlist_id=?"
,
query
.
PlaylistId
)
.
Find
(
&
playlistItems
)
hasPlaylist
,
err
:=
x
.
Id
(
query
.
Id
)
.
Get
(
&
playlist
)
query
.
Result
=
&
playlistItems
query
.
Result
=
&
dashboards
return
err
}
if
err
!=
nil
{
func
GetPlaylistDashboards
(
query
*
m
.
GetPlaylistDashboardsQuery
)
error
{
return
err
if
len
(
query
.
DashboardIds
)
==
0
{
return
m
.
ErrCommandValidationFailed
}
}
if
!
hasPlaylist
||
len
(
playlist
.
Data
)
==
0
{
var
dashboards
=
make
(
m
.
PlaylistDashboards
,
0
)
return
nil
}
err
=
x
.
In
(
"id"
,
playlist
.
Data
)
.
Find
(
&
dashboards
)
err
:=
x
.
In
(
"id"
,
query
.
DashboardIds
)
.
Find
(
&
dashboards
)
query
.
Result
=
&
dashboards
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
public/app/features/playlist/partials/playlist.html
View file @
7e7d9457
...
@@ -59,14 +59,14 @@
...
@@ -59,14 +59,14 @@
<div>
<div>
<div
class=
"span5 pull-left"
>
<div
class=
"span5 pull-left"
>
<h5>
Search results ({{filtered
Dashboard
s.length}})
</h5>
<h5>
Search results ({{filtered
PlaylistItem
s.length}})
</h5>
<table
class=
"grafana-options-table"
>
<table
class=
"grafana-options-table"
>
<tr
ng-repeat=
"
dashboard in filteredDashboard
s"
>
<tr
ng-repeat=
"
playlistItem in filteredPlaylistItem
s"
>
<td
style=
"white-space: nowrap;"
>
<td
style=
"white-space: nowrap;"
>
{{
dashboard
.title}}
{{
playlistItem
.title}}
</td>
</td>
<td
style=
"text-align: center"
>
<td
style=
"text-align: center"
>
<button
class=
"btn btn-inverse btn-mini pull-right"
ng-click=
"add
Dashboard(dashboard
)"
>
<button
class=
"btn btn-inverse btn-mini pull-right"
ng-click=
"add
PlaylistItem(playlistItem
)"
>
<i
class=
"fa fa-plus"
></i>
<i
class=
"fa fa-plus"
></i>
Add to playlist
Add to playlist
</button>
</button>
...
@@ -82,18 +82,18 @@
...
@@ -82,18 +82,18 @@
<div
class=
"span5 pull-left"
>
<div
class=
"span5 pull-left"
>
<h5>
Playlist dashboards
</h5>
<h5>
Playlist dashboards
</h5>
<table
class=
"grafana-options-table"
>
<table
class=
"grafana-options-table"
>
<tr
ng-repeat=
"
dashboard in dashboard
s"
>
<tr
ng-repeat=
"
playlistItem in playlistItem
s"
>
<td
style=
"white-space: nowrap;"
>
<td
style=
"white-space: nowrap;"
>
{{
dashboard
.title}}
{{
playlistItem
.title}}
</td>
</td>
<td
style=
"text-align: right"
>
<td
style=
"text-align: right"
>
<button
class=
"btn btn-inverse btn-mini"
ng-hide=
"$first"
ng-click=
"move
DashboardUp(dashboard
)"
>
<button
class=
"btn btn-inverse btn-mini"
ng-hide=
"$first"
ng-click=
"move
PlaylistItemUp(playlistItem
)"
>
<i
class=
"fa fa-arrow-up"
></i>
<i
class=
"fa fa-arrow-up"
></i>
</button>
</button>
<button
class=
"btn btn-inverse btn-mini"
ng-hide=
"$last"
ng-click=
"move
DashboardDown(dashboard
)"
>
<button
class=
"btn btn-inverse btn-mini"
ng-hide=
"$last"
ng-click=
"move
PlaylistItemDown(playlistItem
)"
>
<i
class=
"fa fa-arrow-down"
></i>
<i
class=
"fa fa-arrow-down"
></i>
</button>
</button>
<button
class=
"btn btn-inverse btn-mini"
ng-click=
"remove
Dashboard(dashboard
)"
>
<button
class=
"btn btn-inverse btn-mini"
ng-click=
"remove
PlaylistItem(playlistItem
)"
>
<i
class=
"fa fa-remove"
></i>
<i
class=
"fa fa-remove"
></i>
</button>
</button>
</td>
</td>
...
@@ -109,11 +109,7 @@
...
@@ -109,11 +109,7 @@
<button
type=
"button"
<button
type=
"button"
class=
"btn btn-success"
class=
"btn btn-success"
ng-disabled=
"playlistEditForm.$invalid || isPlaylistEmpty()"
ng-disabled=
"playlistEditForm.$invalid || isPlaylistEmpty()"
ng-click=
"startPlaylist(playlist, dashboards)"
>
Start
</button>
ng-click=
"savePlaylist(playlist, playlistItems)"
>
Save
</button>
<button
type=
"button"
class=
"btn btn-success"
ng-disabled=
"playlistEditForm.$invalid || isPlaylistEmpty()"
ng-click=
"savePlaylist(playlist, dashboards)"
>
Save
</button>
<button
type=
"button"
<button
type=
"button"
class=
"btn btn-default"
class=
"btn btn-default"
ng-click=
"backToList()"
>
Cancel
</button>
ng-click=
"backToList()"
>
Cancel
</button>
...
...
public/app/features/playlist/playlist_edit_ctrl.js
View file @
7e7d9457
...
@@ -10,12 +10,12 @@ function (angular, config, _) {
...
@@ -10,12 +10,12 @@ function (angular, config, _) {
module
.
controller
(
'PlaylistEditCtrl'
,
function
(
$scope
,
playlistSrv
,
backendSrv
,
$location
,
$route
)
{
module
.
controller
(
'PlaylistEditCtrl'
,
function
(
$scope
,
playlistSrv
,
backendSrv
,
$location
,
$route
)
{
$scope
.
timespan
=
config
.
playlist_timespan
;
$scope
.
timespan
=
config
.
playlist_timespan
;
$scope
.
filtered
Dashboard
s
=
[];
$scope
.
filtered
PlaylistItem
s
=
[];
$scope
.
found
Dashboard
s
=
[];
$scope
.
found
PlaylistItem
s
=
[];
$scope
.
searchQuery
=
''
;
$scope
.
searchQuery
=
''
;
$scope
.
loading
=
false
;
$scope
.
loading
=
false
;
$scope
.
playlist
=
{};
$scope
.
playlist
=
{};
$scope
.
dashboard
s
=
[];
$scope
.
playlistItem
s
=
[];
if
(
$route
.
current
.
params
.
id
)
{
if
(
$route
.
current
.
params
.
id
)
{
var
playlistId
=
$route
.
current
.
params
.
id
;
var
playlistId
=
$route
.
current
.
params
.
id
;
...
@@ -25,9 +25,9 @@ function (angular, config, _) {
...
@@ -25,9 +25,9 @@ function (angular, config, _) {
$scope
.
playlist
=
result
;
$scope
.
playlist
=
result
;
});
});
backendSrv
.
get
(
'/api/playlists/'
+
playlistId
+
'/
dashboard
s'
)
backendSrv
.
get
(
'/api/playlists/'
+
playlistId
+
'/
playlistitem
s'
)
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
$scope
.
dashboard
s
=
result
;
$scope
.
playlistItem
s
=
result
;
});
});
}
}
...
@@ -43,43 +43,43 @@ function (angular, config, _) {
...
@@ -43,43 +43,43 @@ function (angular, config, _) {
backendSrv
.
search
(
query
)
backendSrv
.
search
(
query
)
.
then
(
function
(
results
)
{
.
then
(
function
(
results
)
{
$scope
.
found
Dashboard
s
=
results
;
$scope
.
found
PlaylistItem
s
=
results
;
$scope
.
filterFound
Dashboard
s
();
$scope
.
filterFound
PlaylistItem
s
();
})
})
.
finally
(
function
()
{
.
finally
(
function
()
{
$scope
.
loading
=
false
;
$scope
.
loading
=
false
;
});
});
};
};
$scope
.
filterFound
Dashboard
s
=
function
()
{
$scope
.
filterFound
PlaylistItem
s
=
function
()
{
$scope
.
filtered
Dashboards
=
_
.
reject
(
$scope
.
foundDashboards
,
function
(
dashboard
)
{
$scope
.
filtered
PlaylistItems
=
_
.
reject
(
$scope
.
foundPlaylistItems
,
function
(
playlistItem
)
{
return
_
.
findWhere
(
$scope
.
dashboards
,
function
(
listDashboard
)
{
return
_
.
findWhere
(
$scope
.
playlistItems
,
function
(
listPlaylistItem
)
{
return
listDashboard
.
id
===
dashboard
.
id
;
return
parseInt
(
listPlaylistItem
.
value
)
===
playlistItem
.
id
;
});
});
});
});
};
};
$scope
.
addDashboard
=
function
(
dashboard
)
{
$scope
.
addPlaylistItem
=
function
(
playlistItem
)
{
$scope
.
dashboards
.
push
(
dashboard
);
playlistItem
.
value
=
playlistItem
.
id
.
toString
();
$scope
.
filterFoundDashboards
();
playlistItem
.
type
=
'dashboard_by_id'
;
playlistItem
.
order
=
$scope
.
playlistItems
.
length
+
1
;
$scope
.
playlistItems
.
push
(
playlistItem
);
$scope
.
filterFoundPlaylistItems
();
};
};
$scope
.
remove
Dashboard
=
function
(
dashboard
)
{
$scope
.
remove
PlaylistItem
=
function
(
playlistItem
)
{
_
.
remove
(
$scope
.
dashboards
,
function
(
listedDashboard
)
{
_
.
remove
(
$scope
.
playlistItems
,
function
(
listedPlaylistItem
)
{
return
dashboard
===
listedDashboard
;
return
playlistItem
===
listedPlaylistItem
;
});
});
$scope
.
filterFound
Dashboard
s
();
$scope
.
filterFound
PlaylistItem
s
();
};
};
$scope
.
savePlaylist
=
function
(
playlist
,
dashboard
s
)
{
$scope
.
savePlaylist
=
function
(
playlist
,
playlistItem
s
)
{
var
savePromise
;
var
savePromise
;
playlist
.
data
=
dashboards
.
map
(
function
(
dashboard
)
{
playlist
.
items
=
playlistItems
;
return
dashboard
.
id
;
});
// Hardcoding playlist type for this iteration
playlist
.
type
=
"dashboards"
;
savePromise
=
playlist
.
id
savePromise
=
playlist
.
id
?
backendSrv
.
put
(
'/api/playlists/'
+
playlist
.
id
,
playlist
)
?
backendSrv
.
put
(
'/api/playlists/'
+
playlist
.
id
,
playlist
)
...
@@ -90,7 +90,7 @@ function (angular, config, _) {
...
@@ -90,7 +90,7 @@ function (angular, config, _) {
$scope
.
appEvent
(
'alert-success'
,
[
'Playlist saved'
,
''
]);
$scope
.
appEvent
(
'alert-success'
,
[
'Playlist saved'
,
''
]);
$location
.
path
(
'/playlists'
);
$location
.
path
(
'/playlists'
);
},
function
()
{
},
function
()
{
$scope
.
appEvent
(
'alert-
success
'
,
[
'Unable to save playlist'
,
''
]);
$scope
.
appEvent
(
'alert-
error
'
,
[
'Unable to save playlist'
,
''
]);
});
});
};
};
...
@@ -98,16 +98,12 @@ function (angular, config, _) {
...
@@ -98,16 +98,12 @@ function (angular, config, _) {
return
!
$scope
.
playlist
.
id
;
return
!
$scope
.
playlist
.
id
;
};
};
$scope
.
startPlaylist
=
function
(
playlist
,
dashboards
)
{
playlistSrv
.
start
(
dashboards
,
playlist
.
timespan
);
};
$scope
.
isPlaylistEmpty
=
function
()
{
$scope
.
isPlaylistEmpty
=
function
()
{
return
!
$scope
.
dashboard
s
.
length
;
return
!
$scope
.
playlistItem
s
.
length
;
};
};
$scope
.
isSearchResultsEmpty
=
function
()
{
$scope
.
isSearchResultsEmpty
=
function
()
{
return
!
$scope
.
found
Dashboard
s
.
length
;
return
!
$scope
.
found
PlaylistItem
s
.
length
;
};
};
$scope
.
isSearchQueryEmpty
=
function
()
{
$scope
.
isSearchQueryEmpty
=
function
()
{
...
@@ -122,22 +118,22 @@ function (angular, config, _) {
...
@@ -122,22 +118,22 @@ function (angular, config, _) {
return
$scope
.
loading
;
return
$scope
.
loading
;
};
};
$scope
.
move
Dashboard
=
function
(
dashboard
,
offset
)
{
$scope
.
move
PlaylistItem
=
function
(
playlistItem
,
offset
)
{
var
currentPosition
=
$scope
.
dashboards
.
indexOf
(
dashboard
);
var
currentPosition
=
$scope
.
playlistItems
.
indexOf
(
playlistItem
);
var
newPosition
=
currentPosition
+
offset
;
var
newPosition
=
currentPosition
+
offset
;
if
(
newPosition
>=
0
&&
newPosition
<
$scope
.
dashboard
s
.
length
)
{
if
(
newPosition
>=
0
&&
newPosition
<
$scope
.
playlistItem
s
.
length
)
{
$scope
.
dashboard
s
.
splice
(
currentPosition
,
1
);
$scope
.
playlistItem
s
.
splice
(
currentPosition
,
1
);
$scope
.
dashboards
.
splice
(
newPosition
,
0
,
dashboard
);
$scope
.
playlistItems
.
splice
(
newPosition
,
0
,
playlistItem
);
}
}
};
};
$scope
.
move
DashboardUp
=
function
(
dashboard
)
{
$scope
.
move
PlaylistItemUp
=
function
(
playlistItem
)
{
$scope
.
moveDashboard
(
dashboard
,
-
1
);
$scope
.
moveDashboard
(
playlistItem
,
-
1
);
};
};
$scope
.
move
DashboardDown
=
function
(
dashboard
)
{
$scope
.
move
PlaylistItemDown
=
function
(
playlistItem
)
{
$scope
.
moveDashboard
(
dashboard
,
1
);
$scope
.
moveDashboard
(
playlistItem
,
1
);
};
};
$scope
.
search
();
$scope
.
search
();
...
...
public/app/features/playlist/playlist_routes.js
View file @
7e7d9457
...
@@ -31,7 +31,7 @@ function (angular) {
...
@@ -31,7 +31,7 @@ function (angular) {
return
backendSrv
.
get
(
'/api/playlists/'
+
playlistId
)
return
backendSrv
.
get
(
'/api/playlists/'
+
playlistId
)
.
then
(
function
(
playlist
)
{
.
then
(
function
(
playlist
)
{
return
backendSrv
.
get
(
'/api/playlists/'
+
playlistId
+
'/dashboards'
)
return
backendSrv
.
get
(
'/api/playlists/'
+
playlistId
+
'/
playlist
dashboards'
)
.
then
(
function
(
dashboards
)
{
.
then
(
function
(
dashboards
)
{
playlistSrv
.
start
(
dashboards
,
playlist
.
timespan
);
playlistSrv
.
start
(
dashboards
,
playlist
.
timespan
);
});
});
...
...
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