Commit 8cba5940 by Torkel Ödegaard

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

parents f2c9cc17 a1632e48
......@@ -12,12 +12,25 @@ function (angular, app, _) {
$scope.init = function() {
console.log('hej!');
$scope.datasources = datasourceSrv.listOptions();
$scope.setDatasource(null);
};
$scope.setDatasource = function(datasource) {
$scope.datasource = datasourceSrv.get(datasource);
if (!$scope.datasource) {
$scope.error = "Cannot find datasource " + datasource;
return;
}
};
$scope.listAll = function(query) {
delete $scope.error;
datasourceSrv.default.listDashboards(query)
$scope.datasource.listDashboards(query)
.then(function(results) {
$scope.dashboards = results;
})
......@@ -29,20 +42,20 @@ function (angular, app, _) {
$scope.import = function(dashName) {
delete $scope.error;
datasourceSrv.default.loadDashboard(dashName)
$scope.datasource.loadDashboard(dashName)
.then(function(results) {
if (!results.data || !results.data.state) {
throw { message: 'no dashboard state received from graphite' };
}
graphiteToGrafanaTranslator(results.data.state);
graphiteToGrafanaTranslator(results.data.state, $scope.datasource.name);
})
.then(null, function(err) {
$scope.error = err.message || 'Failed to import dashboard';
});
};
function graphiteToGrafanaTranslator(state) {
function graphiteToGrafanaTranslator(state, datasource) {
var graphsPerRow = 2;
var rowHeight = 300;
var rowTemplate;
......@@ -72,7 +85,8 @@ function (angular, app, _) {
type: 'graphite',
span: 12 / graphsPerRow,
title: graph[1].title,
targets: []
targets: [],
datasource: datasource
};
_.each(graph[1].target, function(target) {
......
<div ng-controller="GraphiteImportCtrl" ng-init="init()">
<div ng-controller="GraphiteImportCtrl" ng-init="init()" style="height: 400px">
<h5>Import dashboards from graphite web</h5>
<div class="editor-row">
<div class="section">
<div class="btn-group">
<button class="btn btn-info dropdown-toggle" data-toggle="dropdown" bs-tooltip="'Datasource'">{{datasource.name}} <span class="caret"></span></button>
<ul class="dropdown-menu" role="menu">
<li ng-repeat="datasource in datasources" role="menuitem">
<a ng-click="setDatasource(datasource.value);">{{datasource.name}}</a>
</li>
</ul>
</div>
<button ng-click="listAll()" class="btn btn-primary">List all dashboards</button>
</div>
</div>
......
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