Commit 8c36dc4d by Tuukka Kivilahti

incomingNäkymään paikanvaraus

1 parent 48d6d281
...@@ -59,6 +59,8 @@ public interface PlaceBeanLocal { ...@@ -59,6 +59,8 @@ public interface PlaceBeanLocal {
PlaceGroup buySelectedPlaces(EventUser user) throws BortalCatchableException; PlaceGroup buySelectedPlaces(EventUser user) throws BortalCatchableException;
PlaceGroup buySelectedPlaces(List<Place> selectedPlaces, EventUser user) throws BortalCatchableException;
// void releaseUsersPlaces(User user) throws PermissionDeniedException; // void releaseUsersPlaces(User user) throws PermissionDeniedException;
Place find(int placeId); Place find(int placeId);
......
...@@ -120,6 +120,9 @@ public class BarcodeBean implements BarcodeBeanLocal { ...@@ -120,6 +120,9 @@ public class BarcodeBean implements BarcodeBeanLocal {
textcode = textcode.substring(textcode.lastIndexOf("=")+1); textcode = textcode.substring(textcode.lastIndexOf("=")+1);
} }
logger.info("Getting user from textcode {}", textcode);
return getUserFromTextCode(textcode, 38, 16); return getUserFromTextCode(textcode, 38, 16);
} }
...@@ -370,8 +373,6 @@ public class BarcodeBean implements BarcodeBeanLocal { ...@@ -370,8 +373,6 @@ public class BarcodeBean implements BarcodeBeanLocal {
if (barcode == null || barcode.isEmpty()) if (barcode == null || barcode.isEmpty())
return null; return null;
logger.debug("Getting user from barcode {}", barcode);
// trim zeros off from barcode // trim zeros off from barcode
String stripped = barcode; String stripped = barcode;
while (stripped.length() > 0 && stripped.charAt(0) == '0') { while (stripped.length() > 0 && stripped.charAt(0) == '0') {
......
...@@ -350,6 +350,7 @@ public class MenuBean implements MenuBeanLocal { ...@@ -350,6 +350,7 @@ public class MenuBean implements MenuBeanLocal {
infonavi.addPage(menuitemfacade.findOrCreate("/info/foodwave/foodwaveshop"), TerminalPermission.INFO); infonavi.addPage(menuitemfacade.findOrCreate("/info/foodwave/foodwaveshop"), TerminalPermission.INFO);
infonavi.addPage(menuitemfacade.findOrCreate("/info/usermapsearch"), TerminalPermission.INFO); infonavi.addPage(menuitemfacade.findOrCreate("/info/usermapsearch"), TerminalPermission.INFO);
infonavi.addPage(menuitemfacade.findOrCreate("/info/viplist"), TerminalPermission.INFO); infonavi.addPage(menuitemfacade.findOrCreate("/info/viplist"), TerminalPermission.INFO);
infonavi.addPage(menuitemfacade.findOrCreate("/info/placeReservation"), TerminalPermission.INFO);
infonavi.addPage(menuitemfacade.findOrCreate("/info/foodwave/foodwaveProducts"), TerminalPermission.INFO).setVisible(false); infonavi.addPage(menuitemfacade.findOrCreate("/info/foodwave/foodwaveProducts"), TerminalPermission.INFO).setVisible(false);
navifacade.create(adminmenu); navifacade.create(adminmenu);
......
...@@ -312,15 +312,27 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -312,15 +312,27 @@ public class PlaceBean implements PlaceBeanLocal {
} }
@Override @Override
@RolesAllowed({ MapPermission.S_BUY_PLACES, MapPermission.S_MANAGE_OTHERS })
public PlaceGroup buySelectedPlaces(List<Place> selectedPlaces, EventUser user) throws BortalCatchableException {
return buyOrReserveSelectedPlaces(user, selectedPlaces, true);
}
@Override
@RolesAllowed({ MapPermission.S_MANAGE_OTHERS }) @RolesAllowed({ MapPermission.S_MANAGE_OTHERS })
public PlaceGroup reserveSelectedPlaces(EventUser eventuser) throws BortalCatchableException { public PlaceGroup reserveSelectedPlaces(EventUser eventuser) throws BortalCatchableException {
return buyOrReserveSelectedPlaces(eventuser, false); return buyOrReserveSelectedPlaces(eventuser, false);
} }
private PlaceGroup buyOrReserveSelectedPlaces(EventUser user, boolean createAccountevents) throws BortalCatchableException {
return buyOrReserveSelectedPlaces(user, null, createAccountevents);
}
/** /**
* Reserves places and creates accountevents for the places. * Reserves places and creates accountevents for the places.
*/ */
public PlaceGroup buyOrReserveSelectedPlaces(EventUser user, boolean createAccountevents) throws BortalCatchableException { private PlaceGroup buyOrReserveSelectedPlaces(EventUser user, List<Place> selectedPlaces, boolean createAccountevents) throws BortalCatchableException {
if (user == null) { if (user == null) {
user = permbean.getCurrentUser(); user = permbean.getCurrentUser();
} else { } else {
...@@ -333,6 +345,21 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -333,6 +345,21 @@ public class PlaceBean implements PlaceBeanLocal {
LanEvent event = eventBean.getCurrentEvent(); LanEvent event = eventBean.getCurrentEvent();
List<Place> places = placeFacade.findUsersReservations(event, user); List<Place> places = placeFacade.findUsersReservations(event, user);
if(selectedPlaces != null) {
List<Place> newPlaces = new ArrayList<>();
for(Place p : selectedPlaces) {
if(!p.isReservedFor(permbean.getCurrentUser()) && p.isTaken())
continue;
p = placeFacade.reload(p); // persist teh shit
newPlaces.add(p);
}
places = newPlaces;
}
if (places.isEmpty()) { if (places.isEmpty()) {
return null; return null;
} }
...@@ -362,8 +389,12 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -362,8 +389,12 @@ public class PlaceBean implements PlaceBeanLocal {
boolean associatedToPlace = isUserMember(user, places.get(0).getProduct()); boolean associatedToPlace = isUserMember(user, places.get(0).getProduct());
for (Place p : places) { for (Place p : places) {
if (!p.isReservedFor(user)) { if (!p.isReservedFor(user)) {
throw new BortalCatchableException("Trying to buy place not reserved for that user"); // if you can mange others, you can give your (or free) place to another user
if (!permbean.hasPermission(MapPermission.MANAGE_OTHERS) || (!p.isReservedFor(permbean.getCurrentUser()) && p.isTaken())) {
throw new BortalCatchableException("Trying to buy place not reserved for that user");
}
} }
logger.info("Buying place {} for user {}", p.getName(), user.getUser().getLogin()); logger.info("Buying place {} for user {}", p.getName(), user.getUser().getLogin());
GroupMembership gm = buy(p, pg); GroupMembership gm = buy(p, pg);
......
...@@ -912,7 +912,7 @@ public class UserBean implements UserBeanLocal { ...@@ -912,7 +912,7 @@ public class UserBean implements UserBeanLocal {
newSearchList.add(group.getCreator()); newSearchList.add(group.getCreator());
} }
} }
returnUsers = new SearchResult<EventUser>(newSearchList, (long) newSearchList.size()); returnUsers = new SearchResult<>(newSearchList, (long) newSearchList.size());
} }
return returnUsers; return returnUsers;
......
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui" xmlns:reader="http://java.sun.com/jsf/composite/cditools/reader"
xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:user="http://java.sun.com/jsf/composite/cditools/user"
xmlns:infoview="http://java.sun.com/jsf/composite/cditools/infoview"
xmlns:shop="http://java.sun.com/jsf/composite/cditools/shop"
>
<h:body>
<ui:composition template="/resources/templates/#{sessionHandler.infoscreen}/template.xhtml">
<ui:param name="ignorenavigationleft" value="true" />
<f:metadata>
<f:viewParam name="userid" value="#{incomingPlaceshopView.userId}" />
<f:event type="preRenderView" listener="#{incomingPlaceshopView.initView}" />
</f:metadata>
<ui:define name="content">
<reader:backendReader selectvalue="#{i18n['barcodeReader.readBarcode']}" selectaction="#{flowShopView.polledRead}" />
<infoview:usermultisearch />
<br />
<br />
<h:form rendered="#{!userView.selectedUser.anonymous}">
<h1>Reserve to user: #{userView.selectedUser.user.nick}</h1>
</h:form>
<h:form rendered="#{userView.selectedUser.anonymous}">
<h1>Infon paikanvaraus</h1>
</h:form>
<br />
<br />
<!--
<p:dialog rendered="#{ajaxMapView.isMgmtPermission()}" visible="#{!empty ajaxMapView.place}" id="fbdiag">
Clicked place name : #{ajaxMapView.place.name};
<h:link rendered="#{!empty ajaxMapView.place}" outcome="/place/edit">
<f:param name="placeid" value="#{ajaxMapView.place.id}"/>
Muokkaa
</h:link>
</p:dialog> -->
<h:outputScript target="head" library="seatjs" name="d3.min.js"/>
<h:outputScript target="head" library="seatjs" name="d3-tip.js"/>
<h:outputScript target="head" library="seatjs" name="seatmap.js"/>
<h:outputStylesheet library="seatjs" name="placemap.css"/>
<h:form id="selectedPlaces">
<h2>#{i18n['placeReservation.selectedPlaces']}</h2>
<div style="min-height: 150px; border: solid red 1px;">
<p:dataTable id="selectedPlacesTable" tableStyle="width: auto;" var="place" value="#{incomingPlaceshopView.selectedPlaces}">
<p:column headerText=" ">
<h:outputText value="#{place.product.name}"/>
</p:column>
<p:column headerText=" ">
<h:outputText value="#{place.name}"/>
</p:column>
</p:dataTable>
</div>
</h:form>
<h:form id="placeselectform">
<p:commandButton update="placeselectform" onclick="$(window).unbind('beforeunload');" oncomplete="updateLastPlace();" value="#{i18n['shop.buyForuser']}" actionListener="#{incomingPlaceshopView.reserveSelectedPlaces}" />
<h:outputText id="successText" styleClass="success" value="#{i18n['shop.buyForuser.success']}" rendered="#{incomingPlaceshopView.userMustGoAway}"/>
</h:form>
<p>#{i18n['placeReservation.mapMultiuserNote']}</p>
<svg id="seatmap" style="margin: auto; border: 1px solid black;" width="#{ajaxMapView.map.width}px" height="#{ajaxMapView.map.height}px"/>
<script type="text/javascript">
function updateMap() {
px.update();
}
function updateQueue(data) {
if (data === undefined) {
alert('not in queue');
return;
}
if (data.value == 0) {
updateWholePage();
} else {
$("#queuepos").text(data.value);
var d = new Date();
$("#queueupdated").text(d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds())
}
}
setInterval(function () {
updateMap()
}, 5000);
</script>
<script type="text/javascript">
var lastplace = false;
px = placemap({
element: document.getElementById("seatmap"),
moyaurl: "#{request.contextPath}",
map_id: #{ajaxMapView.map.id},
placereserve: true,
toggleaction: function (d) {
selectPlace([{name: "placeid", value: d.id}]);
lastplace = d;
return false;
}
});
// document.getElementById("editbutton").addEventListener("click",
// function() {
// px.enable_edit();
// });
// px.enable_edit();
function updateLastPlace() {
px.update();
}
</script>
<h:form>
<p:remoteCommand oncomplete="updateLastPlace();" update="selectedPlaces" name="selectPlace" actionListener="#{incomingPlaceshopView.reserveRemoteCommand}" />
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
...@@ -23,13 +23,18 @@ function placemap(opts) ...@@ -23,13 +23,18 @@ function placemap(opts)
if (opts.onclick === undefined ) if (opts.onclick === undefined )
{ {
throw "onclick is mandatory argument"; opts.onclick = function(x) {return false;};
} }
if (opts.editclick === undefined ) if (opts.editclick === undefined )
{ {
opts.editclick = function(x, y) {return false;}; opts.editclick = function(x, y) {return false;};
} }
if (opts.toggleaction === undefined )
{
opts.toggleaction = false;
}
if(opts.placereserve === undefined) if(opts.placereserve === undefined)
{ {
...@@ -55,6 +60,7 @@ function placemap(opts) ...@@ -55,6 +60,7 @@ function placemap(opts)
clicked_place: undefined, clicked_place: undefined,
locale: opts.locale || 'fi', locale: opts.locale || 'fi',
placereserve: opts.placereserve, placereserve: opts.placereserve,
toggleaction: opts.toggleaction,
}; };
if (px.locale == "und") px.locale == "fi"; if (px.locale == "und") px.locale == "fi";
...@@ -246,28 +252,16 @@ function placemap(opts) ...@@ -246,28 +252,16 @@ function placemap(opts)
data = element.data()[0]; data = element.data()[0];
px.clicked_place = data.id; px.clicked_place = data.id;
//px.onclick(data);
px.toggle_place(data);
if(px.toggleaction) {
px.toggleaction(data);
} else {
px.toggle_place(data);
}
px.onclick(data);
//px.update_place(data.id);
//if ( != true) return;
/*if (data.state == "F")
{
element.transition().duration(100).style("fill", px.place_colors["T"]);
data.state = "T";
}
else if (data.state == "T")
{
element.transition()
.duration(100).style("fill", px.place_colors["F"]);
data.state = "F";
}*/
} }
px.update_leavemessage = function() { px.update_leavemessage = function() {
......
package fi.codecrew.moya.web.flow;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.beans.map.QueueBeanLocal;
import fi.codecrew.moya.beans.map.QueueBeanLocal.MapQueueI;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.exceptions.BortalCatchableException;
import fi.codecrew.moya.model.*;
import fi.codecrew.moya.model.map.MapReservationQueueEntry;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import fi.codecrew.moya.web.cdiview.user.UserView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.*;
@Named
@ConversationScoped
public class IncomingPlaceshopView extends GenericCDIView {
/**
*
*/
private static final long serialVersionUID = 8203589456357519480L;
private static final Logger logger = LoggerFactory.getLogger(IncomingPlaceshopView.class);;
@EJB
private transient EventBeanLocal eventbean;
@EJB
private PlaceBeanLocal placebean;
@EJB
private PermissionBeanLocal permbean;
private Place place;
@Inject
private UserView userview;
@EJB
private QueueBeanLocal quebean;
private List<Place> selectedPlaces = new ArrayList<>();
private boolean userMustGoAway = false;
// shop userid, we need this so we can tell when to show anonymous and when real user.
private Integer userId;
public void initView() {
beginConversation();
if(userId == null || userId == 0) {
userview.setUserid(permbean.getAnonEventUser().getUser().getId());
} else {
userview.setUserid(userId);
}
// TODO: permissionCheck
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public Place getPlace() {
return place;
}
public void setPlace(Place place) {
this.place = place;
}
public void reserveRemoteCommand() {
String placeIdString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("placeid");
logger.debug("selecting place with id: {}", placeIdString);
Integer placeId = null;
try {
placeId = Integer.parseInt(placeIdString);
} catch (NumberFormatException x) {
return;
}
Place place = placebean.find(placeId);
if(place.isTaken() && !place.isReservedFor(userview.getCurrentUser())) {
return; // not your place, sorry
}
if(place.isTaken()) {
placebean.releasePlace(place);
selectedPlaces.remove(place);
} else {
placebean.reservePlace(place, userview.getCurrentUser());
selectedPlaces.add(place);
}
}
public List<Place> getSelectedPlaces() {
return selectedPlaces;
}
public void reserveSelectedPlaces() {
if(selectedPlaces.size() > 0)
placebean.buySelectedPlaces(selectedPlaces, userview.getSelectedUser());
selectedPlaces = new ArrayList<>();
userMustGoAway = true;
}
public boolean isUserMustGoAway() {
return userMustGoAway;
}
}
...@@ -542,3 +542,8 @@ vip.delete=Poista ...@@ -542,3 +542,8 @@ vip.delete=Poista
tmp.yourpmscodes=PMS -koodisi tmp.yourpmscodes=PMS -koodisi
tmp.code=Koodi tmp.code=Koodi
submenu.temp.pms=Pms koodit submenu.temp.pms=Pms koodit
shop.buyForUser=Osta k\u00E4ytt\u00E4j\u00E4lle
shop.buyForUser.success=Ostettu k\u00E4ytt\u00E4j\u00E4lle onnistuneesti
submenu.info.placeReservation=Paikanvaraus
placeReservation.selectedPlaces=Valitut paikat
placeReservation.mapMultiuserNote=Jos sama k\u00E4ytt\u00E4j\u00E4 k\u00E4ytt\u00E4\u00E4 karttaa monelta koneelta, n\u00E4kyv\u00E4t kaikkien koneiden klikkailut kartassa sinisell\u00E4.
...@@ -1782,3 +1782,8 @@ vip.delete=Delete ...@@ -1782,3 +1782,8 @@ vip.delete=Delete
tmp.yourpmscodes=Your pms -codes tmp.yourpmscodes=Your pms -codes
tmp.code=Code tmp.code=Code
submenu.temp.pms=PMS codes submenu.temp.pms=PMS codes
shop.buyForUser=Buy for user
shop.buyForUser.success=Places buyd successfully for user\!
submenu.info.placeReservation=Placereservation
placeReservation.selectedPlaces=Selected places
placeReservation.mapMultiuserNote=If same user uses map from multible computers, you see all computers selections on blue.
...@@ -1767,3 +1767,8 @@ vip.delete=Poista ...@@ -1767,3 +1767,8 @@ vip.delete=Poista
tmp.yourpmscodes=PMS -koodisi tmp.yourpmscodes=PMS -koodisi
tmp.code=Koodi tmp.code=Koodi
submenu.temp.pms=PMS koodit submenu.temp.pms=PMS koodit
shop.buyForUser=Osta k\u00E4ytt\u00E4j\u00E4lle
shop.buyForUser.success=Paikat on ostettu onnistuneesti k\u00E4ytt\u00E4j\u00E4lle. Voit poistua sivulta\!
submenu.info.placeReservation=Paikanvaraus
placeReservation.selectedPlaces=Valitut paikat
placeReservation.mapMultiuserNote=Jos sama k\u00E4ytt\u00E4j\u00E4 k\u00E4ytt\u00E4\u00E4 karttaa monelta koneelta, n\u00E4kyv\u00E4t kaikkien koneiden klikkailut kartassa sinisell\u00E4.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!