mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard: show error when importing dashboard json file with broken/incorrect json syntax, Closes #878
This commit is contained in:
parent
7ad18da08e
commit
1c7b898b01
@ -16,7 +16,13 @@ function (angular, kbn) {
|
|||||||
var readerOnload = function() {
|
var readerOnload = function() {
|
||||||
return function(e) {
|
return function(e) {
|
||||||
scope.$apply(function() {
|
scope.$apply(function() {
|
||||||
window.grafanaImportDashboard = JSON.parse(e.target.result);
|
try {
|
||||||
|
window.grafanaImportDashboard = JSON.parse(e.target.result);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
scope.appEvent('alert-error', ['Import failed', 'JSON -> JS Serialization failed: ' + err.message]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
var title = kbn.slugifyForUrl(window.grafanaImportDashboard.title);
|
var title = kbn.slugifyForUrl(window.grafanaImportDashboard.title);
|
||||||
$location.path('/dashboard/import/' + title);
|
$location.path('/dashboard/import/' + title);
|
||||||
});
|
});
|
||||||
|
@ -31,7 +31,7 @@ function (angular) {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.controller('DashFromDBProvider', function($scope, $rootScope, datasourceSrv, $routeParams, alertSrv) {
|
module.controller('DashFromDBProvider', function($scope, $rootScope, datasourceSrv, $routeParams) {
|
||||||
|
|
||||||
var db = datasourceSrv.getGrafanaDB();
|
var db = datasourceSrv.getGrafanaDB();
|
||||||
var isTemp = window.location.href.indexOf('dashboard/temp') !== -1;
|
var isTemp = window.location.href.indexOf('dashboard/temp') !== -1;
|
||||||
@ -41,14 +41,14 @@ function (angular) {
|
|||||||
$scope.initDashboard(dashboard, $scope);
|
$scope.initDashboard(dashboard, $scope);
|
||||||
}).then(null, function(error) {
|
}).then(null, function(error) {
|
||||||
$scope.initDashboard({ title: 'Grafana'}, $scope);
|
$scope.initDashboard({ title: 'Grafana'}, $scope);
|
||||||
alertSrv.set('Error', error, 'error');
|
$scope.appEvent('alert-error', ['Dashboard load failed', error]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
module.controller('DashFromImportCtrl', function($scope, $location, alertSrv) {
|
module.controller('DashFromImportCtrl', function($scope, $location) {
|
||||||
|
|
||||||
if (!window.grafanaImportDashboard) {
|
if (!window.grafanaImportDashboard) {
|
||||||
alertSrv.set('Not found', 'Cannot reload page with unsaved imported dashboard', 'warning', 7000);
|
$scope.appEvent('alert-warning', ['Dashboard load failed', 'Cannot reload unsaved imported dashboard']);
|
||||||
$location.path('');
|
$location.path('');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user