Skip to content

Commit

Permalink
#349 Add mark all as read button on notification list page
Browse files Browse the repository at this point in the history
  • Loading branch information
koda-masaru committed Aug 21, 2017
1 parent 6054e98 commit 975c2b3
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.support.project.web.boundary.Boundary;
import org.support.project.web.common.HttpStatus;
import org.support.project.web.control.service.Get;
import org.support.project.web.control.service.Post;
import org.support.project.web.entity.NotificationsEntity;
import org.support.project.web.exception.InvalidParamException;

Expand Down Expand Up @@ -75,4 +76,13 @@ public Boundary next() throws InvalidParamException {
setAttribute("no", no);
return forward("view.jsp");
}

@Post
public Boundary markread() {
String no = getAttribute("no", "");
NotificationLogic.get().markAllAsRead(no, getLoginUserId());
return send("OK");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.Iterator;
import java.util.List;

import org.support.project.aop.Aspect;
import org.support.project.common.util.StringUtils;
import org.support.project.di.Container;
import org.support.project.knowledge.logic.notification.AcceptCheckUserNotification;
import org.support.project.knowledge.logic.notification.AddUserNotification;
Expand Down Expand Up @@ -128,4 +130,15 @@ public NotificationsEntity next(long no, LoginedUser loginedUser, boolean all) {
notification.convNotification(notificationsEntity, loginedUser, TARGET.detail);
return notificationsEntity;
}

@Aspect(advice = org.support.project.ormapping.transaction.Transaction.class)
public void markAllAsRead(String no, Integer userID) {
String[] nos = no.split(",");
for (String n : nos) {
if (StringUtils.isInteger(n)) {
int num = Integer.parseInt(n);
super.setStatus(userID, num, NotificationLogic.STATUS_READED);
}
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/appresource.properties
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ label.unread=Unread
label.read=Read
label.save.draft=Save draft
label.delete.draft=Delete draft
label.mark.all.as.read=Mark all as read

label.public.view=<i class="fa fa-globe"></i>&nbsp;[Public]
label.protect.view=<i class="fa fa-gavel"></i>&nbsp;[Protection]
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/appresource_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ label.unread=未読
label.read=既読
label.save.draft=下書き保存
label.delete.draft=下書き削除
label.mark.all.as.read=既読にする

label.public.view=<i class="fa fa-globe"></i>&nbsp;[公開]
label.protect.view=<i class="fa fa-gavel"></i>&nbsp;[保護]
Expand Down
22 changes: 20 additions & 2 deletions src/main/webapp/WEB-INF/views/protect/notification/list.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,27 @@
<c:import url="/WEB-INF/views/commons/layout/layoutMain.jsp">

<c:param name="PARAM_HEAD">
<!-- build:css(src/main/webapp) css/notification-list.css -->
<link rel="stylesheet" href="<%= request.getContextPath() %>/css/knowledge-list.css" />
<!-- endbuild -->
</c:param>

<c:param name="PARAM_SCRIPTS">
<script>
var UNREAD_LIST = [
<c:forEach var="notification" items="${notifications}"><c:if test="${notification.status == 0}"><%= jspUtil.out("notification.no") %>,</c:if></c:forEach>
];
</script>
<!-- build:js(src/main/webapp) js/page-notification-list.js -->
<script type="text/javascript" src="<%= request.getContextPath() %>/js/notification-list.js"></script>
<!-- endbuild -->
</c:param>


<c:param name="PARAM_CONTENT">
<h4 class="title"><%= jspUtil.label("knowledge.notification.title") %></h4>

<div class="col-sm-6">
<c:if test="${empty all}">
<i class="fa fa-dot-circle-o" aria-hidden="true"></i>
<%= jspUtil.label("knowledge.notification.list.only.unread") %>
Expand All @@ -36,6 +47,13 @@
<i class="fa fa-dot-circle-o" aria-hidden="true"></i>
<%= jspUtil.label("knowledge.notification.list.all") %>
</c:if>
</div>
<div class="col-sm-6 text-right">
<button class="btn btn-link" id="btnMarkAllAsRead">
<i class="fa fa-check" aria-hidden="true"></i>
<%= jspUtil.label("label.mark.all.as.read") %>
</button>
</div>

<nav>
<ul class="pager">
Expand Down Expand Up @@ -65,7 +83,7 @@
<a class="list-group-item unread"
href="<%= request.getContextPath() %>/protect.notification/view/<%= jspUtil.out("notification.no") %><c:if test="${!empty all}">?all=true</c:if>" >
<h4 class="list-group-item-heading">
<span class="dispKnowledgeId">#<%= jspUtil.out("notification.no") %></span>
<span class="dispKnowledgeId">@<%= jspUtil.out("notification.no") %></span>
[<%= jspUtil.label("label.unread") %>]
<%= jspUtil.out("notification.title") %>
</h4>
Expand All @@ -76,7 +94,7 @@
<a class="list-group-item "
href="<%= request.getContextPath() %>/protect.notification/view/<%= jspUtil.out("notification.no") %><c:if test="${!empty all}">?all=true</c:if>" >
<h4 class="list-group-item-heading">
<span class="dispKnowledgeId">#<%= jspUtil.out("notification.no") %></span>
<span class="dispKnowledgeId">@<%= jspUtil.out("notification.no") %></span>
<%= jspUtil.out("notification.title") %>
</h4>
<p class="list-group-item-text"><%= jspUtil.date("notification.insertDatetime") %></p>
Expand Down
21 changes: 21 additions & 0 deletions src/main/webapp/js/notification-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
$(document).ready(function() {
$('#btnMarkAllAsRead').click(function() {
console.log(UNREAD_LIST);
if (UNREAD_LIST.length > 0) {
var data = {
no: UNREAD_LIST.join(',')
};
$.ajax({
url: _CONTEXT + '/protect.notification/markread',
type: 'POST',
data: data,
timeout: 10000,
}).done(function(result, textStatus, xhr) {
console.log(result);
location.reload();
}).fail(function(xhr, textStatus, error) {
console.log(error);
});
}
});
});

0 comments on commit 975c2b3

Please sign in to comment.