sort order setting for forum posts in the threaded version now available for users
This commit is contained in:
parent
c6c6e93ac2
commit
19f378ad20
resources/db_update_scripts
src
main/java/se/su/dsv/scipro
forum/panels
settings/dataobjects
springdata
test/java/se/su/dsv/scipro/forum/panels
@ -25,3 +25,5 @@ DROP TABLE Employee_countActiveFromDates;
|
||||
DROP TABLE Employee_projectLimits;
|
||||
|
||||
ALTER TABLE `user_profile` ADD `threadedForum` TINYINT( 1 ) NOT NULL DEFAULT '1';
|
||||
|
||||
ALTER TABLE `user_profile` ADD `sortLatestForumPost` TINYINT( 1 ) NOT NULL DEFAULT '1';
|
||||
|
@ -19,6 +19,7 @@ import org.apache.wicket.model.*;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import se.su.dsv.scipro.SciProSession;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.forum.dataobjects.ForumPost;
|
||||
import se.su.dsv.scipro.forum.dataobjects.ForumThread;
|
||||
@ -28,6 +29,8 @@ import se.su.dsv.scipro.forum.pages.SupervisorThreadedForumPage;
|
||||
import se.su.dsv.scipro.forum.service.ForumService;
|
||||
import se.su.dsv.scipro.reusable.AjaxRadioChoice;
|
||||
import se.su.dsv.scipro.reusable.SciProUtilities;
|
||||
import se.su.dsv.scipro.settings.dataobjects.UserProfile;
|
||||
import se.su.dsv.scipro.springdata.services.UserProfileService;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
@ -40,9 +43,11 @@ import java.util.List;
|
||||
public class ViewForumThreadPanel extends Panel {
|
||||
|
||||
@SpringBean ForumService forumService;
|
||||
@SpringBean UserProfileService profileService;
|
||||
|
||||
private final IModel<ForumThread> threadModel;
|
||||
private final WebMarkupContainer wrapper;
|
||||
private Sort.Direction sortDirection;
|
||||
private SubmitForumReplyPanel replyPanel;
|
||||
private AjaxLink<ForumThread> replyLink;
|
||||
private DataView<ForumPost> dataView;
|
||||
@ -75,6 +80,7 @@ public class ViewForumThreadPanel extends Panel {
|
||||
private void addPostList() {
|
||||
|
||||
final PostProvider provider = new PostProvider(threadModel);
|
||||
sortDirection = profileService.getForumPostSortDirection(SciProSession.get().getUser());
|
||||
|
||||
wrapper.add(dataView = new DataView<ForumPost>(POST_LIST, provider) {
|
||||
|
||||
@ -84,10 +90,11 @@ public class ViewForumThreadPanel extends Panel {
|
||||
}
|
||||
});
|
||||
|
||||
wrapper.add(new AjaxRadioChoice<Sort.Direction>(DIRECTION, Model.of(Sort.Direction.DESC), Arrays.asList(Sort.Direction.DESC, Sort.Direction.ASC), new DirectionRenderer()) {
|
||||
wrapper.add(new AjaxRadioChoice<Sort.Direction>(DIRECTION, Model.of(sortDirection), Arrays.asList(Sort.Direction.DESC, Sort.Direction.ASC), new DirectionRenderer()) {
|
||||
@Override
|
||||
protected void update(AjaxRequestTarget target) {
|
||||
provider.setSortOrder(new Sort(getModelObject(), DATE_CREATED));
|
||||
profileService.setSortLatestForumPost(SciProSession.get().getUser(), getModelObject());
|
||||
sortDirection = getModelObject();
|
||||
target.addComponent(wrapper);
|
||||
}
|
||||
});
|
||||
@ -141,7 +148,6 @@ public class ViewForumThreadPanel extends Panel {
|
||||
private class PostProvider implements IDataProvider<ForumPost> {
|
||||
|
||||
private IModel<ForumThread> threadModel;
|
||||
private Sort sortOrder = new Sort(Sort.Direction.DESC, DATE_CREATED);
|
||||
|
||||
public PostProvider(IModel<ForumThread> threadModel) {
|
||||
this.threadModel = threadModel;
|
||||
@ -149,7 +155,7 @@ public class ViewForumThreadPanel extends Panel {
|
||||
|
||||
@Override
|
||||
public Iterator<ForumPost> iterator(int first, int count) {
|
||||
return forumService.getPosts(threadModel.getObject(), new PageRequest(dataView.getCurrentPage(), dataView.getItemsPerPage(), getSortOrder())).iterator();
|
||||
return forumService.getPosts(threadModel.getObject(), new PageRequest(dataView.getCurrentPage(), dataView.getItemsPerPage(), new Sort(sortDirection, DATE_CREATED))).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -162,14 +168,6 @@ public class ViewForumThreadPanel extends Panel {
|
||||
return Model.of(object);
|
||||
}
|
||||
|
||||
public Sort getSortOrder() {
|
||||
return sortOrder;
|
||||
}
|
||||
|
||||
public void setSortOrder(Sort sortOrder) {
|
||||
this.sortOrder = sortOrder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detach() {
|
||||
}
|
||||
|
@ -32,6 +32,9 @@ public class UserProfile extends DomainObject {
|
||||
|
||||
@Basic(optional = false)
|
||||
private boolean threadedForum = true;
|
||||
|
||||
@Basic(optional = false)
|
||||
private boolean sortLatestForumPost = true;
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
@ -89,4 +92,12 @@ public class UserProfile extends DomainObject {
|
||||
public void setThreadedForum(boolean threadedForum) {
|
||||
this.threadedForum = threadedForum;
|
||||
}
|
||||
|
||||
public boolean isSortLatestForumPost() {
|
||||
return sortLatestForumPost;
|
||||
}
|
||||
|
||||
public void setSortLatestForumPost(boolean sortLatestForumPost) {
|
||||
this.sortLatestForumPost = sortLatestForumPost;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package se.su.dsv.scipro.springdata.serviceimpls;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
@ -46,4 +47,19 @@ public class UserProfileServiceImpl extends AbstractQueryService<UserProfile, Lo
|
||||
return profile.isThreadedForum();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = false)
|
||||
public boolean setSortLatestForumPost(User user, Sort.Direction direction) {
|
||||
UserProfile profile = findByUser(user);
|
||||
profile.setSortLatestForumPost(direction.equals(Sort.Direction.DESC)?true:false);
|
||||
save(profile);
|
||||
return profile.isSortLatestForumPost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sort.Direction getForumPostSortDirection(User user) {
|
||||
UserProfile profile = findByUser(user);
|
||||
return profile.isSortLatestForumPost() ? Sort.Direction.DESC : Sort.Direction.ASC;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package se.su.dsv.scipro.springdata.services;
|
||||
|
||||
import org.springframework.data.domain.Sort;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.settings.dataobjects.UserProfile;
|
||||
|
||||
@ -8,4 +9,8 @@ public interface UserProfileService extends GenericService<UserProfile, Long>, Q
|
||||
UserProfile findByUser(User user);
|
||||
|
||||
boolean setThreadedForum(User user, boolean threadedForum);
|
||||
boolean setSortLatestForumPost(User user, Sort.Direction direction);
|
||||
|
||||
Sort.Direction getForumPostSortDirection(User user);
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package se.su.dsv.scipro.forum.panels;
|
||||
|
||||
import org.apache.wicket.Component;
|
||||
import org.apache.wicket.ajax.markup.html.AjaxLink;
|
||||
import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox;
|
||||
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
||||
import org.apache.wicket.markup.html.list.ListView;
|
||||
import org.apache.wicket.markup.html.panel.Panel;
|
||||
@ -12,14 +14,17 @@ import org.junit.Test;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import se.su.dsv.scipro.SciProTest;
|
||||
import se.su.dsv.scipro.admin.panels.match.AdminKeywordCrudPanel;
|
||||
import se.su.dsv.scipro.data.dataobjects.Member;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.enums.DateStyle;
|
||||
import se.su.dsv.scipro.datatables.GenericDataPanel;
|
||||
import se.su.dsv.scipro.forum.dataobjects.ForumPost;
|
||||
import se.su.dsv.scipro.forum.dataobjects.ForumThread;
|
||||
import se.su.dsv.scipro.forum.forms.ForumForm;
|
||||
import se.su.dsv.scipro.forum.pages.ProjectThreadedForumPage;
|
||||
import se.su.dsv.scipro.reusable.AjaxRadioChoice;
|
||||
import se.su.dsv.scipro.test.ForumBuilder;
|
||||
import se.su.dsv.scipro.test.ProjectBuilder;
|
||||
|
||||
@ -100,6 +105,11 @@ public class ViewForumThreadPanelTest extends SciProTest {
|
||||
assertFalse(isLinkVisible);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPanelContainsRadioChoices() throws Exception {
|
||||
tester.assertComponent(path(panel.getId(), ViewForumThreadPanel.WRAPPER, ViewForumThreadPanel.DIRECTION), AjaxRadioChoice.class);
|
||||
}
|
||||
|
||||
private void startPanel() {
|
||||
panel = (ViewForumThreadPanel) tester.startPanel(new ITestPanelSource() {
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user