mirror of
https://github.com/grafana/grafana.git
synced 2024-11-21 16:38:03 -06:00
added saving and showing temp searches also trailing comman in default.json was causing the default to fail to load for me, #633
This commit is contained in:
parent
67582aaee4
commit
f958924b79
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@ config.js
|
||||
# Editor junk
|
||||
*.sublime-workspace
|
||||
*.swp
|
||||
.idea/
|
||||
|
@ -137,7 +137,7 @@
|
||||
"loader": {
|
||||
"save_temp": true,
|
||||
"save_temp_ttl_enable": true,
|
||||
"save_temp_ttl": "30d",
|
||||
"save_temp_ttl": "30d"
|
||||
},
|
||||
"refresh": false
|
||||
}
|
||||
|
@ -249,11 +249,57 @@ function (angular, _, kbn, InfluxSeries) {
|
||||
});
|
||||
};
|
||||
|
||||
InfluxDatasource.prototype.saveDashboardTemp = function(dashboard, title) {
|
||||
var dashboardClone = angular.copy(dashboard);
|
||||
var tags = dashboardClone.tags.join(',');
|
||||
title = dashboardClone.title = title ? title : dashboard.title;
|
||||
var ttl = dashboard.loader.save_temp_ttl
|
||||
var ttlLength = ttl.substring(0, ttl.length-1);
|
||||
var ttlTerm = ttl.substring(ttl.length-1, ttl.length).toLowerCase();
|
||||
var expires = Date.now();
|
||||
switch(ttlTerm) {
|
||||
case "m":
|
||||
expires += ttlLength * 60000;
|
||||
break;
|
||||
case "d":
|
||||
expires += ttlLength * 86400000;
|
||||
break;
|
||||
case "w":
|
||||
expires += ttlLength * 604800000;
|
||||
default:
|
||||
throw "Unknown ttl duration format";
|
||||
}
|
||||
|
||||
var data = [{
|
||||
name: 'grafana.dashboard_' + btoa(title),
|
||||
columns: ['time', 'sequence_number', 'title', 'tags', 'dashboard', 'expires'],
|
||||
points: [[1, 1, title, tags, angular.toJson(dashboardClone), expires]]
|
||||
}];
|
||||
|
||||
return this._influxRequest('POST', '/series', data).then(function() {
|
||||
var baseUrl = window.location.href.replace(window.location.hash,'');
|
||||
var url = baseUrl + "#dashboard/temp/" + title;
|
||||
return { title: title, url: url };
|
||||
}, function(err) {
|
||||
throw 'Failed to save shared dashboard to InfluxDB: ' + err.data;
|
||||
});
|
||||
};
|
||||
InfluxDatasource.prototype.getDashboard = function(id) {
|
||||
return this._seriesQuery('select dashboard from "grafana.dashboard_' + btoa(id) + '"').then(function(results) {
|
||||
var queryString = 'select dashboard from "grafana.dashboard_' + btoa(id) + '"';
|
||||
// hack to check if it is a temp dashboard
|
||||
if (window.location.href.indexOf('dashboard/temp') > 0) {
|
||||
var isTemp = true;
|
||||
queryString = 'select dashboard, expires from "grafana.dashboard_' + btoa(id) + '"';
|
||||
}
|
||||
return this._seriesQuery(queryString).then(function(results) {
|
||||
if (!results || !results.length) {
|
||||
throw "Dashboard not found";
|
||||
}
|
||||
var expiresCol = _.indexOf(results[0].columns, 'expires');
|
||||
var expiresTime = results[0].points[0][expiresCol];
|
||||
if (Date.now() > expiresTime && isTemp) {
|
||||
throw "Dashboard has expired";
|
||||
}
|
||||
var dashCol = _.indexOf(results[0].columns, 'dashboard');
|
||||
var dashJson = results[0].points[0][dashCol];
|
||||
return angular.fromJson(dashJson);
|
||||
|
Loading…
Reference in New Issue
Block a user