dash.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. 'services/dashboard/all'
  26. ],
  27. function (angular, $, config, _) {
  28. "use strict";
  29. var module = angular.module('kibana.controllers');
  30. module.controller('DashCtrl', function(
  31. $scope, $rootScope, $timeout, ejsResource, dashboard, filterSrv, dashboardKeybindings,
  32. alertSrv, panelMove, keyboardManager, grafanaVersion) {
  33. $scope.requiredElasticSearchVersion = ">=0.90.3";
  34. $scope.editor = {
  35. index: 0
  36. };
  37. $scope.grafanaVersion = grafanaVersion[0] === '@' ? 'master' : grafanaVersion;
  38. // For moving stuff around the dashboard.
  39. $scope.panelMoveDrop = panelMove.onDrop;
  40. $scope.panelMoveStart = panelMove.onStart;
  41. $scope.panelMoveStop = panelMove.onStop;
  42. $scope.panelMoveOver = panelMove.onOver;
  43. $scope.panelMoveOut = panelMove.onOut;
  44. $scope.init = function() {
  45. $scope.config = config;
  46. // Make stuff, including underscore.js available to views
  47. $scope._ = _;
  48. $scope.dashboard = dashboard;
  49. $scope.dashAlerts = alertSrv;
  50. $scope.filter = filterSrv;
  51. $scope.filter.init(dashboard.current);
  52. $rootScope.$on("dashboard-loaded", function(event, dashboard) {
  53. $scope.filter.init(dashboard);
  54. });
  55. // Clear existing alerts
  56. alertSrv.clearAll();
  57. $scope.reset_row();
  58. $scope.ejs = ejsResource(config.elasticsearch, config.elasticsearchBasicAuth);
  59. $scope.bindKeyboardShortcuts();
  60. };
  61. $scope.bindKeyboardShortcuts = dashboardKeybindings.shortcuts;
  62. $scope.isPanel = function(obj) {
  63. if(!_.isNull(obj) && !_.isUndefined(obj) && !_.isUndefined(obj.type)) {
  64. return true;
  65. } else {
  66. return false;
  67. }
  68. };
  69. $scope.add_row = function(dash, row) {
  70. dash.rows.push(row);
  71. };
  72. $scope.reset_row = function() {
  73. $scope.row = {
  74. title: '',
  75. height: '150px',
  76. editable: true,
  77. };
  78. };
  79. $scope.row_style = function(row) {
  80. return { 'min-height': row.collapse ? '5px' : row.height };
  81. };
  82. $scope.panel_path =function(type) {
  83. if(type) {
  84. return 'app/panels/'+type.replace(".","/");
  85. } else {
  86. return false;
  87. }
  88. };
  89. $scope.edit_path = function(type) {
  90. var p = $scope.panel_path(type);
  91. if(p) {
  92. return p+'/editor.html';
  93. } else {
  94. return false;
  95. }
  96. };
  97. $scope.setEditorTabs = function(panelMeta) {
  98. $scope.editorTabs = ['General','Panel'];
  99. if(!_.isUndefined(panelMeta.editorTabs)) {
  100. $scope.editorTabs = _.union($scope.editorTabs,_.pluck(panelMeta.editorTabs,'title'));
  101. }
  102. return $scope.editorTabs;
  103. };
  104. // This is whoafully incomplete, but will do for now
  105. $scope.parse_error = function(data) {
  106. var _error = data.match("nested: (.*?);");
  107. return _.isNull(_error) ? data : _error[1];
  108. };
  109. $scope.colors = [
  110. "#7EB26D","#EAB839","#6ED0E0","#EF843C","#E24D42","#1F78C1","#BA43A9","#705DA0", //1
  111. "#508642","#CCA300","#447EBC","#C15C17","#890F02","#0A437C","#6D1F62","#584477", //2
  112. "#B7DBAB","#F4D598","#70DBED","#F9BA8F","#F29191","#82B5D8","#E5A8E2","#AEA2E0", //3
  113. "#629E51","#E5AC0E","#64B0C8","#E0752D","#BF1B00","#0A50A1","#962D82","#614D93", //4
  114. "#9AC48A","#F2C96D","#65C5DB","#F9934E","#EA6460","#5195CE","#D683CE","#806EB7", //5
  115. "#3F6833","#967302","#2F575E","#99440A","#58140C","#052B51","#511749","#3F2B5B", //6
  116. "#E0F9D7","#FCEACA","#CFFAFF","#F9E2D2","#FCE2DE","#BADFF4","#F9D9F9","#DEDAF7" //7
  117. ];
  118. $scope.init();
  119. });
  120. });