controllers.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. // The global dashboards object should be moved to an $http request for json
  17. if (Modernizr.localstorage &&
  18. !(_.isUndefined(localStorage['dashboard'])) &&
  19. localStorage['dashboard'] !== ''
  20. ) {
  21. $scope.dashboards = JSON.parse(localStorage['dashboard']);
  22. _.defaults($scope.dashboards,_d);
  23. } else {
  24. $http({
  25. url: "default.json",
  26. method: "GET",
  27. }).success(function(data, status, headers, config) {
  28. $scope.dashboards = data
  29. _.defaults($scope.dashboards,_d);
  30. }).error(function(data, status, headers, config) {
  31. $scope.alert('Default dashboard missing!','Could not locate default.json','error')
  32. });
  33. }
  34. eventBus.register($scope,'dashboard', function(event,dashboard){
  35. console.log('got broadcast')
  36. $scope.dashboards = dashboard;
  37. _.defaults($scope.dashboards,_d)
  38. })
  39. var ejs = $scope.ejs = ejsResource(config.elasticsearch);
  40. }
  41. $scope.add_row = function(dashboards,row) {
  42. $scope.dashboards.rows.push(row);
  43. }
  44. $scope.reset_row = function() {
  45. $scope.row = {
  46. title: '',
  47. height: '150px',
  48. editable: true,
  49. };
  50. };
  51. $scope.alert = function(title,text,severity,timeout) {
  52. var alert = {
  53. title: title,
  54. text: text,
  55. severity: severity || 'info',
  56. };
  57. $scope.global_alert.push(alert);
  58. if (timeout > 0)
  59. $timeout(function() {
  60. $scope.global_alert = _.without($scope.global_alert,alert)
  61. console.log($scope.global_alert)
  62. }, timeout);
  63. }
  64. $scope.clear_alert = function(alert) {
  65. $scope.global_alert = _.without($scope.global_alert,alert);
  66. }
  67. $scope.clear_all_alerts = function() {
  68. $scope.global_alert = []
  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. editable: true,
  78. panels: [],
  79. }
  80. _.defaults($scope.row,_d)
  81. $scope.init = function(){
  82. $scope.reset_panel();
  83. }
  84. $scope.toggle_row = function(row) {
  85. row.collapse = row.collapse ? false : true;
  86. if (!row.collapse) {
  87. $timeout(function() {
  88. $scope.$broadcast('render')
  89. });
  90. }
  91. }
  92. $scope.send_render = function() {
  93. $scope.$broadcast('render');
  94. }
  95. $scope.add_panel = function(row,panel) {
  96. console.log(panel)
  97. $scope.row.panels.push(panel);
  98. }
  99. $scope.reset_panel = function() {
  100. $scope.panel = {
  101. span: 3,
  102. editable: true,
  103. group: ['default'],
  104. };
  105. };
  106. $scope.init();
  107. });