Commit cb3593e4 by Torkel Ödegaard

Lots of small fixes, role viewer hides save icon and some actions in

config dropdown. Snapshot dashboard hides save, star, config menu icons.
Can now embedd panel from snapshotted dashboard.
parent 2e6d2802
...@@ -29,7 +29,7 @@ func CreateDashboardSnapshot(c *middleware.Context, cmd m.CreateDashboardSnapsho ...@@ -29,7 +29,7 @@ func CreateDashboardSnapshot(c *middleware.Context, cmd m.CreateDashboardSnapsho
metrics.M_Api_Dashboard_Snapshot_Create.Inc(1) metrics.M_Api_Dashboard_Snapshot_Create.Inc(1)
c.JSON(200, util.DynMap{"key": cmd.Key, "url": setting.ToAbsUrl("/dashboard/snapshots")}) c.JSON(200, util.DynMap{"key": cmd.Key, "url": setting.ToAbsUrl("/dashboard/snapshot")})
} }
func createExternalSnapshot(c *middleware.Context, cmd m.CreateDashboardSnapshotCommand) { func createExternalSnapshot(c *middleware.Context, cmd m.CreateDashboardSnapshotCommand) {
......
...@@ -17,6 +17,7 @@ function (angular, $, config) { ...@@ -17,6 +17,7 @@ function (angular, $, config) {
templateValuesSrv, templateValuesSrv,
dashboardSrv, dashboardSrv,
dashboardViewStateSrv, dashboardViewStateSrv,
contextSrv,
$timeout) { $timeout) {
$scope.editor = { index: 0 }; $scope.editor = { index: 0 };
...@@ -46,7 +47,7 @@ function (angular, $, config) { ...@@ -46,7 +47,7 @@ function (angular, $, config) {
templateValuesSrv.init(dashboard).then(function() { templateValuesSrv.init(dashboard).then(function() {
$scope.dashboard = dashboard; $scope.dashboard = dashboard;
$scope.dashboardViewState = dashboardViewStateSrv.create($scope); $scope.dashboardViewState = dashboardViewStateSrv.create($scope);
$scope.dashboardMeta = data.meta; $scope.initDashboardMeta(data.meta, $scope.dashboard);
dashboardKeybindings.shortcuts($scope); dashboardKeybindings.shortcuts($scope);
...@@ -57,6 +58,32 @@ function (angular, $, config) { ...@@ -57,6 +58,32 @@ function (angular, $, config) {
}); });
}; };
$scope.initDashboardMeta = function(meta, dashboard) {
meta.canShare = true;
meta.canSave = true;
meta.canEdit = true;
meta.canStar = true;
if (contextSrv.hasRole('Viewer')) {
meta.canSave = false;
}
if (meta.isHome) {
meta.canShare = false;
meta.canStar = false;
meta.canSave = false;
meta.canEdit = false;
}
if (dashboard.snapshot) {
meta.canEdit = false;
meta.canSave = false;
meta.canStar = false;
}
$scope.dashboardMeta = meta;
};
$scope.updateSubmenuVisibility = function() { $scope.updateSubmenuVisibility = function() {
$scope.submenuEnabled = $scope.dashboard.hasTemplateVarsOrAnnotations(); $scope.submenuEnabled = $scope.dashboard.hasTemplateVarsOrAnnotations();
}; };
...@@ -132,4 +159,5 @@ function (angular, $, config) { ...@@ -132,4 +159,5 @@ function (angular, $, config) {
}; };
}); });
}); });
...@@ -37,6 +37,7 @@ function (angular, $, kbn, _, moment) { ...@@ -37,6 +37,7 @@ function (angular, $, kbn, _, moment) {
this.templating = this._ensureListExist(data.templating); this.templating = this._ensureListExist(data.templating);
this.annotations = this._ensureListExist(data.annotations); this.annotations = this._ensureListExist(data.annotations);
this.refresh = data.refresh; this.refresh = data.refresh;
this.snapshot = data.snapshot;
this.schemaVersion = data.schemaVersion || 0; this.schemaVersion = data.schemaVersion || 0;
this.version = data.version || 0; this.version = data.version || 0;
......
...@@ -71,12 +71,16 @@ function (angular, _, require, config) { ...@@ -71,12 +71,16 @@ function (angular, _, require, config) {
} }
}); });
$scope.shareUrl = baseUrl + "?" + paramsArray.join('&'); var queryParams = "?" + paramsArray.join('&');
$scope.shareUrl = baseUrl + queryParams;
$scope.soloUrl = $scope.shareUrl.replace('/dashboard/db/', '/dashboard/solo/'); var soloUrl = $scope.shareUrl;
$scope.iframeHtml = '<iframe src="' + $scope.soloUrl + '" width="450" height="200" frameborder="0"></iframe>'; soloUrl = soloUrl.replace('/dashboard/db/', '/dashboard/solo/db/');
soloUrl = soloUrl.replace('/dashboard/snapshot/', '/dashboard/solo/snapshot/');
$scope.imageUrl = $scope.shareUrl.replace('/dashboard/db/', '/render/dashboard/solo/'); $scope.iframeHtml = '<iframe src="' + soloUrl + '" width="450" height="200" frameborder="0"></iframe>';
$scope.imageUrl = soloUrl.replace('/dashboard/', '/render/dashboard/');
$scope.imageUrl += '&width=1000'; $scope.imageUrl += '&width=1000';
$scope.imageUrl += '&height=500'; $scope.imageUrl += '&height=500';
}; };
......
...@@ -12,14 +12,17 @@ function (angular) { ...@@ -12,14 +12,17 @@ function (angular) {
name: $scope.dashboard.title name: $scope.dashboard.title
}; };
$scope.createSnapshot = function(makePublic) { $scope.createSnapshot = function(external) {
$scope.dashboard.snapshot = true; $scope.dashboard.snapshot = {
timestamp: new Date()
};
$scope.loading = true; $scope.loading = true;
$rootScope.$broadcast('refresh'); $rootScope.$broadcast('refresh');
$timeout(function() { $timeout(function() {
$scope.saveSnapshot(makePublic); $scope.saveSnapshot(external);
}, 2000); }, 3000);
}; };
$scope.saveSnapshot = function(external) { $scope.saveSnapshot = function(external) {
...@@ -35,7 +38,7 @@ function (angular) { ...@@ -35,7 +38,7 @@ function (angular) {
}); });
// cleanup snapshotData // cleanup snapshotData
$scope.dashboard.snapshot = false; delete $scope.dashboard.snapshot;
$scope.dashboard.forEachPanel(function(panel) { $scope.dashboard.forEachPanel(function(panel) {
delete panel.snapshotData; delete panel.snapshotData;
}); });
...@@ -47,7 +50,7 @@ function (angular) { ...@@ -47,7 +50,7 @@ function (angular) {
$scope.snapshotUrl = results.url; $scope.snapshotUrl = results.url;
} else { } else {
var baseUrl = $location.absUrl().replace($location.url(), ""); var baseUrl = $location.absUrl().replace($location.url(), "");
$scope.snapshotUrl = baseUrl + '/dashboard/snapshots/' + results.key; $scope.snapshotUrl = baseUrl + '/dashboard/snapshot/' + results.key;
} }
}, function() { }, function() {
$scope.loading = false; $scope.loading = false;
......
...@@ -8,6 +8,7 @@ function (angular, _, kbn, $) { ...@@ -8,6 +8,7 @@ function (angular, _, kbn, $) {
'use strict'; 'use strict';
var module = angular.module('grafana.services'); var module = angular.module('grafana.services');
module.service('panelHelper', function(timeSrv) { module.service('panelHelper', function(timeSrv) {
this.updateTimeRange = function(scope) { this.updateTimeRange = function(scope) {
......
...@@ -26,12 +26,19 @@ function (angular, $) { ...@@ -26,12 +26,19 @@ function (angular, $) {
var params = $location.search(); var params = $location.search();
panelId = parseInt(params.panelId); panelId = parseInt(params.panelId);
backendSrv.getDashboard($routeParams.slug) var request;
.then(function(dashboard) {
$scope.initPanelScope(dashboard); if ($routeParams.slug) {
}).then(null, function(err) { request = backendSrv.getDashboard($routeParams.slug);
$scope.appEvent('alert-error', ['Load panel error', err.message]); } else {
}); request = backendSrv.get('/api/snapshots/' + $routeParams.key);
}
request.then(function(dashboard) {
$scope.initPanelScope(dashboard);
}).then(null, function(err) {
$scope.appEvent('alert-error', ['Load panel error', err.message]);
});
}; };
$scope.initPanelScope = function(dashboard) { $scope.initPanelScope = function(dashboard) {
......
...@@ -18,19 +18,19 @@ ...@@ -18,19 +18,19 @@
</div> </div>
<ul class="nav pull-left top-nav-dash-actions" ng-if="!dashboardMeta.isHome"> <ul class="nav pull-left top-nav-dash-actions">
<li> <li ng-show="dashboardMeta.canStar">
<a class="pointer" ng-click="starDashboard()"> <a class="pointer" ng-click="starDashboard()">
<i class="fa" ng-class="{'fa-star-o': !dashboardMeta.isStarred, 'fa-star': dashboardMeta.isStarred,}" style="color: orange;"></i> <i class="fa" ng-class="{'fa-star-o': !dashboardMeta.isStarred, 'fa-star': dashboardMeta.isStarred}" style="color: orange;"></i>
</a> </a>
</li> </li>
<li> <li ng-show="dashboardMeta.canShare">
<a class="pointer" ng-click="shareDashboard()" bs-tooltip="'Share dashboard'" data-placement="bottom"><i class="fa fa-share-square-o"></i></a> <a class="pointer" ng-click="shareDashboard()" bs-tooltip="'Share dashboard'" data-placement="bottom"><i class="fa fa-share-square-o"></i></a>
</li> </li>
<li> <li ng-show="dashboardMeta.canSave">
<a ng-click="saveDashboard()" bs-tooltip="'Save dashboard'" data-placement="bottom"><i class="fa fa-save"></i></a> <a ng-click="saveDashboard()" bs-tooltip="'Save dashboard'" data-placement="bottom"><i class="fa fa-save"></i></a>
</li> </li>
<li class="dropdown"> <li class="dropdown" ng-if="dashboardMeta.canEdit">
<a class="pointer" data-toggle="dropdown"><i class="fa fa-cog"></i></a> <a class="pointer" data-toggle="dropdown"><i class="fa fa-cog"></i></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a class="pointer" ng-click="openEditView('settings');">Settings</a></li> <li><a class="pointer" ng-click="openEditView('settings');">Settings</a></li>
...@@ -38,8 +38,8 @@ ...@@ -38,8 +38,8 @@
<li><a class="pointer" ng-click="openEditView('templating');">Templating</a></li> <li><a class="pointer" ng-click="openEditView('templating');">Templating</a></li>
<li><a class="pointer" ng-click="exportDashboard();">Export</a></li> <li><a class="pointer" ng-click="exportDashboard();">Export</a></li>
<li><a class="pointer" ng-click="editJson();">View JSON</a></li> <li><a class="pointer" ng-click="editJson();">View JSON</a></li>
<li><a class="pointer" ng-click="saveDashboardAs();">Save As...</a></li> <li ng-if="dashboardMeta.canSave"><a class="pointer" ng-click="saveDashboardAs();">Save As...</a></li>
<li><a class="pointer" ng-click="deleteDashboard();">Delete dashboard</a></li> <li ng-if="dashboardMeta.canSave"><a class="pointer" ng-click="deleteDashboard();">Delete dashboard</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
......
...@@ -35,10 +35,18 @@ define([ ...@@ -35,10 +35,18 @@ define([
controller : 'DashFromImportCtrl', controller : 'DashFromImportCtrl',
reloadOnSearch: false, reloadOnSearch: false,
}) })
.when('/dashboard/snapshots/:key', { .when('/dashboard/snapshot/:key', {
templateUrl: 'app/partials/dashboard.html', templateUrl: 'app/partials/dashboard.html',
controller : 'DashFromSnapshotCtrl', controller : 'DashFromSnapshotCtrl',
}) })
.when('/dashboard/solo/db/:slug', {
templateUrl: 'app/features/panel/partials/soloPanel.html',
controller : 'SoloPanelCtrl',
})
.when('/dashboard/solo/snapshot/:key', {
templateUrl: 'app/features/panel/partials/soloPanel.html',
controller : 'SoloPanelCtrl',
})
.when('/dashboard/new', { .when('/dashboard/new', {
templateUrl: 'app/partials/dashboard.html', templateUrl: 'app/partials/dashboard.html',
controller : 'NewDashboardCtrl', controller : 'NewDashboardCtrl',
...@@ -107,10 +115,6 @@ define([ ...@@ -107,10 +115,6 @@ define([
templateUrl: 'app/partials/login.html', templateUrl: 'app/partials/login.html',
controller : 'LoginCtrl', controller : 'LoginCtrl',
}) })
.when('/dashboard/solo/:slug/', {
templateUrl: 'app/features/panel/partials/soloPanel.html',
controller : 'SoloPanelCtrl',
})
.otherwise({ .otherwise({
templateUrl: 'app/partials/error.html', templateUrl: 'app/partials/error.html',
controller: 'ErrorCtrl' controller: 'ErrorCtrl'
......
...@@ -46,7 +46,7 @@ define([ ...@@ -46,7 +46,7 @@ define([
} }
}; };
routeParams.id = 1; routeParams.slug = "my dash";
search.panelId = 23; search.panelId = 23;
backendSrv.getDashboard = sinon.stub().returns(ctx.$q.when(dashboard)); backendSrv.getDashboard = sinon.stub().returns(ctx.$q.when(dashboard));
......
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