Commit df8b2e62 authored by Liang Ding's avatar Liang Ding

🔥 删除获取 top 标签接口

parent 35a03bd1
...@@ -34,7 +34,6 @@ import org.b3log.latke.util.Strings; ...@@ -34,7 +34,6 @@ import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener; import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.Article; import org.b3log.solo.model.Article;
import org.b3log.solo.model.Option; import org.b3log.solo.model.Option;
import org.b3log.solo.model.Tag;
import org.b3log.solo.service.*; import org.b3log.solo.service.*;
import org.b3log.solo.util.Solos; import org.b3log.solo.util.Solos;
import org.json.JSONArray; import org.json.JSONArray;
...@@ -42,15 +41,12 @@ import org.json.JSONObject; ...@@ -42,15 +41,12 @@ import org.json.JSONObject;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/** /**
* Blog processor. * Blog processor.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.3.1.4, Sep 16, 2018 * @version 1.3.1.5, Oct 20, 2018
* @since 0.4.6 * @since 0.4.6
*/ */
@RequestProcessor @RequestProcessor
...@@ -255,40 +251,4 @@ public class BlogProcessor { ...@@ -255,40 +251,4 @@ public class BlogProcessor {
} }
} }
} }
/**
* Gets interest tags (top 10 and bottom 10).
* <p>
* <pre>
* {
* "data": ["tag1", "tag2", ....]
* }
* </pre>
* </p>
*
* @param context the specified context
* @throws Exception exception
*/
@RequestProcessing(value = "/blog/interest-tags", method = HTTPRequestMethod.GET)
public void getInterestTags(final HTTPRequestContext context)
throws Exception {
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret);
final Set<String> tagTitles = new HashSet<>();
final List<JSONObject> topTags = tagQueryService.getTopTags(10);
for (final JSONObject topTag : topTags) {
tagTitles.add(topTag.optString(Tag.TAG_TITLE));
}
final List<JSONObject> bottomTags = tagQueryService.getBottomTags(10);
for (final JSONObject bottomTag : bottomTags) {
tagTitles.add(bottomTag.optString(Tag.TAG_TITLE));
}
ret.put("data", tagTitles);
}
} }
...@@ -39,7 +39,7 @@ import static org.mockito.Mockito.when; ...@@ -39,7 +39,7 @@ import static org.mockito.Mockito.when;
* {@link BlogProcessor} test case. * {@link BlogProcessor} test case.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Nov 1, 2016 * @version 1.0.0.1, Oct 20, 2018
* @since 1.7.0 * @since 1.7.0
*/ */
@Test(suiteName = "processor") @Test(suiteName = "processor")
...@@ -119,31 +119,4 @@ public class BlogProcessorTestCase extends AbstractTestCase { ...@@ -119,31 +119,4 @@ public class BlogProcessorTestCase extends AbstractTestCase {
final String content = stringWriter.toString(); final String content = stringWriter.toString();
Assert.assertTrue(StringUtils.startsWith(content, "{\"data\":")); Assert.assertTrue(StringUtils.startsWith(content, "{\"data\":"));
} }
/**
* getInterestTags.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = "init")
public void getInterestTags() throws Exception {
final HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getServletContext()).thenReturn(mock(ServletContext.class));
when(request.getRequestURI()).thenReturn("/blog/interest-tags");
when(request.getMethod()).thenReturn("GET");
final MockDispatcherServlet dispatcherServlet = new MockDispatcherServlet();
dispatcherServlet.init();
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
final HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getWriter()).thenReturn(printWriter);
dispatcherServlet.service(request, response);
final String content = stringWriter.toString();
Assert.assertTrue(StringUtils.startsWith(content, "{\"data\":"));
}
} }
...@@ -32,71 +32,54 @@ ...@@ -32,71 +32,54 @@
<script type="text/javascript"> <script type="text/javascript">
plugins.symphonyInterest = { plugins.symphonyInterest = {
init: function () { init: function () {
$("#loadMsg").text("${loadingLabel}"); $('#loadMsg').text("${loadingLabel}")
$("#symphonyInterest").css("background", $('#symphonyInterest').css('background',
"url(${staticServePath}/images/loader.gif) no-repeat scroll center center transparent"); "url(${staticServePath}/images/loader.gif) no-repeat scroll center center transparent")
$.ajax({ $.ajax({
url: "${servePath}/blog/interest-tags", url: 'https://hacpai.com/apis/articles?',
type: "GET", type: 'GET',
dataType: "json", dataType: 'jsonp',
jsonp: 'callback',
error: function () { error: function () {
$("#symphonyInterest").html("Loading Interest failed :-(").css("background", "none"); $('#symphonyInterest').html('Loading Interest failed :-(').css('background', 'none')
}, },
success: function (result, textStatus) { success: function (data, textStatus) {
var tags = result.data; var articles = data.articles
if (0 === tags.length) { if (0 === articles.length) {
return; return
} }
$.ajax({
url: "https://hacpai.com/apis/articles?p=1&size=7&tags=" + tags.join(),
type: "GET",
dataType: "jsonp",
jsonp: "callback",
error: function () {
$("#symphonyInterest").html("Loading Interest failed :-(").css("background", "none");
},
success: function (data, textStatus) {
var articles = data.articles;
if (0 === articles.length) {
return;
}
var listHTML = "<ul>";
for (var i = 0; i < articles.length; i++) {
var article = articles[i];
var articleLiHtml = "<li>"
+ "<a target='_blank' href='" + article.articlePermalink + "'>"
+ article.articleTitle + "</a>&nbsp; <span class='date'>" + $.bowknot.getDate(article.articleCreateTime, 1);
+"</span></li>"
listHTML += articleLiHtml
}
listHTML += "</ul>";
$("#symphonyInterest").html(listHTML).css("background", "none"); var listHTML = '<ul>'
} for (var i = 0; i < articles.length; i++) {
}); var article = articles[i]
}
});
var articleLiHtml = '<li>'
+ '<a target=\'_blank\' href=\'' + article.articlePermalink + '\'>'
+ article.articleTitle + '</a>&nbsp; <span class=\'date\'>' + $.bowknot.getDate(article.articleCreateTime, 1);
+'</span></li>'
listHTML += articleLiHtml
}
listHTML += '</ul>'
$('#symphonyInterest').html(listHTML).css('background', 'none')
}
})
$("#loadMsg").text(""); $('#loadMsg').text('')
} }
}; }
/* /*
* 添加插件 * 添加插件
*/ */
admin.plugin.add({ admin.plugin.add({
"id": "symphonyInterest", 'id': 'symphonyInterest',
"path": "/main/panel1", 'path': '/main/panel1',
"content": $("#symphonyInterestPanel").html() 'content': $('#symphonyInterestPanel').html()
}); })
// 移除现有内容 // 移除现有内容
$("#symphonyInterestPanel").remove(); $('#symphonyInterestPanel').remove()
</script> </script>
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