controllers.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.alert = function(title,text,severity,timeout) {
  41. var alert = {
  42. title: title,
  43. text: text,
  44. severity: severity || 'info',
  45. };
  46. $scope.global_alert.push(alert);
  47. if (timeout > 0)
  48. $timeout(function() {
  49. $scope.global_alert = _.without($scope.global_alert,alert)
  50. }, timeout);
  51. }
  52. $scope.clear_alert = function(alert) {
  53. $scope.global_alert = _.without($scope.global_alert,alert);
  54. }
  55. $scope.clear_all_alerts = function() {
  56. $scope.global_alert = []
  57. }
  58. $scope.edit_path = function(type) {
  59. if(type)
  60. return 'panels/'+type+'/editor.html';
  61. }
  62. // This is whoafully incomplete, but will do for now
  63. $scope.parse_error = function(data) {
  64. var _error = data.match("nested: (.*?);")
  65. return _.isNull(_error) ? data : _error[1];
  66. }
  67. $scope.init();
  68. })
  69. .controller('RowCtrl', function($scope, $rootScope, $timeout, ejsResource) {
  70. var _d = {
  71. title: "Row",
  72. height: "150px",
  73. collapse: false,
  74. collapsable: true,
  75. editable: true,
  76. panels: [],
  77. }
  78. _.defaults($scope.row,_d)
  79. $scope.init = function(){
  80. $scope.reset_panel();
  81. }
  82. $scope.toggle_row = function(row) {
  83. row.collapse = row.collapse ? false : true;
  84. if (!row.collapse) {
  85. $timeout(function() {
  86. $scope.send_render();
  87. });
  88. }
  89. }
  90. // This can be overridden by individual panel
  91. $scope.close_edit = function() {
  92. $scope.$broadcast('render')
  93. }
  94. $scope.add_panel = function(row,panel) {
  95. $scope.row.panels.push(panel);
  96. }
  97. $scope.reset_panel = function() {
  98. $scope.panel = {
  99. loading: false,
  100. error: false,
  101. span: 3,
  102. editable: true,
  103. group: ['default'],
  104. };
  105. };
  106. $scope.init();
  107. });