重构通知管理相关功能

This commit is contained in:
Argo-Lenovo 2016-11-11 21:05:41 +08:00
parent fac7e6a09d
commit 6e7f76e8bf
9 changed files with 86 additions and 81 deletions

View File

@ -53,27 +53,21 @@
height: 46px;
}
.tasks-widget .task-list li > .task-title .task-wrapper {
.tasks-widget .task-list li > .task-title .task-value {
position: absolute;
left: 190px;
right: 40px;
top: 16px;
top: 17px;
display: inline-block;
padding-left: 16px;
}
.tasks-widget .task-list li > .task-title .task-wrapper.notifi {
right: 70px;
left: 90px;
}
.tasks-widget .task-list li > .task-title .task-wrapper span {
display: inline-block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
}
.tasks-widget .task-list li > .task-title span {
display: inline-block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
}
.tasks-widget .task-list li > .task-title .badge {
position: relative;
@ -101,13 +95,26 @@
right: 10px;
}
.tasks-widget .task-list li .task-title.notifi .task-title-sp {
max-width: 80px;
}
.tasks-widget .task-list li .task-title.notifi .task-value {
left: 120px;
right: 190px;
}
.tasks-widget .task-list li .task-title.notifi .task-time {
position: absolute;
right: 66px;
top: 17px;
display: inline-block;
color: #3c763d;
}
.tasks-widget .task-list li .task-title .task-title-sp {
margin-right: 5px;
max-width: 170px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
display: inline-block;
padding-top: 17px;
}
@ -182,6 +189,16 @@
border-left: 3px solid #BEC3C7;
}
@media (max-width: 548px) {
.tasks-widget .task-list li .task-title.notifi .task-value {
right: 66px;
}
.tasks-widget .task-list li .task-title.notifi .task-time {
display: none;
}
}
@media only screen and (max-width: 320px) {
.tasks-widget .task-config-btn {

View File

@ -17,7 +17,7 @@ namespace Bootstrap.Admin.Models
UserID = user.ID;
HomeUrl = "~/";
Menus = MenuHelper.RetrieveLinksByUserName(UserName);
Notifications = NotificationHelper.RetrieveUser();
Notifications = NotificationHelper.RetrieveNotifications();
}
public string UserName { get; protected set; }
/// <summary>
@ -43,6 +43,6 @@ namespace Bootstrap.Admin.Models
/// <summary>
///
/// </summary>
public IEnumerable<User> Notifications { get; set; }
public IEnumerable<Notification> Notifications { get; set; }
}
}

View File

