Commit b995dc54 by Torkel Ödegaard

further refactoring

parent 79404e75
......@@ -32,7 +32,7 @@ function (angular, $, config, _) {
module.controller('DashCtrl', function(
$scope, $rootScope, $timeout, ejsResource, filterSrv, dashboardKeybindings,
alertSrv, panelMove, keyboardManager, grafanaVersion) {
alertSrv, keyboardManager, grafanaVersion) {
$scope.editor = {
index: 0
......@@ -40,13 +40,6 @@ function (angular, $, config, _) {
$scope.grafanaVersion = grafanaVersion[0] === '@' ? 'master' : grafanaVersion;
// 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;
$scope.init = function() {
$scope.config = config;
......@@ -81,7 +74,7 @@ function (angular, $, config, _) {
$scope.add_row_default = function() {
$scope.reset_row();
$scope.row.title = 'New row';
$scope.add_row(dashboard.current, $scope.row);
$scope.add_row($scope.dashboard, $scope.row);
};
$scope.reset_row = function() {
......
......@@ -23,9 +23,6 @@ function (angular, _, moment) {
$scope.zoom(2);
});
$rootScope.$on('dashboard-loaded', function(event, dashboard) {
$scope.loader = dashboard.loader;
});
};
$scope.exitFullscreen = function() {
......@@ -33,11 +30,11 @@ function (angular, _, moment) {
};
$scope.showDropdown = function(type) {
if(_.isUndefined($scope.loader)) {
if(_.isUndefined($scope.dashboard)) {
return true;
}
var _l = $scope.loader;
var _l = $scope.dashboard.loader;
if(type === 'load') {
return (_l.load_elasticsearch || _l.load_gist || _l.load_local);
}
......@@ -51,7 +48,7 @@ function (angular, _, moment) {
};
$scope.set_default = function() {
if(dashboard.set_default($location.path())) {
if($scope.dashboard.set_default($location.path())) {
alertSrv.set('Home Set','This page has been set as your default dashboard','success',5000);
} else {
alertSrv.set('Incompatible Browser','Sorry, your browser is too old for this feature','error',5000);
......@@ -59,7 +56,7 @@ function (angular, _, moment) {
};
$scope.purge_default = function() {
if(dashboard.purge_default()) {
if($scope.dashboard.purge_default()) {
alertSrv.set('Local Default Clear','Your default dashboard has been reset to the default',
'success',5000);
} else {
......@@ -68,7 +65,7 @@ function (angular, _, moment) {
};
$scope.elasticsearch_save = function(type,ttl) {
dashboard.elasticsearch_save(type, dashboard.current.title, ttl)
$scope.dashboard.elasticsearch_save(type, $scope.dashboard.title, ttl)
.then(function(result) {
if(_.isUndefined(result._id)) {
alertSrv.set('Save failed','Dashboard could not be saved to Elasticsearch','error',5000);
......@@ -77,10 +74,10 @@ function (angular, _, moment) {
alertSrv.set('Dashboard Saved', 'Dashboard has been saved to Elasticsearch as "' + result._id + '"','success', 5000);
if(type === 'temp') {
$scope.share = dashboard.share_link(dashboard.current.title,'temp',result._id);
$scope.share = $scope.dashboard.share_link($scope.dashboard.title,'temp',result._id);
}
$rootScope.$emit('dashboard-saved', dashboard.current);
$rootScope.$emit('dashboard-saved', $scope.dashboard);
});
};
......@@ -89,7 +86,7 @@ function (angular, _, moment) {
return;
}
dashboard.elasticsearch_delete(id).then(
$scope.dashboard.elasticsearch_delete(id).then(
function(result) {
if(!_.isUndefined(result)) {
if(result.found) {
......@@ -108,7 +105,7 @@ function (angular, _, moment) {
};
$scope.save_gist = function() {
dashboard.save_gist($scope.gist.title).then(function(link) {
$scope.dashboard.save_gist($scope.gist.title).then(function(link) {
if (!_.isUndefined(link)) {
$scope.gist.last = link;
alertSrv.set('Gist saved','You will be able to access your exported dashboard file at '+
......@@ -120,7 +117,7 @@ function (angular, _, moment) {
};
$scope.gist_dblist = function(id) {
dashboard.gist_list(id).then(function(files) {
$scope.dashboard.gist_list(id).then(function(files) {
if (files && files.length > 0) {
$scope.gist.files = files;
} else {
......@@ -162,7 +159,7 @@ function (angular, _, moment) {
};
$scope.removeAsFavorite = function() {
playlistSrv.removeAsFavorite(dashboard.current);
playlistSrv.removeAsFavorite($scope.dashboard);
$scope.isFavorite = false;
};
......
......@@ -8,7 +8,7 @@ function (angular, app, _) {
var module = angular.module('kibana.controllers');
module.controller('GraphiteImportCtrl', function($scope, $rootScope, $timeout, datasourceSrv, dashboard) {
module.controller('GraphiteImportCtrl', function($scope, $rootScope, $timeout, datasourceSrv) {
$scope.init = function() {
console.log('hej!');
......@@ -68,7 +68,7 @@ function (angular, app, _) {
currentRow = angular.copy(rowTemplate);
var newDashboard = angular.copy(dashboard.current);
var newDashboard = angular.copy($scope.dashboard);
newDashboard.rows = [];
newDashboard.title = state.name;
newDashboard.rows.push(currentRow);
......
......@@ -86,7 +86,7 @@ function (angular, _, $) {
$timeout(function() {
if (oldTimeRange !== $scope.range) {
$scope.dashboard.refresh();
$scope.dashboard.emit_refresh();
}
else {
$scope.$emit('render');
......
......@@ -76,12 +76,12 @@ function (angular, app, _) {
$scope.delete_row = function() {
if (confirm("Are you sure you want to delete this row?")) {
$scope.dashboard.current.rows = _.without($scope.dashboard.current.rows, $scope.row);
$scope.dashboard.rows = _.without($scope.dashboard.rows, $scope.row);
}
};
$scope.move_row = function(direction) {
var rowsList = $scope.dashboard.current.rows;
var rowsList = $scope.dashboard.rows;
var rowIndex = _.indexOf(rowsList, $scope.row);
var newIndex = rowIndex + direction;
if (newIndex >= 0 && newIndex <= (rowsList.length - 1)) {
......@@ -116,12 +116,12 @@ function (angular, app, _) {
row.panels.push(angular.copy(panel));
}
else {
var rowsList = $scope.dashboard.current.rows;
var rowsList = $scope.dashboard.rows;
var rowIndex = _.indexOf(rowsList, row);
if (rowIndex === rowsList.length - 1) {
var newRow = angular.copy($scope.row);
newRow.panels = [];
$scope.dashboard.current.rows.push(newRow);
$scope.dashboard.rows.push(newRow);
$scope.duplicatePanel(panel, newRow);
}
else {
......
......@@ -153,7 +153,7 @@ function (angular, _, config, $) {
};
$scope.addMetricToCurrentDashboard = function (metricId) {
dashboard.current.rows.push({
dashboard.rows.push({
title: '',
height: '250px',
editable: true,
......
......@@ -43,7 +43,7 @@ function (angular, app, _) {
.then(function() {
// only refresh in the outermost call
if (!recursive) {
$scope.dashboard.refresh();
$scope.dashboard.emit_refresh();
}
});
};
......
......@@ -25,7 +25,7 @@
<span class="pointer" ng-show="panel.now">{{time.to.date | moment:'ago'}}</span>
</span>
<span ng-hide="filter.time">Time filter</span>
<span ng-show="dashboard.current.refresh" class="text-warning">refreshed every {{dashboard.current.refresh}} </span>
<span ng-show="dashboard.refresh" class="text-warning">refreshed every {{dashboard.refresh}} </span>
<i class="icon-caret-down"></i>
</a>
......@@ -47,8 +47,8 @@
</ul>
</li>
<li ng-show="!dashboard.current.refresh" class="grafana-menu-refresh">
<a class="icon-refresh" ng-click="dashboard.refresh()"></a>
<li ng-show="!dashboard.refresh" class="grafana-menu-refresh">
<a class="icon-refresh" ng-click="dashboard.emit_refresh()"></a>
</li>
</ul>
......
......@@ -16,7 +16,7 @@
</a>
</li>
<li ng-repeat="pulldown in dashboard.current.nav" ng-controller="PulldownCtrl" ng-show="pulldown.enable"><kibana-simple-panel type="pulldown.type" ng-cloak></kibana-simple-panel></li>
<li ng-repeat="pulldown in dashboard.nav" ng-controller="PulldownCtrl" ng-show="pulldown.enable"><kibana-simple-panel type="pulldown.type" ng-cloak></kibana-simple-panel></li>
<li class="dropdown grafana-menu-save" ng-show="showDropdown('save')">
<a href="#" bs-tooltip="'Save'" data-placement="bottom" class="dropdown-toggle" data-toggle="dropdown" ng-click="openSaveDropdown()">
......@@ -25,17 +25,17 @@
<ul class="save-dashboard-dropdown dropdown-menu">
<li ng-show="dashboard.current.loader.save_elasticsearch">
<li ng-show="dashboard.loader.save_elasticsearch">
<form class="input-prepend nomargin save-dashboard-dropdown-save-form">
<input class='input-medium' ng-model="dashboard.current.title" type="text" ng-model="elasticsearch.title"/>
<input class='input-medium' ng-model="dashboard.title" type="text" ng-model="elasticsearch.title"/>
<button class="btn" ng-click="elasticsearch_save('dashboard')"><i class="icon-save"></i></button>
</form>
</li>
<li ng-show="dashboard.current.loader.save_default">
<li ng-show="dashboard.loader.save_default">
<a class="link" ng-click="set_default()">Save as Home</a>
</li>
<li ng-show="dashboard.current.loader.save_default">
<li ng-show="dashboard.loader.save_default">
<a class="link" ng-click="purge_default()">Reset Home</a>
</li>
<li ng-show="!isFavorite">
......@@ -44,12 +44,12 @@
<li ng-show="isFavorite">
<a class="link" ng-click="removeAsFavorite()">Remove as favorite</a>
</li>
<li ng-show="dashboard.current.loader.save_local">
<li ng-show="dashboard.loader.save_local">
<a class="link" ng-click="dashboard.to_file()">Export dashboard</a>
</li>
<li ng-show="showDropdown('share')"><a bs-tooltip="'Share'" data-placement="bottom" ng-click="elasticsearch_save('temp',dashboard.current.loader.save_temp_ttl)" config-modal="app/partials/dashLoaderShare.html">Share temp copy</i></a></li>
<li ng-show="showDropdown('share')"><a bs-tooltip="'Share'" data-placement="bottom" ng-click="elasticsearch_save('temp',dashboard.loader.save_temp_ttl)" config-modal="app/partials/dashLoaderShare.html">Share temp copy</i></a></li>
<li ng-show="dashboard.current.loader.save_gist" style="margin:10px">
<li ng-show="dashboard.loader.save_gist" style="margin:10px">
<h6>Gist</h6>
<form class="input-append">
<input class='input-medium' placeholder='Title' type="text" ng-model="gist.title"/>
......@@ -68,7 +68,7 @@
<li class="grafana-menu-home"><a bs-tooltip="'Goto saved default'" data-placement="bottom" href='#/dashboard'><i class='icon-home'></i></a></li>
<li class="grafana-menu-edit" ng-show="dashboard.current.editable" bs-tooltip="'Configure dashboard'" data-placement="bottom"><a class="link" config-modal="app/partials/dasheditor.html"><i class='icon-cog pointer'></i></a></li>
<li class="grafana-menu-edit" ng-show="dashboard.editable" bs-tooltip="'Configure dashboard'" data-placement="bottom"><a class="link" config-modal="app/partials/dasheditor.html"><i class='icon-cog pointer'></i></a></li>
<li class="grafana-menu-stop-playlist hide">
<a class='small' ng-click='stopPlaylist(2)'>
......
......@@ -107,7 +107,7 @@
</div>
</div>
<div ng-show='dashboard.editable && dashboard.current.panel_hints' class="row-fluid add-row-panel-hint">
<div ng-show='dashboard.editable && dashboard.panel_hints' class="row-fluid add-row-panel-hint">
<div class="span12" style="text-align:right;">
<span style="margin-right: 10px;" ng-click="add_row_default()" class="pointer btn btn-info btn-mini">
<span><i class="icon-plus-sign"></i> ADD A ROW</span>
......
......@@ -92,7 +92,7 @@
</div>
</li>
<!-- ng-show="dashboard.current.loader.load_gist || dashboard.current.loader.load_local" -->
<!-- ng-show="dashboard.loader.load_gist || dashboard.loader.load_local" -->
<li ng-if="showImport" style="margin: 20px;">
<div class="editor-row">
<div class="section">
......@@ -105,7 +105,7 @@
</div>
</div>
<div class="editor-row" ng-show='dashboard.current.loader.load_gist'>
<div class="editor-row" ng-show='dashboard.loader.load_gist'>
<h5>Gist <tip>Enter a gist number or url</tip></h5>
<form>
<input type="text" ng-model="gist.url" placeholder="Gist number or URL"><br>
......
......@@ -17,7 +17,8 @@ function (angular, $, config, _) {
});
});
module.controller('DashFromFileProvider', function($scope, $rootScope, $http, $routeParams, alertSrv, dashboard, filterSrv) {
module.controller('DashFromFileProvider', function(
$scope, $rootScope, $http, $routeParams, alertSrv, dashboard, filterSrv, panelMoveSrv) {
$scope.init = function() {
console.log('DashFromFileProvider->init()')
......@@ -28,6 +29,14 @@ function (angular, $, config, _) {
$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;
$rootScope.$emit("dashboard-loaded", $scope.dashboard);
});
};
......
......@@ -9,6 +9,7 @@ define([
module.service('annotationsSrv', function(datasourceSrv, $q, alertSrv, $rootScope) {
var promiseCached;
var annotationPanel;
var list = [];
this.init = function() {
......@@ -21,7 +22,7 @@ define([
};
this.getAnnotations = function(filterSrv, rangeUnparsed, dashboard) {
var annotationPanel = _.findWhere(dashboard.pulldowns, { type: 'annotations' });
annotationPanel = _.findWhere(dashboard.pulldowns, { type: 'annotations' });
if (!annotationPanel.enable) {
return $q.when(null);
}
......
......@@ -63,7 +63,7 @@ function (angular, $, kbn, _) {
var p = DashboardModel.prototype;
p.refresh = function() {
p.emit_refresh = function() {
$rootScope.$broadcast('refresh');
};
......
......@@ -39,7 +39,7 @@ function(angular, $) {
}, { inputDisabled: true });
keyboardManager.bind('ctrl+r', function() {
dashboard.refresh();
dashboard.emit_refresh();
}, { inputDisabled: true });
keyboardManager.bind('ctrl+z', function(evt) {
......
......@@ -60,7 +60,7 @@ define([
this.old_refresh = null;
}
$timeout(this.dashboard.refresh, 0);
$timeout(this.dashboard.emit_refresh, 0);
},
timeRange: function(parse) {
......
......@@ -7,27 +7,33 @@ function (angular, _) {
var module = angular.module('kibana.services');
module.service('panelMove', function(dashboard, $rootScope) {
module.service('panelMoveSrv', function($rootScope) {
/* each of these can take event,ui,data parameters */
function PanelMoveSrv(dashboard) {
this.dashboard = dashboard;
_.bindAll(this, 'onStart', 'onOver', 'onOut', 'onDrop', 'onStop', 'cleanup');
}
this.onStart = function() {
dashboard.panelDragging = true;
var p = PanelMoveSrv.prototype;
/* each of these can take event,ui,data parameters */
p.onStart = function() {
this.dashboard.panelDragging = true;
$rootScope.$apply();
};
this.onOver = function() {
p.onOver = function() {
$rootScope.$apply();
};
this.onOut = function() {
p.onOut = function() {
$rootScope.$apply();
};
/*
Use our own drop logic. the $parent.$parent this is ugly.
*/
this.onDrop = function(event,ui,data) {
p.onDrop = function(event,ui,data) {
var
dragRow = data.draggableScope.$parent.$parent.row.panels,
dropRow = data.droppableScope.$parent.$parent.row.panels,
......@@ -42,26 +48,32 @@ function (angular, _) {
dropRow.splice(dropIndex,0,data.dragItem);
}
dashboard.panelDragging = false;
this.dashboard.panelDragging = false;
// Cleanup nulls/undefined left behind
cleanup();
this.cleanup();
$rootScope.$apply();
$rootScope.$broadcast('render');
};
this.onStop = function() {
dashboard.panelDragging = false;
cleanup();
p.onStop = function() {
this.dashboard.panelDragging = false;
this.cleanup();
$rootScope.$apply();
};
var cleanup = function () {
_.each(dashboard.current.rows, function(row) {
p.cleanup = function () {
_.each(this.dashboard.rows, function(row) {
row.panels = _.without(row.panels,{});
row.panels = _.compact(row.panels);
});
};
return {
create: function(dashboard) {
return new PanelMoveSrv(dashboard);
}
}
});
});
\ No newline at end of file
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