Commit 25316cbe by Torkel Ödegaard

Fixed broken feature: new dashboard button

parent a7a8ea30
......@@ -154,7 +154,8 @@ function (angular, _, config, $) {
};
$scope.newDashboard = function() {
$location.url('/dashboard/file/empty.json');
//$location.path('/dashboard/file/empty.json');
$location.url('dashboard/new');
};
});
......
......@@ -20,14 +20,14 @@ define([
controller : 'DashFromDBProvider',
reloadOnSearch: false,
})
.when('/dashboard/temp/:id', {
.when('/dashboard/import/:id', {
templateUrl: 'app/partials/dashboard.html',
controller : 'DashFromDBProvider',
controller : 'DashFromImportCtrl',
reloadOnSearch: false,
})
.when('/dashboard/import/:id', {
.when('/dashboard/new', {
templateUrl: 'app/partials/dashboard.html',
controller : 'DashFromImportCtrl',
controller : 'NewDashboardCtrl',
reloadOnSearch: false,
})
.when('/account', {
......
......@@ -48,18 +48,22 @@ function (angular, store) {
}).then(null, function() {
$scope.initDashboard({}, $scope);
});
});
module.controller('DashFromImportCtrl', function($scope, $location, alertSrv) {
if (!window.grafanaImportDashboard) {
alertSrv.set('Not found', 'Cannot reload page with unsaved imported dashboard', 'warning', 7000);
$location.path('');
return;
}
$scope.initDashboard(window.grafanaImportDashboard, $scope);
});
module.controller('NewDashboardCtrl', function($scope) {
$scope.initDashboard({
title: "New dashboard",
rows: [{ height: '250px', panels:[] }]
}, $scope);
});
});
......@@ -15,10 +15,16 @@ function (angular, $, config, _) {
templateUrl: 'app/partials/dashboard.html',
controller : 'DashFromFileProvider',
reloadOnSearch: false,
})
.when('/dashboard/new', {
templateUrl: 'app/partials/dashboard.html',
controller : 'DashFromFileProvider',
reloadOnSearch: false,
newDashboard: true,
});
});
module.controller('DashFromFileProvider', function($scope, $rootScope, $http, $routeParams, alertSrv) {
module.controller('DashFromFileProvider', function($scope, $rootScope, $http, $routeParams, $route) {
var renderTemplate = function(json,params) {
var _r;
......@@ -46,12 +52,17 @@ function (angular, $, config, _) {
}
return result.data;
},function() {
alertSrv.set('Error',"Could not load <i>dashboards/"+file+"</i>. Please make sure it exists" ,'error');
$scope.appEvent('alert-error', ["Dashboard load failed", "Could not load <i>dashboards/"+file+"</i>. Please make sure it exists"]);
return false;
});
};
file_load($routeParams.jsonFile).then(function(result) {
var fileToLoad = $routeParams.jsonFile;
if ($route.current.newDashboard) {
fileToLoad = 'empty.json';
}
file_load(fileToLoad).then(function(result) {
$scope.initDashboard(result, $scope);
});
......
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