Skip to content

Commit

Permalink
#349 Add function to get previous and next notification
Browse files Browse the repository at this point in the history
  • Loading branch information
koda-masaru committed Aug 20, 2017
1 parent ac9686b commit 9e4290b
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,44 @@ public Boundary view() throws InvalidParamException {
long no = getPathLong(new Long(-1));
NotificationsEntity notification = NotificationLogic.get().load(no, getLoginedUser());
if (notification == null) {
sendError(HttpStatus.SC_403_FORBIDDEN, "FORBIDDEN");
return sendError(HttpStatus.SC_403_FORBIDDEN, "FORBIDDEN");
}
NotificationLogic.get().setStatus(getLoginUserId(), no, NotificationLogic.STATUS_READED);
setAttributeOnProperty(notification);
setAttribute("no", no);
return forward("view.jsp");
}


@Get
public Boundary previous() throws InvalidParamException {
long no = getPathLong(new Long(-1));
boolean all = "true".equals(getAttribute("all", "false"));
NotificationsEntity notification = NotificationLogic.get().previous(no, getLoginedUser(), all);
if (notification == null) {
setAttribute("method", getResource("label.previous"));
setAttribute("no", no);
return forward("not_found.jsp");
}
no = notification.getNo();
NotificationLogic.get().setStatus(getLoginUserId(), no, NotificationLogic.STATUS_READED);
setAttributeOnProperty(notification);
setAttribute("no", no);
return forward("view.jsp");
}
@Get
public Boundary next() throws InvalidParamException {
long no = getPathLong(new Long(-1));
boolean all = "true".equals(getAttribute("all", "false"));
NotificationsEntity notification = NotificationLogic.get().next(no, getLoginedUser(), all);
if (notification == null) {
setAttribute("method", getResource("label.next"));
setAttribute("no", no);
return forward("not_found.jsp");
}
no = notification.getNo();
NotificationLogic.get().setStatus(getLoginUserId(), no, NotificationLogic.STATUS_READED);
setAttributeOnProperty(notification);
setAttribute("no", no);
return forward("view.jsp");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,36 @@ public NotificationsEntity load(long no, LoginedUser loginedUser) {
return null;
}
NotificationsEntity notificationsEntity = NotificationsDao.get().selectOnKey(no);
if (notificationsEntity == null) {
return null;
}
Notification notification = getNotification(notificationsEntity.getTitle());
notification.convNotification(notificationsEntity, loginedUser, TARGET.detail);
return notificationsEntity;
}

public NotificationsEntity previous(long no, LoginedUser loginedUser, boolean all) {
if (loginedUser == null) {
return null;
}
NotificationsEntity notificationsEntity = super.previous(no, loginedUser.getUserId(), all);
if (notificationsEntity == null) {
return null;
}
Notification notification = getNotification(notificationsEntity.getTitle());
notification.convNotification(notificationsEntity, loginedUser, TARGET.detail);
return notificationsEntity;
}
public NotificationsEntity next(long no, LoginedUser loginedUser, boolean all) {
if (loginedUser == null) {
return null;
}
NotificationsEntity notificationsEntity = super.next(no, loginedUser.getUserId(), all);
if (notificationsEntity == null) {
return null;
}
Notification notification = getNotification(notificationsEntity.getTitle());
notification.convNotification(notificationsEntity, loginedUser, TARGET.detail);
return notificationsEntity;
}
}
3 changes: 2 additions & 1 deletion src/main/resources/appresource.properties
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ message.confirm.delete=Are you sure you want to delete?
# Common Label
label.version=v1.11.0 dev
label.login=Sign in
label.previous = Previous
label.previous= Previous
label.next=Next
label.add=Add
label.public=Public
Expand Down Expand Up @@ -841,3 +841,4 @@ knowledge.token.msg.copy=Copied
knowledge.notification.title=Notifications
knowledge.notification.list.all=All items
knowledge.notification.list.only.unread=Only unread
knowledge.notification.view.not.found=Data is not found on "{1}".
2 changes: 1 addition & 1 deletion src/main/resources/appresource_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -841,4 +841,4 @@ knowledge.token.msg.copy=コピーしました
knowledge.notification.title=通知
knowledge.notification.list.all=すべて表示
knowledge.notification.list.only.unread=未読のみ

