Browse Source

Worked on dashoard starring and unstarring, added dashboardMeta model

Torkel Ödegaard 11 years ago
parent
commit
1e3970c6e5

+ 5 - 4
src/app/features/dashboard/dashboardCtrl.js

@@ -23,12 +23,12 @@ function (angular, $, config, _) {
     $scope.panelNames = _.map(config.panels, function(value, key) { return key; });
     $scope.panelNames = _.map(config.panels, function(value, key) { return key; });
     var resizeEventTimeout;
     var resizeEventTimeout;
 
 
-    this.init = function(dashboardData) {
+    this.init = function(dashboard) {
       $scope.availablePanels = config.panels;
       $scope.availablePanels = config.panels;
       $scope.reset_row();
       $scope.reset_row();
       $scope.registerWindowResizeEvent();
       $scope.registerWindowResizeEvent();
       $scope.onAppEvent('show-json-editor', $scope.showJsonEditor);
       $scope.onAppEvent('show-json-editor', $scope.showJsonEditor);
-      $scope.setupDashboard(dashboardData);
+      $scope.setupDashboard(dashboard);
     };
     };
 
 
     $scope.registerWindowResizeEvent = function() {
     $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.dashboardLoadStart = new Date().getTime();
       $rootScope.performance.panelsInitialized = 0;
       $rootScope.performance.panelsInitialized = 0;
       $rootScope.performance.panelsRendered = 0;
       $rootScope.performance.panelsRendered = 0;
 
 
-      $scope.dashboard = dashboardSrv.create(dashboardData);
+      $scope.dashboard = dashboardSrv.create(dashboard.model);
       $scope.dashboardViewState = dashboardViewStateSrv.create($scope);
       $scope.dashboardViewState = dashboardViewStateSrv.create($scope);
+      $scope.dashboardMeta = dashboard.meta;
 
 
       // init services
       // init services
       timeSrv.init($scope.dashboard);
       timeSrv.init($scope.dashboard);

+ 13 - 0
src/app/features/dashboard/dashboardNavCtrl.js

@@ -39,6 +39,19 @@ function (angular, _, moment, config, store) {
       $location.search(search);
       $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.shareDashboard = function() {
       $scope.appEvent('show-modal', {
       $scope.appEvent('show-modal', {
         src: './app/features/dashboard/partials/shareModal.html',
         src: './app/features/dashboard/partials/shareModal.html',

+ 9 - 8
src/app/features/grafanaDatasource/datasource.js

@@ -25,14 +25,7 @@ function (angular, _, kbn) {
         url = '/temp/' + slug;
         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) {
     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 });
       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) {
     GrafanaDatasource.prototype.saveDashboard = function(dashboard) {
       // remove id if title has changed
       // remove id if title has changed
       if (dashboard.title !== dashboard.originalTitle) {
       if (dashboard.title !== dashboard.originalTitle) {

+ 3 - 1
src/app/partials/dashboard_topnav.html

@@ -20,7 +20,9 @@
 
 
 			<ul class="nav pull-left">
 			<ul class="nav pull-left">
 				<li>
 				<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>
 				<li>
 				<li>
 					<a class="pointer" ng-click="shareDashboard()"><i class="fa fa-share-square-o"></i></a>
 					<a class="pointer" ng-click="shareDashboard()"><i class="fa fa-share-square-o"></i></a>

+ 15 - 10
src/app/routes/backend/dashboard.js

@@ -28,7 +28,7 @@ function (angular, store) {
       if (!savedRoute) {
       if (!savedRoute) {
         $http.get("app/dashboards/default.json?" + new Date().getTime()).then(function(result) {
         $http.get("app/dashboards/default.json?" + new Date().getTime()).then(function(result) {
           var dashboard = angular.fromJson(result.data);
           var dashboard = angular.fromJson(result.data);
-          $scope.initDashboard(dashboard, $scope);
+          $scope.initDashboard({model: dashboard, meta: {}}, $scope);
         },function() {
         },function() {
           $scope.initDashboard({}, $scope);
           $scope.initDashboard({}, $scope);
           $scope.appEvent('alert-error', ['Load dashboard failed', '']);
           $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) {
   module.controller('DashFromImportCtrl', function($scope, $location, alertSrv) {
@@ -61,8 +63,11 @@ function (angular, store) {
 
 
   module.controller('NewDashboardCtrl', function($scope) {
   module.controller('NewDashboardCtrl', function($scope) {
     $scope.initDashboard({
     $scope.initDashboard({
-      title: "New dashboard",
-      rows: [{ height: '250px', panels:[] }]
+      meta: {},
+      model: {
+        title: "New dashboard",
+        rows: [{ height: '250px', panels:[] }]
+      },
     }, $scope);
     }, $scope);
   });
   });