controllers.js 3.0 KB

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