merged with master

This commit is contained in:
Torkel Ödegaard 2014-10-01 09:47:32 +02:00
parent 8a2541c220
commit ee42ea5f3b
5 changed files with 36 additions and 14 deletions

View File

@ -1,9 +1,8 @@
define([ define([
'angular', 'angular',
'lodash',
'services/pro/backendSrv', 'services/pro/backendSrv',
], ],
function (angular, _) { function (angular) {
'use strict'; 'use strict';
var module = angular.module('grafana.controllers'); var module = angular.module('grafana.controllers');

View File

@ -10,7 +10,7 @@ function (angular, config, _, $, store) {
var module = angular.module('grafana.controllers'); var module = angular.module('grafana.controllers');
module.controller('GrafanaCtrl', function($scope, alertSrv, grafanaVersion, $rootScope) { module.controller('GrafanaCtrl', function($scope, alertSrv, utilSrv, grafanaVersion, $rootScope, $controller) {
$scope.grafanaVersion = grafanaVersion[0] === '@' ? 'master' : grafanaVersion; $scope.grafanaVersion = grafanaVersion[0] === '@' ? 'master' : grafanaVersion;
$scope.grafana = {}; $scope.grafana = {};
@ -22,6 +22,9 @@ function (angular, config, _, $, store) {
if ($rootScope.profilingEnabled) { $scope.initProfiling(); } if ($rootScope.profilingEnabled) { $scope.initProfiling(); }
alertSrv.init();
utilSrv.init();
$scope.dashAlerts = alertSrv; $scope.dashAlerts = alertSrv;
$scope.grafana.style = 'dark'; $scope.grafana.style = 'dark';
$scope.grafana.sidemenu = store.getBool('grafana.sidemenu'); $scope.grafana.sidemenu = store.getBool('grafana.sidemenu');
@ -41,6 +44,10 @@ function (angular, config, _, $, store) {
}); });
}; };
$scope.initDashboard = function(dashboardData, viewScope) {
$controller('DashboardCtrl', { $scope: viewScope }).init(dashboardData);
};
$scope.toggleProSideMenu = function() { $scope.toggleProSideMenu = function() {
$scope.grafana.sidemenu = !$scope.grafana.sidemenu; $scope.grafana.sidemenu = !$scope.grafana.sidemenu;
store.set('grafana.sidemenu', $scope.grafana.sidemenu); store.set('grafana.sidemenu', $scope.grafana.sidemenu);
@ -51,7 +58,7 @@ function (angular, config, _, $, store) {
this.$on('$destroy', unbind); this.$on('$destroy', unbind);
}; };
$rootScope.emitAppEvent = function(name, payload) { $rootScope.appEvent = function(name, payload) {
$rootScope.$emit(name, payload); $rootScope.$emit(name, payload);
}; };

View File

@ -20,7 +20,7 @@ function (angular) {
$http.post('/logout').then(function() { $http.post('/logout').then(function() {
alertSrv.set('Logged out!', '', 'success', 3000); alertSrv.set('Logged out!', '', 'success', 3000);
$scope.emitAppEvent('logged-out'); $scope.appEvent('logged-out');
$location.search({}); $location.search({});
}, function() { }, function() {
@ -36,7 +36,7 @@ function (angular) {
} }
$http.post('/login', $scope.loginModel).then(function(results) { $http.post('/login', $scope.loginModel).then(function(results) {
$scope.emitAppEvent('logged-in', results.data.user); $scope.appEvent('logged-in', results.data.user);
$location.path('/'); $location.path('/');
}, function(err) { }, function(err) {
if (err.status === 401) { if (err.status === 401) {

View File

@ -23,6 +23,11 @@ function (angular, store) {
templateUrl: '/app/partials/dashboard.html', templateUrl: '/app/partials/dashboard.html',
controller : 'DashFromDBProvider', controller : 'DashFromDBProvider',
reloadOnSearch: false, reloadOnSearch: false,
})
.when('/dashboard/import/:id', {
templateUrl: 'app/partials/dashboard.html',
controller : 'DashFromImportCtrl',
reloadOnSearch: false,
}); });
}); });
@ -39,9 +44,10 @@ function (angular, store) {
if (!savedRoute) { if (!savedRoute) {
$http.get("app/dashboards/default.json?" + new Date().getTime()).then(function(result) { $http.get("app/dashboards/default.json?" + new Date().getTime()).then(function(result) {
var dashboard = angular.fromJson(result.data); var dashboard = angular.fromJson(result.data);
$scope.emitAppEvent('setup-dashboard', dashboard); $scope.initDashboard(dashboard, $scope);
},function() { },function(err) {
alertSrv.set('Error',"Could not load default dashboard", 'error'); $scope.initDashboard({}, $scope);
$scope.appEvent('alert-error', ['Load dashboard failed', err]);
}); });
return; return;
} }
@ -53,12 +59,23 @@ function (angular, store) {
db.getDashboard($routeParams.id, isTemp) db.getDashboard($routeParams.id, isTemp)
.then(function(dashboard) { .then(function(dashboard) {
$scope.emitAppEvent('setup-dashboard', dashboard); $scope.initDashboard(dashboard, $scope);
}).then(null, function(error) { }).then(null, function(err) {
alertSrv.set('Error', error, 'error'); $scope.appEvent('alert-error', ['Load dashboard failed', err]);
$scope.emitAppEvent('setup-dashboard', {}); $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);
});
}); });

View File

@ -42,6 +42,5 @@ function (angular, _) {
}); });
}; };
}); });
}); });