Skip to content

Commit

Permalink
#840 Add activity list
Browse files Browse the repository at this point in the history
  • Loading branch information
koda-masaru committed Sep 7, 2017
1 parent 8758cf0 commit 8403ef4
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 25 deletions.
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"tableExport.jquery.plugin": "1.8.1",
"diff2html": "2.3.0",
"jsdiff": "3.2.0",
"chart.js": "2.6.0"
"chart.js": "2.6.0",
"vue": "2.4.2"
},
"devDependencies": {},
"resolutions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.support.project.knowledge.vo.AccountInfo;
import org.support.project.knowledge.vo.ContributionPointHistory;
import org.support.project.knowledge.vo.StockKnowledge;
import org.support.project.knowledge.vo.StringList;
import org.support.project.web.boundary.Boundary;
import org.support.project.web.control.service.Get;
import org.support.project.web.dao.UsersDao;
Expand Down Expand Up @@ -133,7 +134,40 @@ public Boundary cp() throws Exception {
List<ContributionPointHistory> list = ActivityLogic.get().getUserPointHistoriesByDate(userId, getUserConfigs());
return send(list);
}


@Get
public Boundary knowledge() throws Exception {
Integer userId = getPathInteger(-1);
UsersEntity account = UsersDao.get().selectOnKey(userId);
if (account == null) {
return send(HttpStatus.SC_NOT_FOUND, "NOT FOUND");
}
// そのユーザが登録したナレッジを取得
int offset = 0;
if (StringUtils.isInteger(getParam("offset"))) {
offset = getParam("offset", Integer.class);
}
List<KnowledgesEntity> knowledges = KnowledgeLogic.get().showKnowledgeOnUser(userId, getLoginedUser(), offset * PAGE_LIMIT, PAGE_LIMIT);
List<StockKnowledge> stocks = KnowledgeLogic.get().setStockInfo(knowledges, getLoginedUser());
KnowledgeLogic.get().setViewed(stocks, getLoginedUser());
return send(stocks);
}

@Get
public Boundary activity() throws Exception {
Integer userId = getPathInteger(-1);
UsersEntity account = UsersDao.get().selectOnKey(userId);
if (account == null) {
return send(HttpStatus.SC_NOT_FOUND, "NOT FOUND");
}
int limit = 20;
int offset = 0;
if (StringUtils.isInteger(getParam("offset"))) {
offset = getParam("offset", Integer.class);
}
StringList list = ActivityLogic.get().getUserPointHistoriese(userId, limit, offset, getUserConfigs());
return send(list);
}


}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.support.project.knowledge.dao;

import java.util.List;

import org.support.project.aop.Aspect;
import org.support.project.di.Container;
import org.support.project.di.DI;
import org.support.project.di.Instance;

import org.support.project.knowledge.dao.gen.GenActivitiesDao;
import org.support.project.knowledge.entity.ActivitiesEntity;

