Commit 1e3970c6 by Torkel Ödegaard

Worked on dashoard starring and unstarring, added dashboardMeta model

parent 66d9c4f1
......@@ -23,12 +23,12 @@ function (angular, $, config, _) {
$scope.panelNames = _.map(config.panels, function(value, key) { return key; });
var resizeEventTimeout;
this.init = function(dashboardData) {
this.init = function(dashboard) {
$scope.availablePanels = config.panels;
$scope.reset_row();
$scope.registerWindowResizeEvent();
$scope.onAppEvent('show-json-editor', $scope.showJsonEditor);
$scope.setupDashboard(dashboardData);
$scope.setupDashboard(dashboard);
};
$scope.registerWindowResizeEvent = function() {
......@@ -38,13 +38,14 @@ function (angular, $, config, _) {
});
};
$scope.setupDashboard = function(dashboardData) {
$scope.setupDashboard = function(dashboard) {
$rootScope.performance.dashboardLoadStart = new Date().getTime();
$rootScope.performance.panelsInitialized = 0;
$rootScope.performance.panelsRendered = 0;
$scope.dashboard = dashboardSrv.create(dashboardData);
$scope.dashboard = dashboardSrv.create(dashboard.model);
$scope.dashboardViewState = dashboardViewStateSrv.create($scope);
$scope.dashboardMeta = dashboard.meta;
// init services
timeSrv.init($scope.dashboard);
......
......@@ -39,6 +39,19 @@ function (angular, _, moment, config, store) {
$location.search(search);
};
$scope.starDashboard = function() {
if ($scope.dashboardMeta.isStarred) {
$scope.db.unstarDashboard($scope.dashboard.id).then(function() {
$scope.dashboardMeta.isStarred = false;
});
}
else {
$scope.db.starDashboard($scope.dashboard.id).then(function() {
$scope.dashboardMeta.isStarred = true;
});
}
};
$scope.shareDashboard = function() {
$scope.appEvent('show-modal', {
src: './app/features/dashboard/partials/shareModal.html',
......
......@@ -25,14 +25,7 @@ function (angular, _, kbn) {
url = '/temp/' + slug;
}
return backendSrv.get('/api/dashboard/' + slug)
.then(function(data) {
if (data && data.dashboard) {
return data.dashboard;
} else {
return false;
}
});
return backendSrv.get('/api/dashboard/' + slug);
};
GrafanaDatasource.prototype.query = function(options) {
......@@ -43,6 +36,14 @@ function (angular, _, kbn) {
return backendSrv.get('/api/metrics/test', { from: from, to: to, maxDataPoints: options.maxDataPoints });
};
GrafanaDatasource.prototype.starDashboard = function(dashId) {
return backendSrv.post('/api/user/stars/dashboard/' + dashId);
};
GrafanaDatasource.prototype.unstarDashboard = function(dashId) {
return backendSrv.delete('/api/user/stars/dashboard/' + dashId);
};
GrafanaDatasource.prototype.saveDashboard = function(dashboard) {
// remove id if title has changed
if (dashboard.title !== dashboard.originalTitle) {
......
......@@ -20,7 +20,9 @@
<ul class="nav pull-left">
<li>
<a class="pointer" ng-click="starDashboard()"><i class="fa fa-star-o" style="color: orange;"></i></a>
<a class="pointer" ng-click="starDashboard()">
<i class="fa" ng-class="{'fa-star-o': !dashboardMeta.isStarred, 'fa-star': dashboardMeta.isStarred,}" style="color: orange;"></i>
</a>
</li>
<li>
<a class="pointer" ng-click="shareDashboard()"><i class="fa fa-share-square-o"></i></a>
......
......@@ -28,7 +28,7 @@ function (angular, store) {
if (!savedRoute) {
$http.get("app/dashboards/default.json?" + new Date().getTime()).then(function(result) {
var dashboard = angular.fromJson(result.data);
$scope.initDashboard(dashboard, $scope);
$scope.initDashboard({model: dashboard, meta: {}}, $scope);
},function() {
$scope.initDashboard({}, $scope);
$scope.appEvent('alert-error', ['Load dashboard failed', '']);
......@@ -41,13 +41,15 @@ function (angular, store) {
}
}
db.getDashboard($routeParams.id, isTemp)
.then(function(dashboard) {
prevDashPath = $location.path();
$scope.initDashboard(dashboard, $scope);
}).then(null, function() {
$scope.initDashboard({}, $scope);
});
db.getDashboard($routeParams.id, isTemp).then(function(result) {
prevDashPath = $location.path();
$scope.initDashboard(result, $scope);
}).then(null, function() {
$scope.initDashboard({
meta: {},
model: { title: 'Not found' }
}, $scope);
});
});
module.controller('DashFromImportCtrl', function($scope, $location, alertSrv) {
......@@ -61,8 +63,11 @@ function (angular, store) {
module.controller('NewDashboardCtrl', function($scope) {
$scope.initDashboard({
title: "New dashboard",
rows: [{ height: '250px', panels:[] }]
meta: {},
model: {
title: "New dashboard",
rows: [{ height: '250px', panels:[] }]
},
}, $scope);
});
......
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