Commit 86aba504 by Tuukka Kivilahti

GameCodes

1 parent 5b2d2f0c
...@@ -18,6 +18,7 @@ import fi.codecrew.moya.model.EventMap; ...@@ -18,6 +18,7 @@ import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Game; import fi.codecrew.moya.model.Game;
import fi.codecrew.moya.model.GameCode; import fi.codecrew.moya.model.GameCode;
import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.LanEvent; import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Place; import fi.codecrew.moya.model.Place;
...@@ -55,8 +56,11 @@ public class GameBean implements GameBeanLocal { ...@@ -55,8 +56,11 @@ public class GameBean implements GameBeanLocal {
// first get free gamecodes from user places // first get free gamecodes from user places
if(user.getCurrentPlaces() != null) { if(user.getCurrentPlaces() != null) {
for(Place place : user.getCurrentPlaces()) { for(GroupMembership memberShip : user.getGroupMemberships()) {
for(GameCode placeGameCode : place.getGameCodes()) { if(memberShip.getPlaceReservation() == null)
continue;
for(GameCode placeGameCode : memberShip.getPlaceReservation().getGameCodes()) {
if(placeGameCode.getUser() == null) { if(placeGameCode.getUser() == null) {
returnCodes.add(placeGameCode); returnCodes.add(placeGameCode);
} }
...@@ -76,11 +80,11 @@ public class GameBean implements GameBeanLocal { ...@@ -76,11 +80,11 @@ public class GameBean implements GameBeanLocal {
* *
* @param code * @param code
*/ */
private void generateCode(GameCode code) { private boolean generateCode(GameCode code) {
if (code.getCode() == null || code.getCode().trim().equals("")) { if (code.getCode() == null || code.getCode().trim().equals("")) {
if (code.getGame().getCodeUrl() == null || code.getGame().getCodeUrl().trim().equals("")) if (code.getGame().getCodeUrl() == null || code.getGame().getCodeUrl().trim().equals(""))
return; return false;
try { try {
URL url = new URL(code.getGame().getCodeUrl()); URL url = new URL(code.getGame().getCodeUrl());
...@@ -94,35 +98,47 @@ public class GameBean implements GameBeanLocal { ...@@ -94,35 +98,47 @@ public class GameBean implements GameBeanLocal {
String tmpLine; String tmpLine;
while ((tmpLine = in.readLine()) != null) { while ((tmpLine = in.readLine()) != null) {
if (!code.equals("")) { if (!codeString.equals("")) {
codeString += "\n"; codeString += "\n";
} }
codeString += tmpLine; codeString += tmpLine;
} }
if(codeString.trim().equals("0") || codeString.trim().equals("")) {
return false;
}
code.setCode(codeString); code.setCode(codeString);
code = gameCodeFacade.merge(code); code = gameCodeFacade.merge(code);
return true;
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
return false;
} }
public void accessCode(GameCode code, EventUser user) { public boolean accessCode(GameCode code, EventUser user) {
if(code.getUser() != null) if(code.getUser() != null)
return; return false;
if(!generateCode(code)) {
return false;
}
generateCode(code);
if (!code.isAccessed()) { if (!code.isAccessed()) {
code.setAccessed(Calendar.getInstance()); code.setAccessed(Calendar.getInstance());
code.setUser(user.getUser()); code.setUser(user.getUser());
code = gameCodeFacade.merge(code); code = gameCodeFacade.merge(code);
user.getUser().getGameCodes().add(code); user.getUser().getGameCodes().add(code);
} }
return true;
} }
public List<Game> findAll(LanEvent event) { public List<Game> findAll(LanEvent event) {
......
...@@ -13,7 +13,7 @@ import fi.codecrew.moya.model.Place; ...@@ -13,7 +13,7 @@ import fi.codecrew.moya.model.Place;
@Local @Local
public interface GameBeanLocal { public interface GameBeanLocal {
public GameCode getCode(Place place); public GameCode getCode(Place place);
public void accessCode(GameCode code, EventUser user); public boolean accessCode(GameCode code, EventUser user);
public List<Game> findAll(LanEvent event); public List<Game> findAll(LanEvent event);
public void saveOrCreateGame(Game game); public void saveOrCreateGame(Game game);
public List<GameCode> findUserCodes(EventUser user); public List<GameCode> findUserCodes(EventUser user);
......
...@@ -28,6 +28,9 @@ public class Game extends GenericEntity { ...@@ -28,6 +28,9 @@ public class Game extends GenericEntity {
@Column(name = "name") @Column(name = "name")
private String name; private String name;
@Column(name = "service")
private String service;
@Column(name = "description") @Column(name = "description")
private String description; private String description;
...@@ -104,4 +107,18 @@ public class Game extends GenericEntity { ...@@ -104,4 +107,18 @@ public class Game extends GenericEntity {
} }
public String getService() {
return service;
}
public void setService(String service) {
this.service = service;
}
} }
...@@ -30,9 +30,9 @@ public class GameCode extends GenericEntity { ...@@ -30,9 +30,9 @@ public class GameCode extends GenericEntity {
@Column(name = "accessed", nullable = false) @Column(name = "accessed", nullable = true)
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar accessed = Calendar.getInstance(); private Calendar accessed = null;
......
...@@ -59,6 +59,7 @@ public class GroupMembership extends GenericEntity { ...@@ -59,6 +59,7 @@ public class GroupMembership extends GenericEntity {
private Place placeReservation; private Place placeReservation;
@JoinColumn(name = EVENTUSER_ID, referencedColumnName = EventUser.ID_COLUMN) @JoinColumn(name = EVENTUSER_ID, referencedColumnName = EventUser.ID_COLUMN)
@ManyToOne @ManyToOne
private EventUser user; private EventUser user;
......
<!DOCTYPE html <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "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:products="http://java.sun.com/jsf/composite/tools/products" xmlns:tools="http://java.sun.com/jsf/composite/tools" xmlns:f="http://java.sun.com/jsf/core"> <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:products="http://java.sun.com/jsf/composite/tools/products" xmlns:tools="http://java.sun.com/jsf/composite/tools" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui">
<h:body> <h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml"> <ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<f:metadata> <f:metadata>
...@@ -13,38 +13,46 @@ ...@@ -13,38 +13,46 @@
<ui:define name="content"> <ui:define name="content">
<h:form> <h:form>
<h:dataTable border="1" id="games" value="#{gameCodeView.games}" var="game"> <p:dataTable border="1" id="games" value="#{gameCodeView.games}" var="game">
<h:column> <p:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="${i18n['game.name']}" /> <h:outputText value="${i18n['game.name']}" />
</f:facet> </f:facet>
<h:outputText value="#{game.name}" /> <h:outputText value="#{game.name}" />
</h:column> </p:column>
<h:column> <p:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="edit" /> <h:outputText value="edit" />
</f:facet> </f:facet>
<h:commandButton value="muokkaa" action="#{gameCodeView.editSelected}" /> <h:commandButton value="muokkaa" action="#{gameCodeView.editSelected}" />
</h:column> </p:column>
<h:column> <p:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="GENEROI" /> <h:outputText value="GENEROI" />
</f:facet> </f:facet>
<h:commandButton value="generoi kaikille paikoille" action="#{gameCodeView.generateSelectedToAllPlaces}" /> <h:commandButton value="generoi kaikille paikoille" action="#{gameCodeView.generateSelectedToAllPlaces}" />
HOX: ei vielä valmis, älä paina, oikeasti! </p:column>
</p:dataTable>
</h:column>
</h:dataTable>
</h:form> </h:form>
<br /><br />
<h:form> <h:form>
<p:panelGrid columns="2">
<f:facet name="header">
<h:outputLabel rendered="#{gameCodeView.currentGame.id == null}" value="#{i18n['gamecode.create']}" />
<h:outputLabel rendered="#{gameCodeView.currentGame.id != null}" value="#{i18n['gamecode.edit']}" />
</f:facet>
<h:outputLabel value="service" />
<p:inputText value="#{gameCodeView.currentGame.service}" />
<h:outputLabel value="name" /> <h:outputLabel value="name" />
<h:inputText value="#{gameCodeView.currentGame.name}" /> <p:inputText value="#{gameCodeView.currentGame.name}" />
<h:outputLabel value="description" /> <h:outputLabel value="description" />
<h:inputText value="#{gameCodeView.currentGame.description}" /> <p:inputText value="#{gameCodeView.currentGame.description}" />
<h:outputLabel value="url" /> <h:outputLabel value="url" />
<h:inputText value="#{gameCodeView.currentGame.codeUrl}" /> <p:inputText value="#{gameCodeView.currentGame.codeUrl}" />
<h:commandButton action="#{gameCodeView.saveCurrentGame}" value="save" /> <h:commandButton action="#{gameCodeView.saveCurrentGame}" value="save" />
</p:panelGrid>
</h:form> </h:form>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
......
<!DOCTYPE html <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "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:products="http://java.sun.com/jsf/composite/tools/products" xmlns:tools="http://java.sun.com/jsf/composite/tools" xmlns:f="http://java.sun.com/jsf/core"> <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:products="http://java.sun.com/jsf/composite/tools/products" xmlns:tools="http://java.sun.com/jsf/composite/tools" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui">
<h:body> <h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml"> <ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.gamecode.viewCodes" /> <ui:param name="thispage" value="page.gamecode.viewCodes" />
...@@ -17,27 +17,34 @@ ...@@ -17,27 +17,34 @@
<h:outputLabel rendered="#{gameCodeView.noGameCodes}" value="#{i18n['game.noGameCodes']}" /> <h:outputLabel rendered="#{gameCodeView.noGameCodes}" value="#{i18n['game.noGameCodes']}" />
<h:dataTable rendered="#{not gameCodeView.noGameCodes}" border="1" id="codes" value="#{gameCodeView.gameCodes}" var="code"> <p:dataTable rendered="#{not gameCodeView.noGameCodes}" columnClasses="nowrap,numalign,numalign,nowrap,numalign" styleClass="bordertable" id="codes" value="#{gameCodeView.gameCodes}" var="code">
<h:column> <p:column sortBy="#{code.game.service}">
<f:facet name="header">
<h:outputText value="#{i18n['game.service']}" />
</f:facet>
<h:outputText value="#{code.game.service}" />
</p:column>
<p:column sortBy="#{code.game.name}">
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['game.name']}" /> <h:outputText value="#{i18n['game.name']}" />
</f:facet> </f:facet>
<h:outputText value="#{code.game.name}" /> <h:outputText value="#{code.game.name}" />
</h:column> </p:column>
<h:column> <p:column sortBy="#{code.game.description}">
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['game.description']}" /> <h:outputText value="#{i18n['game.description']}" />
</f:facet> </f:facet>
<h:outputText value="#{code.game.description}" /> <h:outputText value="#{code.game.description}" />
</h:column> </p:column>
<h:column> <p:column sortBy="#{code.code}">
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['gamecode.code']}" /> <h:outputText value="#{i18n['gamecode.code']}" />
</f:facet> </f:facet>
<h:outputText rendered="#{not code.accessed}" value="ei avattu" />
<h:commandButton rendered="#{not code.accessed}" value="#{i18n['gamecode.open']}" action="#{gameCodeView.openSelectedCode}" /> <h:commandButton rendered="#{not code.accessed}" value="#{i18n['gamecode.open']}" action="#{gameCodeView.openSelectedCode}" />
<h:outputText rendered="#{code.accessed}" value="#{code.code}" /> <h:outputText rendered="#{code.accessed}" value="#{code.code}" />
</h:column> </p:column>
</h:dataTable> </p:dataTable>
</h:form> </h:form>
</ui:define> </ui:define>
......
...@@ -136,6 +136,6 @@ resetMail.username = Username ...@@ -136,6 +136,6 @@ resetMail.username = Username
resetmailSent.body = Email has been sent containing a link where you can change the password. resetmailSent.body = Email has been sent containing a link where you can change the password.
resetmailSent.header = Email sent resetmailSent.header = Email sent
subnavi.cards = \t\t subnavi.cards = \u0009\u0009
user.unauthenticated = Kirjautumaton user.unauthenticated = Kirjautumaton
...@@ -270,7 +270,13 @@ foodwavetemplate.selectproducts = Products ...@@ -270,7 +270,13 @@ foodwavetemplate.selectproducts = Products
foodwavetemplate.startTime = Foodwave time foodwavetemplate.startTime = Foodwave time
foodwavetemplate.waveName = Wave name foodwavetemplate.waveName = Wave name
game.code = Code
game.description = Description
game.gamepoints = Game points game.gamepoints = Game points
game.name = Name
game.noGameCodes = You have no gamecodes
game.open = Open code
game.service = Game service
gamepoints = Gamepoints gamepoints = Gamepoints
...@@ -759,6 +765,7 @@ topnavi.createuser = Create user ...@@ -759,6 +765,7 @@ topnavi.createuser = Create user
topnavi.event = Event topnavi.event = Event
topnavi.foodwave = Food topnavi.foodwave = Food
topnavi.frontpage = Front page topnavi.frontpage = Front page
topnavi.game = Gamecodes
topnavi.log = Log topnavi.log = Log
topnavi.maps = Maps topnavi.maps = Maps
topnavi.placemap = Map topnavi.placemap = Map
......
...@@ -270,7 +270,13 @@ foodwavetemplate.selectproducts = Tuotteet ...@@ -270,7 +270,13 @@ foodwavetemplate.selectproducts = Tuotteet
foodwavetemplate.startTime = Tilausaika foodwavetemplate.startTime = Tilausaika
foodwavetemplate.waveName = Tilauksen nimi foodwavetemplate.waveName = Tilauksen nimi
game.code = Koodi
game.description = Kuvaus
game.gamepoints = Insomnia Game pisteet: game.gamepoints = Insomnia Game pisteet:
game.name = Nimi
game.noGameCodes = Sinulla ei ole pelikoodeja
game.open = Ota koodi k\u00E4ytt\u00F6\u00F6n
game.service = Pelipalvelu
gamepoints = Pelipisteit\u00E4 gamepoints = Pelipisteit\u00E4
...@@ -742,6 +748,7 @@ topnavi.createuser = Luo k\u00E4ytt\u00E4j\u00E4 ...@@ -742,6 +748,7 @@ topnavi.createuser = Luo k\u00E4ytt\u00E4j\u00E4
topnavi.event = Tapahtuma topnavi.event = Tapahtuma
topnavi.foodwave = Ruokatilaus topnavi.foodwave = Ruokatilaus
topnavi.frontpage = Etusivu topnavi.frontpage = Etusivu
topnavi.game = Pelikoodit
topnavi.log = Logi topnavi.log = Logi
topnavi.maps = Kartat topnavi.maps = Kartat
topnavi.placemap = Paikkakartta topnavi.placemap = Paikkakartta
......
...@@ -2,6 +2,8 @@ package fi.codecrew.moya.web.cdiview.game; ...@@ -2,6 +2,8 @@ package fi.codecrew.moya.web.cdiview.game;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped; import javax.enterprise.context.ConversationScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.model.ListDataModel; import javax.faces.model.ListDataModel;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
...@@ -50,6 +52,7 @@ public class GameCodeView extends GenericCDIView { ...@@ -50,6 +52,7 @@ public class GameCodeView extends GenericCDIView {
public void initUserView() { public void initUserView() {
if(gamesDataModel == null) { if(gamesDataModel == null) {
this.gameCodesDataModel = new ListDataModel<GameCode>(gameBean.findUserCodes(user)); this.gameCodesDataModel = new ListDataModel<GameCode>(gameBean.findUserCodes(user));
System.out.println("codecount: "+gameCodesDataModel.getRowCount());
this.beginConversation(); this.beginConversation();
} }
} }
...@@ -97,7 +100,9 @@ public class GameCodeView extends GenericCDIView { ...@@ -97,7 +100,9 @@ public class GameCodeView extends GenericCDIView {
if(gameCodesDataModel != null && gameCodesDataModel.isRowAvailable()) { if(gameCodesDataModel != null && gameCodesDataModel.isRowAvailable()) {
GameCode code = gameCodesDataModel.getRowData(); GameCode code = gameCodesDataModel.getRowData();
gameBean.accessCode(code, user); if(!gameBean.accessCode(code, user)) {
this.addFaceMessage("gamecode.out");
}
} }
return null; return null;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!