Expand All @@ -28,6 +29,23 @@ public ActivitiesEntity select(int userId, int type, String target) {
String sql = "SELECT * FROM ACTIVITIES WHERE USER_ID = ? AND KIND = ? AND TARGET = ?";
return executeQuerySingle(sql, ActivitiesEntity.class, userId, type, target);
}
@Aspect(advice = org.support.project.ormapping.transaction.Transaction.class)
public List<ActivitiesEntity> selectOnNos(List<Long> activityNos) {
StringBuilder sql = new StringBuilder();
sql.append("SELECT *, USERS.USER_NAME FROM ACTIVITIES INNER JOIN USERS ON (ACTIVITIES.user_id = users.user_id) ");
sql.append("WHERE activity_no IN (");
boolean appended = false;
for (Long no : activityNos) {
if (appended) {
sql.append(", ");

}
sql.append("?");
appended = true;
}
sql.append(");");
return executeQueryList(sql.toString(), ActivitiesEntity.class, activityNos.toArray(new Long[0]));
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class ActivitiesEntity extends GenActivitiesEntity {

/** SerialVersion */
private static final long serialVersionUID = 1L;

private String userName = "";

/**
* Get instance from DI container.
Expand All @@ -46,4 +48,18 @@ public ActivitiesEntity(Long no) {
super( no);
}

/**
* @return the userName
*/
public String getUserName() {
return userName;
}

/**
* @param userName the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void doFilter(ServletRequest servletrequest, ServletResponse servletrespo
if (StringUtils.isInteger(offset)) {
userConfig.setTimezoneOffset(Integer.parseInt(offset));
}
userConfig.setLocale(HttpUtil.getLocale(req));
req.setAttribute(UserConfig.REQUEST_USER_CONFIG_KEY, userConfig);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.support.project.aop.Aspect;
import org.support.project.common.config.Resources;
import org.support.project.common.log.Log;
import org.support.project.common.log.LogFactory;
import org.support.project.common.util.StringUtils;
import org.support.project.di.Container;
import org.support.project.di.DI;
import org.support.project.di.Instance;
import org.support.project.knowledge.dao.ActivitiesDao;
import org.support.project.knowledge.dao.PointUserHistoriesDao;
import org.support.project.knowledge.entity.ActivitiesEntity;
import org.support.project.knowledge.entity.CommentsEntity;
import org.support.project.knowledge.entity.KnowledgesEntity;
import org.support.project.knowledge.entity.PointUserHistoriesEntity;
import org.support.project.knowledge.vo.ContributionPointHistory;
import org.support.project.knowledge.vo.StringList;
import org.support.project.knowledge.vo.UserConfigs;
import org.support.project.ormapping.config.Order;
import org.support.project.web.bean.LoginedUser;
import org.support.project.web.logic.DateConvertLogic;

@DI(instance = Instance.Singleton)
public class ActivityLogic {
Expand Down Expand Up @@ -98,4 +108,50 @@ public void processActivity(Activity activity, LoginedUser eventUser, Date event
public List<ContributionPointHistory> getUserPointHistoriesByDate(Integer userId, UserConfigs userConfigs) {
return PointUserHistoriesDao.get().selectPointHistoriesByDate(userId, userConfigs);
}

private String getDisplayDate(Date date, UserConfigs userConfigs) {
return DateConvertLogic.get().convertDate(date, userConfigs.getLocale(), String.valueOf(userConfigs.getTimezoneOffset()));
}

private String getActivityMsg(PointUserHistoriesEntity history, Map<Long, ActivitiesEntity> activities, UserConfigs userConfigs) {
Resources resources = Resources.getInstance(userConfigs.getLocale());
ActivitiesEntity activity = activities.get(history.getActivityNo());
if (activity == null) {
return "";
}
if (history.getType() == ActivityProcessor.TYPE_KNOWLEDGE_DO_INSERT) {
return resources.getResource("knowledge.activity.type.11.do.insert",
getDisplayDate(history.getInsertDatetime(), userConfigs), activity.getTarget());
} else if (history.getType() == ActivityProcessor.TYPE_KNOWLEDGE_DO_SHOW) {
return resources.getResource("knowledge.activity.type.21.do.show",
getDisplayDate(history.getInsertDatetime(), userConfigs), activity.getTarget());
} else if (history.getType() == ActivityProcessor.TYPE_KNOWLEDGE_SHOWN_BY_OHER) {
return resources.getResource("knowledge.activity.type.22.shown",
getDisplayDate(history.getInsertDatetime(), userConfigs),activity.getTarget(), activity.getUserName());
}
return "なんかした";
}
public StringList getUserPointHistoriese(Integer userId, int limit, int offset, UserConfigs userConfigs) {
List<PointUserHistoriesEntity> histories = PointUserHistoriesDao.get().selectOnUser(userId, limit, offset, Order.DESC);
List<Long> activityNos = new ArrayList<>();
for (PointUserHistoriesEntity history : histories) {
activityNos.add(history.getActivityNo());
}
List<ActivitiesEntity> activityList = ActivitiesDao.get().selectOnNos(activityNos);
Map<Long, ActivitiesEntity> activities = new HashMap<>();
for (ActivitiesEntity activitiesEntity : activityList) {
activities.put(activitiesEntity.getActivityNo(), activitiesEntity);
}
List<String> list = new ArrayList<>();
for (PointUserHistoriesEntity history : histories) {
String msg = getActivityMsg(history, activities, userConfigs);
if (StringUtils.isNotEmpty(msg)) {
list.add(msg);
}
}
StringList stringList = new StringList();
stringList.setList(list);
return stringList;
}

}
14 changes: 14 additions & 0 deletions src/main/java/org/support/project/knowledge/vo/UserConfigs.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.support.project.knowledge.vo;

import java.io.Serializable;
import java.util.Locale;

public class UserConfigs implements Serializable {
/** serialVersion */
private static final long serialVersionUID = 1L;
private Locale locale = Locale.getDefault();
/** タイムゾーン */
private String timezone = "UTC";
/** タイムゾーンオフセット(分) */
Expand Down Expand Up @@ -61,6 +63,18 @@ public int getHighlight() {
public void setHighlight(int highlight) {
this.highlight = highlight;
}
/**
* @return the locale
*/
public Locale getLocale() {
return locale;
}
/**
* @param locale the locale to set
*/
public void setLocale(Locale locale) {
this.locale = locale;
}



Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/appresource.properties
Original file line number Diff line number Diff line change
Expand Up @@ -853,5 +853,9 @@ knowledge.maintenance.do.migrate.no.login=Execute maintenance(only administrator
knowledge.maintenance.migrate.title=Database migration
knowledge.maintenance.migrate.message=You can execute database migration. recommend to backup database data.


knowledge.activity.type.11.do.insert={1} This user posted #{2}
knowledge.activity.type.13.inserted={1} #{2} was posted by {3}
knowledge.activity.type.21.do.show={1} This user showed #{2}
knowledge.activity.type.22.shown={1} #{2} was shown by {3}
knowledge.activity.type.23.shown={1} #{2} was shown by {3}

6 changes: 6 additions & 0 deletions src/main/resources/appresource_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -853,5 +853,11 @@ knowledge.maintenance.do.migrate.no.login=メンテナンス管理を実行(管
knowledge.maintenance.migrate.title=Database migration
knowledge.maintenance.migrate.message=DBのマイグレーションを実行します。事前にDBのバックアップを取ることをオススメします。

knowledge.activity.type.11.do.insert={1} #{2} の記事を投稿しました
knowledge.activity.type.13.inserted={1} #{2} の記事が、{3} によって投稿されました
knowledge.activity.type.21.do.show={1} #{2} の記事を参照しました
knowledge.activity.type.22.shown={1} #{2} の記事を、{3} が参照しました
knowledge.activity.type.23.shown={1} #{2} の記事を、{3} が参照しました



38 changes: 22 additions & 16 deletions src/main/webapp/WEB-INF/views/open/account/account.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/moment/min/moment.min.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/moment/locale/ja.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/chart.js/dist/Chart.min.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/bower/vue/dist/vue.min.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/js/knowledge-list.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/js/account-page.js"></script>
<!-- endbuild -->
Expand Down Expand Up @@ -80,33 +81,29 @@
</div>
</div>

<div class="row">
<div class="row" id="tabArea">
<ul class="nav nav-tabs">
<li role="presentation" class="active"><a href="<%=request.getContextPath()%>/open.account/info/<%= jspUtil.out("userId") %>">
<li role="presentation" class="active"><a v-on:click="showKnowledge">
<%= jspUtil.label("knowledge.account.label.knowledges") %>
</a></li>
<li role="presentation"><a href="<%=request.getContextPath()%>/open.account/like/<%= jspUtil.out("userId") %>">
<li role="presentation"><a v-on:click="showLike">
<%=jspUtil.label("knowledge.account.label.like")%>
</a></li>
<li role="presentation"><a href="<%=request.getContextPath()%>/open.account/activity/<%= jspUtil.out("userId") %>">
<li role="presentation"><a v-on:click="showActivity">
<%=jspUtil.label("knowledge.account.label.activity")%>
</a></li>
</ul>
</div>



<div class="sub_title">

</div>

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


<div id="knowledgesArea">
<div class="sub_title">
</div>
<!-- リスト -->
<div class="row" id="knowledgeList">
<% request.setAttribute("list_data", jspUtil.getValue("knowledges", List.class)); %>
<c:import url="/WEB-INF/views/open/knowledge/partials/common_list.jsp" />
</div>
<!-- Pager -->
<nav>
<ul class="pager">
Expand All @@ -122,8 +119,17 @@
</li>
</ul>
</nav>
</div>


<div id="activityArea" style="display:none">
<br/><br/>
<ul class="list-group" id="activityList">
<li class="list-group-item" v-for="activity in activities">
{{ activity }}
</li>
</ul>
</div>

</c:param>

Expand Down
Loading

0 comments on commit 8403ef4

Please sign in to comment.