diff --git a/OpenAuth.App/ModuleManagerApp.cs b/OpenAuth.App/ModuleManagerApp.cs index 5f588e59..3c9dc6b8 100644 --- a/OpenAuth.App/ModuleManagerApp.cs +++ b/OpenAuth.App/ModuleManagerApp.cs @@ -54,6 +54,18 @@ namespace OpenAuth.App return _repository.Find(null).ToList(); } + public List LoadTree(int firstId, string key) + { + if (key == "UserElement") //todo:因为在分配菜单页面出现的树,只能收到这个值,蛋疼 + { + return LoadForUser(firstId); + } + else + { + return LoadForRole(firstId); + } + } + /// /// 以组合的方式显示所有的模块信息 /// diff --git a/OpenAuth.App/ResourceManagerApp.cs b/OpenAuth.App/ResourceManagerApp.cs index 95d1a38e..4668caa5 100644 --- a/OpenAuth.App/ResourceManagerApp.cs +++ b/OpenAuth.App/ResourceManagerApp.cs @@ -137,19 +137,5 @@ namespace OpenAuth.App return listVms; } - /// - /// 为角色分配资源 - /// - /// 角色ID - /// 资源ID数组 - public void AssignResForRole(int roleId, int[] resIds) - { - _relevanceRepository.AddRelevance("RoleResource", resIds.ToLookup(u => roleId)); - } - - public void DelResForRole(int roleId, int[] resIds) - { - _relevanceRepository.DeleteBy("RoleResource", resIds.ToLookup(u =>roleId)); - } } } \ No newline at end of file diff --git a/OpenAuth.Mvc/BllScripts/userModuleElement.js b/OpenAuth.Mvc/BllScripts/assignModuleElement.js similarity index 60% rename from OpenAuth.Mvc/BllScripts/userModuleElement.js rename to OpenAuth.Mvc/BllScripts/assignModuleElement.js index 099c818c..05d760ad 100644 --- a/OpenAuth.Mvc/BllScripts/userModuleElement.js +++ b/OpenAuth.Mvc/BllScripts/assignModuleElement.js @@ -1,57 +1,59 @@ // *********************************************************************** // Assembly : OpenAuth.Mvc // Author : yubaolee -// Created : 04-13-2016 +// Created : 04-16-2016 // // Last Modified By : yubaolee -// Last Modified On : 04-13-2016 +// Last Modified On : 04-16-2016 // *********************************************************************** -// +// // 版权所有(C) 2015 // -// 为用户分配模块菜单 +// 分配模块菜单(按钮) // *********************************************************************** $(document).ready(function () { $.CurrentDialog.find("#btnAccess").on("click", function () { - var ids = userMenuList.getSelectedProperties('Id'); + var ids = dlgList.getSelectedProperties('Id'); if (ids == null) return; - $.post("/ModuleElementManager/AssignForUser", - { - userId: $('#userId').val(), - menuIds: ids, - }, function (json) { - userMenuList.reload(); - }); + $.post('/RelevanceManager/Assign', { + type: $("#moduleType").val(), + firstId: $('#firstId').val(), + secIds: ids + }, function (json) { + dlgList.reload(); + }); }); $.CurrentDialog.find("#btnDelAccess").on("click", function () { - var ids = userMenuList.getSelectedProperties('Id'); + var ids = dlgList.getSelectedProperties('Id'); if (ids == null) return; - $.post("/ModuleElementManager/CancelForUser",{ - userId: $('#userId').val(), - menuIds: ids, + $.post('/RelevanceManager/UnAssign', { + type: $("#moduleType").val(), + firstId: $('#firstId').val(), + secIds: ids }, function (json) { - userMenuList.reload(); + dlgList.reload(); }); }); }); //grid列表模块 -function UserMEGrid() { - var selectedId = 0; //ztree选中的模块 +function DialogList() { + var selectedId = 0; //选中的ID + var url = '/ModuleElementManager/LoadWithAccess?tId='; this.maingrid = $.CurrentDialog.find('#maingrid').datagrid({ showToolbar: false, filterThead: false, target: $(this), columns: [ - { - name: 'Id', - label: '元素名称', - hide: true - }, + { + name: 'Id', + label: '元素名称', + hide: true + }, { name: 'Name', label: '元素名称', @@ -65,13 +67,12 @@ function UserMEGrid() { { name: 'Accessed', label: '是否已经授权', - type: 'select', align: 'center', items: [{ 'false': '未授权', 'true': '已授权' }], width: 80 } ], - dataUrl: '/ModuleElementManager/LoadForUser?moduleId=' + selectedId + '&userId=' + $('#userId').val(), + dataUrl: url + selectedId + '&key=' + $('#moduleType').val() + '&firstId=' + $('#firstId').val(), fullGrid: true, showLinenumber: true, showCheckboxcol: true, @@ -80,13 +81,13 @@ function UserMEGrid() { showTfoot: false, }); - this.reload = function(id) { + this.reload = function (id) { if (id != undefined) selectedId = id; - this.maingrid.datagrid('reload', { dataUrl: '/ModuleElementManager/LoadForUser?moduleId=' + selectedId + '&userId=' + $('#userId').val() }); - }; + this.maingrid.datagrid('reload', { dataUrl: url + selectedId + '&key=' + $('#moduleType').val() + '&firstId=' + $('#firstId').val() }); + } }; -UserMEGrid.prototype = new Grid(); -var userMenuList = new UserMEGrid(); +DialogList.prototype = new Grid(); +var dlgList = new DialogList(); var ztree = function () { var setting = { @@ -105,12 +106,11 @@ var ztree = function () { }, callback: { onClick: zTreeOnClick } }; - $.getJSON('/ModuleManager/LoadForUser?userId=' + $('#userId').val(), function (json) { + $.getJSON('/ModuleManager/LoadTree?firstId=' + $('#firstId').val()+ '&key=' + $('#moduleType').val() , function (json) { var zTreeObj = $.fn.zTree.init($.CurrentDialog.find("#tree"), setting, json); zTreeObj.expandAll(true); }); }(); function zTreeOnClick(event, treeId, treeNode) { - userMenuList.reload(treeNode.Id); -} -//@@ sourceURL=userModuleElement.js + dlgList.reload(treeNode.Id); +} \ No newline at end of file diff --git a/OpenAuth.Mvc/BllScripts/roleManager.js b/OpenAuth.Mvc/BllScripts/roleManager.js index b5d2a467..4d81e97e 100644 --- a/OpenAuth.Mvc/BllScripts/roleManager.js +++ b/OpenAuth.Mvc/BllScripts/roleManager.js @@ -271,7 +271,7 @@ function openRoleReourceAccess(obj) { if (selected == null) return; $(obj).dialog({ - id: 'accessUserRole', + id: 'assignRes', url: '/ResourceManager/AssignRes', title: '为角色分配资源', width: 600, @@ -289,11 +289,15 @@ function assignRoleElement(obj) { if (selected == null) return; $(obj).dialog({ - id: 'assignElement', - url: '/ModuleElementManager/AssignForRole?roleId=' + selected.Id, + id: 'accessRoleElement', + url: '/ModuleElementManager/AssignModuleElement', title: '为角色分配菜单', - width: 700, - height: 380 + width: 600, + height: 380, + data: { + firstId: selected.Id, + key: "RoleElement" + } }); } diff --git a/OpenAuth.Mvc/BllScripts/roleModuleElement.js b/OpenAuth.Mvc/BllScripts/roleModuleElement.js deleted file mode 100644 index ccec2b0c..00000000 --- a/OpenAuth.Mvc/BllScripts/roleModuleElement.js +++ /dev/null @@ -1,115 +0,0 @@ -// *********************************************************************** -// Assembly : OpenAuth.Mvc -// Author : yubaolee -// Created : 04-13-2016 -// -// Last Modified By : yubaolee -// Last Modified On : 04-13-2016 -// *********************************************************************** -// -// 版权所有(C) 2015 -// -// 为角色分配模块菜单 -// *********************************************************************** - - -$(document).ready(function () { - $.CurrentDialog.find("#btnAccess").on("click", function () { - var ids = roleMenuList.getSelectedProperties('Id'); - if (ids == null) return; - - $.post("/ModuleElementManager/AssignForRole", - { - RoleId: $('#roleId').val(), - menuIds: ids, - }, function (json) { - roleMenuList.reload(); - }); - }); - $.CurrentDialog.find("#btnDelAccess").on("click", function () { - var ids = roleMenuList.getSelectedProperties('Id'); - if (ids == null) return; - - $.post("/ModuleElementManager/CancelForRole",{ - RoleId: $('#roleId').val(), - menuIds: ids, - }, function (json) { - roleMenuList.reload(); - }); - }); -}); - -//grid列表模块 -function RoleMEGrid() { - var selectedId = 0; //ztree选中的模块 - this.maingrid = $.CurrentDialog.find('#maingrid').datagrid({ - showToolbar: false, - filterThead: false, - target: $(this), - columns: [ - { - name: 'Id', - label: '元素名称', - hide: true - }, - { - name: 'Name', - label: '元素名称', - width: 80 - }, - { - name: 'ModuleName', - label: '所属模块', - width: 80 - }, - { - name: 'Accessed', - label: '是否已经授权', - type: 'select', - align: 'center', - items: [{ 'false': '未授权', 'true': '已授权' }], - width: 80 - } - ], - dataUrl: '/ModuleElementManager/LoadForRole?moduleId=' + selectedId + '&RoleId=' + $('#roleId').val(), - fullGrid: true, - showLinenumber: true, - showCheckboxcol: true, - paging: true, - filterMult: false, - showTfoot: false - }); - this.reload = function(id) { - if (id != undefined) selectedId = id; - this.maingrid.datagrid('reload', { dataUrl: '/ModuleElementManager/LoadForRole?moduleId=' + selectedId + '&RoleId=' + $('#roleId').val() }); - }; -}; -RoleMEGrid.prototype = new Grid(); -var roleMenuList = new RoleMEGrid(); - -var ztree = function () { - var setting = { - view: { selectedMulti: false }, - data: { - key: { - name: 'Name', - title: 'Name' - }, - simpleData: { - enable: true, - idKey: 'Id', - pIdKey: 'ParentId', - rootPId: 'null' - } - }, - callback: { onClick: zTreeOnClick } - }; - $.getJSON('/ModuleManager/LoadForRole?RoleId=' + $('#roleId').val(), function (json) { - var zTreeObj = $.fn.zTree.init($.CurrentDialog.find("#tree"), setting, json); - zTreeObj.expandAll(true); - }); -}(); -function zTreeOnClick(event, treeId, treeNode) { - roleMenuList.reload(treeNode.Id); -} -//@@ sourceURL=RoleModuleElement.js diff --git a/OpenAuth.Mvc/BllScripts/usermanager.js b/OpenAuth.Mvc/BllScripts/usermanager.js index f240a0f0..2189c10a 100644 --- a/OpenAuth.Mvc/BllScripts/usermanager.js +++ b/OpenAuth.Mvc/BllScripts/usermanager.js @@ -317,11 +317,15 @@ function openAssignUserElement(obj) { if (selected == null) return; $(obj).dialog({ - id: 'assignElement', - url: '/ModuleElementManager/AssignForUser?userId=' + selected.Id, - title: '为用户分配菜单', - width: 700, - height: 380 + id: 'accessUserElement', + url: '/ModuleElementManager/AssignModuleElement', + title: '为用户分配资源', + width: 600, + height: 380, + data: { + firstId: selected.Id, + key: "UserElement" + } }); } diff --git a/OpenAuth.Mvc/Controllers/ModuleElementManagerController.cs b/OpenAuth.Mvc/Controllers/ModuleElementManagerController.cs index a423b840..006752a8 100644 --- a/OpenAuth.Mvc/Controllers/ModuleElementManagerController.cs +++ b/OpenAuth.Mvc/Controllers/ModuleElementManagerController.cs @@ -12,16 +12,13 @@ // 模块元素管理,无需权限控制 // *********************************************************************** -using System; -using System.Collections.Generic; -using System.Data.Entity.Validation; -using System.Linq; -using System.Web.Mvc; using Infrastructure; using OpenAuth.App; -using OpenAuth.App.ViewModel; using OpenAuth.Domain; using OpenAuth.Mvc.Models; +using System; +using System.Data.Entity.Validation; +using System.Web.Mvc; namespace OpenAuth.Mvc.Controllers { @@ -76,107 +73,23 @@ namespace OpenAuth.Mvc.Controllers return JsonHelper.Instance.Serialize(_bjuiResponse); } - #region 为角色分配菜单 - - public ActionResult AssignForRole(int roleId) + /// + /// 分配模块菜单(按钮)界面 + /// 可以为用户/角色分配,同过key(UserElement/RoleElement)区分 + /// + /// The first identifier. + /// The key. + /// ActionResult. + public ActionResult AssignModuleElement(int firstId, string key) { - ViewBag.RoleId = roleId; + ViewBag.FirstId = firstId; + ViewBag.ModuleType = key; return View(); } - /// - /// 为角色分配菜单 - /// - /// 角色ID - /// 模块ID - /// 菜单ID列表 - /// - [HttpPost] - public string AssignForRole(int roleId, string menuIds) + public string LoadWithAccess(int tId, int firstId, string key) { - try - { - var ids = JsonHelper.Instance.Deserialize(menuIds); - _app.AssignForRole(roleId, ids); - } - catch (Exception e) - { - _bjuiResponse.statusCode = "300"; - _bjuiResponse.message = e.Message; - } - return JsonHelper.Instance.Serialize(_bjuiResponse); + return JsonHelper.Instance.Serialize(_app.LoadWithAccess(key, firstId, tId)); } - - [HttpPost] - public string CancelForRole(int roleId, string menuIds) - { - try - { - var ids = JsonHelper.Instance.Deserialize(menuIds); - _app.CancelForRole(roleId, ids); - } - catch (Exception e) - { - _bjuiResponse.statusCode = "300"; - _bjuiResponse.message = e.Message; - } - return JsonHelper.Instance.Serialize(_bjuiResponse); - } - - public string LoadForRole(int roleId, int moduleId) - { - return JsonHelper.Instance.Serialize(_app.LoadWithAccess("RoleElement", roleId, moduleId)); - } - #endregion - - #region 为用户分配菜单 - - public ActionResult AssignForUser(int userId) - { - ViewBag.UserId = userId; - return View(); - } - /// - /// 为用户分配菜单 - /// - /// 用户ID - /// 菜单ID列表 - /// - [HttpPost] - public string AssignForUser(int userId, string menuIds) - { - try - { - var ids = JsonHelper.Instance.Deserialize(menuIds); - _app.AssignForUser(userId, ids); - } - catch (Exception e) - { - _bjuiResponse.statusCode = "300"; - _bjuiResponse.message = e.Message; - } - return JsonHelper.Instance.Serialize(_bjuiResponse); - } - [HttpPost] - public string CancelForUser(int userId, string menuIds) - { - try - { - var ids = JsonHelper.Instance.Deserialize(menuIds); - _app.CancelForUser(userId, ids); - } - catch (Exception e) - { - _bjuiResponse.statusCode = "300"; - _bjuiResponse.message = e.Message; - } - return JsonHelper.Instance.Serialize(_bjuiResponse); - } - - public string LoadForUser(int userId, int moduleId) - { - return JsonHelper.Instance.Serialize(_app.LoadWithAccess("UserElement", userId, moduleId)); - } - #endregion } } \ No newline at end of file diff --git a/OpenAuth.Mvc/Controllers/ModuleManagerController.cs b/OpenAuth.Mvc/Controllers/ModuleManagerController.cs index 962d1570..a4405fe8 100644 --- a/OpenAuth.Mvc/Controllers/ModuleManagerController.cs +++ b/OpenAuth.Mvc/Controllers/ModuleManagerController.cs @@ -78,6 +78,29 @@ namespace OpenAuth.Mvc.Controllers return JsonHelper.Instance.Serialize(orgs); } + /// + /// 分配菜单页面的树 + /// todo:key要用UserElement/RoleElement,会造成迷惑,后期优化 + /// + public string LoadTree(int firstId, string key) + { + var orgs = _app.LoadTree(firstId, key); + //添加根节点 + orgs.Add(new Module + { + Id = 0, + ParentId = -1, + Name = "已拥有的模块", + CascadeId = "0" + }); + return JsonHelper.Instance.Serialize(orgs); + } + + /// + /// 加载用户模块 + /// + /// The user identifier. + /// System.String. public string LoadForUser(int userId) { var orgs = _app.LoadForUser(userId); @@ -92,6 +115,11 @@ namespace OpenAuth.Mvc.Controllers return JsonHelper.Instance.Serialize(orgs); } + /// + /// 加载角色模块 + /// + /// The role identifier. + /// System.String. public string LoadForRole(int roleId) { var orgs = _app.LoadForRole(roleId); diff --git a/OpenAuth.Mvc/OpenAuth.Mvc.csproj b/OpenAuth.Mvc/OpenAuth.Mvc.csproj index 7c5b71a1..44d768a0 100644 --- a/OpenAuth.Mvc/OpenAuth.Mvc.csproj +++ b/OpenAuth.Mvc/OpenAuth.Mvc.csproj @@ -151,6 +151,7 @@ + @@ -160,8 +161,6 @@ - - @@ -674,9 +673,8 @@ - - + diff --git a/OpenAuth.Mvc/Views/ModuleElementManager/AssignForUser.cshtml b/OpenAuth.Mvc/Views/ModuleElementManager/AssignForUser.cshtml deleted file mode 100644 index 80befb35..00000000 --- a/OpenAuth.Mvc/Views/ModuleElementManager/AssignForUser.cshtml +++ /dev/null @@ -1,30 +0,0 @@ -
- -
- -
-
-
-
    -
    - -
    -
    -
    -
    -
    - - \ No newline at end of file diff --git a/OpenAuth.Mvc/Views/ModuleElementManager/AssignForRole.cshtml b/OpenAuth.Mvc/Views/ModuleElementManager/AssignModuleElement.cshtml similarity index 83% rename from OpenAuth.Mvc/Views/ModuleElementManager/AssignForRole.cshtml rename to OpenAuth.Mvc/Views/ModuleElementManager/AssignModuleElement.cshtml index 692193c6..a06e4e69 100644 --- a/OpenAuth.Mvc/Views/ModuleElementManager/AssignForRole.cshtml +++ b/OpenAuth.Mvc/Views/ModuleElementManager/AssignModuleElement.cshtml @@ -1,30 +1,31 @@ -
    - -
    - -
    -
    -
    -
      -
      - -
      -
      -
      -
      -
      - - \ No newline at end of file +
      + +
      + +
      +
      +
      +
        +
        + +
        +
        +
        +
        +
        + + \ No newline at end of file