Преглед изворни кода

worked on user frontend state, state like favorites, etc

Torkel Ödegaard пре 11 година
родитељ
комит
3b5c813be7

+ 8 - 16
src/app/controllers/grafanaCtrl.js

@@ -10,17 +10,17 @@ function (angular, config, _, $, store) {
 
   var module = angular.module('grafana.controllers');
 
-  module.controller('GrafanaCtrl', function($scope, alertSrv, utilSrv, grafanaVersion, $rootScope, $controller) {
-    $scope.grafanaVersion = grafanaVersion[0] === '@' ? 'master' : grafanaVersion;
-    $scope.grafana = {};
-
-    $rootScope.profilingEnabled = store.getBool('profilingEnabled');
-    $rootScope.performance = { loadStart: new Date().getTime() };
-    $rootScope.appSubUrl = config.appSubUrl;
+  module.controller('GrafanaCtrl', function($scope, alertSrv, utilSrv, grafanaVersion, $rootScope, $controller, userSrv) {
 
     $scope.init = function() {
+      $scope.grafana = {};
+      $scope.grafana.version = grafanaVersion;
       $scope._ = _;
 
+      $rootScope.profilingEnabled = store.getBool('profilingEnabled');
+      $rootScope.performance = { loadStart: new Date().getTime() };
+      $rootScope.appSubUrl = config.appSubUrl;
+
       if ($rootScope.profilingEnabled) { $scope.initProfiling(); }
 
       alertSrv.init();
@@ -28,16 +28,8 @@ function (angular, config, _, $, store) {
 
       $scope.dashAlerts = alertSrv;
       $scope.grafana.style = 'dark';
-      $scope.grafana.user = {};
-
-      if (window.grafanaBackend) {
-        $scope.initBackendFeatures();
-      }
-    };
-
-    $scope.initBackendFeatures = function() {
+      $scope.grafana.user = userSrv.getSignedInUser();
       $scope.grafana.sidemenu = store.getBool('grafana.sidemenu');
-      $scope.grafana.user = window.grafanaBootData.user;
 
       $scope.onAppEvent('logged-out', function() {
         $scope.grafana.sidemenu = false;

+ 6 - 6
src/app/features/grafanaDatasource/datasource.js

@@ -18,17 +18,17 @@ function (angular, _, kbn) {
       this.editorSrc = 'app/features/grafanaDatasource/partials/query.editor.html';
     }
 
-    GrafanaDatasource.prototype.getDashboard = function(id, isTemp) {
-      var url = '/dashboard/' + id;
+    GrafanaDatasource.prototype.getDashboard = function(slug, isTemp) {
+      var url = '/dashboard/' + slug;
 
       if (isTemp) {
-        url = '/temp/' + id;
+        url = '/temp/' + slug;
       }
 
-      return backendSrv.get('/api/dashboard/' + id)
+      return backendSrv.get('/api/dashboard/' + slug)
         .then(function(data) {
-          if (data) {
-            return angular.fromJson(data);
+          if (data && data.dashboard) {
+            return data.dashboard;
           } else {
             return false;
           }

+ 1 - 1
src/app/partials/dasheditor.html

@@ -96,7 +96,7 @@
 <div class="dashboard-editor-footer">
 	<div class="grafana-version-info" ng-show="editor.index === 0">
 		<span class="editor-option small">
-			Grafana version: {{grafanaVersion}} &nbsp;&nbsp;
+			Grafana version: {{grafana.version}} &nbsp;&nbsp;
 		</span>
 		<span grafana-version-check>
 		</span>

+ 1 - 0
src/app/services/all.js

@@ -2,6 +2,7 @@ define([
   './alertSrv',
   './utilSrv',
   './datasourceSrv',
+  './userSrv',
   './timer',
   './keyboardManager',
   './popoverSrv',

+ 24 - 0
src/app/services/userSrv.js

@@ -0,0 +1,24 @@
+define([
+  'angular',
+  'lodash',
+],
+function (angular, _) {
+  'use strict';
+
+  var module = angular.module('grafana.services');
+
+  module.service('userSrv', function() {
+
+    function User() {
+      if (window.grafanaBootData.user) {
+        _.extend(this, window.grafanaBootData.user);
+      }
+    }
+
+    this.getSignedInUser = function() {
+      return new User();
+    };
+
+  });
+
+});