mirror of
https://github.com/grafana/grafana.git
synced 2024-12-30 10:47:30 -06:00
Enabled snapshot sharing of single panels, enabled sharing of snapshot dashboards (but you cannot snapshot a snapshot
This commit is contained in:
parent
0f791c9fa8
commit
c42d09b267
@ -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) {
|
||||
return _.reduce(row.panels, function(p,v) {
|
||||
return p + v.span;
|
||||
|
@ -1,4 +1,4 @@
|
||||
<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-title">
|
||||
<i class="fa fa-share"></i>
|
||||
@ -59,7 +59,7 @@
|
||||
<input type="text" data-share-panel-url class="input" ng-model='shareUrl'></input>
|
||||
</span>
|
||||
</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>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -13,22 +13,20 @@ function (angular, _, require, config) {
|
||||
|
||||
$scope.init = function() {
|
||||
$scope.editor = { index: 0 };
|
||||
$scope.options = {
|
||||
forCurrent: true,
|
||||
toPanel: $scope.panel ? true : false,
|
||||
includeTemplateVars: true
|
||||
};
|
||||
$scope.options = { forCurrent: true, includeTemplateVars: true };
|
||||
$scope.modeSharePanel = $scope.panel ? true : false;
|
||||
|
||||
$scope.tabs = [{title: 'Link', src: 'shareLink.html'}];
|
||||
|
||||
if ($scope.options.toPanel) {
|
||||
if ($scope.modeSharePanel) {
|
||||
$scope.modalTitle = 'Share Panel';
|
||||
$scope.tabs.push({title: 'Embed', src: 'shareEmbed.html'});
|
||||
} else {
|
||||
$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();
|
||||
@ -64,7 +62,7 @@ function (angular, _, require, config) {
|
||||
delete params.to;
|
||||
}
|
||||
|
||||
if ($scope.options.toPanel) {
|
||||
if ($scope.modeSharePanel) {
|
||||
params.panelId = $scope.panel.id;
|
||||
params.fullscreen = true;
|
||||
} else {
|
||||
@ -97,8 +95,6 @@ function (angular, _, require, config) {
|
||||
$scope.imageUrl += '&height=500';
|
||||
};
|
||||
|
||||
$scope.init();
|
||||
|
||||
});
|
||||
|
||||
module.directive('clipboardButton',function() {
|
||||
|
@ -44,34 +44,12 @@ function (angular, _) {
|
||||
|
||||
$timeout(function() {
|
||||
$scope.saveSnapshot(external);
|
||||
}, 3000);
|
||||
}, 4000);
|
||||
};
|
||||
|
||||
$scope.saveSnapshot = function(external) {
|
||||
var dash = angular.copy($scope.dashboard);
|
||||
// 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;
|
||||
});
|
||||
|
||||
// cleanup snapshotData
|
||||
delete $scope.dashboard.snapshot;
|
||||
$scope.dashboard.forEachPanel(function(panel) {
|
||||
delete panel.snapshotData;
|
||||
});
|
||||
$scope.scrubDashboard(dash);
|
||||
|
||||
var cmdData = {
|
||||
dashboard: dash,
|
||||
@ -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) {
|
||||
// save external in local instance as well
|
||||
cmdData.external = true;
|
||||
|
@ -49,7 +49,7 @@ function (angular, $) {
|
||||
|
||||
$scope.test = "Hej";
|
||||
$scope.$index = 0;
|
||||
$scope.panel = $scope.getPanelById(panelId);
|
||||
$scope.panel = $scope.dashboard.getPanelById(panelId);
|
||||
|
||||
if (!$scope.panel) {
|
||||
$scope.appEvent('alert-error', ['Panel not found', '']);
|
||||
@ -63,20 +63,6 @@ function (angular, $) {
|
||||
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) {
|
||||
$scope.init();
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ define([
|
||||
self.scope.panel = {};
|
||||
self.scope.row = { panels:[] };
|
||||
self.scope.dashboard = {};
|
||||
self.scope.dashboardMeta = {};
|
||||
self.scope.dashboardViewState = new DashboardViewStateStub();
|
||||
self.scope.appEvent = sinon.spy();
|
||||
self.scope.onAppEvent = sinon.spy();
|
||||
|
@ -4,7 +4,7 @@ define([
|
||||
], function(helpers) {
|
||||
'use strict';
|
||||
|
||||
describe('SharePanelCtrl', function() {
|
||||
describe('ShareModalCtrl', function() {
|
||||
var ctx = new helpers.ControllerTestContext();
|
||||
|
||||
function setTime(range) {
|
||||
@ -26,7 +26,7 @@ define([
|
||||
|
||||
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');
|
||||
});
|
||||
|
||||
@ -35,24 +35,23 @@ define([
|
||||
ctx.scope.panel = { id: 22 };
|
||||
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');
|
||||
});
|
||||
|
||||
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.scope.panel = { id: 22 };
|
||||
ctx.scope.options = { toPanel: false, forCurrent: true };
|
||||
ctx.scope.options = { forCurrent: true };
|
||||
ctx.scope.panel = null;
|
||||
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');
|
||||
});
|
||||
|
||||
it('should include template variables in url', function() {
|
||||
ctx.$location.path('/test');
|
||||
ctx.scope.panel = { id: 22 };
|
||||
ctx.scope.options = { includeTemplateVars: true, toPanel: false, forCurrent: true };
|
||||
ctx.scope.options = { includeTemplateVars: true, forCurrent: true };
|
||||
|
||||
ctx.templateSrv.variables = [{ name: 'app', current: {text: 'mupp' }}, {name: 'server', current: {text: 'srv-01'}}];
|
||||
setTime({ from: 'now-1h', to: 'now' });
|
||||
|
Loading…
Reference in New Issue
Block a user