@ -33,7 +33,7 @@
}
});
var html = '<li class="list-primary"><i class="fa fa-ellipsis-v"></i><div class="task-title"><span class="task-title-sp">{2}</span><span class="badge badge-sm label-success">{0}</span><div class="task-wrapper"><span class="task-value tooltips" data-placement="top" data-original-title="{3}">{3}</span></div><div class="pull-right hidden-phone"><button class="btn btn-danger btn-xs fa fa-trash-o tooltips" data-key="{1}" data-placement="left" data-original-title="{1}"></button></div></div></li>';
var html = '<li class="list-primary"><i class="fa fa-ellipsis-v"></i><div class="task-title"><span class="task-title-sp">{2}</span><span class="badge badge-sm label-success">{0}</span><span class="task-value tooltips" data-placement="top" data-original-title="{3}">{3}</span><div class="pull-right hidden-phone"><button class="btn btn-danger btn-xs fa fa-trash-o tooltips" data-key="{1}" data-placement="left" data-original-title="{1}"></button></div></div></li>';
function listCache(options) {
$.ajax({

View File

@ -20,16 +20,15 @@
<div class="panel-heading">用户注册<span class="pull-right"><a href="javascript:;" class="tooltips fa fa-refresh" data-placement="left" data-original-title="点击刷新"></a></span></div>
<div class="panel-body">
<div class="tasks-widget">
<ul id="tasks-users" class="task-list ui-sortable">
@foreach (var u in Model.Notifications)
<ul id="tasks-users" class="task-list ui-sortable" data-category="0">
@foreach (var noti in Model.Notifications.Where(n => n.Category == "0"))
{
<li class="list-primary">
<i class="fa fa-ellipsis-v"></i>
<div class="task-title">
<span class="task-title-sp">@u.DisplayName</span>
<div class="task-wrapper notifi">
<span class="task-value tooltips" data-placement="top" data-original-title="@u.Description">@u.Description</span>
</div>
<div class="task-title notifi">
<span class="task-title-sp">@noti.Title</span>
<span class="task-value">@noti.Content</span>
<span class="task-time">@noti.RegisterTime.ToString("yyyy-MM-dd HH:mm:ss")</span>
<div class="pull-right hidden-phone">
<button class="btn btn-success btn-xs fa fa-check tooltips" data-placement="left" data-original-title="同意授权"></button>
<button class="btn btn-danger btn-xs fa fa-remove tooltips" data-placement="left" data-original-title="拒绝授权"></button>
@ -45,16 +44,15 @@
<div class="panel-heading">程序错误<a href="javascript:;" class="pull-right tooltips fa fa-refresh" data-placement="left" data-original-title="点击刷新"></a></div>
<div class="panel-body">
<div class="tasks-widget">
<ul id="tasks-app" class="task-list ui-sortable">
@foreach (var nofi in Model.Notifications)
<ul id="tasks-app" class="task-list ui-sortable" data-category="1">
@foreach (var nofi in Model.Notifications.Where(n => n.Category == "1"))
{
<li class="list-warning">
<i class="fa fa-ellipsis-v"></i>
<div class="task-title">
<span class="task-title-sp">@nofi.DisplayName</span>
<div class="task-wrapper notifi">
<span class="task-value tooltips" data-placement="top" data-original-title="@nofi.Description">@nofi.Description</span>
</div>
<div class="task-title notifi">
<span class="task-title-sp">@nofi.Title</span>
<span class="task-value">@nofi.Content</span>
<span class="task-time">@nofi.RegisterTime.ToString("yyyy-MM-dd HH:mm:ss")</span>
<div class="pull-right hidden-phone">
<button class="btn btn-success btn-xs fa fa-check tooltips" data-placement="left" data-original-title="同意授权"></button>
<button class="btn btn-danger btn-xs fa fa-remove tooltips" data-placement="left" data-original-title="拒绝授权"></button>
@ -70,16 +68,15 @@
<div class="panel-heading">数据库报警<span class="pull-right"><a href="javascript:;" class="tooltips fa fa-refresh" data-placement="left" data-original-title="点击刷新"></a></span></div>
<div class="panel-body">
<div class="tasks-widget">
<ul id="tasks-db" class="task-list ui-sortable">
@foreach (var nofi in Model.Notifications)
<ul id="tasks-db" class="task-list ui-sortable" data-category="2">
@foreach (var nofi in Model.Notifications.Where(n => n.Category == "2"))
{
<li class="list-danger">
<i class="fa fa-ellipsis-v"></i>
<div class="task-title">
<span class="task-title-sp">@nofi.DisplayName</span>
<div class="task-wrapper notifi">
<span class="task-value tooltips" data-placement="top" data-original-title="@nofi.Description">@nofi.Description</span>
</div>
<div class="task-title notifi">
<span class="task-title-sp">@nofi.Title</span>
<span class="task-time">@nofi.RegisterTime.ToString("yyyy-MM-dd HH:mm:ss")</span>
<span class="task-value">@nofi.Content</span>
<div class="pull-right hidden-phone">
<button class="btn btn-success btn-xs fa fa-check tooltips" data-placement="left" data-original-title="同意授权"></button>
<button class="btn btn-danger btn-xs fa fa-remove tooltips" data-placement="left" data-original-title="拒绝授权"></button>

View File

@ -177,11 +177,22 @@
<li>
<p>您有 @Model.Notifications.Count() 条新通知</p>
</li>
@foreach (var u in Model.Notifications.Take(6))
@foreach (var noti in Model.Notifications.Take(6))
{
<li>
<a href="~/Admin/Notifications">
<span class="label label-success"><i class="fa fa-plus"></i></span><div>@u.DisplayName</div><span class="small italic">@u.Period</span>
<a href="~/Admin/Notifications/@noti.ID?category=@noti.Category">
@if (noti.Category == "0")
{
<span class="label label-success"><i class="fa fa-plus"></i></span><div>@noti.Content</div><span class="small italic">@noti.Period</span>
}
else if (noti.Category == "1")
{
<span class="label label-warning"><i class="fa fa-bell"></i></span><div>@noti.Content</div><span class="small italic">@noti.Period</span>
}
else
{
<span class="label label-danger"><i class="fa fa-bolt"></i></span><div>@noti.Content</div><span class="small italic">@noti.Period</span>
}
</a>
</li>
}

View File

@ -43,7 +43,7 @@
<add key="DictHelper-RetrieveDicts" interval="600" desc="所有字典数据缓存"/>
<add key="DictHelper-RetrieveDictsWebSettings" interval="600" desc="网站配置数据缓存"/>
<add key="NotificationHelper-RetrieveNotifications" interval="600" desc="通知管理数据缓存"/>
<add key="UserHelper-RetrieveUsersForNotify" interval="600" desc="新注册用户通知管理数据缓存" />
<add key="UserHelper-RetrieveNewUsers" interval="300" desc="新用户数据缓存" />
</cacheManager>
<cacheManagerList>

View File

@ -40,6 +40,7 @@ namespace Bootstrap.DataAccess
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIDDataKey, id));
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey);
});
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey);
// final cleanup
CacheManager.Clear(key => cacheKeys.Any(k => k == key) || key.Contains(UserHelper.RetrieveUsersDataKey) || key.Contains(RoleHelper.RetrieveRolesByUserNameDataKey));
cacheKeys.Clear();
@ -80,7 +81,7 @@ namespace Bootstrap.DataAccess
if (notifyIds != null)
{
// final cleanup
CacheManager.Clear(key => key.Contains(NotificationHelper.RetrieveNotifyDataKey));
CacheManager.Clear(key => key.Contains(NotificationHelper.RetrieveNotificationsDataKey));
cacheKeys.Clear();
}
}

