Browse Source

feat(dashboard): have browser use the v2 api

Brandon Philips 12 years ago
parent
commit
c91cb72ee2

+ 12 - 7
mod/dashboard/app/scripts/common/services/etcd.js

@@ -2,10 +2,10 @@
 
 angular.module('etcd', [])
 
-.factory('EtcdV1', ['$http', function($http) {
-  var keyPrefix = '/v1/keys/'
-  var statsPrefix = '/v1/stats/'
-  var baseURL = '/v1/'
+.factory('EtcdV2', ['$http', function($http) {
+  var keyPrefix = '/v2/keys/'
+  var statsPrefix = '/v2/stats/'
+  var baseURL = '/v2/'
 
   delete $http.defaults.headers.common['X-Requested-With'];
 
@@ -15,7 +15,8 @@ angular.module('etcd', [])
       return '';
     }
     parts = parts.filter(function(v){return v!=='';});
-    return parts.join('/');
+    parts = parts.join('/');
+    return parts
   }
 
   function newKey(keyName) {
@@ -32,7 +33,11 @@ angular.module('etcd', [])
     };
 
     self.path = function() {
-      return '/' + cleanupPath(keyPrefix + self.name);
+      var path = '/' + cleanupPath(keyPrefix + self.name);
+      if (path === keyPrefix.substring(0, keyPrefix.length - 1)) {
+        return keyPrefix
+      }
+      return path
     };
 
     self.get = function() {
@@ -43,7 +48,7 @@ angular.module('etcd', [])
       return $http({
         url: self.path(),
         data: $.param({value: keyValue}),
-        method: 'POST',
+        method: 'PUT',
         headers: {'Content-Type': 'application/x-www-form-urlencoded'}
       });
     };

+ 8 - 8
mod/dashboard/app/scripts/controllers/browser.js

@@ -2,7 +2,7 @@
 
 angular.module('etcdBrowser', ['ngRoute', 'etcd', 'timeRelative'])
 
-.constant('keyPrefix', '/v1/keys')
+.constant('keyPrefix', '/v2/keys/')
 
 .config(['$routeProvider', 'keyPrefix', function ($routeProvider, keyPrefix) {
   //read localstorage
@@ -18,7 +18,7 @@ angular.module('etcdBrowser', ['ngRoute', 'etcd', 'timeRelative'])
     });
 }])
 
-.controller('MainCtrl', ['$scope', '$location', 'EtcdV1', 'keyPrefix', function ($scope, $location, EtcdV1, keyPrefix) {
+.controller('MainCtrl', ['$scope', '$location', 'EtcdV2', 'keyPrefix', function ($scope, $location, EtcdV2, keyPrefix) {
   $scope.save = 'etcd-save-hide';
   $scope.preview = 'etcd-preview-hide';
   $scope.enableBack = true;
@@ -43,12 +43,12 @@ angular.module('etcdBrowser', ['ngRoute', 'etcd', 'timeRelative'])
     // Notify everyone of the update
     localStorage.setItem('etcdPath', $scope.etcdPath);
     $scope.enableBack = true;
-    //disable back button if at root (/v1/keys/)
-    if($scope.etcdPath === '/v1/keys') {
+    //disable back button if at root (/v2/keys/)
+    if($scope.etcdPath === keyPrefix) {
       $scope.enableBack = false;
     }
 
-    $scope.key = EtcdV1.getKey(etcdPathKey($scope.etcdPath));
+    $scope.key = EtcdV2.getKey(etcdPathKey($scope.etcdPath));
   });
 
   $scope.$watch('key', function() {
@@ -59,14 +59,14 @@ angular.module('etcdBrowser', ['ngRoute', 'etcd', 'timeRelative'])
       //hide any errors
       $('#etcd-browse-error').hide();
       // Looking at a directory if we got an array
-      if (data.length) {
-        $scope.list = data;
+      if (data.dir === true) {
+        $scope.list = data.kvs;
         $scope.preview = 'etcd-preview-hide';
       } else {
         $scope.singleValue = data.value;
         $scope.preview = 'etcd-preview-reveal';
         $scope.key.getParent().get().success(function(data) {
-          $scope.list = data;
+          $scope.list = data.kvs;
         });
       }
       $scope.previewMessage = 'No key selected.';

+ 1 - 1
mod/dashboard/app/views/browser.html

@@ -56,7 +56,7 @@
 			</thead>
 			<tbody>
 			    <tr ng-repeat="key in list | orderBy:'key'">
-			        <td><a ng-class="{true:'directory'}[key.dir]" href="#/v1/keys{{key.key}}" highlight>{{key.key}}</a></td>
+			        <td><a ng-class="{true:'directory'}[key.dir]" href="#/v2/keys{{key.key}}" highlight>{{key.key}}</a></td>
 			        <td ng-switch on="!!key.expiration" class="etcd-ttl">
 					    <div ng-switch-when="true"><time relative datetime="{{key.expiration.substring(0, key.expiration.lastIndexOf('-'))}}"></time></div>
 					    <div ng-switch-default class="etcd-ttl-none">&mdash;</div>