controllers.js 2.6 KB

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