controllers.js 3.0 KB

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