Refactor to enable separate delete logic for the initial post
This commit is contained in:
parent
dbcf0b603f
commit
e29e9561db
view/src/main/java/se/su/dsv/scipro
@ -6,7 +6,14 @@ import se.su.dsv.scipro.forum.dataobjects.ForumPost;
|
||||
import se.su.dsv.scipro.system.User;
|
||||
|
||||
public interface ForumThread<A> extends IClusterable {
|
||||
List<ForumPost> getPosts(A a);
|
||||
/**
|
||||
* @param a the context of the thread
|
||||
* @return the initial post of the thread
|
||||
*/
|
||||
Optional<ForumPost> getInitialPost(A a);
|
||||
|
||||
List<ForumPost> getReplies(A a);
|
||||
|
||||
ForumPost reply(A a, User poster, String content, Set<Attachment> attachments);
|
||||
String getSubject(A a);
|
||||
void setRead(User user, A a);
|
||||
|
@ -23,7 +23,7 @@ public class ForumPostPanel extends Border {
|
||||
public static final String ATTACHMENT = "attachment";
|
||||
|
||||
public ForumPostPanel(String id, final IModel<ForumPost> model) {
|
||||
super(id);
|
||||
super(id, model);
|
||||
addToBorder(new UserLinkPanel(POSTED_BY, LambdaModel.of(model, ForumPost::getPostedBy, ForumPost::setPostedBy)));
|
||||
addToBorder(
|
||||
new WebMarkupContainer("postedBySystem") {
|
||||
|
@ -17,8 +17,14 @@ public class ProjectForumThread implements ForumThread<ProjectThread> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ForumPost> getPosts(final ProjectThread projectThread) {
|
||||
return projectForumService.getPosts(projectThread);
|
||||
public Optional<ForumPost> getInitialPost(ProjectThread projectThread) {
|
||||
return projectForumService.getPosts(projectThread).stream().findFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ForumPost> getReplies(final ProjectThread projectThread) {
|
||||
List<ForumPost> posts = projectForumService.getPosts(projectThread);
|
||||
return posts.subList(1, posts.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,6 +19,7 @@
|
||||
<div wicket:id="topReplyPanel"></div>
|
||||
<!-- POST LIST-->
|
||||
<div class="d-flex flex-column-reverse">
|
||||
<wicket:container wicket:id="initialPost"></wicket:container>
|
||||
<wicket:container wicket:id="postList">
|
||||
<wicket:container wicket:id="post">
|
||||
<button wicket:id="delete" class="btn btn-sm btn-outline-danger ms-auto">Delete</button>
|
||||
|
@ -13,6 +13,7 @@ import org.apache.wicket.markup.html.list.ListView;
|
||||
import org.apache.wicket.markup.html.panel.GenericPanel;
|
||||
import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.model.LoadableDetachableModel;
|
||||
import se.su.dsv.scipro.components.OrNullModel;
|
||||
import se.su.dsv.scipro.forum.ForumThread;
|
||||
import se.su.dsv.scipro.forum.dataobjects.ForumPost;
|
||||
import se.su.dsv.scipro.session.SciProSession;
|
||||
@ -54,6 +55,13 @@ public class ViewForumThreadPanel<A> extends GenericPanel<A> {
|
||||
}
|
||||
|
||||
private void addPostList() {
|
||||
wrapper.add(new ForumPostPanel("initialPost", new OrNullModel<>(getModel().map(forumThread::getInitialPost))) {
|
||||
@Override
|
||||
protected void onConfigure() {
|
||||
super.onConfigure();
|
||||
setVisible(getDefaultModelObject() != null);
|
||||
}
|
||||
});
|
||||
wrapper.add(
|
||||
new ListView<>(POST_LIST, new PostProvider()) {
|
||||
@Override
|
||||
@ -122,7 +130,7 @@ public class ViewForumThreadPanel<A> extends GenericPanel<A> {
|
||||
|
||||
@Override
|
||||
protected List<ForumPost> load() {
|
||||
List<ForumPost> posts = forumThread.getPosts(getModelObject());
|
||||
List<ForumPost> posts = forumThread.getReplies(getModelObject());
|
||||
posts.sort(Comparator.comparing(ForumPost::getDateCreated));
|
||||
return posts;
|
||||
}
|
||||
|
@ -17,8 +17,14 @@ public class GroupForumThread implements ForumThread<GroupThread> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ForumPost> getPosts(final GroupThread groupThread) {
|
||||
return groupForumService.getPosts(groupThread);
|
||||
public Optional<ForumPost> getInitialPost(GroupThread groupThread) {
|
||||
return groupForumService.getPosts(groupThread).stream().findFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ForumPost> getReplies(final GroupThread groupThread) {
|
||||
List<ForumPost> posts = groupForumService.getPosts(groupThread);
|
||||
return posts.subList(1, posts.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,7 +18,12 @@ public class ReviewerInteractionForumThread implements ForumThread<Project>, ICl
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ForumPost> getPosts(final Project project) {
|
||||
public Optional<ForumPost> getInitialPost(Project project) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ForumPost> getReplies(final Project project) {
|
||||
return reviewerInteractionService.getPosts(project);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user