row.js 3.1 KB

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