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
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) {
......
......@@ -17,6 +17,7 @@ function (angular, $, config) {
templateValuesSrv,
dashboardSrv,
dashboardViewStateSrv,
contextSrv,
$timeout) {
$scope.editor = { index: 0 };
......@@ -46,7 +47,7 @@ function (angular, $, config) {
templateValuesSrv.init(dashboard).then(function() {
$scope.dashboard = dashboard;
$scope.dashboardViewState = dashboardViewStateSrv.create($scope);
$scope.dashboardMeta = data.meta;
$scope.initDashboardMeta(data.meta, $scope.dashboard);
dashboardKeybindings.shortcuts($scope);
......@@ -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.submenuEnabled = $scope.dashboard.hasTemplateVarsOrAnnotations();
};
......@@ -132,4 +159,5 @@ function (angular, $, config) {
};
});
});
......@@ -37,6 +37,7 @@ function (angular, $, kbn, _, moment) {
this.templating = this._ensureListExist(data.templating);
this.annotations = this._ensureListExist(data.annotations);
this.refresh = data.refresh;
this.snapshot = data.snapshot;
this.schemaVersion = data.schemaVersion || 0;
this.version = data.version || 0;
......
......@@ -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/');
$scope.iframeHtml = '<iframe src="' + $scope.soloUrl + '" width="450" height="200" frameborder="0"></iframe>';
var soloUrl = $scope.shareUrl;
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 += '&height=500';
};
......
......@@ -12,14 +12,17 @@ function (angular) {
name: $scope.dashboard.title
};
$scope.createSnapshot = function(makePublic) {
$scope.dashboard.snapshot = true;
$scope.createSnapshot = function(external) {
$scope.dashboard.snapshot = {
timestamp: new Date()
};
$scope.loading = true;
$rootScope.$broadcast('refresh');
$timeout(function() {
$scope.saveSnapshot(makePublic);
}, 2000);
$scope.saveSnapshot(external);
}, 3000);
};
$scope.saveSnapshot = function(external) {
......@@ -35,7 +38,7 @@ function (angular) {
});
// cleanup snapshotData
$scope.dashboard.snapshot = false;
delete $scope.dashboard.snapshot;
$scope.dashboard.forEachPanel(function(panel) {
delete panel.snapshotData;
});
......@@ -47,7 +50,7 @@ function (angular) {
$scope.snapshotUrl = results.url;
} else {
var baseUrl = $location.absUrl().replace($location.url(), "");
$scope.snapshotUrl = baseUrl + '/dashboard/snapshots/' + results.key;
$scope.snapshotUrl = baseUrl + '/dashboard/snapshot/' + results.key;
}
}, function() {
$scope.loading = false;
......
......@@ -8,6 +8,7 @@ function (angular, _, kbn, $) {
'use strict';
var module = angular.module('grafana.services');
module.service('panelHelper', function(timeSrv) {
this.updateTimeRange = function(scope) {
......
......@@ -26,12 +26,19 @@ function (angular, $) {
var params = $location.search();
panelId = parseInt(params.panelId);
backendSrv.getDashboard($routeParams.slug)
.then(function(dashboard) {
$scope.initPanelScope(dashboard);
}).then(null, function(err) {
$scope.appEvent('alert-error', ['Load panel error', err.message]);
});
var request;
if ($routeParams.slug) {
request = backendSrv.getDashboard($routeParams.slug);
} 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) {
......
......@@ -18,19 +18,19 @@
</div>
<ul class="nav pull-left top-nav-dash-actions" ng-if="!dashboardMeta.isHome">
<li>
<ul class="nav pull-left top-nav-dash-actions">
<li ng-show="dashboardMeta.canStar">
<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>
</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>
</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>
</li>
<li class="dropdown">
<li class="dropdown" ng-if="dashboardMeta.canEdit">
<a class="pointer" data-toggle="dropdown"><i class="fa fa-cog"></i></a>
<ul class="dropdown-menu">
<li><a class="pointer" ng-click="openEditView('settings');">Settings</a></li>
......@@ -38,8 +38,8 @@
<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="editJson();">View JSON</a></li>
<li><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="saveDashboardAs();">Save As...</a></li>
<li ng-if="dashboardMeta.canSave"><a class="pointer" ng-click="deleteDashboard();">Delete dashboard</a></li>
</ul>
</li>
</ul>
......
......@@ -35,10 +35,18 @@ define([
controller : 'DashFromImportCtrl',
reloadOnSearch: false,
})
.when('/dashboard/snapshots/:key', {
.when('/dashboard/snapshot/:key', {
templateUrl: 'app/partials/dashboard.html',
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', {
templateUrl: 'app/partials/dashboard.html',
controller : 'NewDashboardCtrl',
......@@ -107,10 +115,6 @@ define([
templateUrl: 'app/partials/login.html',
controller : 'LoginCtrl',
})
.when('/dashboard/solo/:slug/', {
templateUrl: 'app/features/panel/partials/soloPanel.html',
controller : 'SoloPanelCtrl',
})
.otherwise({
templateUrl: 'app/partials/error.html',
controller: 'ErrorCtrl'
......
......@@ -46,7 +46,7 @@ define([
}
};
routeParams.id = 1;
routeParams.slug = "my dash";
search.panelId = 23;
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