controllers.js 2.4 KB

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