Search in sources :

Example 1 with Tag

use of com.willshex.blogwt.shared.api.datatype.Tag in project blogwt by billy1380.

the class EditPostPage method updatePreview.

private void updatePreview() {
    pnlPreview.getElement().removeAllChildren();
    Document d = Document.get();
    HeadingElement title = d.createHElement(1);
    title.setInnerHTML(PostHelper.makeHeading(txtTitle.getValue()));
    pnlPreview.getElement().appendChild(title);
    User user = SessionController.get().user();
    DivElement elDate = d.createDivElement();
    if (post != null) {
        if (post.published == null) {
            elDate.setInnerSafeHtml(PostSummaryCell.Templates.INSTANCE.notPublished(DateTimeHelper.ago(post.created)));
        } else {
            elDate.setInnerSafeHtml(PostSummaryCell.Templates.INSTANCE.publishedDate(DateTimeHelper.ago(post.published)));
        }
    } else {
        elDate.setInnerSafeHtml(PostSummaryCell.Templates.INSTANCE.notPublished(DateTimeHelper.ago(new Date())));
    }
    pnlPreview.getElement().appendChild(elDate);
    DivElement elAuthor = d.createDivElement();
    if (PropertyController.get().booleanProperty(PropertyHelper.POST_SHOW_AUTHOR, false)) {
        elAuthor.setInnerSafeHtml(PostSummaryCell.Templates.INSTANCE.author(UriUtils.fromString((post != null ? post.author.avatar : user.avatar) + "?s=" + UserHelper.AVATAR_HEADER_SIZE + "&default=retro"), UserHelper.handle((post != null ? post.author : user))));
    }
    pnlPreview.getElement().appendChild(elAuthor);
    tagList.getList().clear();
    List<String> tags = TagHelper.convertToTagList(txtTags.getValue());
    if (tags != null) {
        for (String tag : tags) {
            tagList.getList().add(new Tag().name(tag));
        }
    }
    DivElement summary = d.createDivElement();
    summary.setInnerHTML(markup(txtSummary));
    pnlPreview.getElement().appendChild(summary);
    DivElement content = d.createDivElement();
    content.setInnerHTML(markup(txtContent));
    pnlPreview.getElement().appendChild(content);
}
Also used : DivElement(com.google.gwt.dom.client.DivElement) User(com.willshex.blogwt.shared.api.datatype.User) HeadingElement(com.google.gwt.dom.client.HeadingElement) Tag(com.willshex.blogwt.shared.api.datatype.Tag) Document(com.google.gwt.dom.client.Document) Date(java.util.Date)

Example 2 with Tag

use of com.willshex.blogwt.shared.api.datatype.Tag in project blogwt by billy1380.

the class TagService method addTagBatch.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.service.tag.ITagService#addTagBatch(java.
	 * util.Collection) */
@Override
public void addTagBatch(Collection<Tag> tags) {
    for (Tag tag : tags) {
        if (tag.created == null) {
            tag.created = new Date();
        }
        tag.name = tag.name.toLowerCase();
        tag.slug = PostHelper.slugify(tag.name);
        if (tag.posts != null) {
            for (Post post : tag.posts) {
                if (tag.postKeys == null) {
                    tag.postKeys = new ArrayList<Key<Post>>();
                }
                tag.postKeys.add(Key.create(post));
            }
        }
    }
    provide().save().entities(tags).now();
}
Also used : Post(com.willshex.blogwt.shared.api.datatype.Post) Tag(com.willshex.blogwt.shared.api.datatype.Tag) Date(java.util.Date) Key(com.googlecode.objectify.Key)

Example 3 with Tag

use of com.willshex.blogwt.shared.api.datatype.Tag in project blogwt by billy1380.

