Commit 5f399112 by Torkel Ödegaard

refactoring progress

parent b995dc54
......@@ -49,23 +49,6 @@ function (angular, $, _, appLevelRequire, config) {
return module;
};
app.safeApply = function ($scope, fn) {
switch($scope.$$phase) {
case '$apply':
// $digest hasn't started, we should be good
$scope.$eval(fn);
break;
case '$digest':
// waiting to $apply the changes
setTimeout(function () { app.safeApply($scope, fn); }, 10);
break;
default:
// clear to begin an $apply $$phase
$scope.$apply(fn);
break;
}
};
app.config(function ($routeProvider, $controllerProvider, $compileProvider, $filterProvider, $provide) {
$routeProvider.otherwise({ redirectTo: config.default_route });
......@@ -97,12 +80,6 @@ function (angular, $, _, appLevelRequire, config) {
apps_deps.push(module_name);
});
app.panel_helpers = {
partial: function (name) {
return 'app/partials/'+name+'.html';
}
};
// load the core components
require([
'controllers/all',
......@@ -116,7 +93,6 @@ function (angular, $, _, appLevelRequire, config) {
angular
.element(document)
.ready(function() {
$('body').attr('ng-controller', 'DashCtrl');
angular.bootstrap(document, apps_deps)
.invoke(['$rootScope', function ($rootScope) {
_.each(pre_boot_modules, function (module) {
......
define([
'./grafanaCtrl',
'./dash',
'./dashLoader',
'./row',
......
......@@ -30,35 +30,15 @@ function (angular, $, config, _) {
var module = angular.module('kibana.controllers');
module.controller('DashCtrl', function(
$scope, $rootScope, $timeout, ejsResource, filterSrv, dashboardKeybindings,
alertSrv, keyboardManager, grafanaVersion) {
module.controller('DashCtrl', function($scope, $rootScope, dashboardKeybindings) {
$scope.editor = {
index: 0
};
$scope.grafanaVersion = grafanaVersion[0] === '@' ? 'master' : grafanaVersion;
$scope.editor = { index: 0 };
$scope.init = function() {
$scope.config = config;
// Make stuff, including underscore.js available to views
$scope._ = _;
$scope.dashAlerts = alertSrv;
// Clear existing alerts
alertSrv.clearAll();
$scope.reset_row();
$scope.ejs = ejsResource(config.elasticsearch, config.elasticsearchBasicAuth);
$scope.bindKeyboardShortcuts();
dashboardKeybindings.shortcuts();
};
$scope.bindKeyboardShortcuts = dashboardKeybindings.shortcuts;
$scope.isPanel = function(obj) {
if(!_.isNull(obj) && !_.isUndefined(obj) && !_.isUndefined(obj.type)) {
return true;
......
......@@ -96,7 +96,7 @@ function (angular, app, _) {
currentRow.panels.push(panel);
});
dashboard.dash_load(newDashboard);
$scope.dashboard.dash_load(newDashboard);
}
});
......
......@@ -9,14 +9,15 @@ function (angular, _, config, $) {
var module = angular.module('kibana.controllers');
module.controller('SearchCtrl', function($scope, $rootScope, dashboard, $element, $location) {
module.controller('SearchCtrl', function($scope, $rootScope, $element, $location, ejsResource) {
$scope.init = function() {
$scope.ejs = ejsResource(config.elasticsearch, config.elasticsearchBasicAuth);
$scope.giveSearchFocus = 0;
$scope.selectedIndex = -1;
$scope.results = {dashboards: [], tags: [], metrics: []};
$scope.query = { query: 'title:' };
$rootScope.$on('open-search', $scope.openSearch);
$scope.$onRootScope('open-search', $scope.openSearch, $scope);
};
$scope.keyDown = function (evt) {
......@@ -153,7 +154,7 @@ function (angular, _, config, $) {
};
$scope.addMetricToCurrentDashboard = function (metricId) {
dashboard.rows.push({
$scope.dashboard.rows.push({
title: '',
height: '250px',
editable: true,
......
......@@ -21,24 +21,22 @@ function (angular, $, config, _) {
$scope, $rootScope, $http, $routeParams, alertSrv, dashboard, filterSrv, panelMoveSrv) {
$scope.init = function() {
console.log('DashFromFileProvider->init()')
file_load($routeParams.jsonFile)
.then(function(data) {
$scope.dashboard = dashboard.create(data);
$scope.filter = filterSrv;
$scope.filter.init($scope.dashboard);
file_load($routeParams.jsonFile).then(function(data) {
$scope.dashboard = dashboard.create(data);
$scope.filter = filterSrv;
$scope.filter.init($scope.dashboard);
var panelMove = panelMoveSrv.create($scope.dashboard);
// For moving stuff around the dashboard.
$scope.panelMoveDrop = panelMove.onDrop;
$scope.panelMoveStart = panelMove.onStart;
$scope.panelMoveStop = panelMove.onStop;
$scope.panelMoveOver = panelMove.onOver;
$scope.panelMoveOut = panelMove.onOut;
var panelMove = panelMoveSrv.create($scope.dashboard);
// For moving stuff around the dashboard.
$scope.panelMoveDrop = panelMove.onDrop;
$scope.panelMoveStart = panelMove.onStart;
$scope.panelMoveStop = panelMove.onStop;
$scope.panelMoveOver = panelMove.onOver;
$scope.panelMoveOut = panelMove.onOut;
$rootScope.$emit("dashboard-loaded", $scope.dashboard);
});
$rootScope.$emit("dashboard-loaded", $scope.dashboard);
});
};
var renderTemplate = function(json,params) {
......
......@@ -13,7 +13,7 @@ function (angular, $, kbn, _) {
var module = angular.module('kibana.services');
module.service('dashboard', function(timer, $rootScope) {
module.service('dashboard', function(timer, $rootScope, $timeout) {
function DashboardModel (data) {
this.title = data.title;
......
......@@ -9,7 +9,15 @@ function(angular, $) {
var module = angular.module('kibana.services');
module.service('dashboardKeybindings', function($rootScope, keyboardManager, dashboard) {
this.hasRegistered = false;
this.shortcuts = function() {
if (this.hasRegistered) {
return;
}
this.hasRegistered = true;
$rootScope.$on('panel-fullscreen-enter', function() {
$rootScope.fullscreen = true;
});
......
......@@ -72,7 +72,7 @@ function (angular, _) {
create: function(dashboard) {
return new PanelMoveSrv(dashboard);
}
}
};
});
......
......@@ -12,16 +12,19 @@ function(angular, _, config) {
var module = angular.module('kibana.services');
module.service('unsavedChangesSrv', function($rootScope, $modal, dashboard, $q, $location, $timeout) {
module.service('unsavedChangesSrv', function($rootScope, $modal, $q, $location, $timeout) {
var self = this;
var modalScope = $rootScope.$new();
$rootScope.$on("dashboard-loaded", function(event, newDashboard) {
self.original = angular.copy(newDashboard);
self.current = newDashboard;
});
$rootScope.$on("dashboard-saved", function(event, savedDashboard) {
self.original = angular.copy(savedDashboard);
self.current = savedDashboard;
});
$rootScope.$on("$routeChangeSuccess", function() {
......@@ -63,7 +66,7 @@ function(angular, _, config) {
return false;
}
var current = angular.copy(dashboard.current);
var current = angular.copy(self.current);
var original = self.original;
// ignore timespan changes
......
......@@ -18,7 +18,7 @@
</head>
<body ng-cloak body-class>
<body ng-cloak body-class ng-controller="GrafanaCtrl">
<link rel="stylesheet" href="css/bootstrap.light.min.css" ng-if="dashboard.style === 'light'">
<link rel="stylesheet" href="css/bootstrap-responsive.min.css">
......
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