View File

@ -12,31 +12,8 @@ namespace Bootstrap.DataAccess
{
public class NotificationHelper
{
internal const string RetrieveNotifyDataKey = "NotificationHelper-RetrieveNotifications";
/// <summary>
/// 查询新注册用户
/// </summary>
/// <returns></returns>
public static IEnumerable<User> RetrieveUser()
{
var ret = UserHelper.RetrieveUsersForNotify();
if (ret != null)
{
ret.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);
});
return ret;
}
List<User> users = new List<User>();
return users;
}
// UNDOEN: 此处需要继续完善,增强异常的通知管理
internal const string RetrieveNotificationsDataKey = "NotificationHelper-RetrieveNotifications";
/// <summary>
/// 新用户注册的通知的面板显示
/// </summary>
@ -44,7 +21,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static IEnumerable<Notification> RetrieveNotifications()
{
var ret = CacheManager.GetOrAdd(RetrieveNotifyDataKey, CacheSection.RetrieveIntervalByKey(RetrieveNotifyDataKey), key =>
var notifies = CacheManager.GetOrAdd(RetrieveNotificationsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveNotificationsDataKey), key =>
{
string sql = "select * from Notifications";
List<Notification> notifications = new List<Notification>();
@ -73,7 +50,9 @@ namespace Bootstrap.DataAccess
catch (Exception ex) { ExceptionManager.Publish(ex); }
return notifications;
}, CacheSection.RetrieveDescByKey(RetrieveNotifyDataKey));
}, CacheSection.RetrieveDescByKey(RetrieveNotificationsDataKey));
var users = UserHelper.RetrieveNewUsers().Select(u => new Notification() { ID = u.ID, Category = "0", Content = u.Description, Title = u.DisplayName, RegisterTime = u.RegisterTime }).ToList();
var ret = users.Union(notifies);
ret.AsParallel().ForAll(n =>
{
var ts = DateTime.Now - n.RegisterTime;
@ -82,7 +61,7 @@ namespace Bootstrap.DataAccess
else if (ts.Hours > 0) n.Period = string.Format("{0}小时", ts.Hours);
else if (ts.Minutes > 0) n.Period = string.Format("{0}分钟", ts.Minutes);
});
return ret;
return ret.OrderByDescending(n => n.RegisterTime);
}
/// <summary>

View File

@ -23,7 +23,7 @@ namespace Bootstrap.DataAccess
private const string RetrieveUsersByNameDataKey = "UserHelper-RetrieveUsersByName";
internal const string RetrieveUsersByRoleIDDataKey = "UserHelper-RetrieveUsersByRoleId";
internal const string RetrieveUsersByGroupIDDataKey = "UserHelper-RetrieveUsersByGroupId";
internal const string RetrieveUsersForNotifyDataKey = "UserHelper-RetrieveUsersForNotify";
internal const string RetrieveNewUsersDataKey = "UserHelper-RetrieveNewUsers";
/// <summary>
/// 查询所有用户
/// </summary>
@ -100,11 +100,11 @@ namespace Bootstrap.DataAccess
/// 查询所有的新注册用户
/// </summary>
/// <returns></returns>
public static IEnumerable<User> RetrieveUsersForNotify()
public static IEnumerable<User> RetrieveNewUsers()
{
string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null";
var ret = CacheManager.GetOrAdd(RetrieveUsersForNotifyDataKey, CacheSection.RetrieveIntervalByKey(RetrieveUsersForNotifyDataKey), key =>
var ret = CacheManager.GetOrAdd(RetrieveNewUsersDataKey, CacheSection.RetrieveIntervalByKey(RetrieveNewUsersDataKey), key =>
{
string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null";
List<User> Users = new List<User>();
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
try
@ -126,7 +126,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return Users;
}, CacheSection.RetrieveDescByKey(RetrieveUsersForNotifyDataKey));
}, CacheSection.RetrieveDescByKey(RetrieveNewUsersDataKey));
return ret;
}