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 @@