diff --git a/src/app/controllers/panelBaseCtrl.js b/src/app/controllers/panelBaseCtrl.js new file mode 100644 index 00000000000..9df7528cd20 --- /dev/null +++ b/src/app/controllers/panelBaseCtrl.js @@ -0,0 +1,130 @@ +define([ + 'angular', + 'underscore', + 'jquery' +], +function (angular, _, $) { + 'use strict'; + + function PanelBaseCtrl($scope, $rootScope, $timeout) { + + var menu = [ + { + text: 'Edit', + configModal: "app/partials/paneleditor.html", + condition: !$scope.panelMeta.fullscreenEdit + }, + { + text: 'Edit', + click: "toggleFullscreenEdit()", + condition: $scope.panelMeta.fullscreenEdit + }, + { + text: "Fullscreen", + click: 'toggleFullscreen()', + condition: $scope.panelMeta.fullscreenView + }, + { + text: 'Duplicate', + click: 'duplicatePanel(panel)', + condition: true + }, + { + text: 'Span', + submenu: [ + { text: '1', click: 'updateColumnSpan(1)' }, + { text: '2', click: 'updateColumnSpan(2)' }, + { text: '3', click: 'updateColumnSpan(3)' }, + { text: '4', click: 'updateColumnSpan(4)' }, + { text: '5', click: 'updateColumnSpan(5)' }, + { text: '6', click: 'updateColumnSpan(6)' }, + { text: '7', click: 'updateColumnSpan(7)' }, + { text: '8', click: 'updateColumnSpan(8)' }, + { text: '9', click: 'updateColumnSpan(9)' }, + { text: '10', click: 'updateColumnSpan(10)' }, + { text: '11', click: 'updateColumnSpan(11)' }, + { text: '12', click: 'updateColumnSpan(12)' }, + ], + condition: true + }, + { + text: 'Remove', + click: 'remove_panel_from_row(row, panel)', + condition: true + } + ]; + + $scope.inspector = {}; + $scope.panelMeta.menu = _.where(menu, { condition: true }); + + $scope.updateColumnSpan = function(span) { + $scope.panel.span = span; + + $timeout(function() { + $scope.$emit('render'); + }); + }; + + $scope.enterFullscreenMode = function(options) { + var docHeight = $(window).height(); + var editHeight = Math.floor(docHeight * 0.3); + var fullscreenHeight = Math.floor(docHeight * 0.7); + var oldTimeRange = $scope.range; + + $scope.height = options.edit ? editHeight : fullscreenHeight; + $scope.editMode = options.edit; + + if (!$scope.fullscreen) { + var closeEditMode = $rootScope.$on('panel-fullscreen-exit', function() { + $scope.editMode = false; + $scope.fullscreen = false; + delete $scope.height; + + closeEditMode(); + + $timeout(function() { + if (oldTimeRange !== $scope.range) { + $scope.dashboard.refresh(); + } + else { + $scope.$emit('render'); + } + }); + }); + } + + $(window).scrollTop(0); + + $scope.fullscreen = true; + + $rootScope.$emit('panel-fullscreen-enter'); + + $timeout(function() { + $scope.$emit('render'); + }); + + }; + + $scope.toggleFullscreenEdit = function() { + if ($scope.editMode) { + $rootScope.$emit('panel-fullscreen-exit'); + return; + } + + $scope.enterFullscreenMode({edit: true}); + }; + + $scope.toggleFullscreen = function() { + if ($scope.fullscreen && !$scope.editMode) { + $rootScope.$emit('panel-fullscreen-exit'); + return; + } + + $scope.enterFullscreenMode({ edit: false }); + }; + + } + + return PanelBaseCtrl; + +}); \ No newline at end of file diff --git a/src/app/directives/grafanaGraph.js b/src/app/directives/grafanaGraph.js index 8aa9ea9a531..b5130cb3b87 100644 --- a/src/app/directives/grafanaGraph.js +++ b/src/app/directives/grafanaGraph.js @@ -46,10 +46,14 @@ function (angular, $, kbn, moment, _) { function setElementHeight() { try { var height = scope.height || scope.panel.height || scope.row.height; - height = height.replace('px', '') - 32; // subtract panel title bar + if (_.isString(height)) { + height = parseInt(height.replace('px', ''), 10); + } + + height = height - 32; // subtract panel title bar if (scope.panel.legend.show) { - height = height - 35; // subtract one line legend + height = height - 21; // subtract one line legend } elem.css('height', height + 'px'); @@ -64,6 +68,7 @@ function (angular, $, kbn, moment, _) { if (!data) { return true; } + if ($rootScope.fullscreen && !scope.fullscreen) { return true; } diff --git a/src/app/directives/kibanaPanel.js b/src/app/directives/kibanaPanel.js index 429a83803b2..6cf1ebbeb4c 100644 --- a/src/app/directives/kibanaPanel.js +++ b/src/app/directives/kibanaPanel.js @@ -1,14 +1,15 @@ define([ 'angular', 'jquery', - 'underscore' + 'underscore', + '../controllers/PanelBaseCtrl' ], -function (angular, $, _) { +function (angular, $, _, PanelBaseCtrl) { 'use strict'; angular .module('kibana.directives') - .directive('kibanaPanel', function($compile, $timeout, $rootScope) { + .directive('kibanaPanel', function($compile, $timeout, $rootScope, $injector) { var container = '
'; var content = ''; @@ -23,7 +24,7 @@ function (angular, $, _) { '' + '\n' + - '