controllers.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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, alertSrv) {
  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. $scope.dashAlerts = alertSrv;
  16. alertSrv.clearAll();
  17. // Provide a global list of all see fields
  18. $scope.fields = fields;
  19. $scope.reset_row();
  20. var ejs = $scope.ejs = ejsResource(config.elasticsearch);
  21. };
  22. $scope.add_row = function(dash,row) {
  23. dash.rows.push(row);
  24. };
  25. $scope.reset_row = function() {
  26. $scope.row = {
  27. title: '',
  28. height: '150px',
  29. editable: true,
  30. };
  31. };
  32. $scope.row_style = function(row) {
  33. return { 'min-height': row.collapse ? '5px' : row.height };
  34. };
  35. $scope.edit_path = function(type) {
  36. if(type) {
  37. return 'panels/'+type+'/editor.html';
  38. } else {
  39. return false;
  40. }
  41. };
  42. $scope.setEditorTabs = function(panelMeta) {
  43. $scope.editorTabs = ['General','Panel'];
  44. if(!_.isUndefined(panelMeta.editorTabs)) {
  45. $scope.editorTabs = _.union($scope.editorTabs,_.pluck(panelMeta.editorTabs,'title'));
  46. }
  47. return $scope.editorTabs;
  48. };
  49. // This is whoafully incomplete, but will do for now
  50. $scope.parse_error = function(data) {
  51. var _error = data.match("nested: (.*?);");
  52. return _.isNull(_error) ? data : _error[1];
  53. };
  54. $scope.init();
  55. })
  56. .controller('RowCtrl', function($scope, $rootScope, $timeout, ejsResource, querySrv) {
  57. var _d = {
  58. title: "Row",
  59. height: "150px",
  60. collapse: false,
  61. collapsable: true,
  62. editable: true,
  63. panels: [],
  64. };
  65. _.defaults($scope.row,_d);
  66. $scope.init = function() {
  67. $scope.querySrv = querySrv;
  68. $scope.reset_panel();
  69. };
  70. $scope.toggle_row = function(row) {
  71. if(!row.collapsable) {
  72. return;
  73. }
  74. row.collapse = row.collapse ? false : true;
  75. if (!row.collapse) {
  76. $timeout(function() {
  77. $scope.$broadcast('render');
  78. });
  79. }
  80. };
  81. // This can be overridden by individual panels
  82. $scope.close_edit = 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(type) {
  89. $scope.panel = {
  90. error : false,
  91. span : 3,
  92. editable: true,
  93. type : type
  94. };
  95. };
  96. $scope.init();
  97. });