mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
merged with master
This commit is contained in:
parent
8a2541c220
commit
ee42ea5f3b
@ -1,9 +1,8 @@
|
||||
define([
|
||||
'angular',
|
||||
'lodash',
|
||||
'services/pro/backendSrv',
|
||||
],
|
||||
function (angular, _) {
|
||||
function (angular) {
|
||||
'use strict';
|
||||
|
||||
var module = angular.module('grafana.controllers');
|
||||
|
@ -10,7 +10,7 @@ function (angular, config, _, $, store) {
|
||||
|
||||
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.grafana = {};
|
||||
|
||||
@ -22,6 +22,9 @@ function (angular, config, _, $, store) {
|
||||
|
||||
if ($rootScope.profilingEnabled) { $scope.initProfiling(); }
|
||||
|
||||
alertSrv.init();
|
||||
utilSrv.init();
|
||||
|
||||
$scope.dashAlerts = alertSrv;
|
||||
$scope.grafana.style = 'dark';
|
||||
$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.grafana.sidemenu = !$scope.grafana.sidemenu;
|
||||
store.set('grafana.sidemenu', $scope.grafana.sidemenu);
|
||||
@ -51,7 +58,7 @@ function (angular, config, _, $, store) {
|
||||
this.$on('$destroy', unbind);
|
||||
};
|
||||
|
||||
$rootScope.emitAppEvent = function(name, payload) {
|
||||
$rootScope.appEvent = function(name, payload) {
|
||||
$rootScope.$emit(name, payload);
|
||||
};
|
||||
|
||||
|
@ -20,7 +20,7 @@ function (angular) {
|
||||
$http.post('/logout').then(function() {
|
||||
|
||||
alertSrv.set('Logged out!', '', 'success', 3000);
|
||||
$scope.emitAppEvent('logged-out');
|
||||
$scope.appEvent('logged-out');
|
||||
$location.search({});
|
||||
|
||||
}, function() {
|
||||
@ -36,7 +36,7 @@ function (angular) {
|
||||
}
|
||||
|
||||
$http.post('/login', $scope.loginModel).then(function(results) {
|
||||
$scope.emitAppEvent('logged-in', results.data.user);
|
||||
$scope.appEvent('logged-in', results.data.user);
|
||||
$location.path('/');
|
||||
}, function(err) {
|
||||
if (err.status === 401) {
|
||||
|
@ -23,6 +23,11 @@ function (angular, store) {
|
||||
templateUrl: '/app/partials/dashboard.html',
|
||||
controller : 'DashFromDBProvider',
|
||||
reloadOnSearch: false,
|
||||
})
|
||||
.when('/dashboard/import/:id', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromImportCtrl',
|
||||
reloadOnSearch: false,
|
||||
});
|
||||
});
|
||||
|
||||
@ -39,9 +44,10 @@ function (angular, store) {
|
||||
if (!savedRoute) {
|
||||
$http.get("app/dashboards/default.json?" + new Date().getTime()).then(function(result) {
|
||||
var dashboard = angular.fromJson(result.data);
|
||||
$scope.emitAppEvent('setup-dashboard', dashboard);
|
||||
},function() {
|
||||
alertSrv.set('Error',"Could not load default dashboard", 'error');
|
||||
$scope.initDashboard(dashboard, $scope);
|
||||
},function(err) {
|
||||
$scope.initDashboard({}, $scope);
|
||||
$scope.appEvent('alert-error', ['Load dashboard failed', err]);
|
||||
});
|
||||
return;
|
||||
}
|
||||
@ -53,12 +59,23 @@ function (angular, store) {
|
||||
|
||||
db.getDashboard($routeParams.id, isTemp)
|
||||
.then(function(dashboard) {
|
||||
$scope.emitAppEvent('setup-dashboard', dashboard);
|
||||
}).then(null, function(error) {
|
||||
alertSrv.set('Error', error, 'error');
|
||||
$scope.emitAppEvent('setup-dashboard', {});
|
||||
$scope.initDashboard(dashboard, $scope);
|
||||
}).then(null, function(err) {
|
||||
$scope.appEvent('alert-error', ['Load dashboard failed', err]);
|
||||
$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);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -42,6 +42,5 @@ function (angular, _) {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user