knowledge.notification.view.not.found=「{1}」 にデータがありません
10 changes: 7 additions & 3 deletions src/main/webapp/WEB-INF/views/protect/notification/list.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@
<c:forEach var="notification" items="${notifications}">
<c:if test="${notification.status == 0}">
<a class="list-group-item unread"
href="<%= request.getContextPath() %>/protect.notification/view/<%= jspUtil.out("notification.no") %>" >
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>
[<%= jspUtil.label("label.unread") %>]
<%= jspUtil.out("notification.title") %>
</h4>
Expand All @@ -73,8 +74,11 @@
</c:if>
<c:if test="${notification.status != 0}">
<a class="list-group-item "
href="<%= request.getContextPath() %>/protect.notification/view/<%= jspUtil.out("notification.no") %>" >
<h4 class="list-group-item-heading"><%= jspUtil.out("notification.title") %></h4>
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>
<%= jspUtil.out("notification.title") %>
</h4>
<p class="list-group-item-text"><%= jspUtil.date("notification.insertDatetime") %></p>
</a>
</c:if>
Expand Down
51 changes: 51 additions & 0 deletions src/main/webapp/WEB-INF/views/protect/notification/not_found.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<%@page pageEncoding="UTF-8" isELIgnored="false" session="false" errorPage="/WEB-INF/views/commons/errors/jsp_error.jsp"%>
<%@page import="org.support.project.web.util.JspUtil"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<% JspUtil jspUtil = new JspUtil(request, pageContext); %>


<c:import url="/WEB-INF/views/commons/layout/layoutMain.jsp">

<c:param name="PARAM_HEAD">
</c:param>

<c:param name="PARAM_SCRIPTS">
</c:param>


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

<%= jspUtil.label("knowledge.notification.view.not.found", jspUtil.out("method")) %>


<nav>
<ul class="pager">
<li class="previous">
<a href="<%= request.getContextPath() %>/protect.notification/previous/<%= jspUtil.out("no") %><c:if test="${!empty all}">?all=true</c:if>">
<span aria-hidden="true">&larr;</span><%= jspUtil.label("label.previous") %>
</a>
</li>
<li>
<a href="<%= request.getContextPath() %>/protect.notification/list<c:if test="${!empty all}">?all=true</c:if>" >
<i class="fa fa-list-ul"></i>&nbsp;<%= jspUtil.label("label.backlist") %>
</a>
</li>
<li class="next">
<a href="<%= request.getContextPath() %>/protect.notification/next/<%= jspUtil.out("no") %><c:if test="${!empty all}">?all=true</c:if>">
<%= jspUtil.label("label.next") %> <span aria-hidden="true">&rarr;</span>
</a>
</li>
</ul>
</nav>




</c:param>

</c:import>

49 changes: 45 additions & 4 deletions src/main/webapp/WEB-INF/views/protect/notification/view.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,63 @@
<c:import url="/WEB-INF/views/commons/layout/layoutMain.jsp">

<c:param name="PARAM_HEAD">
<link rel="stylesheet" href="<%= request.getContextPath() %>/css/knowledge-list.css" />
</c:param>

<c:param name="PARAM_SCRIPTS">
</c:param>


<c:param name="PARAM_CONTENT">
<h4 class="title"><%= jspUtil.out("title") %></h4>
<h4 class="title">
<span class="dispKnowledgeId">#<%= jspUtil.out("no") %></span>
<%= jspUtil.out("title") %>
</h4>

<nav>
<ul class="pager">
<li class="previous">
<a href="<%= request.getContextPath() %>/protect.notification/previous/<%= jspUtil.out("no") %><c:if test="${!empty all}">?all=true</c:if>">
<span aria-hidden="true">&larr;</span><%= jspUtil.label("label.previous") %>
</a>
</li>
<li>
<a href="<%= request.getContextPath() %>/protect.notification/list<c:if test="${!empty all}">?all=true</c:if>" >
<i class="fa fa-list-ul"></i>&nbsp;<%= jspUtil.label("label.backlist") %>
</a>
</li>
<li class="next">
<a href="<%= request.getContextPath() %>/protect.notification/next/<%= jspUtil.out("no") %><c:if test="${!empty all}">?all=true</c:if>">
<%= jspUtil.label("label.next") %> <span aria-hidden="true">&rarr;</span>
</a>
</li>
</ul>
</nav>

<pre>
<%= jspUtil.out("content") %>
</pre>

<a href="<%= request.getContextPath() %>/protect.notification/list" class="btn btn-success" role="button">
<i class="fa fa-list-ul"></i>&nbsp;<%= jspUtil.label("label.backlist") %>
</a>
<nav>
<ul class="pager">
<li class="previous">
<a href="<%= request.getContextPath() %>/protect.notification/previous/<%= jspUtil.out("no") %><c:if test="${!empty all}">?all=true</c:if>">
<span aria-hidden="true">&larr;</span><%= jspUtil.label("label.previous") %>
</a>
</li>
<li>
<a href="<%= request.getContextPath() %>/protect.notification/list<c:if test="${!empty all}">?all=true</c:if>" >
<i class="fa fa-list-ul"></i>&nbsp;<%= jspUtil.label("label.backlist") %>
</a>
</li>
<li class="next">
<a href="<%= request.getContextPath() %>/protect.notification/next/<%= jspUtil.out("no") %><c:if test="${!empty all}">?all=true</c:if>">
<%= jspUtil.label("label.next") %> <span aria-hidden="true">&rarr;</span>
</a>
</li>
</ul>
</nav>


</c:param>

Expand Down

0 comments on commit 9e4290b

Please sign in to comment.