Commit 86aba504 by Tuukka Kivilahti

GameCodes

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