Commit 67281acb authored by Liang Ding's avatar Liang Ding

加入作者-文章分页 AJAX请求

/articles/authors/{authorId}/{pageNum}
parent b803a476
...@@ -566,6 +566,70 @@ public final class ArticleProcessor { ...@@ -566,6 +566,70 @@ public final class ArticleProcessor {
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
} }
/**
* Gets author articles paged with the specified context.
*
* @param context the specified context
* @param request the specified request
*/
@RequestProcessing(value = "/articles/authors/\\d+/\\d+", uriPatternsMode = URIPatternMode.REGEX,
method = HTTPRequestMethod.GET)
public void getAuthorsArticlesByPage(final HTTPRequestContext context, final HttpServletRequest request) {
final JSONObject jsonObject = new JSONObject();
final String authorId = getAuthorsArticlesPagedAuthorId(request.getRequestURI());
final int currentPageNum = getAuthorsArticlesPagedCurrentPageNum(request.getRequestURI());
Stopwatchs.start("Get Author-Articles Paged[authorId=" + authorId + ", pageNum=" + currentPageNum + ']');
try {
jsonObject.put(Keys.STATUS_CODE, true);
final JSONObject preference = preferenceQueryService.getPreference();
final int pageSize = preference.getInt(Preference.ARTICLE_LIST_DISPLAY_COUNT);
final JSONObject authorRet = userQueryService.getUser(authorId);
if (null == authorRet) {
context.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
final JSONObject author = authorRet.getJSONObject(User.USER);
final String authorEmail = author.optString(User.USER_EMAIL);
final List<JSONObject> articles = articleQueryService.getArticlesByAuthorEmail(authorEmail, currentPageNum, pageSize);
if (!articles.isEmpty()) {
filler.setArticlesExProperties(articles, author, preference);
}
final int articleCount = author.getInt(UserExt.USER_PUBLISHED_ARTICLE_COUNT);
final int pageCount = (int) Math.ceil((double) articleCount / (double) pageSize);
final JSONObject result = new JSONObject();
final JSONObject pagination = new JSONObject();
pagination.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
result.put(Pagination.PAGINATION, pagination);
result.put(Article.ARTICLES, articles);
jsonObject.put(Keys.RESULTS, result);
} catch (final Exception e) {
jsonObject.put(Keys.STATUS_CODE, false);
LOGGER.log(Level.SEVERE, "Gets article paged failed", e);
} finally {
Stopwatchs.end();
}
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
renderer.setJSONObject(jsonObject);
}
/** /**
* Shows author articles with the specified context. * Shows author articles with the specified context.
* *
...@@ -1012,6 +1076,32 @@ public final class ArticleProcessor { ...@@ -1012,6 +1076,32 @@ public final class ArticleProcessor {
return StringUtils.substringBeforeLast(archiveAndPageNum, "/"); return StringUtils.substringBeforeLast(archiveAndPageNum, "/");
} }
/**
* Gets the request page number from the specified request URI.
*
* @param requestURI the specified request URI
* @return page number
*/
private static int getAuthorsArticlesPagedCurrentPageNum(final String requestURI) {
return Requests.getCurrentPageNum(StringUtils.substringAfterLast(requestURI, "/"));
}
/**
* Gets the request author id from the specified request URI.
*
* @param requestURI the specified request URI
* @return author id
*/
private static String getAuthorsArticlesPagedAuthorId(final String requestURI) {
String authorIdAndPageNum = requestURI.substring((Latkes.getContextPath() + "/articles/authors/").length());
if (!authorIdAndPageNum.endsWith("/")) {
authorIdAndPageNum += "/";
}
return StringUtils.substringBefore(authorIdAndPageNum, "/");
}
/** /**
* Gets the request page number from the specified request URI and author id. * Gets the request page number from the specified request URI and author id.
* *
......
...@@ -362,6 +362,8 @@ public final class ArticleQueryService { ...@@ -362,6 +362,8 @@ public final class ArticleQueryService {
// Skips the unpublished article // Skips the unpublished article
continue; continue;
} }
article.put(ARTICLE_CREATE_TIME, ((Date) article.get(ARTICLE_CREATE_DATE)).getTime());
// Markdown to HTML for content and abstract // Markdown to HTML for content and abstract
markdown(article); markdown(article);
...@@ -420,6 +422,8 @@ public final class ArticleQueryService { ...@@ -420,6 +422,8 @@ public final class ArticleQueryService {
// Skips the unpublished article // Skips the unpublished article
continue; continue;
} }
article.put(ARTICLE_CREATE_TIME, ((Date) article.get(ARTICLE_CREATE_DATE)).getTime());
// Markdown to HTML for content and abstract // Markdown to HTML for content and abstract
markdown(article); markdown(article);
...@@ -649,6 +653,8 @@ public final class ArticleQueryService { ...@@ -649,6 +653,8 @@ public final class ArticleQueryService {
for (int i = 0; i < articles.length(); i++) { for (int i = 0; i < articles.length(); i++) {
final JSONObject article = articles.getJSONObject(i); final JSONObject article = articles.getJSONObject(i);
article.put(ARTICLE_CREATE_TIME, ((Date) article.get(ARTICLE_CREATE_DATE)).getTime());
// Markdown to HTML for content and abstract // Markdown to HTML for content and abstract
markdown(article); markdown(article);
......
...@@ -18,16 +18,18 @@ ...@@ -18,16 +18,18 @@
# Description: B3log Solo local environment configurations. Configures this file # Description: B3log Solo local environment configurations. Configures this file
# if B3log Solo runs on a standard Servlet container or Baidu App Engine, # if B3log Solo runs on a standard Servlet container or Baidu App Engine,
# it is unnecessary to care this file if B3log Solo runs on Google App Engine. # it is unnecessary to care this file if B3log Solo runs on Google App Engine.
# Version: 1.0.2.3, Jan 23, 2013 # Version: 1.0.2.4, Jan 24, 2013
# Author: Liang Ding # Author: Liang Ding
# #
#### Runtime Database (RuntimeDatabase) #### #### Runtime Database (RuntimeDatabase) ####
runtimeDatabase=H2 runtimeDatabase=H2
newTCPServer=true
#### JDBC database Configurations #### #### JDBC database Configurations ####
jdbc.driver=org.h2.Driver jdbc.driver=org.h2.Driver
jdbc.URL=jdbc:h2:~/b3log_solo_h2/db jdbc.URL=jdbc:h2:tcp://localhost:8250/~/b3log_solo_h2/db
jdbc.username=root jdbc.username=root
jdbc.password= jdbc.password=
......
...@@ -31,7 +31,7 @@ handlers=java.util.logging.ConsoleHandler ...@@ -31,7 +31,7 @@ handlers=java.util.logging.ConsoleHandler
#org.b3log.latke.logging.LatkeFormatter.format=%L: %m [%C.%M] #org.b3log.latke.logging.LatkeFormatter.format=%L: %m [%C.%M]
org.b3log.solo.level=FINEST org.b3log.solo.level=FINEST
org.b3log.latke.level=WARNING org.b3log.latke.level=FINEST
org.b3log.latke.cache.level=WARNING org.b3log.latke.cache.level=WARNING
org.b3log.latke.repository.jdbc.level=WARNING org.b3log.latke.repository.jdbc.level=WARNING
......
...@@ -3053,7 +3053,7 @@ admin.pluginList = { ...@@ -3053,7 +3053,7 @@ admin.pluginList = {
} }
datas[i].expendRow += "</a> "; datas[i].expendRow += "</a> ";
datas[i].expendRow +="<a href='javascript:void(0)' onclick=\"admin.plugin.toSetting('"+datas[i].oId+"')\"> "+Label.settingLabel+" </a> "; datas[i].expendRow +="<a href='javascript:void(0)' onclick=\"admin.pluginList.toSetting('"+datas[i].oId+"')\"> "+Label.settingLabel+" </a> ";
} }
that.tablePagination.updateTablePagination(result.plugins, pageNum, result.pagination); that.tablePagination.updateTablePagination(result.plugins, pageNum, result.pagination);
...@@ -3062,11 +3062,37 @@ admin.pluginList = { ...@@ -3062,11 +3062,37 @@ admin.pluginList = {
} }
}); });
}, },
toSetting:function(pluginId){ toSetting:function(pluginId){
$("#loadMsg").text(Label.loadingLabel);
var requestJSONObject = {
"oId": pluginId
};
$.ajax({
url: latkeConfig.servePath + "/console/plugin/toSetting",
type: "POST",
cache: false,
data: JSON.stringify(requestJSONObject),
success: function(result, textStatus){
$("#tipMsg").text(result.msg);
$("#PluginSetting").html(result);
$("#PluginSetting").dialog({
width: 700,
height: 190,
"modal": true,
"hideFooter": true
});
$("#PluginSetting").dialog("open");
$("#loadMsg").text("");
}
});
}, },
changeStatus: function (pluginId, status) { changeStatus: function (pluginId, status) {
if (status === "ENABLED") { if (status === "ENABLED") {
status = "DISABLED"; status = "DISABLED";
...@@ -3109,7 +3135,8 @@ admin.register["plugin-list"] = { ...@@ -3109,7 +3135,8 @@ admin.register["plugin-list"] = {
"refresh": function () { "refresh": function () {
$("#loadMsg").text(""); $("#loadMsg").text("");
} }
}/* }
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
...@@ -3620,28 +3647,6 @@ admin.plugin = { ...@@ -3620,28 +3647,6 @@ admin.plugin = {
} }
}, },
toSetting:function(pluginId){
var requestJSONObject = {
"oId": pluginId
};
$.ajax({
url: latkeConfig.servePath + "/console/plugin/toSetting",
type: "POST",
cache: false,
data: JSON.stringify(requestJSONObject),
success: function(result, textStatus){
$("#loadMsg").text(Label.loadingLabel);
$("#tipMsg").text(result.msg);
$("#PluginSetting").html(result);
$("#loadMsg").text("");
$("#PluginSetting").dialog("open");
}
});
},
/* /*
* 根据当前 hash 初始化或刷新插件 * 根据当前 hash 初始化或刷新插件
*/ */
...@@ -3653,7 +3658,7 @@ admin.plugin = { ...@@ -3653,7 +3658,7 @@ admin.plugin = {
isCurrentPlugin = false; isCurrentPlugin = false;
// 根据当前 hash 和插件 path 判别是非为当前插件 // 根据当前 hash 和插件 path 判别是非为当前插件
if (data.index && window.location.hash.indexOf(data.hash) > -1) { if (data.index && window.location.hash.indexOf(data.hash) > -1) {
isCurrentPlugin = true; isCurrentPlugin = true;
} else if(data.path.replace("/", "#") === window.location.hash || } else if(data.path.replace("/", "#") === window.location.hash ||
(window.location.hash === "#main" && data.path.indexOf("/main/panel") > -1)) { (window.location.hash === "#main" && data.path.indexOf("/main/panel") > -1)) {
...@@ -3734,7 +3739,8 @@ admin.plugin = { ...@@ -3734,7 +3739,8 @@ admin.plugin = {
break; break;
} }
} }
};/* };
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment