controllers.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*jshint globalstrict:true */
  2. /*global angular:true */
  3. 'use strict';
  4. angular.module('kibana.controllers', [])
  5. .controller('DashCtrl', function($scope, $rootScope, $http, $timeout, $route, ejsResource, eventBus,
  6. fields, dashboard) {
  7. var _d = {
  8. title: "",
  9. editable: true,
  10. rows: [],
  11. last: null
  12. }
  13. $scope.init = function() {
  14. $scope.config = config;
  15. // Make underscore.js available to views
  16. $scope._ = _;
  17. $scope.dashboard = dashboard;
  18. // Provide a global list of all see fields
  19. $scope.fields = fields
  20. $scope.reset_row();
  21. $scope.clear_all_alerts();
  22. var ejs = $scope.ejs = ejsResource(config.elasticsearch);
  23. }
  24. $scope.add_row = function(dash,row) {
  25. dash.rows.push(row);
  26. }
  27. $scope.reset_row = function() {
  28. $scope.row = {
  29. title: '',
  30. height: '150px',
  31. editable: true,
  32. };
  33. };
  34. $scope.row_style = function(row) {
  35. return { 'min-height': row.collapse ? '5px' : row.height }
  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. // This is whoafully incomplete, but will do for now
  60. $scope.parse_error = function(data) {
  61. var _error = data.match("nested: (.*?);")
  62. return _.isNull(_error) ? data : _error[1];
  63. }
  64. $scope.init();
  65. })
  66. .controller('RowCtrl', function($scope, $rootScope, $timeout, ejsResource) {
  67. var _d = {
  68. title: "Row",
  69. height: "150px",
  70. collapse: false,
  71. collapsable: true,
  72. editable: true,
  73. panels: [],
  74. }
  75. _.defaults($scope.row,_d)
  76. $scope.init = function() {
  77. $scope.reset_panel();
  78. }
  79. $scope.toggle_row = function(row) {
  80. row.collapse = row.collapse ? false : true;
  81. if (!row.collapse) {
  82. $timeout(function() {
  83. $scope.$broadcast('render')
  84. });
  85. }
  86. }
  87. // This can be overridden by individual panel
  88. $scope.close_edit = function() {
  89. $scope.$broadcast('render')
  90. }
  91. $scope.add_panel = function(row,panel) {
  92. $scope.row.panels.push(panel);
  93. }
  94. $scope.reset_panel = function() {
  95. $scope.panel = {
  96. loading : false,
  97. error : false,
  98. span : 3,
  99. editable: true,
  100. group : ['default'],
  101. };
  102. };
  103. $scope.init();
  104. });