controllers.js 2.7 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, $route, ejsResource, eventBus, fields, dashboard) {
  6. var _d = {
  7. title: "",
  8. editable: true,
  9. rows: [],
  10. last: null
  11. }
  12. $scope.init = function() {
  13. $scope.config = config;
  14. // Make underscore.js available to views
  15. $scope._ = _;
  16. $scope.dashboard = dashboard;
  17. // Provide a global list of all see fields
  18. $scope.fields = fields
  19. $scope.reset_row();
  20. $scope.clear_all_alerts();
  21. var ejs = $scope.ejs = ejsResource(config.elasticsearch);
  22. }
  23. $scope.add_row = function(dash,row) {
  24. dash.rows.push(row);
  25. }
  26. $scope.reset_row = function() {
  27. $scope.row = {
  28. title: '',
  29. height: '150px',
  30. editable: true,
  31. };
  32. };
  33. $scope.row_style = function(row) {
  34. return { 'min-height': row.collapse ? '5px' : row.height }
  35. }
  36. $scope.alert = function(title,text,severity,timeout) {
  37. var alert = {
  38. title: title,
  39. text: text,
  40. severity: severity || 'info',
  41. };
  42. $scope.global_alert.push(alert);
  43. if (timeout > 0)
  44. $timeout(function() {
  45. $scope.global_alert = _.without($scope.global_alert,alert)
  46. }, timeout);
  47. }
  48. $scope.clear_alert = function(alert) {
  49. $scope.global_alert = _.without($scope.global_alert,alert);
  50. }
  51. $scope.clear_all_alerts = function() {
  52. $scope.global_alert = []
  53. }
  54. $scope.edit_path = function(type) {
  55. if(type)
  56. return 'panels/'+type+'/editor.html';
  57. }
  58. // This is whoafully incomplete, but will do for now
  59. $scope.parse_error = function(data) {
  60. var _error = data.match("nested: (.*?);")
  61. return _.isNull(_error) ? data : _error[1];
  62. }
  63. $scope.init();
  64. })
  65. .controller('RowCtrl', function($scope, $rootScope, $timeout, ejsResource) {
  66. var _d = {
  67. title: "Row",
  68. height: "150px",
  69. collapse: false,
  70. collapsable: true,
  71. editable: true,
  72. panels: [],
  73. }
  74. _.defaults($scope.row,_d)
  75. $scope.init = function() {
  76. $scope.reset_panel();
  77. }
  78. $scope.toggle_row = function(row) {
  79. row.collapse = row.collapse ? false : true;
  80. if (!row.collapse) {
  81. $timeout(function() {
  82. $scope.$broadcast('render')
  83. });
  84. }
  85. }
  86. // This can be overridden by individual panel
  87. $scope.close_edit = function() {
  88. $scope.$broadcast('render')
  89. }
  90. $scope.add_panel = function(row,panel) {
  91. $scope.row.panels.push(panel);
  92. }
  93. $scope.reset_panel = function() {
  94. $scope.panel = {
  95. loading : false,
  96. error : false,
  97. span : 3,
  98. editable: true,
  99. group : ['default'],
  100. };
  101. };
  102. $scope.init();
  103. });