Added logic to handle different webnotifications.

Change-Id: Ied056f8e1ae3d2baa7a24052e8bdfea3b7fdc41f
This commit is contained in:
joha-asc 2011-07-15 13:03:40 +02:00
parent bc50d1be16
commit 92278f8427
3 changed files with 68 additions and 16 deletions

@ -4,9 +4,11 @@
<body>
<wicket:panel>
<div wicket:id="container">
<h3><span wicket:id="newNotifications"></span> new notifications</h3>
<div wicket:id="notificationsListView">
<div wicket:id="infoText"></div>
<a href="#" wicket:id="readNotification">Read Notification</a>
<a href="#" wicket:id="readNotification">Set read</a>
<a href="#" wicket:id="bookmarkLink">Go to</a>
</div>
</div>
</wicket:panel>

@ -5,10 +5,12 @@ package se.su.dsv.scipro.project.panels;
import java.util.List;
import org.apache.wicket.PageParameters;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
@ -17,17 +19,24 @@ import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import se.su.dsv.scipro.SciProSession;
import se.su.dsv.scipro.conference.pages.ProjectConferencePage;
import se.su.dsv.scipro.conference.pages.SupervisorConferencePage;
import se.su.dsv.scipro.data.dao.interfaces.NotificationDao;
import se.su.dsv.scipro.data.dataobjects.Notification;
import se.su.dsv.scipro.data.dataobjects.WebNotification;
import se.su.dsv.scipro.data.dataobjects.Project;
import se.su.dsv.scipro.data.enums.NotificationEventType;
import se.su.dsv.scipro.message.pages.PrivateMessagesPage;
import se.su.dsv.scipro.security.auth.roles.Roles;
import se.su.dsv.scipro.supervisor.pages.SupervisorProjectDetailsPage;
/**
* @author Johan Aschan <aschan@dsv.su.se>
*
*
*/
public class NotificationsPanel extends Panel {
private static final long serialVersionUID = 1L;
@SpringBean
private NotificationDao notificationDao;
@ -36,42 +45,81 @@ public class NotificationsPanel extends Panel {
*/
public NotificationsPanel(String id) {
super(id);
final IModel<List<Notification>> notificaitonsModel = new LoadableDetachableModel<List<Notification>>() {
final IModel<List<WebNotification>> notificaitonsModel = new LoadableDetachableModel<List<WebNotification>>() {
private static final long serialVersionUID = 1L;
@Override
protected List<Notification> load() {
protected List<WebNotification> load() {
return notificationDao.getNotifications(SciProSession.get().getUser());
}
};
final WebMarkupContainer webMarkupContainer = new WebMarkupContainer("container");
webMarkupContainer.setOutputMarkupId(true);
add(webMarkupContainer);
ListView<Notification> notifications = new ListView<Notification>("notificationsListView", notificaitonsModel) {
final IModel<Integer> numberOfNotificationsModel = new LoadableDetachableModel<Integer>() {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(final ListItem<Notification> item) {
protected Integer load() {
return notificationDao.getNumberOfNotifications(SciProSession.get().getUser());
}
};
Label newNotifications = new Label("newNotifications", numberOfNotificationsModel);
final WebMarkupContainer webMarkupContainer = new WebMarkupContainer("container");
webMarkupContainer.setOutputMarkupId(true);
add(webMarkupContainer);
webMarkupContainer.add(newNotifications);
ListView<WebNotification> notifications = new ListView<WebNotification>("notificationsListView",
notificaitonsModel) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(final ListItem<WebNotification> item) {
item.add(new Label("infoText", item.getModel().getObject().getInfoText()));
item.add(new Link<Void>("bookmarkLink") {
private static final long serialVersionUID = 1L;
@Override
public void onClick() {
WebNotification notification = item.getModel().getObject();
notification.setReadByUser(true);
notification = notificationDao.save(notification);
if (notification.getNotificationEventType().equals(
NotificationEventType.NEW_MESSAGE_IN_CONFERENCE)) {
if (notification.getRole().equals(Roles.STUDENT))
setResponsePage(new ProjectConferencePage(getPage()
.getPageParameters(), item.getModel().getObject()
.getTypeId()));
else
setResponsePage(new SupervisorConferencePage(getPage()
.getPageParameters(), item.getModel().getObject()
.getTypeId()));
} else if (notification.getNotificationEventType().equals(
NotificationEventType.NEW_PRIVATE_MESSAGE)) {
setResponsePage(PrivateMessagesPage.class);
}
}
});
item.add(new AjaxLink<Void>("readNotification") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
Notification notification = item.getModel().getObject();
notification.getSubscribers().remove(SciProSession.get().getUser());
WebNotification notification = item.getModel().getObject();
notification.setReadByUser(true);
notificationDao.save(notification);
notificaitonsModel.detach();
target.addComponent(webMarkupContainer);
}
});
}
};
webMarkupContainer.add(notifications);

@ -7,6 +7,7 @@ import org.apache.wicket.Page;
import se.su.dsv.scipro.SciProSession;
import se.su.dsv.scipro.components.AbstractMenuPanel;
import se.su.dsv.scipro.conference.pages.ProjectConferencePage;
import se.su.dsv.scipro.data.dataobjects.Project;
import se.su.dsv.scipro.peer.pages.ProjectPeerPortalPage;
import se.su.dsv.scipro.project.pages.FinalSeminarProjectListPage;
@ -45,6 +46,7 @@ public class ProjectTabMenuPanel extends AbstractMenuPanel {
itemList.add(new MenuItem("Opposition & Active participation", ProjectOppositionPage.class));
itemList.add(new MenuItem("Peer review", ProjectPeerPortalPage.class));
itemList.add(new MenuItem("All Final Seminars", FinalSeminarProjectListPage.class));
itemList.add(new MenuItem("Conference", ProjectConferencePage.class));
} else {
itemList.add(new MenuItem("No active project!", NoActiveProjectPage.class));
itemList.add(new MenuItem("Project Partner", ProjectPartnerPage.class));