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
541cd2e4
Commit
541cd2e4
authored
Mar 26, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dashboard snapshot: more work on snapshot deletion, and saving external reference, #1623
parent
4322f29f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
29 deletions
+42
-29
pkg/api/dashboard_snapshot.go
+9
-4
pkg/models/dashboard_snapshot.go
+10
-9
pkg/services/sqlstore/dashboard_snapshot.go
+9
-10
src/app/features/dashboard/shareSnapshotCtrl.js
+14
-6
No files found.
pkg/api/dashboard_snapshot.go
View file @
541cd2e4
...
...
@@ -13,14 +13,19 @@ import (
)
func
CreateDashboardSnapshot
(
c
*
middleware
.
Context
,
cmd
m
.
CreateDashboardSnapshotCommand
)
{
cmd
.
Key
=
util
.
GetRandomString
(
32
)
cmd
.
DeleteKey
=
util
.
GetRandomString
(
32
)
if
cmd
.
External
{
// external snapshot ref requires key and delete key
if
cmd
.
Key
!=
""
&&
cmd
.
DeleteKey
!=
""
{
c
.
JsonApiErr
(
400
,
"Missing key and delete key for external snapshot"
,
nil
)
return
}
cmd
.
OrgId
=
-
1
cmd
.
UserId
=
-
1
metrics
.
M_Api_Dashboard_Snapshot_External
.
Inc
(
1
)
}
else
{
cmd
.
Key
=
util
.
GetRandomString
(
32
)
cmd
.
DeleteKey
=
util
.
GetRandomString
(
32
)
cmd
.
OrgId
=
c
.
OrgId
cmd
.
UserId
=
c
.
UserId
metrics
.
M_Api_Dashboard_Snapshot_Create
.
Inc
(
1
)
...
...
@@ -78,5 +83,5 @@ func DeleteDashboardSnapshot(c *middleware.Context) {
return
}
c
.
JSON
(
200
,
util
.
DynMap
{
"message"
:
"Snapshot deleted. It might take an hour before it
i
s cleared from a CDN cache."
})
c
.
JSON
(
200
,
util
.
DynMap
{
"message"
:
"Snapshot deleted. It might take an hour before it
'
s cleared from a CDN cache."
})
}
pkg/models/dashboard_snapshot.go
View file @
541cd2e4
...
...
@@ -24,15 +24,16 @@ type DashboardSnapshot struct {
// COMMANDS
type
CreateDashboardSnapshotCommand
struct
{
Dashboard
map
[
string
]
interface
{}
`json:"dashboard" binding:"Required"`
External
bool
`json:"external"`
ExternalUrl
string
`json:"externalUrl"`
Expires
int64
`json:"expires"`
OrgId
int64
`json:"-"`
UserId
int64
`json:"-"`
Key
string
`json:"-"`
DeleteKey
string
`json:"-"`
Dashboard
map
[
string
]
interface
{}
`json:"dashboard" binding:"Required"`
Expires
int64
`json:"expires"`
// these are passed when storing an external snapshot ref
External
bool
`json:"external"`
Key
string
`json:"key"`
DeleteKey
string
`json:"deleteKey"`
OrgId
int64
`json:"-"`
UserId
int64
`json:"-"`
Result
*
DashboardSnapshot
}
...
...
pkg/services/sqlstore/dashboard_snapshot.go
View file @
541cd2e4
...
...
@@ -24,16 +24,15 @@ func CreateDashboardSnapshot(cmd *m.CreateDashboardSnapshotCommand) error {
}
snapshot
:=
&
m
.
DashboardSnapshot
{
Key
:
cmd
.
Key
,
DeleteKey
:
cmd
.
DeleteKey
,
OrgId
:
cmd
.
OrgId
,
UserId
:
cmd
.
UserId
,
External
:
cmd
.
External
,
ExternalUrl
:
cmd
.
ExternalUrl
,
Dashboard
:
cmd
.
Dashboard
,
Expires
:
expires
,
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
Key
:
cmd
.
Key
,
DeleteKey
:
cmd
.
DeleteKey
,
OrgId
:
cmd
.
OrgId
,
UserId
:
cmd
.
UserId
,
External
:
cmd
.
External
,
Dashboard
:
cmd
.
Dashboard
,
Expires
:
expires
,
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
}
_
,
err
:=
sess
.
Insert
(
snapshot
)
...
...
src/app/features/dashboard/shareSnapshotCtrl.js
View file @
541cd2e4
...
...
@@ -29,6 +29,9 @@ function (angular, _) {
{
text
:
'Public on the web'
,
value
:
3
},
];
$scope
.
externalUrl
=
'http://snapshots-origin.raintank.io'
;
$scope
.
apiUrl
=
'/api/snapshots'
;
$scope
.
createSnapshot
=
function
(
external
)
{
$scope
.
dashboard
.
snapshot
=
{
timestamp
:
new
Date
()
...
...
@@ -71,21 +74,18 @@ function (angular, _) {
var
cmdData
=
{
dashboard
:
dash
,
external
:
external
===
true
,
expires
:
$scope
.
snapshot
.
expires
,
};
var
apiUrl
=
'/api/snapshots/'
;
if
(
external
)
{
apiUrl
=
"http://snapshots-origin.raintank.io/api/snapshots"
;
}
var
postUrl
=
external
?
$scope
.
externalUrl
+
$scope
.
apiUrl
:
$scope
.
apiUrl
;
backendSrv
.
post
(
api
Url
,
cmdData
).
then
(
function
(
results
)
{
backendSrv
.
post
(
post
Url
,
cmdData
).
then
(
function
(
results
)
{
$scope
.
loading
=
false
;
if
(
external
)
{
$scope
.
deleteUrl
=
results
.
deleteUrl
;
$scope
.
snapshotUrl
=
results
.
url
;
$scope
.
saveExternalSnapshotRef
(
cmdData
,
results
);
}
else
{
var
baseUrl
=
$location
.
absUrl
().
replace
(
$location
.
url
(),
""
);
$scope
.
snapshotUrl
=
baseUrl
+
'/dashboard/snapshot/'
+
results
.
key
;
...
...
@@ -98,6 +98,14 @@ function (angular, _) {
});
};
$scope
.
saveExternalSnapshotRef
=
function
(
cmdData
,
results
)
{
// save external in local instance as well
cmdData
.
external
=
true
;
cmdData
.
key
=
results
.
key
;
cmdData
.
delete_key
=
results
.
delete_key
;
backendSrv
.
post
(
'/api/snapshots/'
,
cmdData
);
};
});
});
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