use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class AdminProcessor method showTags.
/**
* Shows admin tags.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/tags", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showTags(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/tags.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
String pageNumStr = request.getParameter("p");
if (Strings.isEmptyOrNull(pageNumStr) || !Strings.isNumeric(pageNumStr)) {
pageNumStr = "1";
}
final int pageNum = Integer.valueOf(pageNumStr);
final int pageSize = PAGE_SIZE;
final int windowSize = WINDOW_SIZE;
final JSONObject requestJSONObject = new JSONObject();
requestJSONObject.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
requestJSONObject.put(Pagination.PAGINATION_PAGE_SIZE, pageSize);
requestJSONObject.put(Pagination.PAGINATION_WINDOW_SIZE, windowSize);
final String tagTitle = request.getParameter(Common.TITLE);
if (!Strings.isEmptyOrNull(tagTitle)) {
requestJSONObject.put(Tag.TAG_TITLE, tagTitle);
}
final Map<String, Class<?>> tagFields = new HashMap<>();
tagFields.put(Keys.OBJECT_ID, String.class);
tagFields.put(Tag.TAG_TITLE, String.class);
tagFields.put(Tag.TAG_DESCRIPTION, String.class);
tagFields.put(Tag.TAG_ICON_PATH, String.class);
tagFields.put(Tag.TAG_COMMENT_CNT, Integer.class);
tagFields.put(Tag.TAG_REFERENCE_CNT, Integer.class);
tagFields.put(Tag.TAG_FOLLOWER_CNT, Integer.class);
tagFields.put(Tag.TAG_STATUS, Integer.class);
tagFields.put(Tag.TAG_GOOD_CNT, Integer.class);
tagFields.put(Tag.TAG_BAD_CNT, Integer.class);
tagFields.put(Tag.TAG_URI, String.class);
tagFields.put(Tag.TAG_CSS, String.class);
final JSONObject result = tagQueryService.getTags(requestJSONObject, tagFields);
dataModel.put(Tag.TAGS, CollectionUtils.jsonArrayToList(result.optJSONArray(Tag.TAGS)));
final JSONObject pagination = result.optJSONObject(Pagination.PAGINATION);
final int pageCount = pagination.optInt(Pagination.PAGINATION_PAGE_COUNT);
final JSONArray pageNums = pagination.optJSONArray(Pagination.PAGINATION_PAGE_NUMS);
dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.opt(0));
dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.opt(pageNums.length() - 1));
dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
dataModel.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
dataModel.put(Pagination.PAGINATION_PAGE_NUMS, CollectionUtils.jsonArrayToList(pageNums));
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class AdminProcessor method showAddTag.
/**
* Shows add tag.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/add-tag", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showAddTag(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/add-tag.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class AdminProcessor method updateUserEmail.
/**
* Updates a user's email.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @param userId the specified user id
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/user/{userId}/email", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void updateUserEmail(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String userId) throws Exception {
final JSONObject user = userQueryService.getUser(userId);
final String oldEmail = user.optString(User.USER_EMAIL);
final String newEmail = request.getParameter(User.USER_EMAIL);
if (oldEmail.equals(newEmail)) {
response.sendRedirect(Latkes.getServePath() + "/admin/user/" + userId);
return;
}
user.put(User.USER_EMAIL, newEmail);
try {
userMgmtService.updateUserEmail(userId, user);
} catch (final ServiceException e) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/error.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put(Keys.MSG, e.getMessage());
dataModelService.fillHeaderAndFooter(request, response, dataModel);
return;
}
response.sendRedirect(Latkes.getServePath() + "/admin/user/" + userId);
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class AdminProcessor method showAddReservedWord.
/**
* Shows add reserved word.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/add-reserved-word", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showAddReservedWord(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/add-reserved-word.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class AdminProcessor method showInvitecodes.
/**
* Shows admin invitecodes.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/invitecodes", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showInvitecodes(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/invitecodes.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
String pageNumStr = request.getParameter("p");
if (Strings.isEmptyOrNull(pageNumStr) || !Strings.isNumeric(pageNumStr)) {
pageNumStr = "1";
}
final int pageNum = Integer.valueOf(pageNumStr);
final int pageSize = PAGE_SIZE;
final int windowSize = WINDOW_SIZE;
final JSONObject requestJSONObject = new JSONObject();
requestJSONObject.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
requestJSONObject.put(Pagination.PAGINATION_PAGE_SIZE, pageSize);
requestJSONObject.put(Pagination.PAGINATION_WINDOW_SIZE, windowSize);
final JSONObject result = invitecodeQueryService.getInvitecodes(requestJSONObject);
dataModel.put(Invitecode.INVITECODES, CollectionUtils.jsonArrayToList(result.optJSONArray(Invitecode.INVITECODES)));
final JSONObject pagination = result.optJSONObject(Pagination.PAGINATION);
final int pageCount = pagination.optInt(Pagination.PAGINATION_PAGE_COUNT);
final JSONArray pageNums = pagination.optJSONArray(Pagination.PAGINATION_PAGE_NUMS);
dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.opt(0));
dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.opt(pageNums.length() - 1));
dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
dataModel.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
dataModel.put(Pagination.PAGINATION_PAGE_NUMS, CollectionUtils.jsonArrayToList(pageNums));
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Aggregations