ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mithm...@apache.org
Subject ambari git commit: AMBARI-13216: Add a "Add" button to Repo management UI. (mithmatt)
Date Thu, 10 Mar 2016 12:03:04 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 23386d0d5 -> d0b999e42


AMBARI-13216: Add a "Add" button to Repo management UI. (mithmatt)


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

Branch: refs/heads/branch-2.2
Commit: d0b999e4261c72a8db8b6fa234ea9cb3db527552
Parents: 23386d0
Author: Matt <mmathew@pivotal.io>
Authored: Thu Mar 10 04:00:37 2016 -0800
Committer: Matt <mmathew@pivotal.io>
Committed: Thu Mar 10 04:00:37 2016 -0800

----------------------------------------------------------------------
 .../app/scripts/services/AddRepositoryModal.js  | 133 ++++++++++---------
 .../app/views/modals/AddRepositoryModal.html    |   6 +-
 .../test/unit/controllers/mainCtrl_test.js      |   1 +
 .../unit/services/AddRepositoryModal_test.js    |  99 ++++++++++++++
 4 files changed, 171 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d0b999e4/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/AddRepositoryModal.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/AddRepositoryModal.js
b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/AddRepositoryModal.js
index d4238c8..96a0155 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/AddRepositoryModal.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/AddRepositoryModal.js
@@ -19,77 +19,80 @@
 
 angular.module('ambariAdminConsole')
   .factory('AddRepositoryModal', ['$modal', '$q', function($modal, $q) {
-    return {
-      show: function(osList, stackName, stackVersion, repositoryVersionId) {
-        var deferred = $q.defer();
-        var modalInstance = $modal.open({
-          templateUrl: 'views/modals/AddRepositoryModal.html',
-          controller: ['$scope', '$modalInstance', function($scope, $modalInstance) {
-            $scope.osTypes = osList.map(function(os) {
-              return os.OperatingSystems.os_type;
-            });
-            $scope.repo = {
-              selectedOS: $scope.osTypes[0]
-            };
+    var modalObject = {};
 
-            // Check if repository with the same repoId exists among repositories for the
selectedOS
-            var repoExists = function(existingRepos, repoId) {
-              for(var i = existingRepos.length - 1; i >= 0; --i) {
-                if (existingRepos[i].Repositories.repo_id === repoId) {
-                  return true;
-                }
-              }
-              return false;
-            };
+    modalObject.repoExists = function(existingRepos, repoId) {
+      for(var i = existingRepos.length - 1; i >= 0; --i) {
+        if (existingRepos[i].Repositories.repo_id === repoId) {
+          return true;
+        }
+      }
+      return false;
+    };
 
-            $scope.add = function(newRepo) {
-              var repositoriesForOS;
+    modalObject.getRepositoriesForOS = function (osList, selectedOS) {
+      // Get existing list of repositories for selectedOS
+      for (var i = osList.length - 1; i >= 0; --i) {
+        if (osList[i].OperatingSystems.os_type === selectedOS) {
+          osList[i].repositories = osList[i].repositories || [];
+          return osList[i].repositories;
+        }
+      }
+      return null;
+    };
 
-              // Get existing list of repositories for selectedOS
-              for(var i = osList.length - 1; i >= 0; --i) {
-                if (osList[i].OperatingSystems.os_type === newRepo.selectedOS) {
-                  osList[i].repositories = osList[i].repositories || [];
-                  repositoriesForOS = osList[i].repositories;
-                  break;
-                }
-              }
+    modalObject.show = function (osList, stackName, stackVersion, repositoryVersionId) {
+      var deferred = $q.defer();
+      var modalInstance = $modal.open({
+        templateUrl: 'views/modals/AddRepositoryModal.html',
+        controller: ['$scope', '$modalInstance', function ($scope, $modalInstance) {
+          $scope.osTypes = osList.map(function (os) {
+            return os.OperatingSystems.os_type;
+          });
+          $scope.repo = {
+            selectedOS: $scope.osTypes[0]
+          };
 
-              // If repo with the same id exists for the selectedOS, show an alert and do
not take any action
-              $scope.showAlert = repoExists(repositoriesForOS, newRepo.id);
-              if($scope.showAlert) {
-                return;
-              }
+          $scope.add = function (newRepo) {
+            var repositoriesForOS = modalObject.getRepositoriesForOS(osList, newRepo.selectedOS);
+
+            // If repo with the same id exists for the selectedOS, show an alert and do not
take any action
+            $scope.showAlert = modalObject.repoExists(repositoriesForOS, newRepo.id);
+            if ($scope.showAlert) {
+              return;
+            }
 
-              // If no duplicate repository is found on the selectedOS, add the new repository
-              repositoriesForOS.push({
-                Repositories: {
-                  repo_id: newRepo.id,
-                  repo_name: newRepo.name,
-                  os_type: newRepo.selectedOS,
-                  base_url: newRepo.baseUrl,
-                  stack_name: stackName,
-                  stack_version: stackVersion,
-                  repository_version_id: repositoryVersionId
-                }
-              });
+            // If no duplicate repository is found on the selectedOS, add the new repository
+            repositoriesForOS.push({
+              Repositories: {
+                repo_id: newRepo.id,
+                repo_name: newRepo.name,
+                os_type: newRepo.selectedOS,
+                base_url: newRepo.baseUrl,
+                stack_name: stackName,
+                stack_version: stackVersion,
+                repository_version_id: repositoryVersionId
+              }
+            });
 
-              $modalInstance.close();
-              deferred.resolve();
-            };
+            $modalInstance.close();
+            deferred.resolve();
+          };
 
-            $scope.cancel = function() {
-              $modalInstance.dismiss();
-              deferred.reject();
-            };
-          }]
-        });
-        modalInstance.result.then(function() {
-          // Gets triggered on close
-        }, function() {
-          // Gets triggered on dismiss
-          deferred.reject();
-        });
-        return deferred.promise;
-      }
+          $scope.cancel = function () {
+            $modalInstance.dismiss();
+            deferred.reject();
+          };
+        }]
+      });
+      modalInstance.result.then(function () {
+        // Gets triggered on close
+      }, function () {
+        // Gets triggered on dismiss
+        deferred.reject();
+      });
+      return deferred.promise;
     };
+
+    return modalObject;
   }]);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/d0b999e4/ambari-admin/src/main/resources/ui/admin-web/app/views/modals/AddRepositoryModal.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/modals/AddRepositoryModal.html
b/ambari-admin/src/main/resources/ui/admin-web/app/views/modals/AddRepositoryModal.html
index c53a908..a439bde 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/modals/AddRepositoryModal.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/modals/AddRepositoryModal.html
@@ -36,7 +36,7 @@
                 <label class="control-label">Repo ID</label>
             </div>
             <div class="col-sm-9">
-                <input name="repoId" type="text" class="form-control" ng-model="repo.id"
ng-required="required">
+                <input name="repoId" type="text" class="form-control" ng-model="repo.id"
ng-required="true">
             </div>
         </div>
         <div class="form-group">
@@ -44,7 +44,7 @@
                 <label class="control-label">Repo Name</label>
             </div>
             <div class="col-sm-9">
-                <input name="repoName" type="text" class="form-control" ng-model="repo.name"
ng-required="required">
+                <input name="repoName" type="text" class="form-control" ng-model="repo.name"
ng-required="true">
             </div>
         </div>
         <div class="form-group">
@@ -52,7 +52,7 @@
                 <label class="control-label">Base URL</label>
             </div>
             <div class="col-sm-9">
-                <input name="repoUrl" type="text" class="form-control" ng-model="repo.baseUrl"
ng-required="required">
+                <input name="repoUrl" type="text" class="form-control" ng-model="repo.baseUrl"
ng-required="true">
             </div>
         </div>
     </div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/d0b999e4/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/mainCtrl_test.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/mainCtrl_test.js
b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/mainCtrl_test.js
index 8d748d2..e12a61d 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/mainCtrl_test.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/mainCtrl_test.js
@@ -97,6 +97,7 @@ describe('#Auth', function () {
             }
           ]
         });
+      $httpBackend.whenGET(/\/persist\/user-pref-.*/).respond(200, {data: {data: {addingNewRepository:
true}}});
       scope = $rootScope.$new();
       scope.$apply();
       ctrl = $controller('MainCtrl', {$scope: scope});

http://git-wip-us.apache.org/repos/asf/ambari/blob/d0b999e4/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/AddRepositoryModal_test.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/AddRepositoryModal_test.js
b/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/AddRepositoryModal_test.js
new file mode 100644
index 0000000..62e3a81
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/AddRepositoryModal_test.js
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+describe('AddRepositoryModal Service', function () {
+  var AddRepositoryModal, $modal;
+
+  beforeEach(module('ambariAdminConsole', function($provide){
+  }));
+
+  beforeEach(inject(function (_AddRepositoryModal_, _$modal_) {
+    AddRepositoryModal = _AddRepositoryModal_;
+    $modal = _$modal_;
+
+    spyOn($modal, 'open').andReturn({
+      result: {
+        then: function() {
+        }
+      }
+    });
+  }));
+
+  it('should open modal window', function () {
+    AddRepositoryModal.show();
+    expect($modal.open).toHaveBeenCalled();
+  });
+
+  it('should check if repo exists', function () {
+    var existingRepos = [
+      {
+        Repositories: {
+          repo_id: 'repo1'
+        }
+      }
+    ];
+    expect(AddRepositoryModal.repoExists(existingRepos, 'repo1')).toBe(true);
+    expect(AddRepositoryModal.repoExists(existingRepos, 'repo2')).toBe(false);
+  });
+
+  it('should get repositories for selected OS', function () {
+    var os1Repos = [
+      {
+        Repositories: {
+          os_type: 'os1',
+          repo_id: 'repo1'
+        }
+      }, {
+        Repositories: {
+          os_type: 'os1',
+          repo_id: 'repo2'
+        }
+      }
+    ];
+    var os2Repos = [
+      {
+        Repositories: {
+          os_type: 'os2',
+          repo_id: 'repo1'
+        }
+      },{
+        Repositories: {
+          os_type: 'os2',
+          repo_id: 'repo2'
+        }
+      }
+    ];
+
+    var osList = [
+      {
+        OperatingSystems: {
+          os_type: 'os1'
+        },
+        repositories: os1Repos
+      }, {
+        OperatingSystems: {
+          os_type: 'os2'
+        },
+        repositories: os2Repos
+      }
+    ];
+    expect(AddRepositoryModal.getRepositoriesForOS(osList, 'os1')).toEqual(os1Repos);
+    expect(AddRepositoryModal.getRepositoriesForOS(osList, 'os2')).toEqual(os2Repos);
+    expect(AddRepositoryModal.getRepositoriesForOS(osList, 'os3')).toBe(null);
+  });
+});
\ No newline at end of file


Mime
View raw message