Просмотр исходного кода

Share link should always have absolute time range, Closes #2060

Torkel Ödegaard 10 лет назад
Родитель
Сommit
aeb8bc8755
2 измененных файлов с 9 добавлено и 23 удалено
  1. 3 3
      public/app/features/dashboard/shareModalCtrl.js
  2. 6 20
      public/test/specs/shareModalCtrl-specs.js

+ 3 - 3
public/app/features/dashboard/shareModalCtrl.js

@@ -43,9 +43,9 @@ function (angular, _, require, config) {
 
 
       var params = angular.copy($location.search());
       var params = angular.copy($location.search());
 
 
-      var range = timeSrv.timeRangeForUrl();
-      params.from = range.from;
-      params.to = range.to;
+      var range = timeSrv.timeRange();
+      params.from = range.from.getTime();
+      params.to = range.to.getTime();
 
 
       if ($scope.options.includeTemplateVars) {
       if ($scope.options.includeTemplateVars) {
         templateSrv.fillVariableValuesForUrl(params);
         templateSrv.fillVariableValuesForUrl(params);

+ 6 - 20
public/test/specs/shareModalCtrl-specs.js

@@ -9,10 +9,10 @@ define([
     var ctx = new helpers.ControllerTestContext();
     var ctx = new helpers.ControllerTestContext();
 
 
     function setTime(range) {
     function setTime(range) {
-      ctx.timeSrv.timeRangeForUrl = sinon.stub().returns(range);
+      ctx.timeSrv.timeRange = sinon.stub().returns(range);
     }
     }
 
 
-    setTime({ from: 'now-1h', to: 'now' });
+    setTime({ from: new Date(1000), to: new Date(2000) });
 
 
     beforeEach(module('grafana.controllers'));
     beforeEach(module('grafana.controllers'));
     beforeEach(module('grafana.services'));
     beforeEach(module('grafana.services'));
@@ -23,57 +23,43 @@ define([
 
 
     describe('shareUrl with current time range and panel', function() {
     describe('shareUrl with current time range and panel', function() {
 
 
-      it('should generate share url relative time', function() {
-        ctx.$location.path('/test');
-        ctx.scope.panel = { id: 22 };
-
-        setTime({ from: 'now-1h', to: 'now' });
-
-        ctx.scope.init();
-        expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now&panelId=22&fullscreen');
-      });
-
       it('should generate share url absolute time', function() {
       it('should generate share url absolute time', function() {
         ctx.$location.path('/test');
         ctx.$location.path('/test');
         ctx.scope.panel = { id: 22 };
         ctx.scope.panel = { id: 22 };
-        setTime({ from: 1362178800000, to: 1396648800000 });
 
 
         ctx.scope.init();
         ctx.scope.init();
-        expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1362178800000&to=1396648800000&panelId=22&fullscreen');
+        expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1000&to=2000&panelId=22&fullscreen');
       });
       });
 
 
       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;
         ctx.scope.panel = null;
         ctx.scope.panel = null;
-        setTime({ from: 'now-1h', to: 'now' });
 
 
         ctx.scope.init();
         ctx.scope.init();
-        expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now');
+        expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1000&to=2000');
       });
       });
 
 
       it('should add theme when specified', function() {
       it('should add theme when specified', function() {
         ctx.$location.path('/test');
         ctx.$location.path('/test');
         ctx.scope.options.theme = 'light';
         ctx.scope.options.theme = 'light';
         ctx.scope.panel = null;
         ctx.scope.panel = null;
-        setTime({ from: 'now-1h', to: 'now' });
 
 
         ctx.scope.init();
         ctx.scope.init();
-        expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now&theme=light');
+        expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1000&to=2000&theme=light');
       });
       });
 
 
       it('should include template variables in url', function() {
       it('should include template variables in url', function() {
         ctx.$location.path('/test');
         ctx.$location.path('/test');
         ctx.scope.options.includeTemplateVars = true;
         ctx.scope.options.includeTemplateVars = true;
 
 
-        setTime({ from: 'now-1h', to: 'now' });
         ctx.templateSrv.fillVariableValuesForUrl = function(params) {
         ctx.templateSrv.fillVariableValuesForUrl = function(params) {
           params['var-app'] = 'mupp';
           params['var-app'] = 'mupp';
           params['var-server'] = 'srv-01';
           params['var-server'] = 'srv-01';
         };
         };
 
 
         ctx.scope.buildUrl();
         ctx.scope.buildUrl();
-        expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now&var-app=mupp&var-server=srv-01');
+        expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1000&to=2000&var-app=mupp&var-server=srv-01');
       });
       });
 
 
     });
     });