controllers.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*jshint globalstrict:true */
  2. /*global angular:true */
  3. 'use strict';
  4. angular.module('kibana.controllers', [])
  5. .controller('DashCtrl', function($scope, $rootScope, $http, ejsResource, timer) {
  6. var _d = {
  7. title: "",
  8. editable: true,
  9. rows: [],
  10. }
  11. $scope.init = function() {
  12. $scope.config = config;
  13. $scope._ = _;
  14. $scope.reset_row();
  15. // The global dashboards object should be moved to an $http request for json
  16. if (Modernizr.localstorage &&
  17. !(_.isUndefined(localStorage['dashboard'])) &&
  18. localStorage['dashboard'] !== ''
  19. ) {
  20. $scope.dashboards = JSON.parse(localStorage['dashboard']);
  21. } else {
  22. $scope.dashboards = dashboards
  23. }
  24. _.defaults($scope.dashboards,_d)
  25. var ejs = $scope.ejs = ejsResource(config.elasticsearch);
  26. }
  27. $scope.export = function() {
  28. var blob = new Blob([angular.toJson($scope.dashboards,true)], {type: "application/json;charset=utf-8"});
  29. saveAs(blob, $scope.dashboards.title+"-"+new Date().getTime());
  30. }
  31. $scope.default = function() {
  32. if (Modernizr.localstorage) {
  33. localStorage['dashboard'] = angular.toJson($scope.dashboards);
  34. alert($scope.dashboards.title + " has been set as your default dashboard")
  35. } else {
  36. alert("Sorry, your browser is too old for this functionality");
  37. }
  38. }
  39. $scope.purge = function() {
  40. if (Modernizr.localstorage) {
  41. localStorage['dashboard'] = '';
  42. alert('Default dashboard cleared')
  43. } else {
  44. alert("Sorry, your browser is too old for this functionality");
  45. }
  46. }
  47. $scope.add_row = function(dashboards,row) {
  48. $scope.dashboards.rows.push(row);
  49. }
  50. $scope.reset_row = function() {
  51. $scope.row = {
  52. title: '',
  53. height: '150px',
  54. editable: true,
  55. };
  56. };
  57. $scope.init();
  58. })
  59. .controller('RowCtrl', function($scope, $rootScope, $timeout, ejsResource, timer) {
  60. var _d = {
  61. title: "Row",
  62. height: "150px",
  63. collapse: false,
  64. editable: true,
  65. panels: [],
  66. }
  67. _.defaults($scope.row,_d)
  68. $scope.init = function(){
  69. $scope.reset_panel();
  70. }
  71. $scope.toggle_row = function(row) {
  72. row.collapse = row.collapse ? false : true;
  73. if (!row.collapse) {
  74. $timeout(function() {
  75. $scope.$broadcast('render')
  76. });
  77. }
  78. }
  79. $scope.send_render = function() {
  80. $scope.$broadcast('render');
  81. }
  82. $scope.add_panel = function(row,panel) {
  83. console.log(panel)
  84. $scope.row.panels.push(panel);
  85. }
  86. $scope.reset_panel = function() {
  87. $scope.panel = {
  88. span: 1,
  89. editable: true,
  90. groups: ['default'],
  91. };
  92. };
  93. $scope.init();
  94. });