controllers.js 2.8 KB

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