the class GetTagsResponse method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("tags")) {
        JsonElement jsonTags = jsonObject.get("tags");
        if (jsonTags != null) {
            tags = new Tag();
            tags.fromJson(jsonTags.getAsJsonObject());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) Tag(com.willshex.blogwt.shared.api.datatype.Tag)

Example 4 with Tag

use of com.willshex.blogwt.shared.api.datatype.Tag in project blogwt by billy1380.

the class PostDetailPage method show.

private void show(Post post) {
    elTitle.setInnerHTML(PostHelper.makeHeading(post.title));
    SafeHtml author = SafeHtmlUtils.EMPTY_SAFE_HTML;
    if (PropertyController.get().booleanProperty(PropertyHelper.POST_SHOW_AUTHOR, false)) {
        author = PostSummaryCell.Templates.INSTANCE.author(UriUtils.fromString(post.author.avatar + "?s=" + UserHelper.AVATAR_HEADER_SIZE + "&default=retro"), UserHelper.handle(post.author));
    }
    if (PropertyController.get().booleanProperty(PropertyHelper.POST_SHOW_AUTHOR_SUMMARY, false)) {
        pnlUserSummary.setUser(post.author);
        pnlUserSummaryRow.setVisible(true);
    }
    elAuthor.setInnerSafeHtml(author);
    if (post.published != null) {
        elDate.setInnerSafeHtml(PostSummaryCell.Templates.INSTANCE.publishedDate(DateTimeHelper.ago(post.published)));
    } else {
        elDate.setInnerSafeHtml(PostSummaryCell.Templates.INSTANCE.notPublished(DateTimeHelper.ago(post.created)));
    }
    lnkEditPost.setTargetHistoryToken(PageType.EditPostPageType.asTargetHistoryToken(post.slug));
    tagList.getList().clear();
    coRelated.setVisible(Boolean.TRUE.equals(post.listed));
    if (post.tags != null) {
        for (String tag : post.tags) {
            tagList.getList().add(new Tag().name(tag));
        }
    }
    final String url = GWT.getHostPageBaseURL() + PageTypeHelper.asHref(PageType.PostDetailPageType, post.slug).asString();
    final String title = post.title;
    ataShare.setUrl(url);
    ataShare.setTitle(title);
    ataShare.setVisible(true);
    if (post.content != null) {
        String markup = PostHelper.makeMarkup(post.content.body);
        pnlContent.getElement().setInnerHTML(markup);
        String comments = PropertyController.get().stringProperty(PropertyHelper.POST_COMMENTS_ENABLED);
        if (comments == null || comments.equals(PropertyHelper.NONE_VALUE)) {
            dsqComments.removeFromParent();
        } else if (Boolean.TRUE.equals(post.commentsEnabled)) {
            final String identifier = "post" + post.id.toString();
            final String tag = post.tags == null || post.tags.size() == 0 ? "none" : post.tags.get(0);
            dsqComments.setUrl(url);
            dsqComments.setTitle(title);
            dsqComments.setIdentifier(identifier);
            dsqComments.setTag(tag);
            dsqComments.setVisible(true);
        } else {
            dsqComments.setVisible(false);
        }
    }
    pnlPostNav.setSlugs(post.previousSlug, post.nextSlug);
    pnlLoading.setVisible(false);
    FooterPart.get().scrollToTop();
    refreshTitle();
}
Also used : SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Tag(com.willshex.blogwt.shared.api.datatype.Tag)

Example 5 with Tag

use of com.willshex.blogwt.shared.api.datatype.Tag in project blogwt by billy1380.

the class GetPostsActionHandler method handle.

/* (non-Javadoc)
	 * 
	 * @see
	 * com.willshex.gson.web.service.server.ActionHandler#handle(com.willshex.
	 * gson.web.service.shared.Request,
	 * com.willshex.gson.web.service.shared.Response) */
@Override
protected void handle(GetPostsRequest input, GetPostsResponse output) throws Exception {
    ApiValidator.request(input, GetPostsRequest.class);
    ApiValidator.accessCode(input.accessCode, "input.accessCode");
    Boolean showAll = Boolean.TRUE.equals(input.showAll) ? Boolean.TRUE : Boolean.FALSE;
    if (input.session != null) {
        try {
            output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
            List<Permission> permissions = new ArrayList<Permission>();
            Permission postPermission = PermissionServiceProvider.provide().getCodePermission(PermissionHelper.MANAGE_POSTS);
            permissions.add(postPermission);
            try {
                UserValidator.authorisation(input.session.user, permissions, "input.session.user");
            } catch (AuthorisationException aEx) {
                showAll = Boolean.FALSE;
            }
        } catch (InputValidationException ex) {
            output.session = input.session = null;
            showAll = Boolean.FALSE;
        }
    } else {
        showAll = Boolean.FALSE;
    }
    if (!showAll) {
        input.pager.sortBy = PostSortType.PostSortTypePublished.toString();
    }
    if (input.includePostContents == null) {
        input.includePostContents = Boolean.FALSE;
    }
    boolean postsForTag = false, postsForArchiveEntry = false, postsForQuery = false;
    if (input.tag != null && input.tag.length() > 0) {
        postsForTag = true;
        Tag tag = TagServiceProvider.provide().getSlugTag(input.tag);
        if (tag != null) {
            output.posts = PersistenceHelper.batchLookup(PostServiceProvider.provide(), tag.postKeys);
        }
    }
    if (!postsForTag && input.archiveEntry != null) {
        postsForTag = true;
        if (input.archiveEntry.posts != null) {
            output.posts = input.archiveEntry.posts = PostValidator.lookupAll(input.archiveEntry.posts, "input.archiveEntry.posts");
        } else {
            input.archiveEntry = ArchiveEntryValidator.lookup(input.archiveEntry, "input.archiveEntry");
            output.posts = PersistenceHelper.batchLookup(PostServiceProvider.provide(), input.archiveEntry.postKeys);
        }
    }
    if (!postsForTag && !postsForArchiveEntry && input.query != null) {
        postsForQuery = true;
        if (input.session != null && input.session.user != null) {
            output.posts = PostServiceProvider.provide().getUserViewablePartialSlugPosts(input.query, input.session.user, showAll, input.includePostContents, input.pager.start, input.pager.count, PostSortType.fromString(input.pager.sortBy), input.pager.sortDirection);
        } else {
            output.posts = PostServiceProvider.provide().getPartialSlugPosts(input.query, showAll, input.includePostContents, input.pager.start, input.pager.count, PostSortType.PostSortTypePublished, SortDirectionType.SortDirectionTypeDescending);
        }
    }
    if (!postsForTag && !postsForArchiveEntry && !postsForQuery) {
        output.posts = PostServiceProvider.provide().getPosts(showAll, input.includePostContents, input.pager.start, input.pager.count, PostSortType.fromString(input.pager.sortBy), input.pager.sortDirection);
    }
    if (output.posts != null) {
        Map<Key<User>, User> users = new HashMap<Key<User>, User>();
        for (Post post : output.posts) {
            if (users.get(post.authorKey) == null) {
                users.put(post.authorKey, UserHelper.stripSensitive(UserServiceProvider.provide().getUser(keyToId(post.authorKey))));
            }
            post.author = users.get(post.authorKey);
        }
    }
    output.pager = PagerHelper.moveForward(input.pager);
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) HashMap(java.util.HashMap) Post(com.willshex.blogwt.shared.api.datatype.Post) ArrayList(java.util.ArrayList) Permission(com.willshex.blogwt.shared.api.datatype.Permission) InputValidationException(com.willshex.gson.web.service.server.InputValidationException) Tag(com.willshex.blogwt.shared.api.datatype.Tag) AuthorisationException(com.willshex.blogwt.server.api.exception.AuthorisationException) Key(com.googlecode.objectify.Key)

Aggregations

Tag (com.willshex.blogwt.shared.api.datatype.Tag)7 Post (com.willshex.blogwt.shared.api.datatype.Post)4 Key (com.googlecode.objectify.Key)3 Date (java.util.Date)3 User (com.willshex.blogwt.shared.api.datatype.User)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 JsonElement (com.google.gson.JsonElement)1 DivElement (com.google.gwt.dom.client.DivElement)1 Document (com.google.gwt.dom.client.Document)1 HeadingElement (com.google.gwt.dom.client.HeadingElement)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 AuthorisationException (com.willshex.blogwt.server.api.exception.AuthorisationException)1 Pager (com.willshex.blogwt.shared.api.Pager)1 Permission (com.willshex.blogwt.shared.api.datatype.Permission)1 InputValidationException (com.willshex.gson.web.service.server.InputValidationException)1