Jelajahi Sumber

dashboards: make scripted dashboards work using the old legacy urls

Scripted dashboards are still requested from /dashboard/script/scripted.js
#7883
Marcus Efraimsson 8 tahun lalu
induk
melakukan
57edf89033

+ 2 - 0
pkg/api/api.go

@@ -67,9 +67,11 @@ func (hs *HttpServer) registerRoutes() {
 
 
 	r.Get("/d/:uid/:slug", reqSignedIn, Index)
 	r.Get("/d/:uid/:slug", reqSignedIn, Index)
 	r.Get("/dashboard/db/:slug", reqSignedIn, redirectFromLegacyDashboardUrl, Index)
 	r.Get("/dashboard/db/:slug", reqSignedIn, redirectFromLegacyDashboardUrl, Index)
+	r.Get("/dashboard/script/*", reqSignedIn, Index)
 	r.Get("/dashboard-solo/snapshot/*", Index)
 	r.Get("/dashboard-solo/snapshot/*", Index)
 	r.Get("/d-solo/:uid/:slug", reqSignedIn, Index)
 	r.Get("/d-solo/:uid/:slug", reqSignedIn, Index)
 	r.Get("/dashboard-solo/db/:slug", reqSignedIn, redirectFromLegacyDashboardSoloUrl, Index)
 	r.Get("/dashboard-solo/db/:slug", reqSignedIn, redirectFromLegacyDashboardSoloUrl, Index)
+	r.Get("/dashboard-solo/script/*", reqSignedIn, Index)
 	r.Get("/import/dashboard", reqSignedIn, Index)
 	r.Get("/import/dashboard", reqSignedIn, Index)
 	r.Get("/dashboards/", reqSignedIn, Index)
 	r.Get("/dashboards/", reqSignedIn, Index)
 	r.Get("/dashboards/*", reqSignedIn, Index)
 	r.Get("/dashboards/*", reqSignedIn, Index)

+ 7 - 2
public/app/features/dashboard/shareModalCtrl.ts

@@ -73,14 +73,19 @@ export class ShareModalCtrl {
 
 
       $scope.shareUrl = linkSrv.addParamsToUrl(baseUrl, params);
       $scope.shareUrl = linkSrv.addParamsToUrl(baseUrl, params);
 
 
-      var soloUrl = baseUrl.replace(config.appSubUrl + '/d/', config.appSubUrl + '/d-solo/');
+      var soloUrl = baseUrl.replace(config.appSubUrl + '/dashboard/', config.appSubUrl + '/dashboard-solo/');
+      soloUrl = soloUrl.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(config.appSubUrl + '/d-solo/', config.appSubUrl + '/render/d-solo/');
+      $scope.imageUrl = soloUrl.replace(
+        config.appSubUrl + '/dashboard-solo/',
+        config.appSubUrl + '/render/dashboard-solo/'
+      );
+      $scope.imageUrl = $scope.imageUrl.replace(config.appSubUrl + '/d-solo/', config.appSubUrl + '/render/d-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'));

+ 11 - 0
public/app/features/dashboard/specs/share_modal_ctrl_specs.ts

@@ -53,6 +53,17 @@ describe('ShareModalCtrl', function() {
       expect(ctx.scope.imageUrl).to.contain(base + params);
       expect(ctx.scope.imageUrl).to.contain(base + params);
     });
     });
 
 
+    it('should generate render url for scripted dashboard', function() {
+      ctx.$location.$$absUrl = 'http://dashboards.grafana.com/dashboard/script/my-dash.js';
+
+      ctx.scope.panel = { id: 22 };
+
+      ctx.scope.init();
+      var base = 'http://dashboards.grafana.com/render/dashboard-solo/script/my-dash.js';
+      var params = '?from=1000&to=2000&orgId=1&panelId=22&width=1000&height=500&tz=UTC';
+      expect(ctx.scope.imageUrl).to.contain(base + params);
+    });
+
     it('should remove panel id when no panel in scope', function() {
     it('should remove panel id when no panel in scope', function() {
       ctx.$location.path('/test');
       ctx.$location.path('/test');
       ctx.scope.options.forCurrent = true;
       ctx.scope.options.forCurrent = true;

+ 1 - 1
public/app/features/panel/solo_panel_ctrl.ts

@@ -14,7 +14,7 @@ export class SoloPanelCtrl {
       $scope.onAppEvent('dashboard-initialized', $scope.initPanelScope);
       $scope.onAppEvent('dashboard-initialized', $scope.initPanelScope);
 
 
       // if no uid, redirect to new route based on slug
       // if no uid, redirect to new route based on slug
-      if (!$routeParams.uid) {
+      if (!($routeParams.type === 'script' || $routeParams.type === 'snapshot') && !$routeParams.uid) {
         backendSrv.get(`/api/dashboards/db/${$routeParams.slug}`).then(res => {
         backendSrv.get(`/api/dashboards/db/${$routeParams.slug}`).then(res => {
           if (res) {
           if (res) {
             $location.path(res.meta.url.replace('/d/', '/d-solo/'));
             $location.path(res.meta.url.replace('/d/', '/d-solo/'));

+ 1 - 1
public/app/routes/dashboard_loaders.ts

@@ -19,7 +19,7 @@ export class LoadDashboardCtrl {
     }
     }
 
 
     // if no uid, redirect to new route based on slug
     // if no uid, redirect to new route based on slug
-    if (!$routeParams.uid) {
+    if (!($routeParams.type === 'script' || $routeParams.type === 'snapshot') && !$routeParams.uid) {
       backendSrv.get(`/api/dashboards/db/${$routeParams.slug}`).then(res => {
       backendSrv.get(`/api/dashboards/db/${$routeParams.slug}`).then(res => {
         if (res) {
         if (res) {
           $location.path(res.meta.url);
           $location.path(res.meta.url);