controllers.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*jshint globalstrict:true */
  2. /*global angular:true */
  3. 'use strict';
  4. angular.module('kibana.controllers', [])
  5. .controller('DashCtrl', function($scope, $rootScope, $http, $timeout, $route, ejsResource, eventBus,
  6. fields, dashboard) {
  7. var _d = {
  8. title: "",
  9. editable: true,
  10. rows: [],
  11. last: null
  12. };
  13. // For
  14. $scope.editor = {
  15. index: 0
  16. };
  17. $scope.init = function() {
  18. $scope.config = config;
  19. // Make underscore.js available to views
  20. $scope._ = _;
  21. $scope.dashboard = dashboard;
  22. // Provide a global list of all see fields
  23. $scope.fields = fields;
  24. $scope.reset_row();
  25. $scope.clear_all_alerts();
  26. var ejs = $scope.ejs = ejsResource(config.elasticsearch);
  27. };
  28. $scope.add_row = function(dash,row) {
  29. dash.rows.push(row);
  30. };
  31. $scope.reset_row = function() {
  32. $scope.row = {
  33. title: '',
  34. height: '150px',
  35. editable: true,
  36. };
  37. };
  38. $scope.row_style = function(row) {
  39. return { 'min-height': row.collapse ? '5px' : row.height };
  40. };
  41. $scope.alert = function(title,text,severity,timeout) {
  42. var alert = {
  43. title: title,
  44. text: text,
  45. severity: severity || 'info',
  46. };
  47. $scope.global_alert.push(alert);
  48. if (timeout > 0) {
  49. $timeout(function() {
  50. $scope.global_alert = _.without($scope.global_alert,alert);
  51. }, timeout);
  52. }
  53. };
  54. $scope.clear_alert = function(alert) {
  55. $scope.global_alert = _.without($scope.global_alert,alert);
  56. };
  57. $scope.clear_all_alerts = function() {
  58. $scope.global_alert = [];
  59. };
  60. $scope.edit_path = function(type) {
  61. if(type) {
  62. return 'panels/'+type+'/editor.html';
  63. } else {
  64. return false;
  65. }
  66. };
  67. // This is whoafully incomplete, but will do for now
  68. $scope.parse_error = function(data) {
  69. var _error = data.match("nested: (.*?);");
  70. return _.isNull(_error) ? data : _error[1];
  71. };
  72. $scope.init();
  73. })
  74. .controller('RowCtrl', function($scope, $rootScope, $timeout, ejsResource, querySrv) {
  75. var _d = {
  76. title: "Row",
  77. height: "150px",
  78. collapse: false,
  79. collapsable: true,
  80. editable: true,
  81. panels: [],
  82. };
  83. _.defaults($scope.row,_d);
  84. $scope.init = function() {
  85. $scope.querySrv = querySrv;
  86. $scope.reset_panel();
  87. };
  88. $scope.toggle_row = function(row) {
  89. if(!row.collapsable) {
  90. return;
  91. }
  92. row.collapse = row.collapse ? false : true;
  93. if (!row.collapse) {
  94. $timeout(function() {
  95. $scope.$broadcast('render');
  96. });
  97. }
  98. };
  99. // This can be overridden by individual panels
  100. $scope.close_edit = function() {
  101. $scope.$broadcast('render');
  102. };
  103. $scope.add_panel = function(row,panel) {
  104. $scope.row.panels.push(panel);
  105. };
  106. $scope.reset_panel = function() {
  107. $scope.panel = {
  108. loading : false,
  109. error : false,
  110. span : 3,
  111. editable: true,
  112. group : ['default']
  113. };
  114. };
  115. $scope.init();
  116. });