From 1c5f902770c260f9bc63a0f07f1e9d22f60ce796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Sat, 17 Jan 2015 10:39:01 +0100 Subject: [PATCH] Added dashboard import feature --- src/app/features/account/datasourcesCtrl.js | 7 ++ src/app/features/account/importCtrl.js | 78 +++++++++++++++++++ .../account/partials/collaborators.html | 10 +-- .../account/partials/datasources.html | 11 ++- src/app/features/account/partials/import.html | 59 ++++++++++++++ src/app/features/admin/partials/accounts.html | 62 ++++++++------- src/app/features/all.js | 1 + .../features/annotations/partials/editor.html | 4 +- src/app/features/elasticsearch/datasource.js | 2 +- src/app/features/influxdb/datasource.js | 2 +- src/app/partials/sidemenu.html | 4 + src/app/routes/backend/all.js | 4 + src/app/services/datasourceSrv.js | 4 + 13 files changed, 208 insertions(+), 40 deletions(-) create mode 100644 src/app/features/account/importCtrl.js create mode 100644 src/app/features/account/partials/import.html diff --git a/src/app/features/account/datasourcesCtrl.js b/src/app/features/account/datasourcesCtrl.js index 983c74b4b9e..b8f9f9fda7a 100644 --- a/src/app/features/account/datasourcesCtrl.js +++ b/src/app/features/account/datasourcesCtrl.js @@ -15,6 +15,13 @@ function (angular) { access: 'proxy' }; + $scope.types = [ + { name: 'Graphite', type: 'graphite' }, + { name: 'InfluxDB', type: 'influxdb' }, + { name: 'Elasticsearch', type: 'elasticsearch' }, + { name: 'OpenTSDB', type: 'opentsdb' }, + ]; + $scope.init = function() { $scope.reset(); $scope.editor = {index: 0}; diff --git a/src/app/features/account/importCtrl.js b/src/app/features/account/importCtrl.js new file mode 100644 index 00000000000..a8548491c60 --- /dev/null +++ b/src/app/features/account/importCtrl.js @@ -0,0 +1,78 @@ +define([ + 'angular', + 'lodash', +], +function (angular, _) { + 'use strict'; + + var module = angular.module('grafana.controllers'); + + module.controller('ImportCtrl', function($scope, $http, backendSrv, datasourceSrv) { + + $scope.init = function() { + $scope.datasources = []; + $scope.sourceName = 'grafana'; + $scope.destName = 'grafana'; + $scope.imported = []; + $scope.dashboards = []; + $scope.infoText = ''; + $scope.importing = false; + + _.each(datasourceSrv.getAll(), function(ds) { + if (ds.type === 'influxdb' || ds.type === 'elasticsearch') { + $scope.sourceName = ds.name; + $scope.datasources.push(ds.name); + } else if (ds.type === 'grafana') { + $scope.datasources.push(ds.name); + } + }); + }; + + $scope.startImport = function() { + $scope.sourceDs = datasourceSrv.get($scope.sourceName); + $scope.destDs = datasourceSrv.get($scope.destName); + + $scope.sourceDs.searchDashboards('title:').then(function(results) { + $scope.dashboards = results.dashboards; + + if ($scope.dashboards.length === 0) { + $scope.infoText = 'No dashboards found'; + return; + } + + $scope.importing = true; + $scope.imported = []; + $scope.next(); + }); + }; + + $scope.next = function() { + if ($scope.dashboards.length === 0) { + $scope.infoText = "Done! Imported " + $scope.imported.length + " dashboards"; + } + + var dash = $scope.dashboards.shift(); + if (!dash.title) { + console.log(dash); + return; + } + + var infoObj = {name: dash.title, info: 'Importing...'}; + $scope.imported.push(infoObj); + $scope.infoText = "Importing " + $scope.imported.length + '/' + ($scope.imported.length + $scope.dashboards.length); + + $scope.sourceDs.getDashboard(dash.id).then(function(loadedDash) { + $scope.destDs.saveDashboard(loadedDash).then(function() { + infoObj.info = "Done!"; + $scope.next(); + }, function(err) { + infoObj.info = "Error: " + err; + $scope.next(); + }); + }); + }; + + $scope.init(); + + }); +}); diff --git a/src/app/features/account/partials/collaborators.html b/src/app/features/account/partials/collaborators.html index e66a55d0766..4d3f581c069 100644 --- a/src/app/features/account/partials/collaborators.html +++ b/src/app/features/account/partials/collaborators.html @@ -17,20 +17,20 @@
diff --git a/src/app/features/account/partials/datasources.html b/src/app/features/account/partials/datasources.html index 86264721cbe..4f5f2399d98 100644 --- a/src/app/features/account/partials/datasources.html +++ b/src/app/features/account/partials/datasources.html @@ -70,7 +70,7 @@
- +
@@ -103,6 +103,15 @@ +
+
+
Elastic search details
+
+ + +
+
+