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