row.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. define([
  2. 'angular',
  3. 'app',
  4. 'underscore'
  5. ],
  6. function (angular, app, _) {
  7. 'use strict';
  8. var module = angular.module('kibana.controllers');
  9. module.controller('RowCtrl', function($scope, $rootScope, $timeout,ejsResource) {
  10. var _d = {
  11. title: "Row",
  12. height: "150px",
  13. collapse: false,
  14. collapsable: true,
  15. editable: true,
  16. panels: [],
  17. notice: false
  18. };
  19. _.defaults($scope.row,_d);
  20. $scope.init = function() {
  21. $scope.reset_panel();
  22. };
  23. $scope.toggle_row = function(row) {
  24. if(!row.collapsable) {
  25. return;
  26. }
  27. row.collapse = row.collapse ? false : true;
  28. if (!row.collapse) {
  29. $timeout(function() {
  30. $scope.$broadcast('render');
  31. });
  32. } else {
  33. row.notice = false;
  34. }
  35. };
  36. $scope.rowSpan = function(row) {
  37. var panels = _.filter(row.panels, function(p) {
  38. return $scope.isPanel(p);
  39. });
  40. return _.reduce(_.pluck(panels,'span'), function(p,v) {
  41. return p+v;
  42. },0);
  43. };
  44. // This can be overridden by individual panels
  45. $scope.close_edit = function() {
  46. $scope.$broadcast('render');
  47. };
  48. $scope.add_panel = function(row,panel) {
  49. $scope.row.panels.push(panel);
  50. };
  51. $scope.remove_panel_from_row = function(row, panel) {
  52. if (confirm('Are you sure you want to remove this ' + panel.type + ' panel?')) {
  53. row.panels = _.without(row.panels,panel);
  54. }
  55. };
  56. /** @scratch /panels/0
  57. * [[panels]]
  58. * = Panels
  59. *
  60. * [partintro]
  61. * --
  62. * *Kibana* dashboards are made up of blocks called +panels+. Panels are organized into rows
  63. * and can serve many purposes, though most are designed to provide the results of a query or
  64. * multiple queries as a visualization. Other panels may show collections of documents or
  65. * allow you to insert instructions for your users.
  66. *
  67. * Panels can be configured easily via the Kibana web interface. For more advanced usage, such
  68. * as templated or scripted dashboards, documentation of panel properties is available in this
  69. * section. You may find settings here which are not exposed via the web interface.
  70. *
  71. * Each panel type has its own properties, hover there are several that are shared.
  72. *
  73. */
  74. $scope.reset_panel = function(type) {
  75. var
  76. defaultSpan = 4,
  77. _as = 12-$scope.rowSpan($scope.row);
  78. $scope.panel = {
  79. error : false,
  80. /** @scratch /panels/1
  81. * span:: A number, 1-12, that describes the width of the panel.
  82. */
  83. span : _as < defaultSpan && _as > 0 ? _as : defaultSpan,
  84. /** @scratch /panels/1
  85. * editable:: Enable or disable the edit button the the panel
  86. */
  87. editable: true,
  88. /** @scratch /panels/1
  89. * type:: The type of panel this object contains. Each panel type will require additional
  90. * properties. See the panel types list to the right.
  91. */
  92. type : type
  93. };
  94. };
  95. /** @scratch /panels/2
  96. * --
  97. */
  98. $scope.init();
  99. }
  100. );
  101. });