|
@@ -14,10 +14,6 @@ function (angular, $, config, _) {
|
|
|
.when('/dashboard/elasticsearch/:id', {
|
|
.when('/dashboard/elasticsearch/:id', {
|
|
|
templateUrl: 'app/partials/dashboard.html',
|
|
templateUrl: 'app/partials/dashboard.html',
|
|
|
controller : 'DashFromElasticProvider',
|
|
controller : 'DashFromElasticProvider',
|
|
|
- })
|
|
|
|
|
- .when('/dashboard/file/:jsonFile', {
|
|
|
|
|
- templateUrl: 'app/partials/dashboard.html',
|
|
|
|
|
- controller : 'DashFromFileProvider',
|
|
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -30,8 +26,12 @@ function (angular, $, config, _) {
|
|
|
url: url +'?' + new Date().getTime(),
|
|
url: url +'?' + new Date().getTime(),
|
|
|
method: "GET",
|
|
method: "GET",
|
|
|
transformResponse: function(response) {
|
|
transformResponse: function(response) {
|
|
|
- var dashJson = angular.fromJson(response)._source.dashboard;
|
|
|
|
|
- return angular.fromJson(dashJson);
|
|
|
|
|
|
|
+ var esResponse = angular.fromJson(response);
|
|
|
|
|
+ if (esResponse._source && esResponse._source.dashboard) {
|
|
|
|
|
+ return angular.fromJson(esResponse._source.dashboard);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -60,61 +60,4 @@ 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);
|
|
|
|
|
- });
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- 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();
|
|
|
|
|
-
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
});
|
|
});
|