dash.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /** @scratch /index/0
  2. * = Kibana
  3. *
  4. * // Why can't I have a preamble here?
  5. *
  6. * == Introduction
  7. *
  8. * Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for
  9. * ElasticSearch. Kibana is a snap to setup and start using. Written entirely in HTML and Javascript
  10. * it requires only a plain webserver, Kibana requires no fancy server side components.
  11. * Kibana strives to be easy to get started with, while also being flexible and powerful, just like
  12. * Elasticsearch.
  13. *
  14. * include::configuration/config.js.asciidoc[]
  15. *
  16. * include::panels.asciidoc[]
  17. *
  18. */
  19. define([
  20. 'angular',
  21. 'jquery',
  22. 'config',
  23. 'underscore',
  24. 'services/all'
  25. ],
  26. function (angular, $, config, _) {
  27. "use strict";
  28. var module = angular.module('kibana.controllers');
  29. module.controller('DashCtrl', function(
  30. $scope, $rootScope, $route, ejsResource, dashboard, alertSrv, panelMove, esVersion, keyboardManager) {
  31. $scope.requiredElasticSearchVersion = ">=0.90.3";
  32. $scope.editor = {
  33. index: 0
  34. };
  35. // For moving stuff around the dashboard.
  36. $scope.panelMoveDrop = panelMove.onDrop;
  37. $scope.panelMoveStart = panelMove.onStart;
  38. $scope.panelMoveStop = panelMove.onStop;
  39. $scope.panelMoveOver = panelMove.onOver;
  40. $scope.panelMoveOut = panelMove.onOut;
  41. $scope.init = function() {
  42. $scope.config = config;
  43. // Make stuff, including underscore.js available to views
  44. $scope._ = _;
  45. $scope.dashboard = dashboard;
  46. $scope.dashAlerts = alertSrv;
  47. $scope.esVersion = esVersion;
  48. // Clear existing alerts
  49. alertSrv.clearAll();
  50. $scope.reset_row();
  51. $scope.ejs = ejsResource(config.elasticsearch);
  52. $scope.bindKeyboardShortcuts();
  53. };
  54. $scope.bindKeyboardShortcuts = function() {
  55. $rootScope.$on('panel-fullscreen-enter', function() {
  56. $scope.fullscreenPanelExists = true;
  57. });
  58. $rootScope.$on('panel-fullscreen-exit', function() {
  59. $scope.fullscreenPanelExists = false;
  60. });
  61. keyboardManager.bind('ctrl+f', function(evt) {
  62. $rootScope.$emit('open-search', evt);
  63. }, { inputDisabled: true });
  64. keyboardManager.bind('ctrl+h', function() {
  65. var current = dashboard.current.hideControls;
  66. dashboard.current.hideControls = !current;
  67. dashboard.current.panel_hints = !current;
  68. }, { inputDisabled: true });
  69. keyboardManager.bind('ctrl+s', function(evt) {
  70. $rootScope.$emit('save-dashboard', evt);
  71. }, { inputDisabled: true });
  72. keyboardManager.bind('ctrl+r', function() {
  73. dashboard.refresh();
  74. }, { inputDisabled: true });
  75. keyboardManager.bind('ctrl+z', function(evt) {
  76. $rootScope.$emit('zoom-out', evt);
  77. }, { inputDisabled: true });
  78. keyboardManager.bind('esc', function() {
  79. var popups = $('.popover.in');
  80. if (popups.length > 0) {
  81. return;
  82. }
  83. $rootScope.$emit('panel-fullscreen-exit');
  84. }, { inputDisabled: true });
  85. };
  86. $scope.countWatchers = function (scopeStart) {
  87. var q = [scopeStart || $rootScope], watchers = 0, scope;
  88. while (q.length > 0) {
  89. scope = q.pop();
  90. if (scope.$$watchers) {
  91. watchers += scope.$$watchers.length;
  92. }
  93. if (scope.$$childHead) {
  94. q.push(scope.$$childHead);
  95. }
  96. if (scope.$$nextSibling) {
  97. q.push(scope.$$nextSibling);
  98. }
  99. }
  100. window.console.log(watchers);
  101. };
  102. $scope.isPanel = function(obj) {
  103. if(!_.isNull(obj) && !_.isUndefined(obj) && !_.isUndefined(obj.type)) {
  104. return true;
  105. } else {
  106. return false;
  107. }
  108. };
  109. $scope.add_row = function(dash,row) {
  110. dash.rows.push(row);
  111. };
  112. $scope.reset_row = function() {
  113. $scope.row = {
  114. title: '',
  115. height: '150px',
  116. editable: true,
  117. };
  118. };
  119. $scope.row_style = function(row) {
  120. return { 'min-height': row.collapse ? '5px' : row.height };
  121. };
  122. $scope.panel_path =function(type) {
  123. if(type) {
  124. return 'app/panels/'+type.replace(".","/");
  125. } else {
  126. return false;
  127. }
  128. };
  129. $scope.edit_path = function(type) {
  130. var p = $scope.panel_path(type);
  131. if(p) {
  132. return p+'/editor.html';
  133. } else {
  134. return false;
  135. }
  136. };
  137. $scope.pulldownTabStyle = function(i) {
  138. var classes = ['bgPrimary','bgSuccess','bgWarning','bgDanger','bgInverse','bgInfo'];
  139. i = i%classes.length;
  140. return classes[i];
  141. };
  142. $scope.setEditorTabs = function(panelMeta) {
  143. $scope.editorTabs = ['General','Panel'];
  144. if(!_.isUndefined(panelMeta.editorTabs)) {
  145. $scope.editorTabs = _.union($scope.editorTabs,_.pluck(panelMeta.editorTabs,'title'));
  146. }
  147. return $scope.editorTabs;
  148. };
  149. // This is whoafully incomplete, but will do for now
  150. $scope.parse_error = function(data) {
  151. var _error = data.match("nested: (.*?);");
  152. return _.isNull(_error) ? data : _error[1];
  153. };
  154. $scope.init();
  155. });
  156. });