mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
dashboards: add new default frontend route for rendering a dashboard panel
New default route /d-solo/<uid>/<slug of dashboard title> where dashboard panel are rendered by unique identifier and panel identifier. If old route /dashboard-solo/db/<slug of dashboard tile> are used, try to lookup dashboard by slug and redirect to new default route. Change url logic for sharing a panel so that the new default route for rendering a dashboard panel are used. #7883
This commit is contained in:
parent
7734df1d18
commit
3efb3d8efa
@ -73,17 +73,14 @@ export class ShareModalCtrl {
|
|||||||
|
|
||||||
$scope.shareUrl = linkSrv.addParamsToUrl(baseUrl, params);
|
$scope.shareUrl = linkSrv.addParamsToUrl(baseUrl, params);
|
||||||
|
|
||||||
var soloUrl = baseUrl.replace(config.appSubUrl + '/dashboard/', config.appSubUrl + '/dashboard-solo/');
|
var soloUrl = baseUrl.replace(config.appSubUrl + '/d/', config.appSubUrl + '/d-solo/');
|
||||||
delete params.fullscreen;
|
delete params.fullscreen;
|
||||||
delete params.edit;
|
delete params.edit;
|
||||||
soloUrl = linkSrv.addParamsToUrl(soloUrl, params);
|
soloUrl = linkSrv.addParamsToUrl(soloUrl, params);
|
||||||
|
|
||||||
$scope.iframeHtml = '<iframe src="' + soloUrl + '" width="450" height="200" frameborder="0"></iframe>';
|
$scope.iframeHtml = '<iframe src="' + soloUrl + '" width="450" height="200" frameborder="0"></iframe>';
|
||||||
|
|
||||||
$scope.imageUrl = soloUrl.replace(
|
$scope.imageUrl = soloUrl.replace(config.appSubUrl + '/d-solo/', config.appSubUrl + '/render/d-solo/');
|
||||||
config.appSubUrl + '/dashboard-solo/',
|
|
||||||
config.appSubUrl + '/render/dashboard-solo/'
|
|
||||||
);
|
|
||||||
$scope.imageUrl += '&width=1000';
|
$scope.imageUrl += '&width=1000';
|
||||||
$scope.imageUrl += '&height=500';
|
$scope.imageUrl += '&height=500';
|
||||||
$scope.imageUrl += '&tz=UTC' + encodeURIComponent(moment().format('Z'));
|
$scope.imageUrl += '&tz=UTC' + encodeURIComponent(moment().format('Z'));
|
||||||
|
@ -43,12 +43,12 @@ describe('ShareModalCtrl', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should generate render url', function() {
|
it('should generate render url', function() {
|
||||||
ctx.$location.$$absUrl = 'http://dashboards.grafana.com/dashboard/db/my-dash';
|
ctx.$location.$$absUrl = 'http://dashboards.grafana.com/d/abcdefghi/my-dash';
|
||||||
|
|
||||||
ctx.scope.panel = { id: 22 };
|
ctx.scope.panel = { id: 22 };
|
||||||
|
|
||||||
ctx.scope.init();
|
ctx.scope.init();
|
||||||
var base = 'http://dashboards.grafana.com/render/dashboard-solo/db/my-dash';
|
var base = 'http://dashboards.grafana.com/render/d-solo/abcdefghi/my-dash';
|
||||||
var params = '?from=1000&to=2000&orgId=1&panelId=22&width=1000&height=500&tz=UTC';
|
var params = '?from=1000&to=2000&orgId=1&panelId=22&width=1000&height=500&tz=UTC';
|
||||||
expect(ctx.scope.imageUrl).to.contain(base + params);
|
expect(ctx.scope.imageUrl).to.contain(base + params);
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,7 @@ import angular from 'angular';
|
|||||||
|
|
||||||
export class SoloPanelCtrl {
|
export class SoloPanelCtrl {
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor($scope, $routeParams, $location, dashboardLoaderSrv, contextSrv) {
|
constructor($scope, $routeParams, $location, dashboardLoaderSrv, contextSrv, backendSrv) {
|
||||||
var panelId;
|
var panelId;
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
@ -13,7 +13,17 @@ export class SoloPanelCtrl {
|
|||||||
|
|
||||||
$scope.onAppEvent('dashboard-initialized', $scope.initPanelScope);
|
$scope.onAppEvent('dashboard-initialized', $scope.initPanelScope);
|
||||||
|
|
||||||
dashboardLoaderSrv.loadDashboard($routeParams.type, $routeParams.slug).then(function(result) {
|
// if no uid, redirect to new route based on slug
|
||||||
|
if (!$routeParams.uid) {
|
||||||
|
backendSrv.get(`/api/dashboards/db/${$routeParams.slug}`).then(res => {
|
||||||
|
if (res) {
|
||||||
|
$location.path(res.meta.url.replace('/d/', '/d-solo/'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dashboardLoaderSrv.loadDashboard($routeParams.type, $routeParams.slug, $routeParams.uid).then(function(result) {
|
||||||
result.meta.soloMode = true;
|
result.meta.soloMode = true;
|
||||||
$scope.initDashboard(result, $scope);
|
$scope.initDashboard(result, $scope);
|
||||||
});
|
});
|
||||||
|
@ -26,6 +26,12 @@ export function setupAngularRoutes($routeProvider, $locationProvider) {
|
|||||||
reloadOnSearch: false,
|
reloadOnSearch: false,
|
||||||
pageClass: 'page-dashboard',
|
pageClass: 'page-dashboard',
|
||||||
})
|
})
|
||||||
|
.when('/d-solo/:uid/:slug', {
|
||||||
|
templateUrl: 'public/app/features/panel/partials/soloPanel.html',
|
||||||
|
controller: 'SoloPanelCtrl',
|
||||||
|
reloadOnSearch: false,
|
||||||
|
pageClass: 'page-dashboard',
|
||||||
|
})
|
||||||
.when('/dashboard-solo/:type/:slug', {
|
.when('/dashboard-solo/:type/:slug', {
|
||||||
templateUrl: 'public/app/features/panel/partials/soloPanel.html',
|
templateUrl: 'public/app/features/panel/partials/soloPanel.html',
|
||||||
controller: 'SoloPanelCtrl',
|
controller: 'SoloPanelCtrl',
|
||||||
|
Loading…
Reference in New Issue
Block a user