diff --git a/Bootstrap.Admin/Controllers/Api/NewController.cs b/Bootstrap.Admin/Controllers/Api/NewController.cs index 299fa029..90ae5afb 100644 --- a/Bootstrap.Admin/Controllers/Api/NewController.cs +++ b/Bootstrap.Admin/Controllers/Api/NewController.cs @@ -1,7 +1,7 @@ using Bootstrap.DataAccess; -using Bootstrap.Security; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; using System.Linq; namespace Bootstrap.Admin.Controllers @@ -13,15 +13,20 @@ namespace Bootstrap.Admin.Controllers public class NewController : Controller { /// - /// 登录页面注册新用户remote validate调用 + /// 通知管理页面获得所有新用户方法调用 /// - /// /// [HttpGet] - [AllowAnonymous] - public bool Get(string userName) + public IEnumerable Get() { - return BootstrapUser.RetrieveUserByUserName(userName) == null && !UserHelper.RetrieveNewUsers().Any(u => u.UserName == userName); + return UserHelper.RetrieveNewUsers().Select(user => new + { + user.Id, + user.UserName, + user.DisplayName, + user.Description, + user.RegisterTime + }); } /// /// 登录页面注册新用户提交按钮调用 diff --git a/Bootstrap.Admin/Controllers/Api/NotificationsController.cs b/Bootstrap.Admin/Controllers/Api/NotificationsController.cs index 06124094..eeab0000 100644 --- a/Bootstrap.Admin/Controllers/Api/NotificationsController.cs +++ b/Bootstrap.Admin/Controllers/Api/NotificationsController.cs @@ -1,7 +1,6 @@ using Bootstrap.DataAccess; using Microsoft.AspNetCore.Mvc; using System; -using System.Collections.Generic; using System.Linq; namespace Bootstrap.Admin.Controllers.Api @@ -17,39 +16,41 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpGet] - public Notifications Get() + public object Get() { - var ret = new Notifications(); - if (!User.IsInRole("Administrators")) return ret; + if (!User.IsInRole("Administrators")) return false; // New Users var user = UserHelper.RetrieveNewUsers(); - ret.Users = user.Take(6).ToList(); - ret.Users.AsParallel().ForAll(n => - { - var ts = DateTime.Now - n.RegisterTime; - if (ts.TotalMinutes < 5) n.Period = "刚刚"; - else if (ts.Days > 0) n.Period = string.Format("{0}天", ts.Days); - else if (ts.Hours > 0) n.Period = string.Format("{0}小时", ts.Hours); - else if (ts.Minutes > 0) n.Period = string.Format("{0}分钟", ts.Minutes); - }); - ret.NewUsersCount = user.Count(); + var usersCount = user.Count(); + + user = user.Take(6); + user.AsParallel().ForAll(n => + { + var ts = DateTime.Now - n.RegisterTime; + if (ts.TotalMinutes < 5) n.Period = "刚刚"; + else if (ts.Days > 0) n.Period = string.Format("{0}天", ts.Days); + else if (ts.Hours > 0) n.Period = string.Format("{0}小时", ts.Hours); + else if (ts.Minutes > 0) n.Period = string.Format("{0}分钟", ts.Minutes); + }); // Tasks var task = TaskHelper.RetrieveTasks(); - ret.Tasks = task.Take(6).ToList(); - ret.TasksCount = task.Count(); + var tasksCount = task.Count(); //Message var message = MessageHelper.RetrieveMessagesHeader(User.Identity.Name); - ret.Messages = message.Take(6).ToList(); - ret.Messages.AsParallel().ForAll(m => m.FromIcon = Url.Content(m.FromIcon)); - ret.MessagesCount = message.Count(); + var messagesCount = message.Count(); + + message = message.Take(6); + message.AsParallel().ForAll(m => m.FromIcon = Url.Content(m.FromIcon)); //Apps var apps = ExceptionHelper.RetrieveExceptions().Where(n => n.ExceptionType != "Longbow.Data.DBAccessException"); - ret.Apps = apps.Take(6).ToList(); - ret.Apps.AsParallel().ForAll(n => + var appExceptionsCount = apps.Count(); + + apps = apps.Take(6); + apps.AsParallel().ForAll(n => { n.ExceptionType = n.ExceptionType.Split('.').Last(); var ts = DateTime.Now - n.LogTime; @@ -58,12 +59,13 @@ namespace Bootstrap.Admin.Controllers.Api else if (ts.Hours > 0) n.Period = string.Format("{0}小时", ts.Hours); else if (ts.Minutes > 0) n.Period = string.Format("{0}分钟", ts.Minutes); }); - ret.AppExceptionsCount = apps.Count(); //Dbs var dbs = ExceptionHelper.RetrieveExceptions().Where(n => n.ExceptionType == "Longbow.Data.DBAccessException"); - ret.Dbs = dbs.Take(6).ToList(); - ret.Dbs.AsParallel().ForAll(n => + var dbExceptionsCount = dbs.Count(); + + dbs = dbs.Take(6); + dbs.AsParallel().ForAll(n => { var ts = DateTime.Now - n.LogTime; if (ts.TotalMinutes < 5) n.Period = "刚刚"; @@ -71,72 +73,20 @@ namespace Bootstrap.Admin.Controllers.Api else if (ts.Hours > 0) n.Period = string.Format("{0}小时", ts.Hours); else if (ts.Minutes > 0) n.Period = string.Format("{0}分钟", ts.Minutes); }); - ret.DbExceptionsCount = dbs.Count(); - return ret; - } - /// - /// - /// - /// - /// - [HttpGet("{id}")] - public object Get(string id) - { - var ret = new object(); - if (id == "newusers") ret = UserHelper.RetrieveNewUsers().ToList(); - return ret; - } - public class Notifications - { - public Notifications() + return new { - Users = new List(); - Apps = new List(); - Dbs = new List(); - Tasks = new List(); - Messages = new List(); - } - /// - /// - /// - public List Users { get; set; } - /// - /// - /// - public List Apps { get; set; } - /// - /// - /// - public List Dbs { get; set; } - /// - /// - /// - public List Tasks { get; set; } - /// - /// - /// - public List Messages { get; set; } - /// - /// 获得/设置 消息数量 - /// - public int MessagesCount { get; set; } - /// - /// 获得/设置 新用户数量 - /// - public int NewUsersCount { get; set; } - /// - /// 获取/设置 任务数量 - /// - public int TasksCount { get; set; } - /// - /// 获取/设置 应用程序错误数量 - /// - public int AppExceptionsCount { get; set; } - /// - /// 获取/设置 数据库错误数量 - /// - public int DbExceptionsCount { get; set; } + NewUsersCount = usersCount, + TasksCount = tasksCount, + MessagesCount = messagesCount, + AppExceptionsCount = appExceptionsCount, + DbExceptionsCount = dbExceptionsCount, + Users = user.Select(i => new { i.Period, i.UserName, i.DisplayName, i.Description }), + Tasks = task.Take(6), + Messages = message, + Apps = apps.Select(n => new { n.ExceptionType, n.Message, n.Period }), + Dbs = dbs.Select(n => new { n.ErrorPage, n.Message, n.Period }) + }; } } } \ No newline at end of file diff --git a/Bootstrap.Admin/Controllers/Api/RegisterController.cs b/Bootstrap.Admin/Controllers/Api/RegisterController.cs new file mode 100644 index 00000000..20bd9d32 --- /dev/null +++ b/Bootstrap.Admin/Controllers/Api/RegisterController.cs @@ -0,0 +1,24 @@ +using Bootstrap.DataAccess; +using Bootstrap.Security; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System.Linq; + +namespace Bootstrap.Admin.Controllers.Api +{ + [AllowAnonymous] + [Route("api/[controller]")] + public class RegisterController : Controller + { + /// + /// 登录页面注册新用户remote validate调用 + /// + /// + /// + [HttpGet] + public bool Get(string userName) + { + return BootstrapUser.RetrieveUserByUserName(userName) == null && !UserHelper.RetrieveNewUsers().Any(u => u.UserName == userName); + } + } +} diff --git a/Bootstrap.Admin/Views/Account/Login.cshtml b/Bootstrap.Admin/Views/Account/Login.cshtml index 229211c0..b9d767dc 100644 --- a/Bootstrap.Admin/Views/Account/Login.cshtml +++ b/Bootstrap.Admin/Views/Account/Login.cshtml @@ -91,7 +91,7 @@ - +
diff --git a/Bootstrap.Admin/Views/Admin/Users.cshtml b/Bootstrap.Admin/Views/Admin/Users.cshtml index a34fe81b..1db05d7e 100644 --- a/Bootstrap.Admin/Views/Admin/Users.cshtml +++ b/Bootstrap.Admin/Views/Admin/Users.cshtml @@ -50,7 +50,7 @@
- +
diff --git a/Bootstrap.Admin/wwwroot/js/common-scripts.js b/Bootstrap.Admin/wwwroot/js/common-scripts.js index 91fcb733..3f347cdc 100644 --- a/Bootstrap.Admin/wwwroot/js/common-scripts.js +++ b/Bootstrap.Admin/wwwroot/js/common-scripts.js @@ -20,6 +20,22 @@ return html; }; + var setBadge = function (source) { + var data = $.extend({ + TasksCount: 0, + AppExceptionsCount: 0, + DbExceptionsCount: 0, + MessagesCount: 0, + NewUsersCount: 0 + }, source); + $('#msgHeaderTaskBadge').text(data.TasksCount === 0 ? "" : data.TasksCount); + $('#msgHeaderUserBadge').text(data.NewUsersCount === 0 ? "" : data.NewUsersCount); + $('#msgHeaderAppBadge').text(data.AppExceptionsCount === 0 ? "" : data.AppExceptionsCount); + $('#msgHeaderDbBadge').text(data.DbExceptionsCount === 0 ? "" : data.DbExceptionsCount); + $('#msgHeaderMsgBadge').text(data.MessagesCount === 0 ? "" : data.MessagesCount); + $('#logoutNoti').text(data.NewUsersCount === 0 ? "" : data.NewUsersCount); + }; + $.fn.extend({ nestMenu: function (callback) { var $this = $(this); @@ -35,6 +51,7 @@ }); }, clearWidgetItems: function () { + setBadge(false); this.children('.dropdown').each(function () { $(this).children('.dropdown-menu').each(function () { $(this).children('a').remove(); @@ -48,11 +65,13 @@ $.bc({ url: Notifications.url, callback: function (result) { - $('#logoutNoti').text(result.NewUsersCount === 0 ? "" : result.NewUsersCount); that.clearWidgetItems(); + if (!result) return; + + setBadge(result); + // tasks $('#msgHeaderTask').text(result.TasksCount); - $('#msgHeaderTaskBadge').text(result.TasksCount === 0 ? "" : result.TasksCount); var htmlUserTemplate = '{0}-{2}{1}%
{1}% 完成
'; var html = result.Tasks.map(function (u) { return $.format(htmlUserTemplate, u.TaskName, u.TaskProgress, u.AssignDisplayName, u.Id, $.formatUrl('Admin/Tasks')); @@ -61,7 +80,6 @@ // new users $('#msgHeaderUser').text(result.NewUsersCount); - $('#msgHeaderUserBadge').text(result.NewUsersCount === 0 ? "" : result.NewUsersCount); htmlUserTemplate = '
{1}({0})
{3}
'; html = result.Users.map(function (u) { return $.format(htmlUserTemplate, u.UserName, u.DisplayName, u.Description, u.Period, $.formatUrl('Admin/Notifications')); @@ -70,7 +88,6 @@ // apps $('#msgHeaderApp').text(result.AppExceptionsCount); - $('#msgHeaderAppBadge').text(result.AppExceptionsCount === 0 ? "" : result.AppExceptionsCount); htmlUserTemplate = '
{0}
{2}
'; html = result.Apps.map(function (u) { return $.format(htmlUserTemplate, u.ExceptionType, u.Message, u.Period, $.formatUrl('Admin/Exceptions')); @@ -79,7 +96,6 @@ // dbs $('#msgHeaderDb').text(result.DbExceptionsCount); - $('#msgHeaderDbBadge').text(result.DbExceptionsCount === 0 ? "" : result.DbExceptionsCount); htmlUserTemplate = '
{0}
{2}
'; html = result.Dbs.map(function (u) { return $.format(htmlUserTemplate, u.ErrorPage, u.Message, u.Period, $.formatUrl('Admin/Exceptions')); @@ -88,7 +104,6 @@ // messages $('#msgHeaderMsg').text(result.MessagesCount); - $('#msgHeaderMsgBadge').text(result.MessagesCount === 0 ? "" : result.MessagesCount); htmlUserTemplate = 'avatar{2}{4}{3}'; html = result.Messages.map(function (u) { return $.format(htmlUserTemplate, u.Id, u.FromIcon, u.FromDisplayName, u.Title, u.Period, u.Content, $.formatUrl('Admin/Messages')); diff --git a/Bootstrap.Admin/wwwroot/js/login.js b/Bootstrap.Admin/wwwroot/js/login.js index d8f98df8..8be7b874 100644 --- a/Bootstrap.Admin/wwwroot/js/login.js +++ b/Bootstrap.Admin/wwwroot/js/login.js @@ -14,7 +14,7 @@ $('#btnSubmit').on('click', function () { $.bc({ - url: 'api/New', + url: "api/New/", data: { UserName: $('#userName').val(), Password: $('#password').val(), DisplayName: $('#displayName').val(), Description: $('#description').val() }, modal: '#dialogNew', method: "post", diff --git a/Bootstrap.Admin/wwwroot/js/noti.js b/Bootstrap.Admin/wwwroot/js/noti.js index 09434336..08acf5d4 100644 --- a/Bootstrap.Admin/wwwroot/js/noti.js +++ b/Bootstrap.Admin/wwwroot/js/noti.js @@ -1,8 +1,9 @@ $(function () { $('.site-footer').footer(); + var apiUrl = "api/New/"; var $table = $('table').smartTable({ - url: Notifications.url + "newusers", + url: apiUrl, sidePagination: "client", showToggle: false, showRefresh: false, @@ -23,7 +24,7 @@ var id = $this.attr('data-id'); var result = $this.attr('data-result'); $.bc({ - id: id, url: 'api/New/', method: "put", data: { Id: id, UserStatus: result }, title: result === "ApproveUser" ? "授权用户" : "拒绝用户", + id: id, url: apiUrl, method: "put", data: { Id: id, UserStatus: result }, title: result === "ApproveUser" ? "授权用户" : "拒绝用户", callback: function (result) { if (!result) return; $table.bootstrapTable('refresh');