| 
									
										
										
										
											2013-01-26 12:10:28 +08:00
										 |  |  | /*jshint globalstrict:true */ | 
					
						
							|  |  |  | /*global angular:true */ | 
					
						
							|  |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-29 03:28:12 +08:00
										 |  |  | angular.module('kibana.controllers', []) | 
					
						
							| 
									
										
										
										
											2013-02-12 23:42:31 +08:00
										 |  |  | .controller('DashCtrl', function($scope, $rootScope, ejsResource, timer) { | 
					
						
							| 
									
										
										
										
											2013-01-26 12:10:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   $scope.config = config; | 
					
						
							| 
									
										
										
										
											2013-02-13 07:25:39 +08:00
										 |  |  |   $scope._ = _; | 
					
						
							| 
									
										
										
										
											2013-02-12 23:42:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-14 03:23:24 +08:00
										 |  |  |   // The global dashboards object should be moved to an $http request for json
 | 
					
						
							| 
									
										
										
										
											2013-02-13 07:25:39 +08:00
										 |  |  |   if (Modernizr.localstorage &&  | 
					
						
							|  |  |  |     !(_.isUndefined(localStorage['dashboard'])) && | 
					
						
							|  |  |  |     localStorage['dashboard'] !== '' | 
					
						
							|  |  |  |   ) { | 
					
						
							| 
									
										
										
										
											2013-02-12 23:42:31 +08:00
										 |  |  |     $scope.dashboards = JSON.parse(localStorage['dashboard']); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     $scope.dashboards = dashboards; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-02-06 05:30:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-26 12:10:28 +08:00
										 |  |  |   var ejs = $scope.ejs = ejsResource(config.elasticsearch);   | 
					
						
							| 
									
										
										
										
											2013-02-02 05:16:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-12 23:42:31 +08:00
										 |  |  |   $scope.export = function() { | 
					
						
							|  |  |  |     var blob = new Blob([angular.toJson($scope.dashboards)], {type: "application/json;charset=utf-8"}); | 
					
						
							|  |  |  |     saveAs(blob, $scope.dashboards.title+"-"+new Date().getTime()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $scope.default = function() { | 
					
						
							|  |  |  |     if (Modernizr.localstorage) { | 
					
						
							|  |  |  |       localStorage['dashboard'] = angular.toJson($scope.dashboards); | 
					
						
							|  |  |  |       alert($scope.dashboards.title + " has been set as your default dashboard") | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       alert("Sorry, your browser is too old for this functionality"); | 
					
						
							|  |  |  |     }   | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-13 07:25:39 +08:00
										 |  |  |   $scope.purge = function() { | 
					
						
							|  |  |  |     if (Modernizr.localstorage) { | 
					
						
							|  |  |  |       localStorage['dashboard'] = ''; | 
					
						
							|  |  |  |       alert('Default dashboard cleared') | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       alert("Sorry, your browser is too old for this functionality"); | 
					
						
							|  |  |  |     }   | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | .controller('RowCtrl', function($scope, $rootScope, $timeout, ejsResource, timer) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-14 03:23:24 +08:00
										 |  |  |   $scope.init = function(){ | 
					
						
							|  |  |  |     $scope.reset_panel(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-13 07:25:39 +08:00
										 |  |  |   $scope.toggle_row = function(row) { | 
					
						
							|  |  |  |     row.collapse = row.collapse ? false : true; | 
					
						
							|  |  |  |     if (!row.collapse) { | 
					
						
							|  |  |  |       $timeout(function() { | 
					
						
							|  |  |  |         $scope.$broadcast('render') | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-14 03:23:24 +08:00
										 |  |  |   $scope.add_panel = function(row,panel) { | 
					
						
							|  |  |  |     console.log(panel) | 
					
						
							|  |  |  |     $scope.row.panels.push(panel); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $scope.reset_panel = function() { | 
					
						
							|  |  |  |     $scope.panel = { | 
					
						
							|  |  |  |       span: 1, | 
					
						
							|  |  |  |       editable: true, | 
					
						
							|  |  |  |       groups: ['default'], | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $scope.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-26 12:10:28 +08:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |