controllers.js 2.5 KB

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