Ver Fonte

import from non-default dashboard support

Nikolay Bryskin há 11 anos atrás
pai
commit
8ea4351797
2 ficheiros alterados com 25 adições e 3 exclusões
  1. 15 2
      src/app/controllers/graphiteImport.js
  2. 10 1
      src/app/partials/import.html

+ 15 - 2
src/app/controllers/graphiteImport.js

@@ -12,12 +12,25 @@ function (angular, app, _) {
 
 
     $scope.init = function() {
     $scope.init = function() {
       console.log('hej!');
       console.log('hej!');
+      $scope.datasources = datasourceSrv.listOptions();
+      $scope.setDatasource(datasourceSrv.default.value);
     };
     };
 
 
+
+    $scope.setDatasource = function(datasource) {
+      $scope.datasource = datasourceSrv.get(datasource);
+
+      if (!$scope.datasource) {
+          $scope.error = "Cannot find datasource " + datasource;
+        return;
+      }
+    };
+
+
     $scope.listAll = function(query) {
     $scope.listAll = function(query) {
       delete $scope.error;
       delete $scope.error;
 
 
-      datasourceSrv.default.listDashboards(query)
+      $scope.datasource.listDashboards(query)
         .then(function(results) {
         .then(function(results) {
           $scope.dashboards = results;
           $scope.dashboards = results;
         })
         })
@@ -29,7 +42,7 @@ function (angular, app, _) {
     $scope.import = function(dashName) {
     $scope.import = function(dashName) {
       delete $scope.error;
       delete $scope.error;
 
 
-      datasourceSrv.default.loadDashboard(dashName)
+      $scope.datasource.loadDashboard(dashName)
         .then(function(results) {
         .then(function(results) {
           if (!results.data || !results.data.state) {
           if (!results.data || !results.data.state) {
             throw { message: 'no dashboard state received from graphite' };
             throw { message: 'no dashboard state received from graphite' };

+ 10 - 1
src/app/partials/import.html

@@ -1,8 +1,17 @@
-<div ng-controller="GraphiteImportCtrl" ng-init="init()">
+<div ng-controller="GraphiteImportCtrl" ng-init="init()" style="height: 400px">
   <h5>Import dashboards from graphite web</h5>
   <h5>Import dashboards from graphite web</h5>
 
 
   <div class="editor-row">
   <div class="editor-row">
     <div class="section">
     <div class="section">
+      <div class="btn-group">
+        <button class="btn btn-info dropdown-toggle" data-toggle="dropdown" bs-tooltip="'Datasource'">{{datasource.name}} <span class="caret"></span></button>
+
+        <ul class="dropdown-menu" role="menu">
+          <li ng-repeat="datasource in datasources" role="menuitem">
+            <a ng-click="setDatasource(datasource.value);">{{datasource.name}}</a>
+          </li>
+        </ul>
+      </div>
       <button ng-click="listAll()" class="btn btn-primary">List all dashboards</button>
       <button ng-click="listAll()" class="btn btn-primary">List all dashboards</button>
     </div>
     </div>
   </div>
   </div>