Panel for showing webnotifications
Change-Id: Ifca8d40e73a8fb17371456f3df7d2932c55961a2
This commit is contained in:
parent
c236d6addf
commit
520ce8b5b9
src/main/java/se/su/dsv/scipro/project/panels
@ -4,12 +4,14 @@
|
||||
<body>
|
||||
<wicket:panel>
|
||||
<div wicket:id="container">
|
||||
<h3><span wicket:id="newNotifications"></span> new notifications</h3>
|
||||
<div wicket:id="notificationsListView">
|
||||
<strong><span wicket:id="newNotifications"></span> new notifications</strong>
|
||||
<a href="#" wicket:id="readAllNotification">Set all read</a>
|
||||
<div wicket:id="notificationsListView" class="rounded-border-notification">
|
||||
<div wicket:id="infoText"></div>
|
||||
<a href="#" wicket:id="readNotification">Set read</a>
|
||||
<a href="#" wicket:id="bookmarkLink">Go to</a>
|
||||
</div>
|
||||
<div wicket:id="paging"></div>
|
||||
</div>
|
||||
</wicket:panel>
|
||||
</body>
|
||||
|
@ -5,29 +5,27 @@ package se.su.dsv.scipro.project.panels;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.management.Notification;
|
||||
|
||||
import org.apache.wicket.RequestCycle;
|
||||
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.navigation.paging.PagingNavigator;
|
||||
import org.apache.wicket.markup.html.panel.Panel;
|
||||
import org.apache.wicket.markup.repeater.Item;
|
||||
import org.apache.wicket.markup.repeater.data.DataView;
|
||||
import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.model.LoadableDetachableModel;
|
||||
import org.apache.wicket.protocol.http.RequestUtils;
|
||||
import org.apache.wicket.request.target.basic.RedirectRequestTarget;
|
||||
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.WebNotificationDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.WebNotification;
|
||||
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.dataproviders.WebNotificationDataProvider;
|
||||
|
||||
/**
|
||||
* @author Johan Aschan <aschan@dsv.su.se>
|
||||
@ -38,7 +36,7 @@ public class NotificationsPanel extends Panel {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@SpringBean
|
||||
private WebNotificationDao notificationDao;
|
||||
private WebNotificationDao webNotificationDao;
|
||||
|
||||
/**
|
||||
* @param id
|
||||
@ -46,23 +44,13 @@ public class NotificationsPanel extends Panel {
|
||||
public NotificationsPanel(String id) {
|
||||
super(id);
|
||||
|
||||
final IModel<List<WebNotification>> notificaitonsModel = new LoadableDetachableModel<List<WebNotification>>() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected List<WebNotification> load() {
|
||||
return notificationDao.getWebNotifications(SciProSession.get().getUser());
|
||||
}
|
||||
};
|
||||
|
||||
final IModel<Integer> numberOfNotificationsModel = new LoadableDetachableModel<Integer>() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected Integer load() {
|
||||
return notificationDao.getNumberOfWebNotifications(SciProSession.get().getUser());
|
||||
return webNotificationDao.getCountOfWebNotifications(SciProSession.get().getUser());
|
||||
}
|
||||
};
|
||||
|
||||
@ -72,13 +60,16 @@ public class NotificationsPanel extends Panel {
|
||||
webMarkupContainer.setOutputMarkupId(true);
|
||||
add(webMarkupContainer);
|
||||
webMarkupContainer.add(newNotifications);
|
||||
ListView<WebNotification> notifications = new ListView<WebNotification>("notificationsListView",
|
||||
notificaitonsModel) {
|
||||
|
||||
WebNotificationDataProvider webNotificationDataProvider = new WebNotificationDataProvider(
|
||||
SciProSession.get().getUser());
|
||||
DataView<WebNotification> notifications = new DataView<WebNotification>(
|
||||
"notificationsListView", webNotificationDataProvider, 5) {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void populateItem(final ListItem<WebNotification> item) {
|
||||
protected void populateItem(final Item<WebNotification> item) {
|
||||
item.add(new Label("infoText", item.getModel().getObject().getInfoText()));
|
||||
item.add(new Link<Void>("bookmarkLink") {
|
||||
|
||||
@ -86,12 +77,13 @@ public class NotificationsPanel extends Panel {
|
||||
|
||||
@Override
|
||||
public void onClick() {
|
||||
WebNotification notification = item.getModel().getObject();
|
||||
|
||||
WebNotification notification = item.getModelObject();
|
||||
notification.setReadByUser(true);
|
||||
notification = notificationDao.save(notification);
|
||||
String url = RequestUtils.toAbsolutePath(RequestCycle.get().getRequest().getRelativePathPrefixToWicketHandler());
|
||||
url += notification.getRestRelativeURL();
|
||||
getRequestCycle().setRequestTarget(new RedirectRequestTarget(notification.getRestRelativeURL()));
|
||||
notification = webNotificationDao.save(notification);
|
||||
|
||||
RequestCycle.get().setRequestTarget(
|
||||
new RedirectRequestTarget(notification.getUrl()));
|
||||
}
|
||||
});
|
||||
item.add(new AjaxLink<Void>("readNotification") {
|
||||
@ -100,16 +92,32 @@ public class NotificationsPanel extends Panel {
|
||||
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
WebNotification notification = item.getModel().getObject();
|
||||
WebNotification notification = item.getModelObject();
|
||||
notification.setReadByUser(true);
|
||||
notificationDao.save(notification);
|
||||
notificaitonsModel.detach();
|
||||
webNotificationDao.save(notification);
|
||||
target.addComponent(webMarkupContainer);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
webMarkupContainer.add(new AjaxLink<Void>("readAllNotification") {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
for (WebNotification webnotification : webNotificationDao.getWebNotifications(SciProSession
|
||||
.get().getUser())) {
|
||||
webnotification.setReadByUser(true);
|
||||
webNotificationDao.save(webnotification);
|
||||
}
|
||||
target.addComponent(webMarkupContainer);
|
||||
}
|
||||
});
|
||||
PagingNavigator pagingNavigator = new PagingNavigator("paging", notifications);
|
||||
webMarkupContainer.add(pagingNavigator);
|
||||
webMarkupContainer.add(notifications);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user