mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Worked on loading a home dashboard through backend
This commit is contained in:
parent
a127f2d572
commit
bc673fd969
@ -20,7 +20,7 @@ function (angular, _, $, config) {
|
|||||||
text: "Dashbords",
|
text: "Dashbords",
|
||||||
icon: "fa fa-th-large",
|
icon: "fa fa-th-large",
|
||||||
href: $scope.getUrl("/"),
|
href: $scope.getUrl("/"),
|
||||||
startsWith: config.appSubUrl + '/dashboard/',
|
//startsWith: config.appSubUrl + '/dashboard/',
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.menu.push({
|
$scope.menu.push({
|
||||||
|
@ -19,13 +19,13 @@ function (angular, _, kbn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GrafanaDatasource.prototype.getDashboard = function(slug, isTemp) {
|
GrafanaDatasource.prototype.getDashboard = function(slug, isTemp) {
|
||||||
var url = '/dashboard/' + slug;
|
var url = '/dashboards/' + slug;
|
||||||
|
|
||||||
if (isTemp) {
|
if (isTemp) {
|
||||||
url = '/temp/' + slug;
|
url = '/temp/' + slug;
|
||||||
}
|
}
|
||||||
|
|
||||||
return backendSrv.get('/api/dashboard/' + slug);
|
return backendSrv.get('/api/dashboards/db/' + slug);
|
||||||
};
|
};
|
||||||
|
|
||||||
GrafanaDatasource.prototype.query = function(options) {
|
GrafanaDatasource.prototype.query = function(options) {
|
||||||
@ -50,7 +50,7 @@ function (angular, _, kbn) {
|
|||||||
dashboard.id = null;
|
dashboard.id = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return backendSrv.post('/api/dashboard/', { dashboard: dashboard })
|
return backendSrv.post('/api/dashboards/db/', { dashboard: dashboard })
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
return { title: dashboard.title, url: '/dashboard/db/' + data.slug };
|
return { title: dashboard.title, url: '/dashboard/db/' + data.slug };
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
@ -61,7 +61,7 @@ function (angular, _, kbn) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
GrafanaDatasource.prototype.deleteDashboard = function(id) {
|
GrafanaDatasource.prototype.deleteDashboard = function(id) {
|
||||||
return backendSrv.delete('/api/dashboard/' + id);
|
return backendSrv.delete('/api/dashboards/db/' + id);
|
||||||
};
|
};
|
||||||
|
|
||||||
GrafanaDatasource.prototype.searchDashboards = function(query) {
|
GrafanaDatasource.prototype.searchDashboards = function(query) {
|
||||||
|
@ -2,47 +2,27 @@ define([
|
|||||||
'angular',
|
'angular',
|
||||||
'store',
|
'store',
|
||||||
],
|
],
|
||||||
function (angular, store) {
|
function (angular) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var module = angular.module('grafana.routes');
|
var module = angular.module('grafana.routes');
|
||||||
|
|
||||||
// remember previous dashboard
|
module.controller('DashFromDBProvider', function($scope, datasourceSrv, $routeParams, backendSrv) {
|
||||||
var prevDashPath = null;
|
|
||||||
|
|
||||||
module.controller('DashFromDBProvider', function(
|
|
||||||
$scope, $rootScope, datasourceSrv, $routeParams,
|
|
||||||
alertSrv, $http, $location) {
|
|
||||||
|
|
||||||
var db = datasourceSrv.getGrafanaDB();
|
var db = datasourceSrv.getGrafanaDB();
|
||||||
var isTemp = window.location.href.indexOf('dashboard/temp') !== -1;
|
|
||||||
|
|
||||||
if (!$routeParams.id) {
|
if (!$routeParams.id) {
|
||||||
// do we have a previous dash
|
backendSrv.get('api/dashboards/home').then(function(result) {
|
||||||
if (prevDashPath) {
|
$scope.initDashboard(result, $scope);
|
||||||
$location.path(prevDashPath);
|
},function() {
|
||||||
return;
|
$scope.initDashboard({}, $scope);
|
||||||
}
|
$scope.appEvent('alert-error', ['Load dashboard failed', '']);
|
||||||
|
});
|
||||||
|
|
||||||
var savedRoute = store.get('grafanaDashboardDefault');
|
return;
|
||||||
if (!savedRoute) {
|
|
||||||
$http.get("app/dashboards/default.json?" + new Date().getTime()).then(function(result) {
|
|
||||||
var dashboard = angular.fromJson(result.data);
|
|
||||||
$scope.initDashboard({model: dashboard, meta: {}}, $scope);
|
|
||||||
},function() {
|
|
||||||
$scope.initDashboard({}, $scope);
|
|
||||||
$scope.appEvent('alert-error', ['Load dashboard failed', '']);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$location.path(savedRoute);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
db.getDashboard($routeParams.id, isTemp).then(function(result) {
|
db.getDashboard($routeParams.id, false).then(function(result) {
|
||||||
prevDashPath = $location.path();
|
|
||||||
$scope.initDashboard(result, $scope);
|
$scope.initDashboard(result, $scope);
|
||||||
}).then(null, function() {
|
}).then(null, function() {
|
||||||
$scope.initDashboard({
|
$scope.initDashboard({
|
||||||
|
Loading…
Reference in New Issue
Block a user