Commit 0bf721a7 by utkarshcmu

Able to save home dashboard

parent 43b47414
......@@ -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;
......
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