Support for restinterface for comments
Change-Id: Ie85022e2f32878f283bdcfdbb4440f47d972e1bb
This commit is contained in:
parent
aea255173d
commit
9f133859c8
src/main/java/se/su/dsv/scipro/conference
@ -5,6 +5,7 @@ package se.su.dsv.scipro.conference.pages;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.RequestCycle;
|
||||
@ -19,7 +20,9 @@ import se.su.dsv.scipro.SciProApplication;
|
||||
import se.su.dsv.scipro.SciProSession;
|
||||
import se.su.dsv.scipro.conference.model.SubscriberModel;
|
||||
import se.su.dsv.scipro.conference.panels.ConferencePanel;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.BoardMessageDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.MessageBoardDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.BoardMessage;
|
||||
import se.su.dsv.scipro.data.dataobjects.MessageBoard;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectFollower;
|
||||
@ -39,16 +42,34 @@ public class ProjectConferencePage extends ProjectPage {
|
||||
|
||||
@SpringBean
|
||||
private MessageBoardDao messageBoardDao;
|
||||
@SpringBean
|
||||
private BoardMessageDao boardMessageDao;
|
||||
|
||||
private IModel<Project> projectModel;
|
||||
private IModel<MessageBoard> messageBoardModel;
|
||||
private MessageBoard messageBoard;
|
||||
private IModel<BoardMessage> boardMessageModel;
|
||||
private final static String PROJECTID = "pid";
|
||||
|
||||
public ProjectConferencePage(PageParameters pp) {
|
||||
super(pp);
|
||||
String projectId = pp.getString("pid");
|
||||
if (projectId == null && SciProSession.get().getActiveProject().getId() != null) {
|
||||
String boardMessageId = null;
|
||||
if (projectId != null) {
|
||||
StringTokenizer stringTokenizer = new StringTokenizer(projectId, "&");
|
||||
boolean first = true;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (stringTokenizer.hasMoreTokens()) {
|
||||
if (first) {
|
||||
projectId = stringTokenizer.nextToken().trim();
|
||||
first = false;
|
||||
} else {
|
||||
boardMessageId = stringTokenizer.nextToken().trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (projectId == null && SciProSession.get().getActiveProject() != null) {
|
||||
projectId = String.valueOf(SciProSession.get().getActiveProject().getId());
|
||||
}
|
||||
if (projectId != null) {
|
||||
@ -110,9 +131,24 @@ public class ProjectConferencePage extends ProjectPage {
|
||||
return messageBoardDao.reLoad(messageBoard);
|
||||
}
|
||||
};
|
||||
add(new ConferencePanel("conferencePanel", messageBoardModel, subscriberModel));
|
||||
if (boardMessageId != null) {
|
||||
final BoardMessage bm = boardMessageDao.load(Long.valueOf(boardMessageId));
|
||||
|
||||
if (bm != null && messageBoard.getBoardMessageSet().contains(bm)) {
|
||||
boardMessageModel = new LoadableDetachableModel<BoardMessage>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected BoardMessage load() {
|
||||
return boardMessageDao.reLoad(bm);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
add(new ConferencePanel("conferencePanel", messageBoardModel, subscriberModel,
|
||||
boardMessageModel));
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
add(new EmptyPanel("conferencePanel"));
|
||||
}
|
||||
|
||||
@ -125,7 +161,7 @@ public class ProjectConferencePage extends ProjectPage {
|
||||
|
||||
public static String getAbsoluteForProjectConferenceURL(Long id) {
|
||||
PageParameters pageParameters = new PageParameters();
|
||||
pageParameters.add(PROJECTID, id.toString());
|
||||
pageParameters.put(PROJECTID, id.toString());
|
||||
return RequestUtils.toAbsolutePath(RequestCycle.get()
|
||||
.urlFor(ProjectConferencePage.class, pageParameters).toString());
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ package se.su.dsv.scipro.conference.pages;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.wicket.PageParameters;
|
||||
import org.apache.wicket.RequestCycle;
|
||||
@ -19,8 +20,10 @@ import se.su.dsv.scipro.SciProApplication;
|
||||
import se.su.dsv.scipro.SciProSession;
|
||||
import se.su.dsv.scipro.conference.model.SubscriberModel;
|
||||
import se.su.dsv.scipro.conference.panels.ConferencePanel;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.BoardMessageDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.MessageBoardDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.BoardMessage;
|
||||
import se.su.dsv.scipro.data.dataobjects.MessageBoard;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectFollower;
|
||||
@ -42,7 +45,10 @@ public class SupervisorConferencePage extends AbstractSupervisorPage {
|
||||
private MessageBoardDao messageBoardDao;
|
||||
@SpringBean
|
||||
protected ProjectDao projectDao;
|
||||
@SpringBean
|
||||
protected BoardMessageDao boardMessageDao;
|
||||
|
||||
private IModel<BoardMessage> boardMessageModel;
|
||||
private IModel<Project> projectModel;
|
||||
private IModel<MessageBoard> messageBoardModel;
|
||||
private MessageBoard messageBoard;
|
||||
@ -51,6 +57,21 @@ public class SupervisorConferencePage extends AbstractSupervisorPage {
|
||||
public SupervisorConferencePage(PageParameters pp) {
|
||||
super(pp);
|
||||
String projectId = pp.getString("pid");
|
||||
String boardMessageId = null;
|
||||
if (projectId != null) {
|
||||
StringTokenizer stringTokenizer = new StringTokenizer(projectId, "&");
|
||||
boolean first = true;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (stringTokenizer.hasMoreTokens()) {
|
||||
if (first) {
|
||||
projectId = stringTokenizer.nextToken().trim();
|
||||
first = false;
|
||||
} else {
|
||||
boardMessageId = stringTokenizer.nextToken().trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (projectId == null) {
|
||||
add(new EmptyPanel("conferencePanel"));
|
||||
} else {
|
||||
@ -109,7 +130,22 @@ public class SupervisorConferencePage extends AbstractSupervisorPage {
|
||||
return messageBoardDao.reLoad(messageBoard);
|
||||
}
|
||||
};
|
||||
add(new ConferencePanel("conferencePanel", messageBoardModel, subscriberModel));
|
||||
if (boardMessageId != null) {
|
||||
final BoardMessage bm = boardMessageDao.load(Long.valueOf(boardMessageId));
|
||||
|
||||
if (bm != null && messageBoard.getBoardMessageSet().contains(bm)) {
|
||||
boardMessageModel = new LoadableDetachableModel<BoardMessage>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected BoardMessage load() {
|
||||
return boardMessageDao.reLoad(bm);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
add(new ConferencePanel("conferencePanel", messageBoardModel, subscriberModel,
|
||||
boardMessageModel));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,20 +54,26 @@ public class ConferencePanel extends Panel {
|
||||
@SpringBean
|
||||
private NotificationController notificationController;
|
||||
|
||||
|
||||
private DataView<BoardMessage> dataView;
|
||||
private WebMarkupContainer webMarkupContainer;
|
||||
private IModel<MessageBoard> messageBoardModel;
|
||||
private IModel<BoardMessage> boardMessageModel;
|
||||
private Set<SubscriberModel> subscriberModels;
|
||||
|
||||
public ConferencePanel(String id,
|
||||
IModel<MessageBoard> messageBoardModel, Set<SubscriberModel> subscriberModels) {
|
||||
public ConferencePanel(String id, IModel<MessageBoard> messageBoardModel,
|
||||
Set<SubscriberModel> subscriberModels, IModel<BoardMessage> boardMessageModel) {
|
||||
super(id);
|
||||
this.boardMessageModel = boardMessageModel;
|
||||
this.messageBoardModel = messageBoardModel;
|
||||
this.subscriberModels = subscriberModels;
|
||||
initPanel();
|
||||
}
|
||||
|
||||
public ConferencePanel(String id, IModel<MessageBoard> messageBoardModel,
|
||||
Set<SubscriberModel> subscriberModels) {
|
||||
this(id, messageBoardModel, subscriberModels, null);
|
||||
}
|
||||
|
||||
private void initPanel() {
|
||||
add(new SendWallMessageForm("sendForm"));
|
||||
webMarkupContainer = new WebMarkupContainer("container");
|
||||
@ -130,41 +136,79 @@ public class ConferencePanel extends Panel {
|
||||
webMarkupContainer.setOutputMarkupPlaceholderTag(true);
|
||||
item.add(webMarkupContainer);
|
||||
|
||||
CommentThreadPanel ctp = new CommentThreadPanel("commentThread", bm, 5);
|
||||
CommentThreadPanel ctp = new CommentThreadPanel("commentThread", bm, 5,
|
||||
subscriberModels, messageBoardModel.getObject().getTitle());
|
||||
ctp.setOutputMarkupPlaceholderTag(true);
|
||||
webMarkupContainer.add(ctp);
|
||||
|
||||
if (boardMessageModel != null && boardMessageModel.getObject().equals(bm)) {
|
||||
comment.setDefaultModelObject("Hide comments");
|
||||
webMarkupContainer.setVisible(true);
|
||||
item.add(new AjaxLink<String>("showComments",
|
||||
new Model<String>("Hide Comments")) {
|
||||
|
||||
webMarkupContainer.setVisible(false);
|
||||
private static final long serialVersionUID = 1L;
|
||||
private boolean clicked = true;
|
||||
|
||||
item.add(new AjaxLink<String>("showComments", new Model<String>("Show Comments")) {
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
clicked = !clicked;
|
||||
if (clicked) {
|
||||
comment.setDefaultModelObject("Hide comments");
|
||||
} else {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private boolean clicked = false;
|
||||
int commentSize = commentThreadDao.getCommentThreadSize(bm);
|
||||
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
clicked = !clicked;
|
||||
if (clicked) {
|
||||
comment.setDefaultModelObject("Hide comments");
|
||||
} else {
|
||||
|
||||
int commentSize = commentThreadDao.getCommentThreadSize(bm);
|
||||
|
||||
String comments = " Comments";
|
||||
if (commentSize == 1) {
|
||||
comments = " Comment";
|
||||
String comments = " Comments";
|
||||
if (commentSize == 1) {
|
||||
comments = " Comment";
|
||||
}
|
||||
comment.setDefaultModelObject(commentSize + comments);
|
||||
}
|
||||
comment.setDefaultModelObject(commentSize + comments);
|
||||
webMarkupContainer.removeAll();
|
||||
webMarkupContainer.add(new CommentThreadPanel("commentThread",
|
||||
boardMessageDao.reLoad(bm), 5, subscriberModels,
|
||||
messageBoardModel.getObject().getTitle()));
|
||||
webMarkupContainer.setVisible(clicked);
|
||||
target.addComponent(webMarkupContainer);
|
||||
target.addComponent(comment);
|
||||
}
|
||||
webMarkupContainer.removeAll();
|
||||
webMarkupContainer.add(new CommentThreadPanel("commentThread",
|
||||
boardMessageDao.reLoad(bm), 5));
|
||||
webMarkupContainer.setVisible(clicked);
|
||||
target.addComponent(webMarkupContainer);
|
||||
target.addComponent(comment);
|
||||
}
|
||||
|
||||
}.add(comment));
|
||||
}.add(comment));
|
||||
} else {
|
||||
webMarkupContainer.setVisible(false);
|
||||
item.add(new AjaxLink<String>("showComments",
|
||||
new Model<String>("Show Comments")) {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private boolean clicked = false;
|
||||
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
clicked = !clicked;
|
||||
if (clicked) {
|
||||
comment.setDefaultModelObject("Hide comments");
|
||||
} else {
|
||||
|
||||
int commentSize = commentThreadDao.getCommentThreadSize(bm);
|
||||
|
||||
String comments = " Comments";
|
||||
if (commentSize == 1) {
|
||||
comments = " Comment";
|
||||
}
|
||||
comment.setDefaultModelObject(commentSize + comments);
|
||||
}
|
||||
webMarkupContainer.removeAll();
|
||||
webMarkupContainer.add(new CommentThreadPanel("commentThread",
|
||||
boardMessageDao.reLoad(bm), 5, subscriberModels,
|
||||
messageBoardModel.getObject().getTitle()));
|
||||
webMarkupContainer.setVisible(clicked);
|
||||
target.addComponent(webMarkupContainer);
|
||||
target.addComponent(comment);
|
||||
}
|
||||
|
||||
}.add(comment));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -193,10 +237,10 @@ public class ConferencePanel extends Panel {
|
||||
bm.setFromUser(SciProSession.get().getUser());
|
||||
bm = boardMessageDao.save(bm);
|
||||
|
||||
|
||||
for (SubscriberModel subscriberModel : subscriberModels) {
|
||||
createNotification(subscriberModel.getUser(), message,
|
||||
subscriberModel.getNotificationPriority(), subscriberModel.getAbsolutePath());
|
||||
subscriberModel.getNotificationPriority(),
|
||||
subscriberModel.getAbsolutePath());
|
||||
}
|
||||
|
||||
webMarkupContainer.removeAll();
|
||||
@ -213,7 +257,7 @@ public class ConferencePanel extends Panel {
|
||||
}
|
||||
|
||||
private void createNotification(final User user, final String message,
|
||||
final NotificationPriority notificationPriority, final String relativePath) {
|
||||
final NotificationPriority notificationPriority, final String absolutePath) {
|
||||
|
||||
Properties props = null;
|
||||
try {
|
||||
@ -225,16 +269,14 @@ public class ConferencePanel extends Panel {
|
||||
String conferenceNotification = props.getProperty("conferenceNotification");
|
||||
String twoNewLines = props.getProperty("twoNewLines");
|
||||
|
||||
|
||||
String webNotificationMessage = SciProSession.get().getUser() + conferenceNotification
|
||||
+ messageBoardModel.getObject().getTitle();
|
||||
|
||||
String mailMessage = webNotificationMessage + twoNewLines + message;
|
||||
|
||||
|
||||
NotificationMessage notificationMessage = new NotificationMessage(webNotificationMessage,
|
||||
mailSubject, mailMessage);
|
||||
notificationController.processNotification(user, notificationMessage, relativePath,
|
||||
notificationController.processNotification(user, notificationMessage, absolutePath,
|
||||
notificationPriority);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user