controllers.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*jshint globalstrict:true */
  2. /*global angular:true */
  3. 'use strict';
  4. angular.module('kibana.controllers', [])
  5. .controller('DashCtrl', function($scope, $rootScope, $http, $timeout, ejsResource, eventBus, fields) {
  6. var _d = {
  7. title: "",
  8. editable: true,
  9. rows: [],
  10. last: null
  11. }
  12. $scope.init = function() {
  13. $scope.config = config;
  14. // Make underscore.js available to views
  15. $scope._ = _;
  16. // Provide a global list of all see fields
  17. $scope.fields = fields
  18. $scope.reset_row();
  19. $scope.clear_all_alerts();
  20. // Load dashboard by event
  21. eventBus.register($scope,'dashboard', function(event,dashboard){
  22. $scope.dashboards = dashboard.dashboard;
  23. $scope.dashboards.last = dashboard.last;
  24. _.defaults($scope.dashboards,_d)
  25. })
  26. // If the route changes, clear the existing dashboard
  27. $rootScope.$on( "$routeChangeStart", function(event, next, current) {
  28. delete $scope.dashboards
  29. });
  30. var ejs = $scope.ejs = ejsResource(config.elasticsearch);
  31. }
  32. $scope.add_row = function(dashboards,row) {
  33. $scope.dashboards.rows.push(row);
  34. }
  35. $scope.reset_row = function() {
  36. $scope.row = {
  37. title: '',
  38. height: '150px',
  39. editable: true,
  40. };
  41. };
  42. $scope.row_style = function(row) {
  43. return { 'min-height': row.collapse ? '5px' : row.height }
  44. }
  45. $scope.alert = function(title,text,severity,timeout) {
  46. var alert = {
  47. title: title,
  48. text: text,
  49. severity: severity || 'info',
  50. };
  51. $scope.global_alert.push(alert);
  52. if (timeout > 0)
  53. $timeout(function() {
  54. $scope.global_alert = _.without($scope.global_alert,alert)
  55. }, timeout);
  56. }
  57. $scope.clear_alert = function(alert) {
  58. $scope.global_alert = _.without($scope.global_alert,alert);
  59. }
  60. $scope.clear_all_alerts = function() {
  61. $scope.global_alert = []
  62. }
  63. $scope.edit_path = function(type) {
  64. if(type)
  65. return 'panels/'+type+'/editor.html';
  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) {
  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.reset_panel();
  86. }
  87. $scope.toggle_row = function(row) {
  88. row.collapse = row.collapse ? false : true;
  89. if (!row.collapse) {
  90. $timeout(function() {
  91. $scope.$broadcast('render')
  92. });
  93. }
  94. }
  95. // This can be overridden by individual panel
  96. $scope.close_edit = function() {
  97. $scope.$broadcast('render')
  98. }
  99. $scope.add_panel = function(row,panel) {
  100. $scope.row.panels.push(panel);
  101. }
  102. $scope.reset_panel = function() {
  103. $scope.panel = {
  104. loading : false,
  105. error : false,
  106. span : 3,
  107. editable: true,
  108. group : ['default'],
  109. };
  110. };
  111. $scope.init();
  112. });