Commit ed491b0c by Torkel Ödegaard

Merge branch 'master' of github.com:jordanrinke/grafana into jordanrinke-master

parents d6814587 48c18ee8
...@@ -9,3 +9,4 @@ config.js ...@@ -9,3 +9,4 @@ config.js
# Editor junk # Editor junk
*.sublime-workspace *.sublime-workspace
*.swp *.swp
.idea/
...@@ -137,7 +137,7 @@ ...@@ -137,7 +137,7 @@
"loader": { "loader": {
"save_temp": true, "save_temp": true,
"save_temp_ttl_enable": true, "save_temp_ttl_enable": true,
"save_temp_ttl": "30d", "save_temp_ttl": "30d"
}, },
"refresh": false "refresh": false
} }
...@@ -249,11 +249,58 @@ function (angular, _, kbn, InfluxSeries) { ...@@ -249,11 +249,58 @@ 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;
break;
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) { 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) { if (!results || !results.length) {
throw "Dashboard not found"; 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 dashCol = _.indexOf(results[0].columns, 'dashboard');
var dashJson = results[0].points[0][dashCol]; var dashJson = results[0].points[0][dashCol];
return angular.fromJson(dashJson); return angular.fromJson(dashJson);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment