mirror of https://github.com/grafana/grafana
parent
a0036179d5
commit
1c5f902770
@ -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(); |
||||
|
||||
}); |
||||
}); |
@ -0,0 +1,59 @@ |
||||
<div ng-include="'app/partials/navbar.html'" ng-init="pageTitle='Import'"></div> |
||||
|
||||
<div class="dashboard-edit-view" style="min-height: 500px"> |
||||
|
||||
<div class="dashboard-editor-header"> |
||||
<div class="dashboard-editor-title"> |
||||
<i class="fa fa-th-large"></i> |
||||
Import Dashboards |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="dashboard-editor-body"> |
||||
|
||||
<div class="editor-row"> |
||||
<div class="section"> |
||||
<div class="tight-form"> |
||||
<ul class="tight-form-list"> |
||||
<li class="tight-form-item" style="width: 160px"> |
||||
<strong>Dashboard source</strong> |
||||
</li> |
||||
<li> |
||||
<select type="text" ng-model="sourceName" class="input-small tight-form-input" ng-options="f for f in datasources"> |
||||
</select> |
||||
</li> |
||||
<li class="tight-form-item" style="width: 160px"> |
||||
<strong>Destination</strong> |
||||
</li> |
||||
<li> |
||||
<select type="text" ng-model="destName" class="input-small tight-form-input" ng-options="f for f in datasources"> |
||||
</select> |
||||
</li> |
||||
<li> |
||||
<button class="btn btn-success tight-form-btn" ng-click="startImport()">Import</button> |
||||
</li> |
||||
</ul> |
||||
<div class="clearfix"></div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="editor-row" ng-if="importing"> |
||||
<section class="section"> |
||||
<h5>{{infoText}}</h5> |
||||
|
||||
<div class="editor-row row"> |
||||
<table class="grafana-options-table span5"> |
||||
<tr ng-repeat="dash in imported"> |
||||
<td>{{dash.name}}</td> |
||||
<td> |
||||
{{dash.info}} |
||||
</td> |
||||
</tr> |
||||
</table> |
||||
</div> |
||||
</section> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
@ -1,37 +1,39 @@ |
||||
<div ng-include="'app/partials/navbar.html'" ng-init="pageTitle='Accounts'"></div> |
||||
<div ng-include="'app/partials/navbar.html'" ng-init="pageTitle='Admin > Accounts'"></div> |
||||
|
||||
<div class="dashboard-edit-view" style="min-height: 500px"> |
||||
|
||||
<div class="row-fluid"> |
||||
<div class="span8"> |
||||
<div class="dashboard-editor-body"> |
||||
|
||||
<table class="grafana-options-table"> |
||||
<tr> |
||||
<th style="text-align:left">Id</th> |
||||
<th>Login</th> |
||||
<th>Email</th> |
||||
<th>Name</th> |
||||
<th>Admin</th> |
||||
<th></th> |
||||
</tr> |
||||
<tr ng-repeat="account in accounts"> |
||||
<td>{{account.id}}</td> |
||||
<td>{{account.login}}</td> |
||||
<td>{{account.email}}</td> |
||||
<td>{{account.name}}</td> |
||||
<td>{{account.isAdmin}}</td> |
||||
<td style="width: 1%"> |
||||
<a ng-click="edit(variable)" class="btn btn-success"> |
||||
<i class="fa fa-edit"></i> |
||||
Edit |
||||
</a> |
||||
|
||||
<a ng-click="edit(variable)" class="btn btn-danger"> |
||||
<i class="fa fa-remove"></i> |
||||
</a> |
||||
</td> |
||||
</tr> |
||||
</table> |
||||
<div class="editor-row row"> |
||||
<div class="section span6"> |
||||
<table class="grafana-options-table"> |
||||
<tr> |
||||
<th style="text-align:left">Id</th> |
||||
<th>Login</th> |
||||
<th>Email</th> |
||||
<th>Name</th> |
||||
<th>Admin</th> |
||||
<th></th> |
||||
</tr> |
||||
<tr ng-repeat="account in accounts"> |
||||
<td>{{account.id}}</td> |
||||
<td>{{account.login}}</td> |
||||
<td>{{account.email}}</td> |
||||
<td>{{account.name}}</td> |
||||
<td>{{account.isAdmin}}</td> |
||||
<td style="width: 1%"> |
||||
<a ng-click="edit(variable)" class="btn btn-success btn-small"> |
||||
<i class="fa fa-edit"></i> |
||||
Edit |
||||
</a> |
||||
|
||||
<a ng-click="edit(variable)" class="btn btn-danger btn-small"> |
||||
<i class="fa fa-remove"></i> |
||||
</a> |
||||
</td> |
||||
</tr> |
||||
</table> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
Loading…
Reference in new issue