Skip to content

Commit

Permalink
Add unread tab (support-project#1114)
Browse files Browse the repository at this point in the history
  • Loading branch information
y-okumura-isp committed Apr 30, 2021
1 parent c5eb93b commit 8c222d7
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@
import org.support.project.web.dao.SystemConfigsDao;
import org.support.project.web.dao.UserConfigsDao;
import org.support.project.web.dao.UsersDao;
import org.support.project.web.dao.ReadMarksDao;
import org.support.project.web.entity.GroupsEntity;
import org.support.project.web.entity.SystemConfigsEntity;
import org.support.project.web.entity.UserConfigsEntity;
import org.support.project.web.entity.UsersEntity;
import org.support.project.web.entity.ReadMarksEntity;
import org.support.project.web.exception.InvalidParamException;

/**
Expand Down Expand Up @@ -685,6 +687,37 @@ public Boundary show_history() throws InvalidParamException {
return forward("show_history.jsp");
}

@Get
public Boundary show_unread() throws InvalidParamException {
LoginedUser loginedUser = super.getLoginedUser();
KnowledgeLogic knowledgeLogic = KnowledgeLogic.get();

Integer offset = getOffsetParameter();
List<Long> unreadIds = knowledgeLogic.getUnreadKnowledgeIds(loginedUser, offset * PAGE_LIMIT, PAGE_LIMIT);

List<String> getIds = new ArrayList<>();
for(Long i : unreadIds) {
getIds.add(String.valueOf(i));
}

List<KnowledgesEntity> unreadKnowledges = knowledgeLogic.getKnowledges(getIds, loginedUser);
ArrayList<Long> knowledgeIds = new ArrayList<>();
for(KnowledgesEntity e : unreadKnowledges) {
knowledgeIds.add(e.getKnowledgeId());
}

List<StockKnowledge> stocks = knowledgeLogic.setStockInfo(unreadKnowledges, loginedUser);
setAttribute("unreads", stocks);
LOG.trace("未読取得完了");

// ナレッジの公開先の情報を取得
setKnowledgeTargets(loginedUser, knowledgeIds);
// タグとグループの情報を取得(一覧画面の右側のサブリスト部分に表示する情報をセット)
setSublistInformations(loginedUser);

return forward("show_unread.jsp");
}

/**
* 人気のKnowledgeを表示
*
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/support/project/knowledge/dao/KnowledgesDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,22 @@ public void updatePoint(long knowledgeId, int point) {
executeUpdate(sql, point, knowledgeId);
}

@Aspect(advice = org.support.project.ormapping.transaction.Transaction.class)
public List<Long> getUnreadKnowledgeIds(Integer userId,
int exclude_public_flag,
int offset, int limit) {
// TODO check protected knowledges
String sql = "SELECT knowledge_id FROM KNOWLEDGES "
+ "WHERE knowledge_id NOT IN (SELECT DISTINCT knowledge_id FROM VIEW_HISTORIES WHERE INSERT_USER = ?) "
+ "AND public_flag <> ?"
+ "ORDER BY UPDATE_DATETIME DESC "
+ "Limit ? offset ? "
;
return executeQueryList(sql,
Long.class,
userId,
exclude_public_flag,
limit, offset);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,25 @@ private void setTags(KnowledgesEntity entity) {
entity.setTagNames(builder.toString());
}

/**
* get unread knowledges
*
* @param user
* @param offset
* @param limit
*/
public List<Long> getUnreadKnowledgeIds(LoginedUser user,
int offset,
int limit) {
Integer userId = user.getUserId();

return KnowledgesDao.get().getUnreadKnowledgeIds(userId,
PUBLIC_FLAG_PRIVATE,
offset,
limit);

}

/**
* ナレッジを取得
*
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/appresource.properties
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ knowledge.list.info.group=Required SignIn
knowledge.list.kind.list=List
knowledge.list.kind.stock=Stock
knowledge.list.kind.history=History
knowledge.list.kind.history=Unread
knowledge.list.kind.popular=Popular
knowledge.list.invalid.keyword=Invalid search keyword
knowledge.list.link.stock=Link to stock list
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 @@ -229,6 +229,7 @@ knowledge.list.info.group=グループ機能はサインインする必要があ
knowledge.list.kind.list=一覧
knowledge.list.kind.stock=ストック
knowledge.list.kind.history=履歴
knowledge.list.kind.unread=未読
knowledge.list.kind.popular=人気
knowledge.list.invalid.keyword=検索のキーワードが不正です
knowledge.list.link.stock=ストックの一覧へ
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/WEB-INF/views/open/knowledge/list.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/show_popularity"><%=jspUtil.label("knowledge.list.kind.popular")%></a></li>
<% if (jspUtil.logined()) { %>
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/stocks"><%= jspUtil.label("knowledge.list.kind.stock") %></a></li>
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/show_unread"><%=jspUtil.label("knowledge.list.kind.unread")%></a></li>
<% } %>
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/show_history"><%=jspUtil.label("knowledge.list.kind.history")%></a></li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<li role="presentation" class="active"><a href="<%=request.getContextPath()%>/open.knowledge/show_popularity"><%=jspUtil.label("knowledge.list.kind.popular")%></a></li>
<% if (jspUtil.logined()) { %>
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/stocks"><%= jspUtil.label("knowledge.list.kind.stock") %></a></li>
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/show_unread"><%=jspUtil.label("knowledge.list.kind.unread")%></a></li>
<% } %>
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/show_history"><%=jspUtil.label("knowledge.list.kind.history")%></a></li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/show_popularity"><%=jspUtil.label("knowledge.list.kind.popular")%></a></li>
<% if (jspUtil.logined()) { %>
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/stocks"><%=jspUtil.label("knowledge.list.kind.stock")%></a></li>
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/show_unread"><%=jspUtil.label("knowledge.list.kind.unread")%></a></li>
<% } %>
<li role="presentation" class="active"><a href="<%=request.getContextPath()%>/open.knowledge/show_history"><%=jspUtil.label("knowledge.list.kind.history")%></a></li>
</ul>
Expand Down
68 changes: 68 additions & 0 deletions src/main/webapp/WEB-INF/views/open/knowledge/show_unread.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<%@page import="java.util.List"%>
<%@page pageEncoding="UTF-8" isELIgnored="false" session="false" errorPage="/WEB-INF/views/commons/errors/jsp_error.jsp"%>
<%@page import="org.support.project.common.util.NumberUtils"%>
<%@page import="org.support.project.knowledge.logic.KnowledgeLogic"%>
<%@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">
<jsp:include page="partials/partials-list-styles.jsp"></jsp:include>
</c:param>

<c:param name="PARAM_SCRIPTS">
<jsp:include page="partials/partials-list-scripts.jsp"></jsp:include>
</c:param>

<c:param name="PARAM_CONTENT">

<!-- Title -->
<div class="row">
<ul class="nav nav-tabs">
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/list"><%=jspUtil.label("knowledge.list.kind.list")%></a></li>
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/show_popularity"><%=jspUtil.label("knowledge.list.kind.popular")%></a></li>
<% if (jspUtil.logined()) { %>
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/stocks"><%=jspUtil.label("knowledge.list.kind.stock")%></a></li>
<li role="presentation" class="active"><a href="<%=request.getContextPath()%>/open.knowledge/show_unread"><%=jspUtil.label("knowledge.list.kind.unread")%></a></li>
<% } %>
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/show_history"><%=jspUtil.label("knowledge.list.kind.history")%></a></li>

</ul>
</div>

<!-- リスト -->
<div class="row" id="knowledgeList">
<%
request.setAttribute("list_data", jspUtil.getValue("unreads", List.class));
%>
<c:import url="/WEB-INF/views/open/knowledge/partials/common_list.jsp" />
<c:import url="/WEB-INF/views/open/knowledge/partials/common_sub_list.jsp" />
</div>

<!-- Pager -->
<nav>
<ul class="pager">
<li class="previous"><a
href="<%=request.getContextPath()%>/open.knowledge/show_unread/<%=jspUtil.out("previous")%><%=jspUtil.out("params")%>">
<span aria-hidden="true">&larr;</span><%=jspUtil.label("label.previous")%>
</a></li>
<li class="next"><a
href="<%=request.getContextPath()%>/open.knowledge/show_unread/<%=jspUtil.out("next")%><%=jspUtil.out("params")%>">
<%=jspUtil.label("label.next")%> <span aria-hidden="true">&rarr;</span>
</a></li>
</ul>
</nav>

</c:param>

</c:import>


1 change: 1 addition & 0 deletions src/main/webapp/WEB-INF/views/open/knowledge/stocks.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/show_popularity"><%=jspUtil.label("knowledge.list.kind.popular")%></a></li>
<% if (jspUtil.logined()) { %>
<li role="presentation" class="active"><a href="<%=request.getContextPath()%>/open.knowledge/stocks"><%= jspUtil.label("knowledge.list.kind.stock") %></a></li>
<li role="presentation" class="active"><a href="<%=request.getContextPath()%>/open.knowledge/show_unread"><%=jspUtil.label("knowledge.list.kind.unread")%></a></li>
<% } %>
<li role="presentation"><a href="<%=request.getContextPath()%>/open.knowledge/show_history"><%=jspUtil.label("knowledge.list.kind.history")%></a></li>
</ul>
Expand Down

0 comments on commit 8c222d7

Please sign in to comment.