Commit 7bd7e3b6 by Rashid Khan

Added loading of ES stored dashboards from URL

parent 59ccc6c9
......@@ -5,6 +5,7 @@ var Settings = function (s) {
elasticsearch : 'localhost:9200',
timeformat : 'mm/dd HH:MM:ss',
modules : [],
kibana_index : 'kibana-int'
}
// This initializes a new hash on purpose, to avoid adding parameters to
......
......@@ -49,6 +49,9 @@ labjs.wait(function(){
.when('/dashboard', {
templateUrl: 'partials/dashboard.html'
})
.when('/dashboard/:type/:id', {
templateUrl: 'partials/dashboard.html'
})
.otherwise({
redirectTo: 'dashboard'
});
......
......@@ -12,35 +12,24 @@ angular.module('kibana.controllers', [])
}
$scope.init = function() {
$scope.config = config;
$scope._ = _;
$scope.reset_row();
$scope.clear_all_alerts();
// The global dashboards object should be moved to an $http request for json
if (Modernizr.localstorage &&
!(_.isUndefined(localStorage['dashboard'])) &&
localStorage['dashboard'] !== ''
) {
$scope.dashboards = JSON.parse(localStorage['dashboard']);
_.defaults($scope.dashboards,_d);
} else {
$http({
url: "default.json",
method: "GET",
}).success(function(data, status, headers, config) {
$scope.dashboards = data
_.defaults($scope.dashboards,_d);
}).error(function(data, status, headers, config) {
$scope.alert('Default dashboard missing!','Could not locate default.json','error')
});
}
// Load dashboard by event
eventBus.register($scope,'dashboard', function(event,dashboard){
console.log(dashboard)
$scope.dashboards = dashboard;
_.defaults($scope.dashboards,_d)
})
// If the route changes, clear the existing dashboard
$rootScope.$on( "$routeChangeStart", function(event, next, current) {
delete $scope.dashboards
});
var ejs = $scope.ejs = ejsResource(config.elasticsearch);
}
......
angular.module('kibana.dashcontrol', [])
.controller('dashcontrol', function($scope, $http, eventBus, timer) {
.controller('dashcontrol', function($scope, $routeParams, $http, eventBus, timer) {
$scope.panel = $scope.panel || {};
// Set and populate defaults
var _d = {
group : "default",
......@@ -16,11 +16,55 @@ angular.module('kibana.dashcontrol', [])
local: true,
},
elasticsearch_size: 20,
elasticsearch_saveto: 'kibana-int'
elasticsearch_saveto: $scope.config.kibana_index,
}
_.defaults($scope.panel,_d);
$scope.init = function() {
// A hash of defaults for the dashboard object
var _dash = {
title: "",
editable: true,
rows: [],
}
// Long ugly if statement for figuring out which dashboard to load on init
// If there is no dashboard defined, find one
if(_.isUndefined($scope.dashboards)) {
// First check the URL for a path to a dashboard
if(!(_.isUndefined($routeParams.type)) && !(_.isUndefined($routeParams.id))) {
var _type = $routeParams.type;
var _id = $routeParams.id;
if(_type === 'elasticsearch') {
$scope.elasticsearch_load(_id)
}
// No dashboard in the URL
} else {
// Check if browser supports localstorage, and if there's a dashboard
if (Modernizr.localstorage &&
!(_.isUndefined(localStorage['dashboard'])) &&
localStorage['dashboard'] !== ''
) {
var dashboard = JSON.parse(localStorage['dashboard']);
_.defaults(dashboard,_dash);
// No? Ok, grab default.json, its all we have now
} else {
$http({
url: "default.json",
method: "GET",
}).success(function(data, status, headers, config) {
var dashboard = data
_.defaults(dashboard,_dash);
}).error(function(data, status, headers, config) {
$scope.alert('Default dashboard missing!','Could not locate default.json','error')
});
}
// Load whatever we have
$scope.dash_load(dashboard)
}
}
$scope.gist_pattern = /(^\d{5,}$)|(^[a-z0-9]{10,}$)|(gist.github.com(\/*.*)\/[a-z0-9]{5,}\/*$)/;
$scope.gist = {};
$scope.elasticsearch = {};
......@@ -81,6 +125,21 @@ angular.module('kibana.dashcontrol', [])
})
}
$scope.elasticsearch_load = function(id) {
var request = $scope.ejs.Request().indices($scope.panel.elasticsearch_saveto).types('dashboard');
var results = request.query(
$scope.ejs.IdsQuery(id)
).size($scope.panel.elasticsearch_size).doSearch();
results.then(function(results) {
if(_.isUndefined(results)) {
$scope.panel.error = 'Your query was unsuccessful';
return;
}
$scope.panel.error = false;
$scope.dash_load(results.hits.hits[0]['_source']['dashboard'])
});
}
$scope.elasticsearch_dblist = function(query) {
if($scope.panel.load.elasticsearch) {
var request = $scope.ejs.Request().indices($scope.panel.elasticsearch_saveto).types('dashboard');
......
<div class="row-fluid container" style="margin-top:50px">
<!-- Rows -->
<div ng-controller="dashcontrol"></div>
<div class="row-fluid" ng-controller="RowCtrl" ng-repeat="(row_name, row) in dashboards.rows">
<div class="span12">
<div class="row-fluid row-header" style="padding:0px;margin:0px;height:0px">
......
<div style="margin-top:50px" ng-controller="dashcontrol">
<strong>type: </strong>{{type}} <br>
<strong>id: </strong>{{id}} <br>
</div>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment