ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ababiic...@apache.org
Subject ambari git commit: AMBARI-20025 Incorrect work of filters on Versions page of Admin View. (ababiichuk)
Date Wed, 15 Feb 2017 16:33:09 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 45842645c -> d75756efa


AMBARI-20025 Incorrect work of filters on Versions page of Admin View. (ababiichuk)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d75756ef
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d75756ef
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d75756ef

Branch: refs/heads/trunk
Commit: d75756efa7bcecb09d0ee73db6c29b018ba964fc
Parents: 4584264
Author: ababiichuk <ababiichuk@hortonworks.com>
Authored: Wed Feb 15 17:29:05 2017 +0200
Committer: ababiichuk <ababiichuk@hortonworks.com>
Committed: Wed Feb 15 18:41:52 2017 +0200

----------------------------------------------------------------------
 .../stackVersions/StackVersionsListCtrl.js      | 56 +++++++++++++-------
 .../ui/admin-web/app/scripts/services/Stack.js  | 15 ++++--
 .../stackVersions/StackversionsListCtrl_test.js | 38 +++++++++----
 3 files changed, 76 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d75756ef/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsListCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsListCtrl.js
b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsListCtrl.js
index 1de8817..2990cef 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsListCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsListCtrl.js
@@ -77,29 +77,47 @@ angular.module('ambariAdminConsole')
       $scope.resetPagination();
     };
 
-    $scope.fetchRepoClusterStatus = function () {
-      var clusterName = ($scope.clusters && $scope.clusters.length > 0) ? $scope.clusters[0].Clusters.cluster_name
: null; // only support one cluster at the moment
-      if (clusterName) {
-        angular.forEach($scope.repos, function (repo) {
-          Cluster.getRepoVersionStatus(clusterName, repo.id).then(function (response) {
-            repo.status = response.status;
-            repo.totalHosts = response.totalHosts;
-            repo.currentHosts = response.currentHosts;
-            repo.installedHosts = response.installedHosts;
-            repo.stackVersionId = response.stackVersionId;
-            repo.cluster = (repo.status == 'current' || repo.status == 'installed') ? clusterName
: '';
+    $scope.fetchRepoClusterStatus = function (allRepos) {
+      if (allRepos && allRepos.length) {
+        var clusterName = ($scope.clusters && $scope.clusters.length > 0) ? $scope.clusters[0].Clusters.cluster_name
: null, // only support one cluster at the moment
+          repos = [],
+          processedRepos = 0;
+        if (clusterName) {
+          angular.forEach(allRepos, function (repo) {
+            Cluster.getRepoVersionStatus(clusterName, repo.id).then(function (response) {
+              repo.cluster = (response.status == 'current' || response.status == 'installed')
? clusterName : '';
+              if (!$scope.filter.cluster.current.value || repo.cluster) {
+                repo.status = response.status;
+                repo.totalHosts = response.totalHosts;
+                repo.currentHosts = response.currentHosts;
+                repo.installedHosts = response.installedHosts;
+                repo.stackVersionId = response.stackVersionId;
+                repos.push(repo);
+              }
+              processedRepos++;
+              if (processedRepos === allRepos.length) {
+                var from = ($scope.pagination.currentPage - 1) * $scope.pagination.itemsPerPage;
+                var to = (repos.length - from > $scope.pagination.itemsPerPage) ? from
+ $scope.pagination.itemsPerPage : repos.length;
+                $scope.repos = repos.slice(from, to);
+                $scope.tableInfo.total = repos.length;
+                $scope.pagination.totalRepos = repos.length;
+                $scope.tableInfo.showed = to - from;
+              }
+            });
           });
-        });
+        }
+      } else {
+        $scope.repos = [];
+        $scope.tableInfo.total = 0;
+        $scope.pagination.totalRepos = 0;
+        $scope.tableInfo.showed = 0;
       }
     };
 
     $scope.fetchRepos = function () {
-      return Stack.allRepos($scope.filter, $scope.pagination).then(function (repos) {
+      return Stack.allRepos($scope.filter).then(function (repos) {
         $scope.isLoading = false;
-        $scope.pagination.totalRepos = repos.itemTotal;
-        $scope.repos = repos.items;
-        $scope.tableInfo.total = repos.itemTotal;
-        $scope.tableInfo.showed = repos.showed;
+        return repos.items;
       });
     };
 
@@ -161,8 +179,8 @@ angular.module('ambariAdminConsole')
         .then(function () {
           return $scope.fetchRepos();
         })
-        .then(function () {
-          $scope.fetchRepoClusterStatus();
+        .then(function (repos) {
+          $scope.fetchRepoClusterStatus(repos);
         });
     };
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/d75756ef/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Stack.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Stack.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Stack.js
index 84d7b33..e028906 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Stack.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Stack.js
@@ -179,11 +179,16 @@ angular.module('ambariAdminConsole')
         // prepare response data with client side pagination
         var response = {};
         response.itemTotal = repos.length;
-        var from = (pagination.currentPage - 1) * pagination.itemsPerPage;
-        var to = (repos.length - from > pagination.itemsPerPage)? from + pagination.itemsPerPage
: repos.length;
-        response.items = repos.slice(from, to);
-        response.showed = to - from;
-        deferred.resolve(response)
+        if (pagination) {
+          var from = (pagination.currentPage - 1) * pagination.itemsPerPage;
+          var to = (repos.length - from > pagination.itemsPerPage)? from + pagination.itemsPerPage
: repos.length;
+          response.items = repos.slice(from, to);
+          response.showed = to - from;
+        } else {
+          response.items = repos;
+          response.showed = repos.length;
+        }
+        deferred.resolve(response);
       })
       .error(function (data) {
         deferred.reject(data);

http://git-wip-us.apache.org/repos/asf/ambari/blob/d75756ef/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/stackVersions/StackversionsListCtrl_test.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/stackVersions/StackversionsListCtrl_test.js
b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/stackVersions/StackversionsListCtrl_test.js
index 6f168db..e6f2cc1 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/stackVersions/StackversionsListCtrl_test.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/stackVersions/StackversionsListCtrl_test.js
@@ -18,24 +18,44 @@
 
 describe('#Cluster', function () {
   describe('StackVersionsListCtrl', function() {
-    var scope, ctrl, $httpBackend;
+    var scope, ctrl, Stack;
 
     beforeEach(module('ambariAdminConsole', function($provide) {
 
     }));
 
-    beforeEach(inject(function($rootScope, $controller, _$httpBackend_) {
-      scope = $rootScope.$new();
-      ctrl = $controller('StackVersionsListCtrl', {$scope: scope});
-      $httpBackend = _$httpBackend_;
-    }));
+    beforeEach(function () {
+      module('ambariAdminConsole');
+      inject(function($rootScope, $controller) {
+        scope = $rootScope.$new();
+        ctrl = $controller('StackVersionsListCtrl', {$scope: scope});
+      });
+    });
 
     describe('#fetchRepos()', function () {
 
-      it('saves list of stacks', function() {
-        scope.fetchRepos().then(function() {
-          expect(Array.isArray(scope.repos)).toBe(true);
+      var repos;
+
+      beforeEach(inject(function(_Stack_) {
+        Stack = _Stack_;
+        spyOn(Stack, 'allRepos').andReturn({
+          then: function (callback) {
+            repos = callback({
+              items: [{}, {}]
+            });
+          }
         });
+        repos = [];
+        scope.isLoading = true;
+        scope.fetchRepos();
+      }));
+
+      it('saves list of stacks', function() {
+        expect(repos.length).toEqual(2);
+      });
+
+      it('isLoading should be set to false', function() {
+        expect(scope.isLoading).toBe(false);
       });
 
     });


Mime
View raw message