Commit 219aff4a by lepdou

用户模糊搜索 流程优化

parent 2f620e6f
......@@ -7,6 +7,7 @@
<link rel="stylesheet" type="text/css" href="../vendor/angular/angular-toastr-1.4.1.min.css">
<link rel="stylesheet" type="text/css" media='all' href="../vendor/angular/loading-bar.min.css">
<link rel="stylesheet" type="text/css" href="../styles/common-style.css">
<link rel="stylesheet" type="text/css" href="../vendor/select2/select2.min.css">
<title>权限管理</title>
</head>
......@@ -37,9 +38,9 @@
<div class="col-sm-8">
<form class="form-inline" ng-submit="assignMasterRoleToUser()">
<div class="form-group">
<input type="text" class="form-control" placeholder="域账号" required ng-model="toAssignMasterRoleUser">
<apollouserselector apollo-id="userSelectWidgetId"></apollouserselector>
</div>
<button type="submit" class="btn btn-default">添加</button>
<button type="submit" class="btn btn-default" style="margin-left: 20px;">添加</button>
</form>
<!-- Split button -->
<div class="user-container">
......@@ -88,6 +89,7 @@
<!--nicescroll-->
<script src="../vendor/jquery.nicescroll.min.js"></script>
<script src="../vendor/select2/select2.min.js" type="text/javascript"></script>
<!--biz-->
<!--must import-->
<script type="application/javascript" src="../scripts/app.js"></script>
......
......@@ -32,15 +32,26 @@
</header>
<div class="panel-body">
<form class="form-horizontal" ng-show="step == 1" ng-submit="createNamespace()">
<div class="row text-right" style="padding-right: 20px;">
<div class="btn-group btn-group-sm" role="group" aria-label="...">
<button type="button" class="btn btn-default" ng-class="{active:type=='link'}" ng-click="switchType('link')">关联已存在的Namespace</button>
<button type="button" class="btn btn-default" ng-class="{active:type=='create'}" ng-click="switchType('create')">创建新的Namespace</button>
</div>
</div>
<form class="form-horizontal" style="margin-top: 30px;" ng-show="step == 1" ng-submit="createNamespace()">
<div class="form-group">
<label class="col-sm-3 control-label">应用ID</label>
<div class="col-sm-6" ng-bind="appId">
<div class="col-sm-6">
<label ng-bind="appId"></label>
</div>
</div>
<div class="form-horizontal" ng-show="type == 'link'">
<div class="form-group">
<label class="col-sm-3 control-label"><apollorequiredfiled></apollorequiredfiled> 选择集群</label>
<label class="col-sm-3 control-label">
<apollorequiredfiled></apollorequiredfiled>
选择集群</label>
<div class="col-sm-6">
<apolloclusterselector apollo-app-id="appId" apollo-default-all-checked="true"
apollo-select="collectSelectedClusters"></apolloclusterselector>
......@@ -48,7 +59,9 @@
</div>
</div>
<div class="form-group" ng-show="type == 'create'">
<label class="col-sm-3 control-label"><apollorequiredfiled></apollorequiredfiled> 名称</label>
<label class="col-sm-3 control-label">
<apollorequiredfiled></apollorequiredfiled>
名称</label>
<div class="col-sm-4">
<div class="input-group">
<span class="input-group-addon" ng-bind="appBaseInfo.namespacePrefix"></span>
......@@ -65,7 +78,9 @@
</div>
</div>
<div class="form-group" ng-show="type == 'link'">
<label class="col-sm-3 control-label"><apollorequiredfiled></apollorequiredfiled> namespace</label>
<label class="col-sm-3 control-label">
<apollorequiredfiled></apollorequiredfiled>
namespace</label>
<div class="col-sm-4">
<select id="namespaces">
<option></option>
......@@ -75,7 +90,7 @@
<div class="form-group">
<div class="col-sm-offset-3 col-sm-10">
<button type="submit" class="btn btn-default">提交</button>
<button type="submit" class="btn btn-primary">提交</button>
</div>
</div>
</form>
......
......@@ -7,6 +7,7 @@
<link rel="stylesheet" type="text/css" href="../vendor/angular/angular-toastr-1.4.1.min.css">
<link rel="stylesheet" type="text/css" media='all' href="../vendor/angular/loading-bar.min.css">
<link rel="stylesheet" type="text/css" href="../styles/common-style.css">
<link rel="stylesheet" type="text/css" href="../vendor/select2/select2.min.css">
<title>权限管理</title>
</head>
......@@ -37,9 +38,9 @@
<div class="col-sm-8">
<form class="form-inline" ng-submit="assignRoleToUser('ModifyNamespace')">
<div class="form-group">
<input type="text" class="form-control" placeholder="域账号" required ng-model="toAssignModifyNamespaceRoleUser">
<apollouserselector apollo-id="modifyRoleWidgetId"></apollouserselector>
</div>
<button type="submit" class="btn btn-default">添加</button>
<button type="submit" class="btn btn-default" style="margin-left: 20px;">添加</button>
</form>
<!-- Split button -->
<div class="user-container">
......@@ -66,9 +67,10 @@
<div class="col-sm-8">
<form class="form-inline" ng-submit="assignRoleToUser('ReleaseNamespace')">
<div class="form-group">
<input type="text" class="form-control" placeholder="域账号" required ng-model="toAssignReleaseNamespaceRoleUser">
<apollouserselector apollo-id="releaseRoleWidgetId"></apollouserselector>
</div>
<button type="submit" class="btn btn-default">添加</button>
<button type="submit" class="btn btn-default" style="margin-left: 20px;">添加</button>
</form>
<!-- Split button -->
<div style="margin-top: 15px;">
......@@ -116,6 +118,8 @@
<!--nicescroll-->
<script src="../vendor/jquery.nicescroll.min.js"></script>
<script src="../vendor/select2/select2.min.js" type="text/javascript"></script>
<!--biz-->
<!--must import-->
<script type="application/javascript" src="../scripts/app.js"></script>
......
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;
};
}]);
......@@ -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), "添加失败");
});
......
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';
}]);
......@@ -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);
}
}
}
});
......@@ -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;
}
}
}]);
<select class="{{id}}" style="width: 450px;">
</select>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment