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
179f35a5
Unverified
Commit
179f35a5
authored
Feb 02, 2021
by
Hugo Häggmark
Committed by
GitHub
Feb 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PanelLibrary: Adds library panel meta information to dashboard json (#30770)
parent
07e7f47d
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
36 deletions
+68
-36
pkg/services/librarypanels/database.go
+50
-36
pkg/services/librarypanels/librarypanels.go
+16
-0
pkg/services/librarypanels/librarypanels_test.go
+0
-0
pkg/services/librarypanels/models.go
+2
-0
No files found.
pkg/services/librarypanels/database.go
View file @
179f35a5
...
...
@@ -12,6 +12,21 @@ import (
"github.com/grafana/grafana/pkg/util"
)
var
(
sqlStatmentLibrayPanelDTOWithMeta
=
`
SELECT lp.id, lp.org_id, lp.folder_id, lp.uid, lp.name, lp.model, lp.created, lp.created_by, lp.updated, lp.updated_by
, 0 AS can_edit
, u1.login AS created_by_name
, u1.email AS created_by_email
, u2.login AS updated_by_name
, u2.email AS updated_by_email
, (SELECT COUNT(dashboard_id) FROM library_panel_dashboard WHERE librarypanel_id = lp.id) AS connected_dashboards
FROM library_panel AS lp
LEFT JOIN user AS u1 ON lp.created_by = u1.id
LEFT JOIN user AS u2 ON lp.updated_by = u2.id
`
)
// createLibraryPanel adds a Library Panel.
func
(
lps
*
LibraryPanelService
)
createLibraryPanel
(
c
*
models
.
ReqContext
,
cmd
createLibraryPanelCommand
)
(
LibraryPanelDTO
,
error
)
{
libraryPanel
:=
LibraryPanel
{
...
...
@@ -46,6 +61,7 @@ func (lps *LibraryPanelService) createLibraryPanel(c *models.ReqContext, cmd cre
Model
:
libraryPanel
.
Model
,
Meta
:
LibraryPanelDTOMeta
{
CanEdit
:
true
,
ConnectedDashboards
:
0
,
Created
:
libraryPanel
.
Created
,
Updated
:
libraryPanel
.
Updated
,
CreatedBy
:
LibraryPanelDTOMetaUser
{
...
...
@@ -179,18 +195,7 @@ func (lps *LibraryPanelService) disconnectLibraryPanelsForDashboard(dashboardID
func
getLibraryPanel
(
session
*
sqlstore
.
DBSession
,
uid
string
,
orgID
int64
)
(
LibraryPanelWithMeta
,
error
)
{
libraryPanels
:=
make
([]
LibraryPanelWithMeta
,
0
)
sql
:=
`SELECT
lp.id, lp.org_id, lp.folder_id, lp.uid, lp.name, lp.model, lp.created, lp.created_by, lp.updated, lp.updated_by
, 0 AS can_edit
, u1.login AS created_by_name
, u1.email AS created_by_email
, u2.login AS updated_by_name
, u2.email AS updated_by_email
FROM library_panel AS lp
LEFT JOIN user AS u1 ON lp.created_by = u1.id
LEFT JOIN user AS u2 ON lp.updated_by = u2.id
WHERE lp.uid=? AND lp.org_id=?`
sql
:=
sqlStatmentLibrayPanelDTOWithMeta
+
"WHERE lp.uid=? AND lp.org_id=?"
sess
:=
session
.
SQL
(
sql
,
uid
,
orgID
)
err
:=
sess
.
Find
(
&
libraryPanels
)
if
err
!=
nil
{
...
...
@@ -224,6 +229,7 @@ func (lps *LibraryPanelService) getLibraryPanel(c *models.ReqContext, uid string
Model
:
libraryPanel
.
Model
,
Meta
:
LibraryPanelDTOMeta
{
CanEdit
:
true
,
ConnectedDashboards
:
libraryPanel
.
ConnectedDashboards
,
Created
:
libraryPanel
.
Created
,
Updated
:
libraryPanel
.
Updated
,
CreatedBy
:
LibraryPanelDTOMetaUser
{
...
...
@@ -247,18 +253,7 @@ func (lps *LibraryPanelService) getAllLibraryPanels(c *models.ReqContext) ([]Lib
orgID
:=
c
.
SignedInUser
.
OrgId
libraryPanels
:=
make
([]
LibraryPanelWithMeta
,
0
)
err
:=
lps
.
SQLStore
.
WithDbSession
(
context
.
Background
(),
func
(
session
*
sqlstore
.
DBSession
)
error
{
sql
:=
`SELECT
lp.id, lp.org_id, lp.folder_id, lp.uid, lp.name, lp.model, lp.created, lp.created_by, lp.updated, lp.updated_by
, 0 AS can_edit
, u1.login AS created_by_name
, u1.email AS created_by_email
, u2.login AS updated_by_name
, u2.email AS updated_by_email
FROM library_panel AS lp
LEFT JOIN user AS u1 ON lp.created_by = u1.id
LEFT JOIN user AS u2 ON lp.updated_by = u2.id
WHERE lp.org_id=?`
sql
:=
sqlStatmentLibrayPanelDTOWithMeta
+
"WHERE lp.org_id=?"
sess
:=
session
.
SQL
(
sql
,
orgID
)
err
:=
sess
.
Find
(
&
libraryPanels
)
if
err
!=
nil
{
...
...
@@ -279,6 +274,7 @@ func (lps *LibraryPanelService) getAllLibraryPanels(c *models.ReqContext) ([]Lib
Model
:
panel
.
Model
,
Meta
:
LibraryPanelDTOMeta
{
CanEdit
:
true
,
ConnectedDashboards
:
panel
.
ConnectedDashboards
,
Created
:
panel
.
Created
,
Updated
:
panel
.
Updated
,
CreatedBy
:
LibraryPanelDTOMetaUser
{
...
...
@@ -325,17 +321,11 @@ func (lps *LibraryPanelService) getConnectedDashboards(c *models.ReqContext, uid
return
connectedDashboardIDs
,
err
}
func
(
lps
*
LibraryPanelService
)
getLibraryPanelsForDashboardID
(
dashboardID
int64
)
(
map
[
string
]
LibraryPanel
,
error
)
{
libraryPanelMap
:=
make
(
map
[
string
]
LibraryPanel
)
func
(
lps
*
LibraryPanelService
)
getLibraryPanelsForDashboardID
(
dashboardID
int64
)
(
map
[
string
]
LibraryPanel
DTO
,
error
)
{
libraryPanelMap
:=
make
(
map
[
string
]
LibraryPanel
DTO
)
err
:=
lps
.
SQLStore
.
WithDbSession
(
context
.
Background
(),
func
(
session
*
sqlstore
.
DBSession
)
error
{
sql
:=
`SELECT
lp.id, lp.org_id, lp.folder_id, lp.uid, lp.name, lp.model, lp.created, lp.created_by, lp.updated, lp.updated_by
FROM
library_panel_dashboard AS lpd
INNER JOIN
library_panel AS lp ON lpd.librarypanel_id = lp.id AND lpd.dashboard_id=?`
var
libraryPanels
[]
LibraryPanel
var
libraryPanels
[]
LibraryPanelWithMeta
sql
:=
sqlStatmentLibrayPanelDTOWithMeta
+
"INNER JOIN library_panel_dashboard AS lpd ON lpd.librarypanel_id = lp.id AND lpd.dashboard_id=?"
sess
:=
session
.
SQL
(
sql
,
dashboardID
)
err
:=
sess
.
Find
(
&
libraryPanels
)
if
err
!=
nil
{
...
...
@@ -343,7 +333,30 @@ func (lps *LibraryPanelService) getLibraryPanelsForDashboardID(dashboardID int64
}
for
_
,
panel
:=
range
libraryPanels
{
libraryPanelMap
[
panel
.
UID
]
=
panel
libraryPanelMap
[
panel
.
UID
]
=
LibraryPanelDTO
{
ID
:
panel
.
ID
,
OrgID
:
panel
.
OrgID
,
FolderID
:
panel
.
FolderID
,
UID
:
panel
.
UID
,
Name
:
panel
.
Name
,
Model
:
panel
.
Model
,
Meta
:
LibraryPanelDTOMeta
{
CanEdit
:
panel
.
CanEdit
,
ConnectedDashboards
:
panel
.
ConnectedDashboards
,
Created
:
panel
.
Created
,
Updated
:
panel
.
Updated
,
CreatedBy
:
LibraryPanelDTOMetaUser
{
ID
:
panel
.
CreatedBy
,
Name
:
panel
.
CreatedByName
,
AvatarUrl
:
dtos
.
GetGravatarUrl
(
panel
.
CreatedByEmail
),
},
UpdatedBy
:
LibraryPanelDTOMetaUser
{
ID
:
panel
.
UpdatedBy
,
Name
:
panel
.
UpdatedByName
,
AvatarUrl
:
dtos
.
GetGravatarUrl
(
panel
.
UpdatedByEmail
),
},
},
}
}
return
nil
...
...
@@ -402,10 +415,11 @@ func (lps *LibraryPanelService) patchLibraryPanel(c *models.ReqContext, cmd patc
Model
:
libraryPanel
.
Model
,
Meta
:
LibraryPanelDTOMeta
{
CanEdit
:
true
,
ConnectedDashboards
:
panelInDB
.
ConnectedDashboards
,
Created
:
libraryPanel
.
Created
,
Updated
:
libraryPanel
.
Updated
,
CreatedBy
:
LibraryPanelDTOMetaUser
{
ID
:
libraryPanel
.
CreatedBy
,
ID
:
panelInDB
.
CreatedBy
,
Name
:
panelInDB
.
CreatedByName
,
AvatarUrl
:
dtos
.
GetGravatarUrl
(
panelInDB
.
CreatedByEmail
),
},
...
...
pkg/services/librarypanels/librarypanels.go
View file @
179f35a5
...
...
@@ -104,6 +104,22 @@ func (lps *LibraryPanelService) LoadLibraryPanelsForDashboard(dash *models.Dashb
elem
.
Set
(
"libraryPanel"
,
map
[
string
]
interface
{}{
"uid"
:
libraryPanelInDB
.
UID
,
"name"
:
libraryPanelInDB
.
Name
,
"meta"
:
map
[
string
]
interface
{}{
"canEdit"
:
libraryPanelInDB
.
Meta
.
CanEdit
,
"connectedDashboards"
:
libraryPanelInDB
.
Meta
.
ConnectedDashboards
,
"created"
:
libraryPanelInDB
.
Meta
.
Created
,
"updated"
:
libraryPanelInDB
.
Meta
.
Updated
,
"createdBy"
:
map
[
string
]
interface
{}{
"id"
:
libraryPanelInDB
.
Meta
.
CreatedBy
.
ID
,
"name"
:
libraryPanelInDB
.
Meta
.
CreatedBy
.
Name
,
"avatarUrl"
:
libraryPanelInDB
.
Meta
.
CreatedBy
.
AvatarUrl
,
},
"updatedBy"
:
map
[
string
]
interface
{}{
"id"
:
libraryPanelInDB
.
Meta
.
UpdatedBy
.
ID
,
"name"
:
libraryPanelInDB
.
Meta
.
UpdatedBy
.
Name
,
"avatarUrl"
:
libraryPanelInDB
.
Meta
.
UpdatedBy
.
AvatarUrl
,
},
},
})
}
...
...
pkg/services/librarypanels/librarypanels_test.go
View file @
179f35a5
This diff is collapsed.
Click to expand it.
pkg/services/librarypanels/models.go
View file @
179f35a5
...
...
@@ -35,6 +35,7 @@ type LibraryPanelWithMeta struct {
Updated
time
.
Time
CanEdit
bool
ConnectedDashboards
int64
CreatedBy
int64
UpdatedBy
int64
CreatedByName
string
...
...
@@ -57,6 +58,7 @@ type LibraryPanelDTO struct {
// LibraryPanelDTOMeta is the meta information for LibraryPanelDTO.
type
LibraryPanelDTOMeta
struct
{
CanEdit
bool
`json:"canEdit"`
ConnectedDashboards
int64
`json:"connectedDashboards"`
Created
time
.
Time
`json:"created"`
Updated
time
.
Time
`json:"updated"`
...
...
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