2013-09-13 15:52:13 -05:00
|
|
|
define([
|
|
|
|
'angular',
|
|
|
|
'app',
|
2014-08-07 07:35:19 -05:00
|
|
|
'lodash'
|
2013-09-13 15:52:13 -05:00
|
|
|
],
|
|
|
|
function (angular, app, _) {
|
|
|
|
'use strict';
|
|
|
|
|
2014-07-28 11:11:52 -05:00
|
|
|
var module = angular.module('grafana.controllers');
|
2013-09-13 15:52:13 -05:00
|
|
|
|
2013-12-27 07:50:08 -06:00
|
|
|
module.controller('RowCtrl', function($scope, $rootScope, $timeout) {
|
2014-02-28 01:02:20 -06:00
|
|
|
var _d = {
|
|
|
|
title: "Row",
|
|
|
|
height: "150px",
|
|
|
|
collapse: false,
|
2014-09-24 03:51:20 -05:00
|
|
|
editable: true,
|
2014-02-28 01:02:20 -06:00
|
|
|
panels: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
_.defaults($scope.row,_d);
|
|
|
|
|
|
|
|
$scope.init = function() {
|
|
|
|
$scope.reset_panel();
|
|
|
|
};
|
|
|
|
|
2014-09-23 03:52:31 -05:00
|
|
|
$scope.togglePanelMenu = function(posX) {
|
|
|
|
$scope.showPanelMenu = !$scope.showPanelMenu;
|
|
|
|
$scope.panelMenuPos = posX;
|
|
|
|
};
|
|
|
|
|
2014-02-28 01:02:20 -06:00
|
|
|
$scope.toggle_row = function(row) {
|
|
|
|
row.collapse = row.collapse ? false : true;
|
|
|
|
if (!row.collapse) {
|
|
|
|
$timeout(function() {
|
|
|
|
$scope.$broadcast('render');
|
2013-09-26 17:42:43 -05:00
|
|
|
});
|
2014-02-28 01:02:20 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-15 03:26:41 -05:00
|
|
|
// This can be overridden by individual panels
|
2014-02-28 01:02:20 -06:00
|
|
|
$scope.close_edit = function() {
|
|
|
|
$scope.$broadcast('render');
|
|
|
|
};
|
|
|
|
|
2014-06-06 11:30:15 -05:00
|
|
|
$scope.add_panel = function(panel) {
|
2014-08-13 09:35:34 -05:00
|
|
|
$scope.dashboard.add_panel(panel, $scope.row);
|
2014-02-28 01:02:20 -06:00
|
|
|
};
|
|
|
|
|
2014-06-06 11:30:15 -05:00
|
|
|
$scope.delete_row = function() {
|
|
|
|
if (confirm("Are you sure you want to delete this row?")) {
|
2014-06-07 14:00:05 -05:00
|
|
|
$scope.dashboard.rows = _.without($scope.dashboard.rows, $scope.row);
|
2014-06-06 11:30:15 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.move_row = function(direction) {
|
2014-06-07 14:00:05 -05:00
|
|
|
var rowsList = $scope.dashboard.rows;
|
2014-06-06 11:30:15 -05:00
|
|
|
var rowIndex = _.indexOf(rowsList, $scope.row);
|
|
|
|
var newIndex = rowIndex + direction;
|
|
|
|
if (newIndex >= 0 && newIndex <= (rowsList.length - 1)) {
|
|
|
|
_.move(rowsList, rowIndex, rowIndex + direction);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.add_panel_default = function(type) {
|
|
|
|
$scope.reset_panel(type);
|
|
|
|
$scope.add_panel($scope.panel);
|
|
|
|
|
|
|
|
$timeout(function() {
|
|
|
|
$scope.$broadcast('render');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.set_height = function(height) {
|
|
|
|
$scope.row.height = height;
|
|
|
|
$scope.$broadcast('render');
|
|
|
|
};
|
|
|
|
|
2014-02-28 01:02:20 -06:00
|
|
|
$scope.remove_panel_from_row = function(row, panel) {
|
2014-11-10 03:40:45 -06:00
|
|
|
$scope.appEvent('confirm-modal', {
|
|
|
|
title: 'Are you sure you want to remove this panel?',
|
|
|
|
onConfirm: function() {
|
|
|
|
row.panels = _.without(row.panels, panel);
|
|
|
|
}
|
|
|
|
});
|
2014-02-28 01:02:20 -06:00
|
|
|
};
|
|
|
|
|
2014-09-03 04:15:01 -05:00
|
|
|
$scope.replacePanel = function(newPanel, oldPanel) {
|
|
|
|
var row = $scope.row;
|
|
|
|
var index = _.indexOf(row.panels, oldPanel);
|
|
|
|
row.panels.splice(index, 1);
|
|
|
|
|
|
|
|
// adding it back needs to be done in next digest
|
|
|
|
$timeout(function() {
|
|
|
|
newPanel.id = oldPanel.id;
|
|
|
|
newPanel.span = oldPanel.span;
|
|
|
|
row.panels.splice(index, 0, newPanel);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-02-28 01:02:20 -06:00
|
|
|
$scope.reset_panel = function(type) {
|
2014-08-13 09:35:34 -05:00
|
|
|
var defaultSpan = 12;
|
|
|
|
var _as = 12 - $scope.dashboard.rowSpan($scope.row);
|
2014-02-28 01:02:20 -06:00
|
|
|
|
|
|
|
$scope.panel = {
|
2014-10-08 05:44:46 -05:00
|
|
|
title: 'no title [click here]',
|
2014-02-28 01:02:20 -06:00
|
|
|
error : false,
|
|
|
|
span : _as < defaultSpan && _as > 0 ? _as : defaultSpan,
|
|
|
|
editable: true,
|
|
|
|
type : type
|
2013-12-09 02:13:13 -06:00
|
|
|
};
|
2014-04-05 06:26:48 -05:00
|
|
|
|
2014-04-07 01:33:52 -05:00
|
|
|
function fixRowHeight(height) {
|
|
|
|
if (!height) {
|
|
|
|
return '200px';
|
|
|
|
}
|
|
|
|
if (!_.isString(height)) {
|
|
|
|
return height + 'px';
|
|
|
|
}
|
|
|
|
return height;
|
2014-04-05 06:26:48 -05:00
|
|
|
}
|
2014-04-07 01:33:52 -05:00
|
|
|
|
|
|
|
$scope.row.height = fixRowHeight($scope.row.height);
|
2014-02-28 01:02:20 -06:00
|
|
|
};
|
2013-12-09 02:13:13 -06:00
|
|
|
|
2014-02-28 01:02:20 -06:00
|
|
|
$scope.init();
|
2013-09-13 15:52:13 -05:00
|
|
|
|
2014-02-28 01:02:20 -06:00
|
|
|
});
|
2013-09-13 15:52:13 -05:00
|
|
|
|
2014-08-15 03:26:41 -05:00
|
|
|
module.directive('rowHeight', function() {
|
|
|
|
return function(scope, element) {
|
|
|
|
scope.$watchGroup(['row.collapse', 'row.height'], function() {
|
|
|
|
element[0].style.minHeight = scope.row.collapse ? '5px' : scope.row.height;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2014-08-15 06:19:11 -05:00
|
|
|
module.directive('panelWidth', function() {
|
|
|
|
return function(scope, element) {
|
|
|
|
scope.$watch('panel.span', function() {
|
|
|
|
element[0].style.width = ((scope.panel.span / 1.2) * 10) + '%';
|
|
|
|
});
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2014-08-15 10:23:27 -05:00
|
|
|
module.directive('panelDropZone', function() {
|
|
|
|
return function(scope, element) {
|
2014-10-09 19:30:23 -05:00
|
|
|
scope.$on("ANGULAR_DRAG_START", function() {
|
|
|
|
var dropZoneSpan = 12 - scope.dashboard.rowSpan(scope.row);
|
|
|
|
|
|
|
|
if (dropZoneSpan > 0) {
|
|
|
|
element.find('.panel-container').css('height', scope.row.height);
|
|
|
|
element[0].style.width = ((dropZoneSpan / 1.2) * 10) + '%';
|
2014-08-15 10:23:27 -05:00
|
|
|
element.show();
|
|
|
|
}
|
2014-10-09 19:30:23 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
scope.$on("ANGULAR_DRAG_END", function() {
|
|
|
|
element.hide();
|
2014-08-15 10:23:27 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2014-08-03 05:07:50 -05:00
|
|
|
});
|