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
972ac99b
Commit
972ac99b
authored
Jan 28, 2016
by
utkarshcmu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added more metadata
parent
b30dcce4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
18 deletions
+43
-18
docs/sources/reference/http_api.md
+1
-3
pkg/api/dashboard.go
+38
-11
pkg/api/dtos/models.go
+4
-4
No files found.
docs/sources/reference/http_api.md
View file @
972ac99b
...
@@ -70,15 +70,13 @@ Creates a new dashboard or updates an existing dashboard.
...
@@ -70,15 +70,13 @@ Creates a new dashboard or updates an existing dashboard.
"schemaVersion": 6,
"schemaVersion": 6,
"version": 0
"version": 0
},
},
"overwrite": false,
"overwrite": false
"userId:": 3
}
}
JSON Body schema:
JSON Body schema:
-
**dashboard**
– The complete dashboard model, id = null to create a new dashboard.
-
**dashboard**
– The complete dashboard model, id = null to create a new dashboard.
-
**overwrite**
– Set to true if you want to overwrite existing dashboard with newer version or with same dashboard title.
-
**overwrite**
– Set to true if you want to overwrite existing dashboard with newer version or with same dashboard title.
-
**userId**
- Set userId if you want to record who created or updated a dashboard.
**Example Response**
:
**Example Response**
:
...
...
pkg/api/dashboard.go
View file @
972ac99b
...
@@ -49,7 +49,7 @@ func GetDashboard(c *middleware.Context) {
...
@@ -49,7 +49,7 @@ func GetDashboard(c *middleware.Context) {
dash
:=
query
.
Result
dash
:=
query
.
Result
// Finding
the last creator and
updater of the dashboard
// Finding
creator and last
updater of the dashboard
updater
,
creator
:=
"Anonymous"
,
"Anonymous"
updater
,
creator
:=
"Anonymous"
,
"Anonymous"
if
dash
.
UpdatedBy
>
0
{
if
dash
.
UpdatedBy
>
0
{
updater
=
getUserLogin
(
dash
.
UpdatedBy
)
updater
=
getUserLogin
(
dash
.
UpdatedBy
)
...
@@ -58,19 +58,26 @@ func GetDashboard(c *middleware.Context) {
...
@@ -58,19 +58,26 @@ func GetDashboard(c *middleware.Context) {
creator
=
getUserLogin
(
dash
.
CreatedBy
)
creator
=
getUserLogin
(
dash
.
CreatedBy
)
}
}
// Finding total panels and queries on the dashboard
totalRows
,
totalPanels
,
totalQueries
:=
getTotalRowsPanelsAndQueries
(
dash
.
Data
)
dto
:=
dtos
.
DashboardFullWithMeta
{
dto
:=
dtos
.
DashboardFullWithMeta
{
Dashboard
:
dash
.
Data
,
Dashboard
:
dash
.
Data
,
Meta
:
dtos
.
DashboardMeta
{
Meta
:
dtos
.
DashboardMeta
{
IsStarred
:
isStarred
,
IsStarred
:
isStarred
,
Slug
:
slug
,
Slug
:
slug
,
Type
:
m
.
DashTypeDB
,
Type
:
m
.
DashTypeDB
,
CanStar
:
c
.
IsSignedIn
,
CanStar
:
c
.
IsSignedIn
,
CanSave
:
c
.
OrgRole
==
m
.
ROLE_ADMIN
||
c
.
OrgRole
==
m
.
ROLE_EDITOR
,
CanSave
:
c
.
OrgRole
==
m
.
ROLE_ADMIN
||
c
.
OrgRole
==
m
.
ROLE_EDITOR
,
CanEdit
:
canEditDashboard
(
c
.
OrgRole
),
CanEdit
:
canEditDashboard
(
c
.
OrgRole
),
Created
:
dash
.
Created
,
Created
:
dash
.
Created
,
Updated
:
dash
.
Updated
,
Updated
:
dash
.
Updated
,
UpdatedBy
:
updater
,
UpdatedBy
:
updater
,
CreatedBy
:
creator
,
CreatedBy
:
creator
,
TotalRows
:
totalRows
,
TotalPanels
:
totalPanels
,
TotalQueries
:
totalQueries
,
Version
:
dash
.
Version
,
},
},
}
}
...
@@ -88,6 +95,26 @@ func getUserLogin(userId int64) string {
...
@@ -88,6 +95,26 @@ func getUserLogin(userId int64) string {
}
}
}
}
func
getTotalRowsPanelsAndQueries
(
data
map
[
string
]
interface
{})
(
int
,
int
,
int
)
{
totalRows
,
totalPanels
,
totalQueries
:=
0
,
0
,
0
if
rows
,
rowsOk
:=
data
[
"rows"
];
rowsOk
{
totalRows
=
len
(
rows
.
([]
interface
{}))
if
totalRows
>
0
{
for
_
,
rowElement
:=
range
rows
.
([]
interface
{})
{
if
panels
,
panelsOk
:=
rowElement
.
(
map
[
string
]
interface
{})[
"panels"
];
panelsOk
{
totalPanels
+=
len
(
panels
.
([]
interface
{}))
for
_
,
panelElement
:=
range
panels
.
([]
interface
{})
{
if
targets
,
targetsOk
:=
panelElement
.
(
map
[
string
]
interface
{})[
"targets"
];
targetsOk
{
totalQueries
+=
len
(
targets
.
([]
interface
{}))
}
}
}
}
}
}
return
totalRows
,
totalPanels
,
totalQueries
}
func
DeleteDashboard
(
c
*
middleware
.
Context
)
{
func
DeleteDashboard
(
c
*
middleware
.
Context
)
{
slug
:=
c
.
Params
(
":slug"
)
slug
:=
c
.
Params
(
":slug"
)
...
...
pkg/api/dtos/models.go
View file @
972ac99b
...
@@ -43,10 +43,10 @@ type DashboardMeta struct {
...
@@ -43,10 +43,10 @@ type DashboardMeta struct {
Updated
time
.
Time
`json:"updated"`
Updated
time
.
Time
`json:"updated"`
UpdatedBy
string
`json:"updatedBy"`
UpdatedBy
string
`json:"updatedBy"`
CreatedBy
string
`json:"createdBy"`
CreatedBy
string
`json:"createdBy"`
TotalRows
int64
`json:"totalRows"`
TotalRows
int
`json:"totalRows"`
TotalPanels
int64
`json:"totalPanels"`
TotalPanels
int
`json:"totalPanels"`
TotalQueries
int64
`json:"totalQueries"`
TotalQueries
int
`json:"totalQueries"`
Version
int
`json:"version"`
Version
int
`json:"version"`
}
}
type
DashboardFullWithMeta
struct
{
type
DashboardFullWithMeta
struct
{
...
...
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