use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.
the class PostController method createPost.
public void createPost(String title, Boolean listed, Boolean commentsEnabled, String summary, String content, Boolean publish, String tags) {
BlogService blogService = ApiHelper.createBlogClient();
final CreatePostRequest input = SessionController.get().setSession(ApiHelper.setAccessCode(new CreatePostRequest())).post(new Post().title(title).summary(summary).content(new PostContent().body(content)).tags(TagHelper.convertToTagList(tags)).listed(listed).commentsEnabled(commentsEnabled)).publish(publish);
blogService.createPost(input, new AsyncCallback<CreatePostResponse>() {
@Override
public void onSuccess(CreatePostResponse output) {
if (output.status == StatusType.StatusTypeSuccess) {
}
DefaultEventBus.get().fireEventFromSource(new CreatePostSuccess(input, output), PostController.this);
}
@Override
public void onFailure(Throwable caught) {
DefaultEventBus.get().fireEventFromSource(new CreatePostFailure(input, caught), PostController.this);
}
});
}
use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.
the class PostController method getPost.
public void getPost(Post post) {
final GetPostRequest input = SessionController.get().setSession(ApiHelper.setAccessCode(new GetPostRequest())).post(post);
if (getPostRequest != null) {
getPostRequest.cancel();
}
getPostRequest = ApiHelper.createBlogClient().getPost(input, new AsyncCallback<GetPostResponse>() {
@Override
public void onSuccess(GetPostResponse output) {
getPostRequest = null;
boolean retryingGetWithSlug = false;
if (output.status == StatusType.StatusTypeSuccess) {
if (output.post != null) {
}
} else {
if (input.post.id != null) {
getPost(new Post().slug(input.post.id.toString()));
retryingGetWithSlug = true;
}
}
if (!retryingGetWithSlug) {
DefaultEventBus.get().fireEventFromSource(new GetPostSuccess(input, output), PostController.this);
}
}
@Override
public void onFailure(Throwable caught) {
getPostRequest = null;
DefaultEventBus.get().fireEventFromSource(new GetPostFailure(input, caught), PostController.this);
}
});
}
use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.
the class PostsPlugin method emit.
/* (non-Javadoc)
*
* @see org.markdown4j.Plugin#emit(java.lang.StringBuilder, java.util.List,
* java.util.Map) */
@Override
public void emit(StringBuilder out, List<String> lines, Map<String, String> params) {
String count = params.get("count");
final String id = HTMLPanel.createUniqueId();
out.append("<div id=\"");
out.append(id);
out.append("\">Loading...</div>");
ApiHelper.createBlogClient().getPosts(SessionController.get().setSession(ApiHelper.setAccessCode(new GetPostsRequest())).pager(PagerHelper.createDefaultPager().count(Integer.valueOf(count)).sortBy(PostSortType.PostSortTypeCreated.toString())), (i, o) -> {
if (manager != null) {
String content = "";
if (o.status == StatusType.StatusTypeSuccess && o.posts != null && !o.posts.isEmpty()) {
SafeHtmlBuilder b = new SafeHtmlBuilder();
for (Post object : o.posts) {
RENDERER.render(null, object, b);
}
content = b.toSafeHtml().asString();
}
manager.fireEvent(new PluginContentReadyEvent(this, lines, params, id, content));
}
}, (i, c) -> {
if (manager != null) {
String content = "";
manager.fireEvent(new PluginContentReadyEvent(this, lines, params, id, content));
}
});
}
use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.
the class StaticPost method appendPage.
/* (non-Javadoc)
*
* @see com.willshex.blogwt.server.page.StaticTemplate#appendPage(java.lang.
* StringBuffer) */
@Override
protected void appendPage(StringBuffer markup) {
Post post = ensurePost();
if (post != null) {
markup.append(process("##" + post.title));
markup.append("<div><span>");
markup.append(DateTimeHelper.ago(post.published));
markup.append("</span> by <img src=\"");
markup.append(post.author.avatar);
markup.append("?s=");
markup.append(UserHelper.AVATAR_HEADER_SIZE);
markup.append("&default=retro\" /> ");
markup.append(UserHelper.handle(post.author));
if (post.content != null) {
markup.append(process(post.content.body));
}
if (post.tags != null) {
markup.append("<ul>");
for (String tag : post.tags) {
markup.append("<li><a href=\"");
markup.append("#" + PageType.TagPostsPageType.asTargetHistoryToken(tag));
markup.append("\">");
markup.append(tag);
markup.append("</a></li>");
}
markup.append("</ul>");
}
} else {
markup.append("Page not found.");
}
}
use of com.willshex.blogwt.shared.api.datatype.Post in project blogwt by billy1380.
the class ArchiveEntryService method generateArchive.
@Override
public void generateArchive() {
Map<String, ArchiveEntry> archiveEntryLookup = new HashMap<String, ArchiveEntry>();
List<Post> posts;
ArchiveEntry archiveEntry;
Pager pager = PagerHelper.createDefaultPager();
do {
posts = PostServiceProvider.provide().getPosts(Boolean.FALSE, Boolean.FALSE, pager.start, pager.count, PostSortType.PostSortTypePublished, SortDirectionType.SortDirectionTypeDescending);
if (posts != null) {
PagerHelper.moveForward(pager);
for (Post post : posts) {
if (Boolean.TRUE.equals(post.listed) && post.published != null) {
Calendar c = ensureCalendar();
c.setTime(post.published);
Integer month = Integer.valueOf(c.get(java.util.Calendar.MONTH));
Integer year = Integer.valueOf(c.get(java.util.Calendar.YEAR));
String key = year + "/" + month;
if ((archiveEntry = archiveEntryLookup.get(key)) == null) {
archiveEntry = new ArchiveEntry().month(month).year(year).posts(new ArrayList<Post>());
archiveEntryLookup.put(key, archiveEntry);
}
archiveEntry.posts.add(post);
}
}
}
} while (posts != null && posts.size() >= pager.count.intValue());
if (archiveEntryLookup.size() > 0) {
addArchiveEntryBatch(archiveEntryLookup.values());
}
}
Aggregations