controllers.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. return data.match("nested: (.*?);")[1]
  65. }
  66. $scope.init();
  67. })
  68. .controller('RowCtrl', function($scope, $rootScope, $timeout, ejsResource) {
  69. var _d = {
  70. title: "Row",
  71. height: "150px",
  72. collapse: false,
  73. collapsable: true,
  74. editable: true,
  75. panels: [],
  76. }
  77. _.defaults($scope.row,_d)
  78. $scope.init = function(){
  79. $scope.reset_panel();
  80. }
  81. $scope.toggle_row = function(row) {
  82. row.collapse = row.collapse ? false : true;
  83. if (!row.collapse) {
  84. $timeout(function() {
  85. $scope.send_render();
  86. });
  87. }
  88. }
  89. $scope.send_render = function() {
  90. $scope.$broadcast('render');
  91. }
  92. $scope.add_panel = function(row,panel) {
  93. $scope.row.panels.push(panel);
  94. }
  95. $scope.reset_panel = function() {
  96. $scope.panel = {
  97. loading: false,
  98. error: false,
  99. span: 3,
  100. editable: true,
  101. group: ['default'],
  102. };
  103. };
  104. $scope.init();
  105. });