完成分配

This commit is contained in:
yubaolee 2016-10-21 00:33:35 +08:00
parent de50581f8b
commit b3a7afc32b
10 changed files with 206 additions and 284 deletions

View File

@ -130,7 +130,7 @@ namespace OpenAuth.App
foreach (var role in orgroles)
{
RoleVM rolevm = role;
rolevm.IsBelongUser = userroles.Any(u => u.Id == role.Id);
rolevm.Checked = userroles.Any(u => u.Id == role.Id);
var orgs = _orgRepository.LoadByRole(role.Id);
rolevm.Organizations = string.Join(",", orgs.Select(u => u.Name).ToList());
rolevm.OrganizationIds = string.Join(",", orgs.Select(u => u.Id).ToList());
@ -139,16 +139,6 @@ namespace OpenAuth.App
return rolevms;
}
public void AccessRole(Guid userId, Guid[] roleIds)
{
_relevanceRepository.AddRelevance("UserRole", roleIds.ToLookup(roleId => userId));
}
public void DelAccessRole(Guid userId, Guid[] roleids)
{
_relevanceRepository.DeleteBy("UserRole", roleids.ToLookup(roleId => userId));
}
public List<Guid> GetUsersInRole(string ruleName)
{
var role = _repository.FindSingle(u => u.Name == ruleName);

View File

@ -55,7 +55,7 @@ namespace OpenAuth.App.ViewModel
/// <summary>
///是否属于某用户
/// </summary>
public bool IsBelongUser { get; set; }
public bool Checked { get; set; }
public static implicit operator RoleVM(Role role)
{

View File

@ -157,7 +157,7 @@ namespace OpenAuth.Domain.Service
{
Id = element.Id,
Name = element.Name,
IsBelongUser = accessed != null,
Checked = accessed != null,
Description = element.Description,
Key = element.Key,
Status = element.Status

View File

@ -12,92 +12,66 @@
// <summary>分配资源模块处理</summary>
// ***********************************************************************
function renderLayui() {
layui.use(['layer', 'form'], function () {
var form = layui.form();
$(document).ready(function () {
$.CurrentDialog.find("#btnAccess").on("click", function () {
var ids = dlgList.getSelectedProperties('Id');
if (ids == null) return;
form.on('checkbox', function (data) {
if (data.elem.checked) {
$.post('/RelevanceManager/Assign', {
type: $("#moduleType").val(),
firstId: $('#firstId').val(),
secIds: ids
secIds: data.value
}, function (json) {
json = $.parseJSON(json);
if (json.statusCode != "200") {
$(this).alertmsg('warn', json.message);
return;
}
dlgList.reload();
});
});
$.CurrentDialog.find("#btnDelAccess").on("click", function () {
var ids = dlgList.getSelectedProperties('Id');
if (ids == null) return;
});
}
else {
$.post('/RelevanceManager/UnAssign', {
type: $("#moduleType").val(),
firstId: $('#firstId').val(),
secIds: ids
secIds: data.value
}, function (json) {
json = $.parseJSON(json);
if (json.statusCode != "200") {
$(this).alertmsg('warn', json.message);
return;
}
dlgList.reload();
});
});
});
//grid列表模块
function DialogList() {
});
}
});
form.render();
});
}
var list = function () {
var selectedId = '00000000-0000-0000-0000-000000000000'; //选中的ID
var url = '/ResourceManager/LoadWithAccess?cId=';
this.maingrid = $.CurrentDialog.find('#maingrid').datagrid({
showToolbar: false,
loadType: 'GET',
filterThead: false,
target: $(this),
columns: [
{
name: 'Id',
label: '角色ID',
hide: true
},
{
name: 'Name',
label: '资源名称',
width: 100
},
{
name: 'IsBelongUser',
label: '是否已经授权',
type: 'select',
align: 'center',
items: [{ 'false': '未授权', 'true': '已授权' }],
width: 100
}
],
dataUrl: url + selectedId + '&key=' + $('#moduleType').val() + '&firstId=' + $('#firstId').val(),
fullGrid: true,
showLinenumber: true,
showCheckboxcol: true,
paging: true,
filterMult: false,
showTfoot: false,
});
this.reload = function (id) {
var url = '/ResourceManager/LoadWithAccess?firstId=' + $("#firstId").val() + "&key=" + $("#moduleType").val() + "&cId=";
return {
reload: function (id) {
if (id != undefined) selectedId = id;
this.maingrid.datagrid('reload', { dataUrl: url + selectedId + '&key=' + $('#moduleType').val() + '&firstId=' + $('#firstId').val() });
$.getJSON(url + selectedId,
function (data) {
var str = '';
if (data.length > 0) {
$.each(data,
function () {
str += "<input type=\"checkbox\" name=\"\" value=\"" + this.Id + "\" title=\"" + this.Name + "\"";
if (this.Checked) {
str += " checked ";
}
};
DialogList.prototype = new Grid();
var dlgList = new DialogList();
str += ">\r\n";
});
}
$("#resources").html(str);
renderLayui();
});
}
};
}();
//左边导航
var ztree = function () {
var url = "/CategoryManager/LoadForTree";
var setting = {
view: { selectedMulti: false },
data: {
@ -112,13 +86,24 @@ var ztree = function () {
rootPId: 'null'
}
},
callback: { onClick: zTreeOnClick }
callback: {
onClick: function (event, treeId, treeNode) {
list.reload(treeNode.Id);
}
}
};
$.getJSON('/CategoryManager/LoadForTree', function (json) {
var zTreeObj = $.fn.zTree.init($.CurrentDialog.find("#tree"), setting, json);
var load = function () {
$.getJSON(url,
function (json) {
var zTreeObj = $.fn.zTree.init($("#orgtree"), setting, json);
list.reload();
zTreeObj.expandAll(true);
});
};
load();
return {
reload: load
}
}();
function zTreeOnClick(event, treeId, treeNode) {
dlgList.reload(treeNode.Id);
}

View File

@ -207,16 +207,11 @@ function openRoleReourceAccess(obj) {
var selected = list.getSelectedObj();
if (selected == null) return;
$(obj).dialog({
id: 'assignRes',
url: '/ResourceManager/AssignRes',
title: '为角色分配资源',
width: 600,
height: 380,
data: {
firstId: selected.Id,
key:"RoleResource"
}
layer.open({
type: 2,
skin: 'layui-layer-rim', //加上边框
area: ['410px', '390px'], //宽高
content: '/ResourceManager/AssignRes?key=RoleResource&firstId=' + selected.Id
});
}

View File

@ -11,85 +11,67 @@
// </copyright>
// <summary>用户分配角色模块</summary>
// ***********************************************************************
function renderLayui() {
layui.use(['layer', 'form'], function () {
var form = layui.form();
$(document).ready(function () {
$.CurrentDialog.find("#btnAccess").on("click", function () {
var ids = userRolesList.getSelectedProperties('Id');
if (ids == null) return;
$.post('/RoleManager/AccessRoles', {
userId: $('#userId').val(),
ids: ids
form.on('checkbox', function (data) {
if (data.elem.checked) {
$.post('/RelevanceManager/Assign', {
type: $("#moduleType").val(),
firstId: $('#firstId').val(),
secIds: data.value
}, function (json) {
userRolesList.reload();
});
});
$.CurrentDialog.find("#btnDelAccess").on("click", function () {
var ids = userRolesList.getSelectedProperties('Id');
if (ids == null) return;
json = $.parseJSON(json);
$.post('/RoleManager/DelAccessRoles', {
userId: $('#userId').val(),
ids: ids
}, function (json) {
userRolesList.reload();
});
});
});
//grid列表模块
function UserRolesList() {
var selectedId = '00000000-0000-0000-0000-000000000000'; //ztree选中的模块
this.maingrid = $.CurrentDialog.find('#maingrid').datagrid({
showToolbar: false,
loadType: 'GET',
filterThead: false,
target: $(this),
columns: [
{
name: 'Id',
label: '角色ID',
hide: true
},
{
name: 'Name',
label: '角色名称',
width: 100
},
{
name: 'Organizations',
label: '所属组织',
width: 100
},
{
name: 'IsBelongUser',
label: '是否已经授权',
type: 'select',
align: 'center',
items: [{ 'false': '未授权', 'true': '已授权' }],
width: 100
}
],
data: [],
fullGrid: true,
showLinenumber: true,
showCheckboxcol: true,
paging: true,
filterMult: false,
showTfoot: false,
else {
$.post('/RelevanceManager/UnAssign', {
type: $("#moduleType").val(),
firstId: $('#firstId').val(),
secIds: data.value
}, function (json) {
json = $.parseJSON(json);
});
this.reload = function (id) {
}
});
form.render();
});
}
var list = function () {
var selectedId = '00000000-0000-0000-0000-000000000000'; //选中的ID
var url = '/RoleManager/LoadForOrgAndUser?userId=' + $("#firstId").val()
+ "&key=" + $("#moduleType").val() + "&orgId=";
return {
reload: function (id) {
if (id != undefined) selectedId = id;
console.log(id);
this.maingrid.datagrid('reload', { dataUrl: '/RoleManager/LoadForOrgAndUser?orgId=' + selectedId + '&userId=' + $('#userId').val() });
$.getJSON(url + selectedId,
function (data) {
var str = '';
if (data.length > 0) {
$.each(data,
function () {
str += "<input type=\"checkbox\" name=\"\" value=\"" + this.Id + "\" title=\"" + this.Name + "\"";
if (this.Checked) {
str += " checked ";
}
};
UserRolesList.prototype = new Grid();
var userRolesList = new UserRolesList();
str += ">\r\n";
});
}
$("#roles").html(str);
renderLayui();
});
}
};
}();
//左边导航
var ztree = function () {
var url = "/OrgManager/LoadOrg";
var setting = {
view: { selectedMulti: false },
data: {
@ -104,22 +86,24 @@ var ztree = function () {
rootPId: 'null'
}
},
callback: { onClick: zTreeOnClick }
};
$.getJSON('/OrgManager/LoadOrg', function (json) {
var zTreeObj = $.fn.zTree.init($("#tree"), setting, json);
var firstId; //tree的第一个ID
if (json.length > 0) {
firstId = json[0].Id;
} else {
firstId = -1;
callback: {
onClick: function (event, treeId, treeNode) {
list.reload(treeNode.Id);
}
userRolesList.reload(firstId);
}
};
var load = function () {
$.getJSON(url,
function (json) {
var zTreeObj = $.fn.zTree.init($("#orgtree"), setting, json);
list.reload();
zTreeObj.expandAll(true);
});
}();
function zTreeOnClick(event, treeId, treeNode) {
userRolesList.reload(treeNode.Id);
}
};
load();
return {
reload: load
}
}();

View File

@ -218,15 +218,11 @@ function openUserRoleAccess(obj) {
var selected = list.getSelectedObj();
if (selected == null) return;
$(obj).dialog({
id: 'accessUserRole',
url: '/RoleManager/LookupMulti',
title: '为用户分配角色',
width: 600,
height: 380,
data: {
userId: selected.Id
}
layer.open({
type: 2,
skin: 'layui-layer-rim', //加上边框
area: ['410px', '390px'], //宽高
content: '/RoleManager/LookupMulti?key=UserRole&firstId=' + selected.Id
});
}
@ -235,16 +231,11 @@ function openUserReourceAccess(obj) {
var selected = list.getSelectedObj();
if (selected == null) return;
$(obj).dialog({
id: 'accessUserResource',
url: '/ResourceManager/AssignRes',
title: '为用户分配资源',
width: 600,
height: 380,
data: {
firstId: selected.Id,
key:"UserResource"
}
layer.open({
type: 2,
skin: 'layui-layer-rim', //加上边框
area: ['410px', '390px'], //宽高
content: '/ResourceManager/AssignRes?key=UserResource&firstId=' + selected.Id
});
}

View File

@ -69,9 +69,10 @@ namespace OpenAuth.Mvc.Controllers
}
#region
public ActionResult LookupMulti(Guid userId)
public ActionResult LookupMulti(Guid firstId, string key)
{
ViewBag.UserId = userId;
ViewBag.FirstId = firstId;
ViewBag.ModuleType = key;
return View();
}
@ -80,20 +81,6 @@ namespace OpenAuth.Mvc.Controllers
return JsonHelper.Instance.Serialize(_app.LoadForOrgAndUser(orgId, userId));
}
[System.Web.Mvc.HttpPost]
public string AccessRoles(Guid userId, Guid[] ids)
{
_app.AccessRole(userId, ids);
return JsonHelper.Instance.Serialize(Result);
}
[System.Web.Mvc.HttpPost]
public string DelAccessRoles(Guid userId, Guid[] ids)
{
_app.DelAccessRole(userId, ids);
return JsonHelper.Instance.Serialize(Result);
}
#endregion
}
}

View File

@ -1,31 +1,26 @@
<div class="bjui-pageHeader">
<div class="bjui-searchBar">
<input style="display: none" id="firstId" value="@ViewBag.FirstId"/>
<input style="display: none" id="moduleType", value="@ViewBag.ModuleType"/>
<div class="pull-right">
<div class="alert alert-info search-inline">
<i class="fa fa-info-circle"></i> 点击行为单选,点击复选框可多选统一授权
</div>&nbsp;
<button type="button" class="btn btn-green" data-num="1" data-icon="plus" id="btnAccess">
授权选中
</button>&nbsp;
<button type="button" class="btn btn-danger" data-num="1" data-icon="trash" id="btnDelAccess">
取消授权
</button>&nbsp;
</div>
</div>

@{
Layout = null;
}
<link href="~/Content/layui/css/layui.css" rel="stylesheet" />
<link href="~/Content/mylayer.css" rel="stylesheet" />
<script src="~/Content/layui/layui.js"></script>
<script src="~/Content/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="~/Content/plugins/zTree/js/jquery.ztree.core.js"></script>
<link href="/Content/plugins/zTree/css/metroStyle/metroStyle.css" rel="stylesheet" />
<div style="display: inline-block; width: 180px; height: 210px; padding: 10px; border: 1px solid #ddd; overflow: auto;">
<input style="display: none" id="firstId" value="@ViewBag.FirstId" />
<input style="display: none" id="moduleType" , value="@ViewBag.ModuleType" />
<ul id="orgtree" class="ztree" style="width: 100%"></ul>
</div>
<div class="bjui-pageContent tableContent">
<div class="clearfix">
<div style="float: left; width: 220px; overflow: auto;" class="table table-bordered">
<ul id="tree" class="ztree"></ul>
</div>
<div style="margin-left: 225px;">
<table id="maingrid" class="table table-bordered table-hover table-striped table-top"></table>
</div>
</div>
<div class="site-tips" style="display: inline-block; height: 210px; width: 340px; padding: 10px; margin-left: 10px; vertical-align: top;" id="demo2-view">
<form class="layui-form " action="" id="resources"></form>
</div>
<script src="~/BllScripts/grid.js"></script>
<script src="~/BllScripts/assignRes.js"></script>

View File

@ -1,31 +1,26 @@
<div class="bjui-pageHeader">
<div class="bjui-searchBar">
<input style="display: none" id="userId" value="@ViewBag.UserId" />
<div class="pull-right">
<div class="alert alert-info search-inline">
<i class="fa fa-info-circle"></i> 点击行为单选,点击复选框可多选统一授权
</div>&nbsp;
<button type="button" class="btn btn-green" data-num="1" data-icon="plus" id="btnAccess">
授权选中
</button>&nbsp;
<button type="button" class="btn btn-danger" data-num="1" data-icon="trash" id="btnDelAccess">
取消授权
</button>&nbsp;
</div>
</div>

@{
Layout = null;
}
<link href="~/Content/layui/css/layui.css" rel="stylesheet" />
<link href="~/Content/mylayer.css" rel="stylesheet" />
<script src="~/Content/layui/layui.js"></script>
<script src="~/Content/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="~/Content/plugins/zTree/js/jquery.ztree.core.js"></script>
<link href="/Content/plugins/zTree/css/metroStyle/metroStyle.css" rel="stylesheet" />
<div style="display: inline-block; width: 180px; height: 210px; padding: 10px; border: 1px solid #ddd; overflow: auto;">
<input style="display: none" id="firstId" value="@ViewBag.FirstId" />
<input style="display: none" id="moduleType" , value="@ViewBag.ModuleType" />
<ul id="orgtree" class="ztree" style="width: 100%"></ul>
</div>
<div class="bjui-pageContent tableContent">
<div class="clearfix">
<div style="float: left; width: 220px; overflow: auto;" class="table table-bordered">
<ul id="tree" class="ztree"></ul>
</div>
<div style="margin-left: 225px;">
<table id="maingrid" class="table table-bordered table-hover table-striped table-top"></table>
</div>
</div>
<div class="site-tips" style="display: inline-block; height: 210px; width: 340px; padding: 10px; margin-left: 10px; vertical-align: top;" id="demo2-view">
<form class="layui-form " action="" id="roles"></form>
</div>
<script src="~/BllScripts/grid.js"></script>
<script src="~/BllScripts/userRoleManager.js"></script>