mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 02:23:31 -06:00
ES and file loading is working
This commit is contained in:
parent
5f3991127b
commit
d5882f2efe
@ -86,7 +86,7 @@ function (angular, $, _, appLevelRequire, config) {
|
||||
'directives/all',
|
||||
'filters/all',
|
||||
'components/partials',
|
||||
'routes/dashboard-loader',
|
||||
'routes/all',
|
||||
], function () {
|
||||
|
||||
// bootstrap the app
|
||||
|
@ -30,13 +30,32 @@ function (angular, $, config, _) {
|
||||
|
||||
var module = angular.module('kibana.controllers');
|
||||
|
||||
module.controller('DashCtrl', function($scope, $rootScope, dashboardKeybindings) {
|
||||
module.controller('DashCtrl', function(
|
||||
$scope, $rootScope, dashboardKeybindings, filterSrv, dashboard, panelMoveSrv) {
|
||||
|
||||
$scope.editor = { index: 0 };
|
||||
|
||||
$scope.init = function() {
|
||||
$scope.reset_row();
|
||||
dashboardKeybindings.shortcuts();
|
||||
|
||||
$scope.onAppEvent('setup-dashboard', $scope.setupDashboard, $scope);
|
||||
};
|
||||
|
||||
$scope.setupDashboard = function(event, dashboardData) {
|
||||
$scope.dashboard = dashboard.create(dashboardData);
|
||||
$scope.filter = filterSrv;
|
||||
$scope.filter.init($scope.dashboard);
|
||||
|
||||
var panelMove = panelMoveSrv.create($scope.dashboard);
|
||||
|
||||
$scope.panelMoveDrop = panelMove.onDrop;
|
||||
$scope.panelMoveStart = panelMove.onStart;
|
||||
$scope.panelMoveStop = panelMove.onStop;
|
||||
$scope.panelMoveOver = panelMove.onOver;
|
||||
$scope.panelMoveOut = panelMove.onOut;
|
||||
|
||||
$scope.emitAppEvent("dashboard-loaded", $scope.dashboard);
|
||||
};
|
||||
|
||||
$scope.isPanel = function(obj) {
|
||||
|
35
src/app/controllers/grafanaCtrl.js
Normal file
35
src/app/controllers/grafanaCtrl.js
Normal file
@ -0,0 +1,35 @@
|
||||
define([
|
||||
'angular',
|
||||
'config',
|
||||
'underscore',
|
||||
],
|
||||
function (angular, config, _) {
|
||||
"use strict";
|
||||
|
||||
var module = angular.module('kibana.controllers');
|
||||
|
||||
module.controller('GrafanaCtrl', function($scope, alertSrv, grafanaVersion, $rootScope) {
|
||||
|
||||
$scope.grafanaVersion = grafanaVersion[0] === '@' ? 'master' : grafanaVersion;
|
||||
|
||||
$scope.init = function() {
|
||||
$scope._ = _;
|
||||
$scope.dashAlerts = alertSrv;
|
||||
|
||||
// Clear existing alerts
|
||||
alertSrv.clearAll();
|
||||
};
|
||||
|
||||
$scope.onAppEvent = function(name, callback, scope) {
|
||||
var unbind = $rootScope.$on(name, callback);
|
||||
scope.$on('$destroy', unbind);
|
||||
};
|
||||
|
||||
$scope.emitAppEvent = function(name, payload) {
|
||||
$rootScope.$emit(name, payload);
|
||||
};
|
||||
|
||||
$scope.init();
|
||||
|
||||
});
|
||||
});
|
@ -17,7 +17,7 @@ function (angular, _, config, $) {
|
||||
$scope.selectedIndex = -1;
|
||||
$scope.results = {dashboards: [], tags: [], metrics: []};
|
||||
$scope.query = { query: 'title:' };
|
||||
$scope.$onRootScope('open-search', $scope.openSearch, $scope);
|
||||
$scope.onAppEvent('open-search', $scope.openSearch, $scope);
|
||||
};
|
||||
|
||||
$scope.keyDown = function (evt) {
|
||||
|
5
src/app/routes/all.js
Normal file
5
src/app/routes/all.js
Normal file
@ -0,0 +1,5 @@
|
||||
define([
|
||||
'./dashboard-from-es',
|
||||
'./dashboard-from-file'
|
||||
],
|
||||
function () {});
|
120
src/app/routes/dashboard-from-es.js
Normal file
120
src/app/routes/dashboard-from-es.js
Normal file
@ -0,0 +1,120 @@
|
||||
define([
|
||||
'angular',
|
||||
'jquery',
|
||||
'config',
|
||||
'underscore'
|
||||
],
|
||||
function (angular, $, config, _) {
|
||||
"use strict";
|
||||
|
||||
var module = angular.module('kibana.routes');
|
||||
|
||||
module.config(function($routeProvider) {
|
||||
$routeProvider
|
||||
.when('/dashboard/elasticsearch/:id', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromElasticProvider',
|
||||
})
|
||||
.when('/dashboard/file/:jsonFile', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromFileProvider',
|
||||
});
|
||||
});
|
||||
|
||||
module.controller('DashFromElasticProvider', function($scope, $rootScope, $http, $routeParams, alertSrv) {
|
||||
|
||||
var elasticsearch_load = function(id) {
|
||||
var url = config.elasticsearch + "/" + config.grafana_index + "/dashboard/" + id;
|
||||
|
||||
var options = {
|
||||
url: url +'?' + new Date().getTime(),
|
||||
method: "GET",
|
||||
transformResponse: function(response) {
|
||||
var dashJson = angular.fromJson(response)._source.dashboard;
|
||||
return angular.fromJson(dashJson);
|
||||
}
|
||||
};
|
||||
|
||||
if (config.elasticsearchBasicAuth) {
|
||||
options.withCredentials = true;
|
||||
options.headers = {
|
||||
"Authorization": "Basic " + config.elasticsearchBasicAuth
|
||||
};
|
||||
}
|
||||
|
||||
return $http(options)
|
||||
.error(function(data, status) {
|
||||
if(status === 0) {
|
||||
alertSrv.set('Error',"Could not contact Elasticsearch at " +
|
||||
config.elasticsearch + ". Please ensure that Elasticsearch is reachable from your browser.",'error');
|
||||
} else {
|
||||
alertSrv.set('Error',"Could not find dashboard " + id, 'error');
|
||||
}
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
elasticsearch_load($routeParams.id).then(function(result) {
|
||||
$scope.emitAppEvent('setup-dashboard', result.data);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
module.controller('DashFromFileProvider', function(
|
||||
$scope, $rootScope, $http, $routeParams, alertSrv, dashboard, filterSrv, panelMoveSrv) {
|
||||
|
||||
$scope.init = function() {
|
||||
|
||||
file_load($routeParams.jsonFile).then(function(data) {
|
||||
$scope.dashboard = dashboard.create(data);
|
||||
$scope.filter = filterSrv;
|
||||
$scope.filter.init($scope.dashboard);
|
||||
|
||||
var panelMove = panelMoveSrv.create($scope.dashboard);
|
||||
// For moving stuff around the dashboard.
|
||||
$scope.panelMoveDrop = panelMove.onDrop;
|
||||
$scope.panelMoveStart = panelMove.onStart;
|
||||
$scope.panelMoveStop = panelMove.onStop;
|
||||
$scope.panelMoveOver = panelMove.onOver;
|
||||
$scope.panelMoveOut = panelMove.onOut;
|
||||
|
||||
$rootScope.$emit("dashboard-loaded", $scope.dashboard);
|
||||
});
|
||||
};
|
||||
|
||||
var renderTemplate = function(json,params) {
|
||||
var _r;
|
||||
_.templateSettings = {interpolate : /\{\{(.+?)\}\}/g};
|
||||
var template = _.template(json);
|
||||
var rendered = template({ARGS:params});
|
||||
try {
|
||||
_r = angular.fromJson(rendered);
|
||||
} catch(e) {
|
||||
_r = false;
|
||||
}
|
||||
return _r;
|
||||
};
|
||||
|
||||
var file_load = function(file) {
|
||||
return $http({
|
||||
url: "app/dashboards/"+file.replace(/\.(?!json)/,"/")+'?' + new Date().getTime(),
|
||||
method: "GET",
|
||||
transformResponse: function(response) {
|
||||
return renderTemplate(response,$routeParams);
|
||||
}
|
||||
}).then(function(result) {
|
||||
if(!result) {
|
||||
return false;
|
||||
}
|
||||
return result.data;
|
||||
},function() {
|
||||
alertSrv.set('Error',"Could not load <i>dashboards/"+file+"</i>. Please make sure it exists" ,'error');
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.init();
|
||||
|
||||
});
|
||||
|
||||
});
|
@ -17,27 +17,7 @@ function (angular, $, config, _) {
|
||||
});
|
||||
});
|
||||
|
||||
module.controller('DashFromFileProvider', function(
|
||||
$scope, $rootScope, $http, $routeParams, alertSrv, dashboard, filterSrv, panelMoveSrv) {
|
||||
|
||||
$scope.init = function() {
|
||||
|
||||
file_load($routeParams.jsonFile).then(function(data) {
|
||||
$scope.dashboard = dashboard.create(data);
|
||||
$scope.filter = filterSrv;
|
||||
$scope.filter.init($scope.dashboard);
|
||||
|
||||
var panelMove = panelMoveSrv.create($scope.dashboard);
|
||||
// For moving stuff around the dashboard.
|
||||
$scope.panelMoveDrop = panelMove.onDrop;
|
||||
$scope.panelMoveStart = panelMove.onStart;
|
||||
$scope.panelMoveStop = panelMove.onStop;
|
||||
$scope.panelMoveOver = panelMove.onOver;
|
||||
$scope.panelMoveOut = panelMove.onOut;
|
||||
|
||||
$rootScope.$emit("dashboard-loaded", $scope.dashboard);
|
||||
});
|
||||
};
|
||||
module.controller('DashFromFileProvider', function($scope, $rootScope, $http, $routeParams, alertSrv) {
|
||||
|
||||
var renderTemplate = function(json,params) {
|
||||
var _r;
|
||||
@ -70,7 +50,9 @@ function (angular, $, config, _) {
|
||||
});
|
||||
};
|
||||
|
||||
$scope.init();
|
||||
file_load($routeParams.jsonFile).then(function(result) {
|
||||
$scope.emitAppEvent('setup-dashboard', result);
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user