mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Able to save home dashboard
This commit is contained in:
parent
43b474143c
commit
0bf721a74c
@ -48,6 +48,7 @@
|
||||
<li ng-if="dashboardMeta.canEdit"><a class="pointer" ng-click="editJson();">View JSON</a></li>
|
||||
<li ng-if="contextSrv.isEditor && !dashboard.editable"><a class="pointer" ng-click="makeEditable();">Make Editable</a></li>
|
||||
<li ng-if="contextSrv.isEditor"><a class="pointer" ng-click="saveDashboardAs();">Save As...</a></li>
|
||||
<li ng-if="contextSrv.isEditor"><a class="pointer" ng-click="saveDashboardAsHome();">Save As Home</a></li>
|
||||
<li ng-if="dashboardMeta.canSave"><a class="pointer" ng-click="deleteDashboard();">Delete dashboard</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
@ -7,7 +7,7 @@ import angular from 'angular';
|
||||
export class DashNavCtrl {
|
||||
|
||||
/** @ngInject */
|
||||
constructor($scope, $rootScope, alertSrv, $location, playlistSrv, backendSrv, $timeout) {
|
||||
constructor($scope, $rootScope, alertSrv, $location, playlistSrv, backendSrv, contextSrv, $timeout) {
|
||||
|
||||
$scope.init = function() {
|
||||
$scope.onAppEvent('save-dashboard', $scope.saveDashboard);
|
||||
@ -103,6 +103,26 @@ export class DashNavCtrl {
|
||||
}, $scope.handleSaveDashError);
|
||||
};
|
||||
|
||||
$scope.saveDashboardAsHome = function() {
|
||||
var orgId = 'org-' + contextSrv.user.orgId;
|
||||
backendSrv.get('/api/preferences').then(function(prefs) {
|
||||
|
||||
// Checking if the preferences already exists or not
|
||||
if (prefs.userId === 0 && prefs.orgId === 0 && prefs.preference === null) {
|
||||
prefs.preference = {};
|
||||
}
|
||||
if (prefs.preference == null) {
|
||||
prefs.preference = {
|
||||
home_dashboard_id: $scope.dashboard.id
|
||||
};
|
||||
} else {
|
||||
var orgPrefs = prefs.preference;
|
||||
orgPrefs.home_dashboard = $scope.dashboard.id;
|
||||
}
|
||||
backendSrv.put('api/preferences', prefs);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.handleSaveDashError = function(err) {
|
||||
if (err.data && err.data.status === "version-mismatch") {
|
||||
err.isHandled = true;
|
||||
|
Loading…
Reference in New Issue
Block a user