controllers.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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) {
  6. var _d = {
  7. title: "",
  8. editable: true,
  9. rows: [],
  10. }
  11. $scope.init = function() {
  12. $scope.config = config;
  13. $scope._ = _;
  14. $scope.reset_row();
  15. $scope.clear_all_alerts();
  16. // Load dashboard by event
  17. eventBus.register($scope,'dashboard', function(event,dashboard){
  18. console.log(dashboard)
  19. $scope.dashboards = dashboard;
  20. _.defaults($scope.dashboards,_d)
  21. })
  22. // If the route changes, clear the existing dashboard
  23. $rootScope.$on( "$routeChangeStart", function(event, next, current) {
  24. delete $scope.dashboards
  25. });
  26. var ejs = $scope.ejs = ejsResource(config.elasticsearch);
  27. }
  28. $scope.add_row = function(dashboards,row) {
  29. $scope.dashboards.rows.push(row);
  30. }
  31. $scope.reset_row = function() {
  32. $scope.row = {
  33. title: '',
  34. height: '150px',
  35. editable: true,
  36. };
  37. };
  38. $scope.alert = function(title,text,severity,timeout) {
  39. var alert = {
  40. title: title,
  41. text: text,
  42. severity: severity || 'info',
  43. };
  44. $scope.global_alert.push(alert);
  45. if (timeout > 0)
  46. $timeout(function() {
  47. $scope.global_alert = _.without($scope.global_alert,alert)
  48. }, timeout);
  49. }
  50. $scope.clear_alert = function(alert) {
  51. $scope.global_alert = _.without($scope.global_alert,alert);
  52. }
  53. $scope.clear_all_alerts = function() {
  54. $scope.global_alert = []
  55. }
  56. $scope.init();
  57. })
  58. .controller('RowCtrl', function($scope, $rootScope, $timeout, ejsResource) {
  59. var _d = {
  60. title: "Row",
  61. height: "150px",
  62. collapse: false,
  63. editable: true,
  64. panels: [],
  65. }
  66. _.defaults($scope.row,_d)
  67. $scope.init = function(){
  68. $scope.reset_panel();
  69. }
  70. $scope.toggle_row = function(row) {
  71. row.collapse = row.collapse ? false : true;
  72. if (!row.collapse) {
  73. $timeout(function() {
  74. $scope.send_render();
  75. });
  76. }
  77. }
  78. $scope.send_render = function() {
  79. $scope.$broadcast('render');
  80. }
  81. $scope.add_panel = function(row,panel) {
  82. $scope.row.panels.push(panel);
  83. }
  84. $scope.reset_panel = function() {
  85. $scope.panel = {
  86. loading: false,
  87. error: false,
  88. span: 3,
  89. editable: true,
  90. group: ['default'],
  91. };
  92. };
  93. $scope.init();
  94. });