From 6e1a306ac67ea37dea860e0ab5c3de382ba986b1 Mon Sep 17 00:00:00 2001 From: summer853300975 <853300975@qq.com> Date: Mon, 7 Nov 2016 21:41:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=92=E8=89=B2=E9=85=8D=E7=BD=AE=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=AE=8C=E6=88=90=EF=BC=8C=E5=A4=84=E7=90=86=E4=BA=86?= =?UTF-8?q?=E5=87=A0=E4=B8=AAToDo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/Bootstrap.Admin.csproj | 1 + Bootstrap.Admin/Content/js/framework.js | 15 ++ .../Controllers/GroupsController.cs | 176 +++++++++--------- .../Controllers/MenusController.cs | 34 ++++ Bootstrap.Admin/Models/QueryGroupOption.cs | 1 - Bootstrap.Admin/Models/QueryRoleOption.cs | 1 - Bootstrap.Admin/Models/QueryUserOption.cs | 13 +- Bootstrap.Admin/Scripts/Roles.js | 37 +++- Bootstrap.Admin/Views/Admin/Roles.cshtml | 10 + .../Views/Shared/NavigatorConfig.cshtml | 7 + Bootstrap.Admin/Web.config | 1 + Bootstrap.DataAccess/MenuHelper.cs | 85 +++++++++ Bootstrap.DataAccessTests/MenuHelperTests.cs | 28 +++ 13 files changed, 314 insertions(+), 95 deletions(-) create mode 100644 Bootstrap.Admin/Views/Shared/NavigatorConfig.cshtml diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index 60912a61..993dfbaf 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -264,6 +264,7 @@ + diff --git a/Bootstrap.Admin/Content/js/framework.js b/Bootstrap.Admin/Content/js/framework.js index 932e78c2..aea0d9b5 100644 --- a/Bootstrap.Admin/Content/js/framework.js +++ b/Bootstrap.Admin/Content/js/framework.js @@ -310,4 +310,19 @@ Group.saveGroupsByRoleId = function (roleId, groupIds, callback) { processData.call(this, { Id: roleId, callback: callback, method: "PUT", data: { type: "role", groupIds: groupIds } }); }; + htmlTemplateForMenu='
  • '; + //Menus + Menu = { + url: '../api/Menus/', title: "授权菜单", html: function (result) { + return $.map(result, function (element, index) { + return $.format(htmlTemplateForMenu, element.ID, element.Name, element.Active); + }).join(''); + } + } + Menu.getMenusByRoleId = function (roleId, callback) { + processData.call(this, { Id: roleId, callback: callback, data: { type: "role" } }); + }; + Menu.saveMenusByRoleId = function (roleId, menuIds, callback) { + processData.call(this, { Id: roleId, callback: callback, method: "PUT", data: { type: "role", menuIds:menuIds } }); + }; })(jQuery); \ No newline at end of file diff --git a/Bootstrap.Admin/Controllers/GroupsController.cs b/Bootstrap.Admin/Controllers/GroupsController.cs index 54e9e1c7..298c9d47 100644 --- a/Bootstrap.Admin/Controllers/GroupsController.cs +++ b/Bootstrap.Admin/Controllers/GroupsController.cs @@ -7,94 +7,94 @@ using System.Web.Http; namespace Bootstrap.Admin.Controllers { - public class GroupsController : ApiController - { - /// - /// - /// - /// - /// - [HttpGet] - public QueryData Get([FromUri]QueryGroupOption value) - { - return value.RetrieveData(); - } - /// - /// - /// - /// - /// - [HttpGet] - public Group Get(int id) - { - return GroupHelper.RetrieveGroups().FirstOrDefault(t => t.ID == id); - } - /// - /// - /// - /// - [HttpPost] - public bool Post([FromBody]Group value) - { - return GroupHelper.SaveGroup(value); - } - /// - /// - /// - /// - [HttpDelete] - public bool Delete([FromBody]string value) - { - return GroupHelper.DeleteGroup(value); - } - /// - /// - /// - /// - /// - /// - [HttpPost] - public IEnumerable Post(int id, [FromBody]JObject value) - { - var ret = new List(); - dynamic json = value; - switch ((string)json.type) - { - case "user": - ret = GroupHelper.RetrieveGroupsByUserId(id).ToList(); - break; + public class GroupsController : ApiController + { + /// + /// + /// + /// + /// + [HttpGet] + public QueryData Get([FromUri]QueryGroupOption value) + { + return value.RetrieveData(); + } + /// + /// + /// + /// + /// + [HttpGet] + public Group Get(int id) + { + return GroupHelper.RetrieveGroups().FirstOrDefault(t => t.ID == id); + } + /// + /// + /// + /// + [HttpPost] + public bool Post([FromBody]Group value) + { + return GroupHelper.SaveGroup(value); + } + /// + /// + /// + /// + [HttpDelete] + public bool Delete([FromBody]string value) + { + return GroupHelper.DeleteGroup(value); + } + /// + /// + /// + /// + /// + /// + [HttpPost] + public IEnumerable Post(int id, [FromBody]JObject value) + { + var ret = new List(); + dynamic json = value; + switch ((string)json.type) + { + case "user": + ret = GroupHelper.RetrieveGroupsByUserId(id).ToList(); + break; case "role": - ret = GroupHelper.RetrieveGroupsByRoleId(id).ToList(); - break; - default: - break; - } - return ret; - } - /// - /// - /// - /// - /// - /// - [HttpPut] - public bool Put(int id, [FromBody]JObject value) - { - var ret = false; - dynamic json = value; - string groupIds = json.groupIds; - switch ((string)json.type) - { - case "user": - ret = GroupHelper.SaveGroupsByUserId(id, groupIds); - break; + ret = GroupHelper.RetrieveGroupsByRoleId(id).ToList(); + break; + default: + break; + } + return ret; + } + /// + /// + /// + /// + /// + /// + [HttpPut] + public bool Put(int id, [FromBody]JObject value) + { + var ret = false; + dynamic json = value; + string groupIds = json.groupIds; + switch ((string)json.type) + { + case "user": + ret = GroupHelper.SaveGroupsByUserId(id, groupIds); + break; case "role": - ret = GroupHelper.SaveGroupsByRoleId(id, groupIds); - break; - default: - break; - } - return ret; - } - } + ret = GroupHelper.SaveGroupsByRoleId(id, groupIds); + break; + default: + break; + } + return ret; + } + } } diff --git a/Bootstrap.Admin/Controllers/MenusController.cs b/Bootstrap.Admin/Controllers/MenusController.cs index 02050b38..ea3e39e5 100644 --- a/Bootstrap.Admin/Controllers/MenusController.cs +++ b/Bootstrap.Admin/Controllers/MenusController.cs @@ -1,5 +1,8 @@ using Bootstrap.Admin.Models; using Bootstrap.DataAccess; +using Newtonsoft.Json.Linq; +using System.Collections.Generic; +using System.Linq; using System.Web.Http; namespace Bootstrap.Admin.Controllers @@ -34,5 +37,36 @@ namespace Bootstrap.Admin.Controllers { return MenuHelper.DeleteMenu(value); } + [HttpPost] + public IEnumerable Post(int id, [FromBody]JObject value) + { + var ret = new List(); + dynamic json = value; + switch ((string)json.type) + { + case "role": + ret = MenuHelper.RetrieveMenusByRoleId(id).ToList(); + break; + default: + break; + } + return ret; + } + [HttpPut] + public bool Put(int id, [FromBody]JObject value) + { + var ret = false; + dynamic json = value; + string menuIds = json.menuIds.ToString(); + switch ((string)json.type) + { + case "role": + ret = MenuHelper.SaveMenusByRoleId(id, menuIds); + break; + default: + break; + } + return ret; + } } } \ No newline at end of file diff --git a/Bootstrap.Admin/Models/QueryGroupOption.cs b/Bootstrap.Admin/Models/QueryGroupOption.cs index 75285939..ab60e419 100644 --- a/Bootstrap.Admin/Models/QueryGroupOption.cs +++ b/Bootstrap.Admin/Models/QueryGroupOption.cs @@ -32,7 +32,6 @@ namespace Bootstrap.Admin.Models } var ret = new QueryData(); ret.total = data.Count(); - // TODO: 通过option.Sort属性判断对那列进行排序,现在统一对名称列排序 data = Order == "asc" ? data.OrderBy(t => t.GroupName) : data.OrderByDescending(t => t.GroupName); ret.rows = data.Skip(Offset).Take(Limit); return ret; diff --git a/Bootstrap.Admin/Models/QueryRoleOption.cs b/Bootstrap.Admin/Models/QueryRoleOption.cs index dea041db..4838a2b8 100644 --- a/Bootstrap.Admin/Models/QueryRoleOption.cs +++ b/Bootstrap.Admin/Models/QueryRoleOption.cs @@ -32,7 +32,6 @@ namespace Bootstrap.Admin.Models } var ret = new QueryData(); ret.total = data.Count(); - // TODO: 通过option.Sort属性判断对那列进行排序,现在统一对名称列排序 data = Order == "asc" ? data.OrderBy(t => t.RoleName) : data.OrderByDescending(t => t.RoleName); ret.rows = data.Skip(Offset).Take(Limit); return ret; diff --git a/Bootstrap.Admin/Models/QueryUserOption.cs b/Bootstrap.Admin/Models/QueryUserOption.cs index e9ac0d4e..dc9a226f 100644 --- a/Bootstrap.Admin/Models/QueryUserOption.cs +++ b/Bootstrap.Admin/Models/QueryUserOption.cs @@ -32,8 +32,17 @@ namespace Bootstrap.Admin.Models } var ret = new QueryData(); ret.total = data.Count(); - // TODO: 通过option.Sort属性判断对那列进行排序,现在统一对名称列排序 - data = Order == "asc" ? data.OrderBy(t => t.UserName) : data.OrderByDescending(t => t.UserName); + switch (Sort) + { + case "UserName": + data = Order == "asc" ? data.OrderBy(t => t.UserName) : data.OrderByDescending(t => t.UserName); + break; + case "RegisterTime": + data = Order == "asc" ? data.OrderBy(t => t.RegisterTime) : data.OrderByDescending(t => t.RegisterTime); + break; + default: + break; + } ret.rows = data.Skip(Offset).Take(Limit); return ret; } diff --git a/Bootstrap.Admin/Scripts/Roles.js b/Bootstrap.Admin/Scripts/Roles.js index 2c152f82..e0832f91 100644 --- a/Bootstrap.Admin/Scripts/Roles.js +++ b/Bootstrap.Admin/Scripts/Roles.js @@ -44,14 +44,45 @@ var groupIds = $('#dialogGroup :checked').map(function (index, element) { return $(element).val(); }).toArray().join(','); - Group.saveGroupsByRoleId(roleId, groupIds, { modal: 'dialogGroup' }); - - + Group.saveGroupsByRoleId(roleId, groupIds, { modal: 'dialogGroup' }); + } + }, + { + id: 'btn_assignMenu', + click: function (row) { + Menu.getMenusByRoleId(row.ID, function (data) { + $(".menu-content .modal-header .modal-title").text($.format('{0}-菜单授权窗口', row.RoleName)); + $('.menu-content button:last').data('type', 'menu'); + $('ol.dd-list').html(data); + $('#dialogMenu').modal('show'); + $('.menu-content').show(); + $('div.dd3-content :checkbox').show(); + $('div.dd3-content :radio').hide(); + }) + } + }, + { + id: 'btnSubmitMenu', + click: function (row) { + var roleId = row.ID; + var type = $('.menu-content button:last').data('type'); + switch (type) { + case "menu": + var menuIds = $('.dd3-content :checkbox:checked').map(function (index, element) { + return $(element).val(); + }).toArray().join(','); + break; + default: + break; + } + Menu.saveMenusByRoleId(roleId, menuIds, { modal: 'dialogMenu' }); } }] } }); + $('#nestable_menu').nestable(); + $('table').smartTable({ url: '../api/Roles', //请求后台的URL(*) sortName: 'RoleName', diff --git a/Bootstrap.Admin/Views/Admin/Roles.cshtml b/Bootstrap.Admin/Views/Admin/Roles.cshtml index 5fece261..485ff0a5 100644 --- a/Bootstrap.Admin/Views/Admin/Roles.cshtml +++ b/Bootstrap.Admin/Views/Admin/Roles.cshtml @@ -3,8 +3,14 @@ ViewBag.Title = "角色管理"; Layout = "~/Views/Shared/_Default.cshtml"; } +@section css { + + +} @section Javascript { + + } @section header { @Html.Partial("Header", Model) @@ -34,6 +40,9 @@ + } @section modal {