diff --git a/apollo-portal/src/main/resources/static/app/role.html b/apollo-portal/src/main/resources/static/app/role.html index 0db6a324a8bd5e3ab7cfedfe9e33c77b82bdf2f9..809d953f4856972fcac46b9b103cbcf463404b05 100644 --- a/apollo-portal/src/main/resources/static/app/role.html +++ b/apollo-portal/src/main/resources/static/app/role.html @@ -7,6 +7,7 @@ + 权限管理 @@ -37,9 +38,9 @@
- +
- +
@@ -88,6 +89,7 @@ + diff --git a/apollo-portal/src/main/resources/static/namespace.html b/apollo-portal/src/main/resources/static/namespace.html index 08de5c434d19bea9cb19d69daf567f3252993340..abbd837f8efc3f7f1aefff4f0d9635c8ae0c1fdf 100644 --- a/apollo-portal/src/main/resources/static/namespace.html +++ b/apollo-portal/src/main/resources/static/namespace.html @@ -32,15 +32,26 @@
-
+ +
+
+ + +
+
+ +
-
+
+
- +
@@ -48,7 +59,9 @@
- +
@@ -65,7 +78,9 @@
- +
+
- +
@@ -66,9 +67,10 @@
- + +
- +
@@ -116,6 +118,8 @@ + + diff --git a/apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js b/apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js index 235b9db7c0057945102e9c901689578db231c7c5..9e4516e8de24dd3dcef76dac2437755227134d24 100644 --- a/apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js +++ b/apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js @@ -1,107 +1,120 @@ namespace_module.controller("LinkNamespaceController", - ['$scope', '$location', '$window', 'toastr', 'AppService', 'AppUtil', 'NamespaceService', - function ($scope, $location, $window, toastr, AppService, AppUtil, NamespaceService) { + ['$scope', '$location', '$window', 'toastr', 'AppService', 'AppUtil', 'NamespaceService', + function ($scope, $location, $window, toastr, AppService, AppUtil, NamespaceService) { - var params = AppUtil.parseParams($location.$$url); - $scope.appId = params.appid; - $scope.type = params.type; + var params = AppUtil.parseParams($location.$$url); + $scope.appId = params.appid; + $scope.type = params.type; - $scope.step = 1; + $scope.step = 1; - NamespaceService.find_public_namespaces().then(function (result) { - var publicNamespaces = []; - result.forEach(function (item) { - var namespace = {}; - namespace.id = item.name; - namespace.text = item.name; - publicNamespaces.push(namespace); - }); - $('#namespaces').select2({ - placeholder: '请选择Namespace', - width: '100%', - data: publicNamespaces - }); - }, function (result) { - toastr.error(AppUtil.errorMsg(result), "load public namespace error"); - }); + NamespaceService.find_public_namespaces().then(function (result) { + var publicNamespaces = []; + result.forEach(function (item) { + var namespace = {}; + namespace.id = item.name; + namespace.text = item.name; + publicNamespaces.push(namespace); + }); + $('#namespaces').select2({ + placeholder: '请选择Namespace', + width: '100%', + data: publicNamespaces + }); + }, function (result) { + toastr.error(AppUtil.errorMsg(result), "load public namespace error"); + }); - AppService.load($scope.appId).then(function (result) { - $scope.appBaseInfo = result; - $scope.appBaseInfo.namespacePrefix = result.orgId + '.'; - }, function (result) { - toastr.error(AppUtil.errorMsg(result), "加载App信息出错"); - }); + AppService.load($scope.appId).then(function (result) { + $scope.appBaseInfo = result; + $scope.appBaseInfo.namespacePrefix = result.orgId + '.'; + }, function (result) { + toastr.error(AppUtil.errorMsg(result), "加载App信息出错"); + }); - $scope.appNamespace = { - appId:$scope.appId, - name:'', - comment:'' - }; + $scope.appNamespace = { + appId: $scope.appId, + name: '', + comment: '' + }; - $scope.concatNamespace = function() { - if (!$scope.appBaseInfo) { - return ''; - } - return $scope.appBaseInfo.namespacePrefix + - ($scope.appNamespace.name ? $scope.appNamespace.name : ''); - }; + $scope.concatNamespace = function () { + if (!$scope.appBaseInfo) { + return ''; + } + return $scope.appBaseInfo.namespacePrefix + + ($scope.appNamespace.name ? $scope.appNamespace.name : ''); + }; - var selectedClusters = []; - $scope.collectSelectedClusters = function (data) { - selectedClusters = data; - }; - $scope.createNamespace = function () { - if ($scope.type == 'link'){ - if (selectedClusters.length == 0){ - toastr.warning("请选择集群"); - return; - } + var selectedClusters = []; + $scope.collectSelectedClusters = function (data) { + selectedClusters = data; + }; + $scope.createNamespace = function () { + if ($scope.type == 'link') { + if (selectedClusters.length == 0) { + toastr.warning("请选择集群"); + return; + } - if ($scope.namespaceType == 1){ - var selectedNamespaceName = $('#namespaces').select2('data')[0].id; - if (!selectedNamespaceName) { - toastr.warning("请选择Namespace"); - return; - } + if ($scope.namespaceType == 1) { + var selectedNamespaceName = $('#namespaces').select2('data')[0].id; + if (!selectedNamespaceName) { + toastr.warning("请选择Namespace"); + return; + } - $scope.namespaceName = selectedNamespaceName; - } + $scope.namespaceName = selectedNamespaceName; + } - var namespaceCreationModels = []; - selectedClusters.forEach(function (cluster) { - namespaceCreationModels.push({ - env: cluster.env, - namespace: { - appId: $scope.appId, - clusterName: cluster.clusterName, - namespaceName: $scope.namespaceName - } - }); - }); - NamespaceService.createNamespace($scope.appId, namespaceCreationModels) - .then(function (result) { - toastr.success("创建成功"); - $scope.step = 2; - }, function (result) { - toastr.error(AppUtil.errorMsg(result)); - }); - }else { - NamespaceService.createAppNamespace($scope.appId, $scope.appNamespace).then(function (result) { - $scope.step = 2; - }, function (result) { - toastr.error(AppUtil.errorMsg(result), "创建失败"); - }); - } + var namespaceCreationModels = []; + selectedClusters.forEach(function (cluster) { + namespaceCreationModels.push({ + env: cluster.env, + namespace: { + appId: $scope.appId, + clusterName: cluster.clusterName, + namespaceName: $scope.namespaceName + } + }); + }); + NamespaceService.createNamespace($scope.appId, namespaceCreationModels) + .then(function (result) { + toastr.success("创建成功"); + $scope.step = 2; + setInterval(function () { + $window.location.href = + '/namespace/role.html?#appid=' + $scope.appId + + "&namespaceName=" + $scope.namespaceName; + }, 1000); + }, function (result) { + toastr.error(AppUtil.errorMsg(result)); + }); + } else { + NamespaceService.createAppNamespace($scope.appId, $scope.appNamespace).then( + function (result) { + $scope.step = 2; + setInterval(function () { + $window.location.reload(); + }, 1000); + }, function (result) { + toastr.error(AppUtil.errorMsg(result), "创建失败"); + }); + } - }; + }; - $scope.namespaceType = 1; - $scope.selectNamespaceType = function (type) { - $scope.namespaceType = type; - }; + $scope.namespaceType = 1; + $scope.selectNamespaceType = function (type) { + $scope.namespaceType = type; + }; - $scope.back = function () { - $window.location.href = '/config.html?#appid=' + $scope.appId; - }; - }]); + $scope.back = function () { + $window.location.href = '/config.html?#appid=' + $scope.appId; + }; + + $scope.switchType = function (type) { + $scope.type = type; + }; + }]); diff --git a/apollo-portal/src/main/resources/static/scripts/controller/role/AppRoleController.js b/apollo-portal/src/main/resources/static/scripts/controller/role/AppRoleController.js index 6f6d1bcd6949c047b030fa631e47c48255c09d82..b77ba72917c23842453a516953b832f989ea4645 100644 --- a/apollo-portal/src/main/resources/static/scripts/controller/role/AppRoleController.js +++ b/apollo-portal/src/main/resources/static/scripts/controller/role/AppRoleController.js @@ -7,6 +7,8 @@ role_module.controller('AppRoleController', appId: params.appid }; + $scope.userSelectWidgetId = 'toAssignMasterRoleUser'; + PermissionService.has_assign_user_permission($scope.pageContext.appId) .then(function (result) { $scope.hasAssignUserPermission = result.hasPermission; @@ -21,14 +23,14 @@ role_module.controller('AppRoleController', }); - $scope.toAssignMasterRoleUser = ''; $scope.assignMasterRoleToUser = function () { + var toAssignMasterRoleUser = $('.' + $scope.userSelectWidgetId).select2('data')[0].id; PermissionService.assign_master_role($scope.pageContext.appId, - $scope.toAssignMasterRoleUser) + toAssignMasterRoleUser) .then(function (result) { toastr.success("添加成功"); - $scope.appRoleUsers.masterUsers.push({userId: $scope.toAssignMasterRoleUser}); + $scope.appRoleUsers.masterUsers.push({userId: toAssignMasterRoleUser}); }, function (result) { toastr.error(AppUtil.errorMsg(result), "添加失败"); }); diff --git a/apollo-portal/src/main/resources/static/scripts/controller/role/NamespaceRoleController.js b/apollo-portal/src/main/resources/static/scripts/controller/role/NamespaceRoleController.js index ceca031cc77d3ea430014df022bca127bfc998a9..2538b1abce29689e580e3251e38b1a543038bc80 100644 --- a/apollo-portal/src/main/resources/static/scripts/controller/role/NamespaceRoleController.js +++ b/apollo-portal/src/main/resources/static/scripts/controller/role/NamespaceRoleController.js @@ -1,12 +1,17 @@ role_module.controller('NamespaceRoleController', - ['$scope', '$location', '$window', 'toastr', 'AppService', 'AppUtil', 'PermissionService', - function ($scope, $location, $window, toastr, AppService, AppUtil, PermissionService) { + ['$scope', '$location', '$window', 'toastr', 'AppService', 'UserService', 'AppUtil', + 'PermissionService', + function ($scope, $location, $window, toastr, AppService, UserService, AppUtil, + PermissionService) { var params = AppUtil.parseParams($location.$$url); $scope.pageContext = { appId: params.appid, namespaceName: params.namespaceName }; + + $scope.releaseRoleWidgetId = 'releaseRoleWidgetId'; + $scope.modifyRoleWidgetId = 'modifyRoleWidgetId'; PermissionService.has_assign_user_permission($scope.pageContext.appId) .then(function (result) { @@ -24,26 +29,29 @@ role_module.controller('NamespaceRoleController', toastr.error(AppUtil.errorMsg(result), "加载授权用户出错"); }); - $scope.toAssignReleaseNamespaceRoleUser = '', $scope.toAssignModifyNamespaceRoleUser = ''; $scope.assignRoleToUser = function (roleType) { if ('ReleaseNamespace' == roleType) { + var toAssignReleaseNamespaceRoleUser = $('.' + $scope.releaseRoleWidgetId).select2('data')[0].id; PermissionService.assign_release_namespace_role($scope.pageContext.appId, $scope.pageContext.namespaceName, - $scope.toAssignReleaseNamespaceRoleUser) + toAssignReleaseNamespaceRoleUser) .then(function (result) { toastr.success("添加成功"); - $scope.rolesAssignedUsers.releaseRoleUsers.push({userId: $scope.toAssignReleaseNamespaceRoleUser}); + $scope.rolesAssignedUsers.releaseRoleUsers.push( + {userId: toAssignReleaseNamespaceRoleUser}); }, function (result) { toastr.error(AppUtil.errorMsg(result), "添加失败"); }); } else { + var toAssignModifyNamespaceRoleUser = $('.' + $scope.modifyRoleWidgetId).select2('data')[0].id; PermissionService.assign_modify_namespace_role($scope.pageContext.appId, $scope.pageContext.namespaceName, - $scope.toAssignModifyNamespaceRoleUser) + toAssignModifyNamespaceRoleUser) .then(function (result) { toastr.success("添加成功"); - $scope.rolesAssignedUsers.modifyRoleUsers.push({userId: $scope.toAssignModifyNamespaceRoleUser}); + $scope.rolesAssignedUsers.modifyRoleUsers.push( + {userId: toAssignModifyNamespaceRoleUser}); }, function (result) { toastr.error(AppUtil.errorMsg(result), "添加失败"); }); @@ -84,5 +92,8 @@ role_module.controller('NamespaceRoleController', } list.splice(index, 1); } + + $scope.modifyRoleUsersId = 'J_modify_role_users'; + $scope.releaseRoleUsersId = 'J_release_role_users'; }]); diff --git a/apollo-portal/src/main/resources/static/scripts/directive.js b/apollo-portal/src/main/resources/static/scripts/directive.js index 6e98407b850f1c0fd2aef47a0148597558e39abf..671c626b795e06e91efc47bd920e793424511eb8 100644 --- a/apollo-portal/src/main/resources/static/scripts/directive.js +++ b/apollo-portal/src/main/resources/static/scripts/directive.js @@ -258,3 +258,55 @@ directive_module.directive('apolloentrance', function ($compile, $window) { }); +/** entrance */ +directive_module.directive('apollouserselector', function ($compile, $window) { + return { + restrict: 'E', + templateUrl: '../views/component/user-selector.html', + transclude: true, + replace: true, + scope: { + id: '=apolloId' + }, + link: function (scope, element, attrs) { + + scope.$watch("id", initSelect2); + + var searchUsersAjax = { + ajax: { + url: '/users', + dataType: 'json', + delay: 250, + data: function (params) { + return { + keyword: params.term ? params.term: '', + limit: 100 + } + }, + processResults: function (data, params) { + var users = []; + data.forEach(function (user) { + users.push({ + id: user.userId, + text: user.userId + " | " + user.name + " | " + user.email + }) + }); + return { + results: users + } + + }, + cache: true, + minimumInputLength: 5 + } + }; + + function initSelect2(){ + $('.' + scope.id).select2(searchUsersAjax); + } + + } + } +}); + + diff --git a/apollo-portal/src/main/resources/static/scripts/services/UserService.js b/apollo-portal/src/main/resources/static/scripts/services/UserService.js index 0f7a76eedddf125f82aaf346005e07758f1f736c..d80f5cdcd3be063175243af0c70c946d7828931b 100644 --- a/apollo-portal/src/main/resources/static/scripts/services/UserService.js +++ b/apollo-portal/src/main/resources/static/scripts/services/UserService.js @@ -3,6 +3,10 @@ appService.service('UserService', ['$resource', '$q', function ($resource, $q) { load_user:{ method: 'GET', url:'/user' + }, + find_users: { + method: 'GET', + url: '/users' } }); return { @@ -16,6 +20,18 @@ appService.service('UserService', ['$resource', '$q', function ($resource, $q) { d.reject(result); }); return d.promise; + }, + find_users: function (keyword) { + var d = $q.defer(); + user_resource.find_users({ + keyword: keyword + }, + function (result) { + d.resolve(result); + }, function (result) { + d.reject(result); + }); + return d.promise; } } }]); diff --git a/apollo-portal/src/main/resources/static/views/component/user-selector.html b/apollo-portal/src/main/resources/static/views/component/user-selector.html new file mode 100644 index 0000000000000000000000000000000000000000..51a5e41dc9b1e7e9da18225c45616c4eb516431a --- /dev/null +++ b/apollo-portal/src/main/resources/static/views/component/user-selector.html @@ -0,0 +1,2 @@ +