Commit 602bcc35 by Tuomas Riihimäki

Ajax stuff for queue management

1 parent 17e0fb65
...@@ -47,7 +47,7 @@ public class QueueBean implements QueueBeanLocal { ...@@ -47,7 +47,7 @@ public class QueueBean implements QueueBeanLocal {
private final Map<Integer, MapQueue> mapqueues; private final Map<Integer, MapQueue> mapqueues;
private int reservingSize = 2; private int reservingSize = 1;
private class MapQueue { private class MapQueue {
// private final Set<MapReservationQueueEntry> reserving = new HashSet<>(); // private final Set<MapReservationQueueEntry> reserving = new HashSet<>();
...@@ -94,6 +94,16 @@ public class QueueBean implements QueueBeanLocal { ...@@ -94,6 +94,16 @@ public class QueueBean implements QueueBeanLocal {
public boolean isReserving(EventUser e) { public boolean isReserving(EventUser e) {
// Check queue size and add entry to queue // Check queue size and add entry to queue
checkReservingEntry();
MapReservationQueueEntry que = queEntries.get(e);
if (que != null) {
que.setSeenTime(new Date());
}
return reserving.contains(e);
}
private void checkReservingEntry() {
if (reserving.size() < reservingSize) { if (reserving.size() < reservingSize) {
synchronized (queue) { synchronized (queue) {
if (reserving.size() < reservingSize) { if (reserving.size() < reservingSize) {
...@@ -104,12 +114,6 @@ public class QueueBean implements QueueBeanLocal { ...@@ -104,12 +114,6 @@ public class QueueBean implements QueueBeanLocal {
} }
} }
} }
MapReservationQueueEntry que = queEntries.get(e);
if (que != null) {
que.setSeenTime(new Date());
}
return reserving.contains(e);
} }
public MapReservationQueueEntry remove(EventUser user) public MapReservationQueueEntry remove(EventUser user)
...@@ -124,6 +128,7 @@ public class QueueBean implements QueueBeanLocal { ...@@ -124,6 +128,7 @@ public class QueueBean implements QueueBeanLocal {
logger.info("Removed user {} from queue"); logger.info("Removed user {} from queue");
} }
ret = queEntries.remove(user); ret = queEntries.remove(user);
checkReservingEntry();
} }
return ret; return ret;
} }
...@@ -132,10 +137,16 @@ public class QueueBean implements QueueBeanLocal { ...@@ -132,10 +137,16 @@ public class QueueBean implements QueueBeanLocal {
MapReservationQueueEntry ret = null; MapReservationQueueEntry ret = null;
synchronized (queue) { synchronized (queue) {
if (!reserving.contains(user) && !queue.contains(user)) { if (!reserving.contains(user) && !queue.contains(user)) {
ret = new MapReservationQueueEntry(); ret = new MapReservationQueueEntry();
queEntries.put(user, ret); queEntries.put(user, ret);
boolean queStat = queue.offer(user); if (reserving.size() < reservingSize) {
logger.info("User {} not in queue, offer state {}", user, queStat); boolean resStat = reserving.add(user);
logger.info("User {} not in queue and reserving smaller than size Entering directly: Success: {}", user, resStat);
} else {
boolean queStat = queue.offer(user);
logger.info("User {} not in queue, offer state {}", user, queStat);
}
} else { } else {
ret = queEntries.get(user); ret = queEntries.get(user);
logger.info("User {} already in queue. Not entering again {}", user, ret); logger.info("User {} already in queue. Not entering again {}", user, ret);
...@@ -286,4 +297,7 @@ public class QueueBean implements QueueBeanLocal { ...@@ -286,4 +297,7 @@ public class QueueBean implements QueueBeanLocal {
return ret; return ret;
} }
} }
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
action="#{ajaxMapView.placeClicked()}" /> action="#{ajaxMapView.placeClicked()}" />
</h:form> </h:form>
--> -->
<p:dialog rendered="#{ajaxMapView.isMgmtPermission()}" visible="#{!empty ajaxMapView.place}" id="fbdiag"> <p:dialog rendered="#{ajaxMapView.isMgmtPermission()}"
visible="#{!empty ajaxMapView.place}" id="fbdiag">
Clicked place name : #{ajaxMapView.place.name}; Clicked place name : #{ajaxMapView.place.name};
<h:link rendered="#{!empty ajaxMapView.place}" outcome="/place/edit"> <h:link rendered="#{!empty ajaxMapView.place}" outcome="/place/edit">
<f:param name="placeid" value="#{ajaxMapView.place.id}" /> <f:param name="placeid" value="#{ajaxMapView.place.id}" />
...@@ -43,10 +44,13 @@ ...@@ -43,10 +44,13 @@
action="#{ajaxMapView.buySelectedPlaces()}" ajax="false" /> action="#{ajaxMapView.buySelectedPlaces()}" ajax="false" />
</h:form> </h:form>
</div> </div>
<p:outputPanel rendered="#{ajaxMapView.queueEnabled}"> <p:outputPanel rendered="#{ajaxMapView.queueEnabled}">
<h:form> <h:form>
<p:commandButton value="#{i18n['mapView.enterQueue']}" action="#{ajaxMapView.enterQueue()}" ajax="false" /> <p:commandButton value="#{i18n['mapView.enterQueue']}"
<p:commandButton value="#{i18n['mapView.check']}" action="#{ajaxMapView.checkReserving()}" /> action="#{ajaxMapView.enterQueue()}" ajax="false" />
<p:commandButton value="#{i18n['mapView.check']}"
action="#{ajaxMapView.checkReserving()}" ajax="false" />
</h:form> </h:form>
queueEntry #{ajaxMapView.queueEntry} <br /> queueEntry #{ajaxMapView.queueEntry} <br />
QueuePosition: #{ajaxMapView.queuePosition} <br /> QueuePosition: #{ajaxMapView.queuePosition} <br />
...@@ -54,14 +58,37 @@ ...@@ -54,14 +58,37 @@
isReserving #{ajaxMapView.reserving} <br /> isReserving #{ajaxMapView.reserving} <br />
</p:outputPanel> </p:outputPanel>
<svg id="seatmap" style="margin: auto; border: 1px solid black;" width="#{ajaxMapView.map.width}px" height="#{ajaxMapView.map.height}px" />
<svg id="seatmap" style="margin: auto; border: 1px solid black;"
width="#{ajaxMapView.map.width}px"
height="#{ajaxMapView.map.height}px" />
<script type="text/javascript"> <script type="text/javascript">
px = placemap({
function updateQueue(data) {
if(data.value === undefined) {
alert('not in queue');
} else if(data.value == 0) {
alert("Reserving");
} else {
alert("Quue position " + data.value);
}
}
function updateMap() {
px.update();
$.getJSON("#{request.contextPath}/rest/placemap/v1/queue/#{ajaxMapView.map.id}/#{ajaxMapView.eventuser.id}")
.done(function(data){ updateQueue(data); } );
}
px = placemap({
element : document.getElementById("seatmap"), element : document.getElementById("seatmap"),
moyaurl : "#{request.contextPath}", moyaurl : "#{request.contextPath}",
map_id : #{ajaxMapView.map.id}, map_id : #{ajaxMapView.map.id},
onclick : function(d) { onclick : function(d) {
px.update(); // px.update();
//alert(d); //alert(d);
// #{ajaxMapView.isMgmtPermission()?'placeClicker([{name: \'placeId\', value: d}])':''} // #{ajaxMapView.isMgmtPermission()?'placeClicker([{name: \'placeId\', value: d}])':''}
return false; return false;
...@@ -72,6 +99,8 @@ ...@@ -72,6 +99,8 @@
// px.enable_edit(); // px.enable_edit();
// }); // });
//px.enable_edit(); //px.enable_edit();
setInterval(function () { updateMap() }, 5000);
</script> </script>
<h:panelGrid columns="3" cellpadding="10"> <h:panelGrid columns="3" cellpadding="10">
......
...@@ -23,9 +23,12 @@ import org.slf4j.LoggerFactory; ...@@ -23,9 +23,12 @@ import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.PermissionBeanLocal; import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal; import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.beans.QueueBeanLocal; import fi.codecrew.moya.beans.QueueBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.model.EventMap; import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place; import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.rest.pojo.placemap.IntegerRoot;
import fi.codecrew.moya.rest.pojo.placemap.PlacemapMapRootPojo; import fi.codecrew.moya.rest.pojo.placemap.PlacemapMapRootPojo;
import fi.codecrew.moya.rest.pojo.placemap.SimplePlacePojo; import fi.codecrew.moya.rest.pojo.placemap.SimplePlacePojo;
import fi.codecrew.moya.rest.pojo.placemap.SimplePlacelistRoot; import fi.codecrew.moya.rest.pojo.placemap.SimplePlacelistRoot;
...@@ -50,6 +53,8 @@ public class PlacemapRestViewV1 { ...@@ -50,6 +53,8 @@ public class PlacemapRestViewV1 {
@EJB @EJB
private QueueBeanLocal quebean; private QueueBeanLocal quebean;
@EJB
private UserBeanLocal userbean;
// @GET // @GET
// @Path("/maps") // @Path("/maps")
...@@ -110,6 +115,29 @@ public class PlacemapRestViewV1 { ...@@ -110,6 +115,29 @@ public class PlacemapRestViewV1 {
return SimplePlacelistRoot.wrap(thisplace, permbean.getCurrentUser()); return SimplePlacelistRoot.wrap(thisplace, permbean.getCurrentUser());
} }
@GET
@Path("/queue/{mapid}/{userid}")
public IntegerRoot getQueue(@PathParam("mapid") Integer mapid, @PathParam("userid") Integer userid) {
EventUser user = null;
if (userid != null) {
// We might not have permission to create user.. It should exist if we are querying this, but
// there is no guarantees of that
user = userbean.findByEventUserId(userid);
} else {
user = permbean.getCurrentUser();
}
if (user == null) {
return null;
}
EventMap map = placebean.findMap(mapid);
IntegerRoot root = new IntegerRoot();
root.setValue(quebean.getQueuePosition(map, user));
return root;
}
@POST @POST
@Path("/place/{place}") @Path("/place/{place}")
public Response togglePlaceReservation(@PathParam("place") Integer placeId) public Response togglePlaceReservation(@PathParam("place") Integer placeId)
......
package fi.codecrew.moya.rest.pojo.placemap;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class IntegerRoot {
private Integer value = -1;
@XmlElement(name = "value")
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!