Commit c42d09b2 by Torkel Ödegaard

Enabled snapshot sharing of single panels, enabled sharing of snapshot…

Enabled snapshot sharing of single panels, enabled sharing of snapshot dashboards (but you cannot snapshot a snapshot
parent 0f791c9f
...@@ -78,6 +78,19 @@ function (angular, $, kbn, _, moment) { ...@@ -78,6 +78,19 @@ function (angular, $, kbn, _, moment) {
} }
}; };
p.getPanelById = function(id) {
for (var i = 0; i < this.rows.length; i++) {
var row = this.rows[i];
for (var j = 0; j < row.panels.length; j++) {
var panel = row.panels[j];
if (panel.id === id) {
return panel;
}
}
}
return null;
};
p.rowSpan = function(row) { p.rowSpan = function(row) {
return _.reduce(row.panels, function(p,v) { return _.reduce(row.panels, function(p,v) {
return p + v.span; return p + v.span;
......
<div class="modal-body gf-box gf-box-no-margin" ng-controller="ShareModalCtrl"> <div class="modal-body gf-box gf-box-no-margin" ng-controller="ShareModalCtrl" ng-init="init()">
<div class="gf-box-header"> <div class="gf-box-header">
<div class="gf-box-title"> <div class="gf-box-title">
<i class="fa fa-share"></i> <i class="fa fa-share"></i>
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
<input type="text" data-share-panel-url class="input" ng-model='shareUrl'></input> <input type="text" data-share-panel-url class="input" ng-model='shareUrl'></input>
</span> </span>
</div> </div>
<div class="editor-row" style="margin-top: 5px;" ng-show="options.toPanel"> <div class="editor-row" style="margin-top: 5px;" ng-show="modeSharePanel">
<a href="{{imageUrl}}" target="_blank"><i class="fa fa-camera"></i> Direct link rendered image</a> <a href="{{imageUrl}}" target="_blank"><i class="fa fa-camera"></i> Direct link rendered image</a>
</div> </div>
</div> </div>
......
...@@ -13,22 +13,20 @@ function (angular, _, require, config) { ...@@ -13,22 +13,20 @@ function (angular, _, require, config) {
$scope.init = function() { $scope.init = function() {
$scope.editor = { index: 0 }; $scope.editor = { index: 0 };
$scope.options = { $scope.options = { forCurrent: true, includeTemplateVars: true };
forCurrent: true, $scope.modeSharePanel = $scope.panel ? true : false;
toPanel: $scope.panel ? true : false,
includeTemplateVars: true
};
$scope.tabs = [{title: 'Link', src: 'shareLink.html'}]; $scope.tabs = [{title: 'Link', src: 'shareLink.html'}];
if ($scope.options.toPanel) { if ($scope.modeSharePanel) {
$scope.modalTitle = 'Share Panel'; $scope.modalTitle = 'Share Panel';
$scope.tabs.push({title: 'Embed', src: 'shareEmbed.html'}); $scope.tabs.push({title: 'Embed', src: 'shareEmbed.html'});
} else { } else {
$scope.modalTitle = 'Share Dashboard'; $scope.modalTitle = 'Share Dashboard';
if (!$scope.dashboardMeta.isSnapshot) { }
$scope.tabs.push({title: 'Snapshot sharing', src: 'shareSnapshot.html'});
} if (!$scope.dashboardMeta.isSnapshot) {
$scope.tabs.push({title: 'Snapshot sharing', src: 'shareSnapshot.html'});
} }
$scope.buildUrl(); $scope.buildUrl();
...@@ -64,7 +62,7 @@ function (angular, _, require, config) { ...@@ -64,7 +62,7 @@ function (angular, _, require, config) {
delete params.to; delete params.to;
} }
if ($scope.options.toPanel) { if ($scope.modeSharePanel) {
params.panelId = $scope.panel.id; params.panelId = $scope.panel.id;
params.fullscreen = true; params.fullscreen = true;
} else { } else {
...@@ -97,8 +95,6 @@ function (angular, _, require, config) { ...@@ -97,8 +95,6 @@ function (angular, _, require, config) {
$scope.imageUrl += '&height=500'; $scope.imageUrl += '&height=500';
}; };
$scope.init();
}); });
module.directive('clipboardButton',function() { module.directive('clipboardButton',function() {
......
...@@ -44,34 +44,12 @@ function (angular, _) { ...@@ -44,34 +44,12 @@ function (angular, _) {
$timeout(function() { $timeout(function() {
$scope.saveSnapshot(external); $scope.saveSnapshot(external);
}, 3000); }, 4000);
}; };
$scope.saveSnapshot = function(external) { $scope.saveSnapshot = function(external) {
var dash = angular.copy($scope.dashboard); var dash = angular.copy($scope.dashboard);
// change title $scope.scrubDashboard(dash);
dash.title = $scope.snapshot.name;
// make relative times absolute
dash.time = timeSrv.timeRange();
// remove panel queries & links
dash.forEachPanel(function(panel) {
panel.targets = [];
panel.links = [];
});
// remove annotations
dash.annotations.list = [];
// remove template queries
_.each(dash.templating.list, function(variable) {
variable.query = "";
variable.options = [];
variable.refresh = false;
});
// cleanup snapshotData
delete $scope.dashboard.snapshot;
$scope.dashboard.forEachPanel(function(panel) {
delete panel.snapshotData;
});
var cmdData = { var cmdData = {
dashboard: dash, dashboard: dash,
...@@ -99,6 +77,38 @@ function (angular, _) { ...@@ -99,6 +77,38 @@ function (angular, _) {
}); });
}; };
$scope.scrubDashboard = function(dash) {
// change title
dash.title = $scope.snapshot.name;
// make relative times absolute
dash.time = timeSrv.timeRange();
// remove panel queries & links
dash.forEachPanel(function(panel) {
panel.targets = [];
panel.links = [];
});
// remove annotations
dash.annotations.list = [];
// remove template queries
_.each(dash.templating.list, function(variable) {
variable.query = "";
variable.options = [];
variable.refresh = false;
});
// snapshot single panel
if ($scope.modeSharePanel) {
var singlePanel = dash.getPanelById($scope.panel.id);
dash.rows = [{ height: '500px', span: 12, panels: [singlePanel] }];
}
// cleanup snapshotData
delete $scope.dashboard.snapshot;
$scope.dashboard.forEachPanel(function(panel) {
delete panel.snapshotData;
});
};
$scope.saveExternalSnapshotRef = function(cmdData, results) { $scope.saveExternalSnapshotRef = function(cmdData, results) {
// save external in local instance as well // save external in local instance as well
cmdData.external = true; cmdData.external = true;
......
...@@ -49,7 +49,7 @@ function (angular, $) { ...@@ -49,7 +49,7 @@ function (angular, $) {
$scope.test = "Hej"; $scope.test = "Hej";
$scope.$index = 0; $scope.$index = 0;
$scope.panel = $scope.getPanelById(panelId); $scope.panel = $scope.dashboard.getPanelById(panelId);
if (!$scope.panel) { if (!$scope.panel) {
$scope.appEvent('alert-error', ['Panel not found', '']); $scope.appEvent('alert-error', ['Panel not found', '']);
...@@ -63,20 +63,6 @@ function (angular, $) { ...@@ -63,20 +63,6 @@ function (angular, $) {
templateValuesSrv.init($scope.dashboard, $scope.dashboardViewState); templateValuesSrv.init($scope.dashboard, $scope.dashboardViewState);
}; };
$scope.getPanelById = function(id) {
var rows = $scope.dashboard.rows;
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
for (var j = 0; j < row.panels.length; j++) {
var panel = row.panels[j];
if (panel.id === id) {
return panel;
}
}
}
return null;
};
if (!$scope.skipAutoInit) { if (!$scope.skipAutoInit) {
$scope.init(); $scope.init();
} }
......
...@@ -44,6 +44,7 @@ define([ ...@@ -44,6 +44,7 @@ define([
self.scope.panel = {}; self.scope.panel = {};
self.scope.row = { panels:[] }; self.scope.row = { panels:[] };
self.scope.dashboard = {}; self.scope.dashboard = {};
self.scope.dashboardMeta = {};
self.scope.dashboardViewState = new DashboardViewStateStub(); self.scope.dashboardViewState = new DashboardViewStateStub();
self.scope.appEvent = sinon.spy(); self.scope.appEvent = sinon.spy();
self.scope.onAppEvent = sinon.spy(); self.scope.onAppEvent = sinon.spy();
......
...@@ -4,7 +4,7 @@ define([ ...@@ -4,7 +4,7 @@ define([
], function(helpers) { ], function(helpers) {
'use strict'; 'use strict';
describe('SharePanelCtrl', function() { describe('ShareModalCtrl', function() {
var ctx = new helpers.ControllerTestContext(); var ctx = new helpers.ControllerTestContext();
function setTime(range) { function setTime(range) {
...@@ -26,7 +26,7 @@ define([ ...@@ -26,7 +26,7 @@ define([
setTime({ from: 'now-1h', to: 'now' }); setTime({ from: 'now-1h', to: 'now' });
ctx.scope.buildUrl(); ctx.scope.init();
expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now&panelId=22&fullscreen'); expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now&panelId=22&fullscreen');
}); });
...@@ -35,24 +35,23 @@ define([ ...@@ -35,24 +35,23 @@ define([
ctx.scope.panel = { id: 22 }; ctx.scope.panel = { id: 22 };
setTime({ from: 1362178800000, to: 1396648800000 }); setTime({ from: 1362178800000, to: 1396648800000 });
ctx.scope.buildUrl(); 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=1362178800000&to=1396648800000&panelId=22&fullscreen');
}); });
it('should remove panel id when toPanel is false', function() { it('should remove panel id when no panel in scope', function() {
ctx.$location.path('/test'); ctx.$location.path('/test');
ctx.scope.panel = { id: 22 }; ctx.scope.options = { forCurrent: true };
ctx.scope.options = { toPanel: false, forCurrent: true }; ctx.scope.panel = null;
setTime({ from: 'now-1h', to: 'now' }); setTime({ from: 'now-1h', to: 'now' });
ctx.scope.buildUrl(); 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=now-1h&to=now');
}); });
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.panel = { id: 22 }; ctx.scope.options = { includeTemplateVars: true, forCurrent: true };
ctx.scope.options = { includeTemplateVars: true, toPanel: false, forCurrent: true };
ctx.templateSrv.variables = [{ name: 'app', current: {text: 'mupp' }}, {name: 'server', current: {text: 'srv-01'}}]; ctx.templateSrv.variables = [{ name: 'app', current: {text: 'mupp' }}, {name: 'server', current: {text: 'srv-01'}}];
setTime({ from: 'now-1h', to: 'now' }); setTime({ from: 'now-1h', to: 'now' });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment