You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jl...@apache.org on 2016/03/11 06:47:22 UTC
[14/21] ambari git commit: AMBARI-13216: Add a "Add" button to Repo
management UI. (mithmatt)
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/3f3fdbd4
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3f3fdbd4
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3f3fdbd4
Branch: refs/heads/AMBARI-13364
Commit: 3f3fdbd47a20a6401c7090a909d5235ccf996d83
Parents: e4544a5
Author: Matt <mm...@pivotal.io>
Authored: Thu Mar 10 03:52:33 2016 -0800
Committer: Matt <mm...@pivotal.io>
Committed: Thu Mar 10 03:52:33 2016 -0800
----------------------------------------------------------------------
.../main/resources/ui/admin-web/app/index.html | 1 +
.../app/scripts/controllers/mainCtrl.js | 8 +-
.../stackVersions/StackVersionsCreateCtrl.js | 11 ++-
.../stackVersions/StackVersionsEditCtrl.js | 9 +-
.../app/scripts/services/AddRepositoryModal.js | 98 +++++++++++++++++++
.../resources/ui/admin-web/app/styles/main.css | 5 +-
.../app/views/modals/AddRepositoryModal.html | 63 +++++++++++++
.../views/stackVersions/stackVersionPage.html | 8 +-
.../test/unit/controllers/mainCtrl_test.js | 1 +
.../unit/services/AddRepositoryModal_test.js | 99 ++++++++++++++++++++
ambari-web/app/config.js | 3 +-
11 files changed, 298 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/3f3fdbd4/ambari-admin/src/main/resources/ui/admin-web/app/index.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/index.html b/ambari-admin/src/main/resources/ui/admin-web/app/index.html
index e7cda02..6557b55 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/index.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/index.html
@@ -162,6 +162,7 @@
<script src="scripts/services/GetDifference.js"></script>
<script src="scripts/services/UnsavedDialog.js"></script>
<script src="scripts/services/Stack.js"></script>
+ <script src="scripts/services/AddRepositoryModal.js"></script>
<!-- endbuild -->
</body>
</html>
http://git-wip-us.apache.org/repos/asf/ambari/blob/3f3fdbd4/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js
index 17f5981..5d1d261 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js
@@ -18,7 +18,7 @@
'use strict';
angular.module('ambariAdminConsole')
-.controller('MainCtrl',['$scope','$rootScope','$window','Auth', 'Alert', '$modal', 'Cluster', 'View', '$translate', function($scope, $rootScope, $window, Auth, Alert, $modal, Cluster, View, $translate) {
+.controller('MainCtrl',['$scope','$rootScope','$window','Auth', 'Alert', '$modal', 'Cluster', 'View', '$translate', '$http', 'Settings', function($scope, $rootScope, $window, Auth, Alert, $modal, Cluster, View, $translate, $http, Settings) {
var $t = $translate.instant;
$scope.signOut = function() {
Auth.signout().finally(function() {
@@ -27,6 +27,12 @@ angular.module('ambariAdminConsole')
};
$scope.ambariVersion = null;
+ $rootScope.supports = {};
+
+ $http.get(Settings.baseUrl + "/persist/user-pref-" + Auth.getCurrentUser() + "-supports")
+ .then(function(data) {
+ $rootScope.supports = data.data ? data.data : {};
+ });
$scope.about = function() {
var ambariVersion = $scope.ambariVersion;
http://git-wip-us.apache.org/repos/asf/ambari/blob/3f3fdbd4/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsCreateCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsCreateCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsCreateCtrl.js
index 46e4a11..544e282 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsCreateCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsCreateCtrl.js
@@ -18,7 +18,7 @@
'use strict';
angular.module('ambariAdminConsole')
-.controller('StackVersionsCreateCtrl', ['$scope', 'Stack', '$routeParams', '$location', 'Alert', '$translate', 'Cluster', function($scope, Stack, $routeParams, $location, Alert, $translate, Cluster) {
+.controller('StackVersionsCreateCtrl', ['$scope', 'Stack', '$routeParams', '$location', 'Alert', '$translate', 'Cluster', 'AddRepositoryModal', function($scope, Stack, $routeParams, $location, Alert, $translate, Cluster, AddRepositoryModal) {
var $t = $translate.instant;
$scope.constants = {
os: $t('versions.os')
@@ -195,6 +195,13 @@ angular.module('ambariAdminConsole')
}
};
+ /**
+ * On click handler for adding a new repository
+ */
+ $scope.addRepository = function() {
+ AddRepositoryModal.show($scope.osList, $scope.upgradeStack.stack_name, $scope.upgradeStack.stack_version, $scope.id);
+ };
+
$scope.isSaveButtonDisabled = function() {
var enabled = false;
$scope.osList.forEach(function(os) {
@@ -203,7 +210,7 @@ angular.module('ambariAdminConsole')
}
});
return !enabled;
- }
+ };
$scope.defaulfOSRepos = {};
http://git-wip-us.apache.org/repos/asf/ambari/blob/3f3fdbd4/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsEditCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsEditCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsEditCtrl.js
index d1da4c4..2c3f000 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsEditCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsEditCtrl.js
@@ -18,7 +18,7 @@
'use strict';
angular.module('ambariAdminConsole')
-.controller('StackVersionsEditCtrl', ['$scope', '$location', 'Cluster', 'Stack', '$routeParams', 'ConfirmationModal', 'Alert', '$translate', function($scope, $location, Cluster, Stack, $routeParams, ConfirmationModal, Alert, $translate) {
+.controller('StackVersionsEditCtrl', ['$scope', '$location', 'Cluster', 'Stack', '$routeParams', 'ConfirmationModal', 'Alert', '$translate', 'AddRepositoryModal', function($scope, $location, Cluster, Stack, $routeParams, ConfirmationModal, Alert, $translate, AddRepositoryModal) {
var $t = $translate.instant;
$scope.constants = {
os: $t('versions.os')
@@ -234,6 +234,13 @@ angular.module('ambariAdminConsole')
}
};
+ /**
+ * On click handler for adding a new repository
+ */
+ $scope.addRepository = function() {
+ AddRepositoryModal.show($scope.osList, $scope.upgradeStack.stack_name, $scope.upgradeStack.stack_version, $scope.id);
+ };
+
$scope.isSaveButtonDisabled = function() {
var enabled = false;
$scope.osList.forEach(function(os) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/3f3fdbd4/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
new file mode 100644
index 0000000..96a0155
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/AddRepositoryModal.js
@@ -0,0 +1,98 @@
+/**
+ * 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.
+ */
+'use strict';
+
+angular.module('ambariAdminConsole')
+ .factory('AddRepositoryModal', ['$modal', '$q', function($modal, $q) {
+ var modalObject = {};
+
+ 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;
+ };
+
+ 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;
+ };
+
+ 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]
+ };
+
+ $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
+ }
+ });
+
+ $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;
+ };
+
+ return modalObject;
+ }]);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/3f3fdbd4/ambari-admin/src/main/resources/ui/admin-web/app/styles/main.css
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/styles/main.css b/ambari-admin/src/main/resources/ui/admin-web/app/styles/main.css
index 9348564..c435914 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/styles/main.css
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/styles/main.css
@@ -1487,5 +1487,6 @@ thead.view-permission-header > tr > th {
text-align: center;
}
-
-
+.pull-up {
+ margin-top: -2px;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/3f3fdbd4/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
new file mode 100644
index 0000000..a439bde
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/modals/AddRepositoryModal.html
@@ -0,0 +1,63 @@
+<!--
+* 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.
+-->
+<div class="modal-header" xmlns="http://www.w3.org/1999/html">
+ <h3 class="modal-title">Add Repository</h3>
+</div>
+<form class="form-horizontal" name="addRepoForm" novalidate>
+ <div class="modal-body">
+ <div class="alert alert-warning hide-soft" ng-class="{'visible' : showAlert}" role="alert">
+ A repository with the same Repo ID already exists for {{repo.selectedOS}}!
+ </div>
+ <div class="form-group">
+ <div class="col-sm-3">
+ <label class="control-label">OS</label>
+ </div>
+ <div class="col-sm-4">
+ <select class="form-control" ng-options="os for os in osTypes" ng-model="repo.selectedOS"></select>
+ </div>
+ </div>
+ <div class="form-group">
+ <div class="col-sm-3">
+ <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="true">
+ </div>
+ </div>
+ <div class="form-group">
+ <div class="col-sm-3">
+ <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="true">
+ </div>
+ </div>
+ <div class="form-group">
+ <div class="col-sm-3">
+ <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="true">
+ </div>
+ </div>
+ </div>
+ <div class="modal-footer">
+ <button class="btn btn-default" ng-click="cancel()">Cancel</button>
+ <button class="btn btn-primary" ng-disabled="addRepoForm.$invalid" ng-click="add(repo)" >Add</button>
+ </div>
+</form>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/3f3fdbd4/ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/stackVersionPage.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/stackVersionPage.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/stackVersionPage.html
index 839b47d..1eac23f 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/stackVersionPage.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/stackVersionPage.html
@@ -127,7 +127,13 @@
</div>
<div class="panel panel-default repos-panel">
<div class="panel-heading">
- <h3 class="panel-title">{{'versions.repos' | translate}}</h3>
+ <h3 class="panel-title">
+ {{'versions.repos' | translate}}
+ <button ng-show="supports.addingNewRepository" class="btn btn-primary pull-right btn-xs pull-up" ng-click="addRepository()">
+ <span class="glyphicon glyphicon-plus"></span>
+ {{'common.add' | translate:'{ term: "Repository" }'}}
+ </button>
+ </h3>
</div>
<div class="panel-body">
<div class="alert alert-info" role="alert">{{'versions.alerts.baseURLs' | translate}}</div>
http://git-wip-us.apache.org/repos/asf/ambari/blob/3f3fdbd4/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/3f3fdbd4/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..73239b5
--- /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);
+ });
+});
http://git-wip-us.apache.org/repos/asf/ambari/blob/3f3fdbd4/ambari-web/app/config.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/config.js b/ambari-web/app/config.js
index 92ba8ae..5d3b27a 100644
--- a/ambari-web/app/config.js
+++ b/ambari-web/app/config.js
@@ -79,7 +79,8 @@ App.supports = {
hostComboSearchBox: true,
serviceAutoStart: false,
logSearch: false,
- redhatSatellite: false
+ redhatSatellite: false,
+ addingNewRepository: false
};
if (App.enableExperimental) {