Commit 6242fc9e by Tuukka Kivilahti

moar of gamecodes

1 parent c3aff761
...@@ -4,10 +4,15 @@ ...@@ -4,10 +4,15 @@
*/ */
package fi.codecrew.moya.model; package fi.codecrew.moya.model;
import java.util.List;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table; import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking; import org.eclipse.persistence.annotations.OptimisticLocking;
...@@ -42,6 +47,10 @@ public class Game extends GenericEntity { ...@@ -42,6 +47,10 @@ public class Game extends GenericEntity {
@ManyToOne @ManyToOne
private LanEvent event; private LanEvent event;
@OneToMany(mappedBy = "game", fetch = FetchType.LAZY)
@OrderBy()
private List<GameCode> gameCodes;
...@@ -121,4 +130,18 @@ public class Game extends GenericEntity { ...@@ -121,4 +130,18 @@ public class Game extends GenericEntity {
} }
public List<GameCode> getGameCodes() {
return gameCodes;
}
public void setGameCodes(List<GameCode> gameCodes) {
this.gameCodes = gameCodes;
}
} }
...@@ -24,24 +24,34 @@ ...@@ -24,24 +24,34 @@
<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}" /> <p:commandButton value="muokkaa" update=":editgame" >
<f:setPropertyActionListener value="#{game}" target="#{gameCodeView.currentGame}" />
</p:commandButton>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="game.codecount" />
</f:facet>
<h:outputText value="#{game.gameCodes.size()}" />
</p:column> </p:column>
<p: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}" /> <p:commandButton value="generoi kaikille paikoille" action="#{gameCodeView.generateSelectedToAllPlaces}">
<f:setPropertyActionListener value="#{game}" target="#{gameCodeView.currentGame}" />
</p:commandButton>
</p:column> </p:column>
</p:dataTable> </p:dataTable>
</h:form> </h:form>
<br /><br /> <br /><br />
<h:form> <h:form id="editgame" >
<p:panelGrid columns="2"> <p:panelGrid columns="2">
<f:facet name="header"> <f:facet name="header">
<h:outputLabel rendered="#{gameCodeView.currentGame.id == null}" value="#{i18n['gamecode.create']}" /> <h:outputLabel rendered="#{gameCodeView.currentGame.id == null}" value="#{i18n['game.create']}" />
<h:outputLabel rendered="#{gameCodeView.currentGame.id != null}" value="#{i18n['gamecode.edit']}" /> <h:outputLabel rendered="#{gameCodeView.currentGame.id != null}" value="#{i18n['game.edit']}" />
</f:facet> </f:facet>
<h:outputLabel value="service" /> <h:outputLabel value="service" />
<p:inputText value="#{gameCodeView.currentGame.service}" /> <p:inputText value="#{gameCodeView.currentGame.service}" />
...@@ -51,9 +61,26 @@ ...@@ -51,9 +61,26 @@
<p:inputText value="#{gameCodeView.currentGame.description}" /> <p:inputText value="#{gameCodeView.currentGame.description}" />
<h:outputLabel value="url" /> <h:outputLabel value="url" />
<p:inputText value="#{gameCodeView.currentGame.codeUrl}" /> <p:inputText value="#{gameCodeView.currentGame.codeUrl}" />
<h:commandButton action="#{gameCodeView.saveCurrentGame}" value="save" /> <p:commandButton action="#{gameCodeView.saveCurrentGame}" value="save" />
</p:panelGrid> </p:panelGrid>
</h:form> </h:form>
<h:form>
<p:commandButton id="cancelbtn" onclick="confirmation.show()" value="#{i18n['bill.cancel']}" />
<p:confirmDialog id="confirmDialog" message="#{i18n['generic.sure.message']}" header="#{i18n['generic.sure.header']}" severity="alert" widgetVar="confirmation">
<p:commandButton value="#{i18n['generic.sure.yes']}" onclick="confirmation.hide()" actionListener="#{billEditView.expireBill()}" ajax="false" />
<p:commandButton value="#{i18n['generic.sure.no']}" onclick="confirmation.hide()" type="button" />
</p:confirmDialog>
</h:form>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
<h:form> <h:form>
<h:outputLabel rendered="#{gameCodeView.noGameCodes}" value="#{i18n['game.noGameCodes']}" /> <h:outputLabel rendered="#{gameCodeView.noGameCodes}" value="#{i18n['game.noGameCodes']}" />
<p:dataTable rendered="#{not gameCodeView.noGameCodes}" columnClasses="nowrap,numalign,numalign,nowrap,numalign" styleClass="bordertable" 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">
...@@ -38,10 +37,10 @@ ...@@ -38,10 +37,10 @@
</p:column> </p:column>
<p:column sortBy="#{code.code}"> <p:column sortBy="#{code.code}">
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['gamecode.code']}" /> <h:outputText value="#{i18n['game.code']}" />
</f:facet> </f:facet>
<h:outputText rendered="#{not code.accessed}" value="ei avattu" /> <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['game.open']}" action="#{gameCodeView.openSelectedCode}" />
<h:outputText rendered="#{code.accessed}" value="#{code.code}" /> <h:outputText rendered="#{code.accessed}" value="#{code.code}" />
</p:column> </p:column>
</p:dataTable> </p:dataTable>
......
...@@ -85,6 +85,10 @@ error.error = You have encountered an error. ...@@ -85,6 +85,10 @@ error.error = You have encountered an error.
eventorg.create = Create eventorg.create = Create
game.create = Create
game.edit = Edit
game.out = Gamecodes are out, pleace contact administration
generic.sure.header = Confirmation generic.sure.header = Confirmation
generic.sure.message = Are you sure? generic.sure.message = Are you sure?
generic.sure.no = No generic.sure.no = No
......
...@@ -277,11 +277,14 @@ foodwavetemplate.startTime = Foodwave time ...@@ -277,11 +277,14 @@ foodwavetemplate.startTime = Foodwave time
foodwavetemplate.waveName = Wave name foodwavetemplate.waveName = Wave name
game.code = Code game.code = Code
game.create = Create
game.description = Description game.description = Description
game.edit = Edit
game.gamepoints = Game points game.gamepoints = Game points
game.name = Name game.name = Name
game.noGameCodes = You have no gamecodes game.noGameCodes = You have no gamecodes
game.open = Open code game.open = Open code
game.out = Please contact out customer service
game.service = Game service game.service = Game service
gamepoints = Gamepoints gamepoints = Gamepoints
......
...@@ -277,11 +277,14 @@ foodwavetemplate.startTime = Tilausaika ...@@ -277,11 +277,14 @@ foodwavetemplate.startTime = Tilausaika
foodwavetemplate.waveName = Tilauksen nimi foodwavetemplate.waveName = Tilauksen nimi
game.code = Koodi game.code = Koodi
game.create = Luo
game.description = Kuvaus game.description = Kuvaus
game.edit = Muokkaa
game.gamepoints = Insomnia Game pisteet: game.gamepoints = Insomnia Game pisteet:
game.name = Nimi game.name = Nimi
game.noGameCodes = Sinulla ei ole pelikoodeja game.noGameCodes = Sinulla ei ole pelikoodeja
game.open = Ota koodi k\u00E4ytt\u00F6\u00F6n game.open = Ota koodi k\u00E4ytt\u00F6\u00F6n
game.out = Ei voitu avata pelikoodia, ota yhteytt\u00E4 asiakaspalveluun.
game.service = Pelipalvelu game.service = Pelipalvelu
gamepoints = Pelipisteit\u00E4 gamepoints = Pelipisteit\u00E4
......
...@@ -10,6 +10,9 @@ import javax.inject.Named; ...@@ -10,6 +10,9 @@ import javax.inject.Named;
import fi.codecrew.moya.beans.EventBeanLocal; import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.GameBeanLocal; import fi.codecrew.moya.beans.GameBeanLocal;
import fi.codecrew.moya.enums.apps.BillPermission;
import fi.codecrew.moya.enums.apps.GamePermission;
import fi.codecrew.moya.model.Bill;
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;
...@@ -21,98 +24,101 @@ import fi.codecrew.moya.web.cdiview.GenericCDIView; ...@@ -21,98 +24,101 @@ import fi.codecrew.moya.web.cdiview.GenericCDIView;
public class GameCodeView extends GenericCDIView { public class GameCodeView extends GenericCDIView {
private static final long serialVersionUID = -8346420143750551402L; private static final long serialVersionUID = -8346420143750551402L;
@Inject @Inject
@SelectedUser @SelectedUser
private EventUser user; private EventUser user;
@EJB @EJB
EventBeanLocal eventBean; EventBeanLocal eventBean;
@EJB @EJB
GameBeanLocal gameBean; GameBeanLocal gameBean;
ListDataModel<Game> gamesDataModel; ListDataModel<Game> gamesDataModel;
ListDataModel<GameCode> gameCodesDataModel; ListDataModel<GameCode> gameCodesDataModel;
private Game currentGame; private Game currentGame;
public void initAdminView() { public void initAdminView() {
if(gamesDataModel == null) {
this.currentGame = new Game(); if (super.requirePermissions(GamePermission.MANAGE)) {
this.currentGame.setEvent(eventBean.getCurrentEvent()); if (gamesDataModel == null) {
this.gamesDataModel = new ListDataModel<Game>(gameBean.findAll(eventBean.getCurrentEvent())); this.currentGame = new Game();
this.beginConversation(); this.currentGame.setEvent(eventBean.getCurrentEvent());
this.gamesDataModel = new ListDataModel<Game>(gameBean.findAll(eventBean.getCurrentEvent()));
this.beginConversation();
}
} }
} }
public void initUserView() { public void initUserView() {
if(gamesDataModel == null) { if (super.requirePermissions(GamePermission.VIEW_OWN_CODES)) {
this.gameCodesDataModel = new ListDataModel<GameCode>(gameBean.findUserCodes(user)); if (gamesDataModel == null) {
System.out.println("codecount: "+gameCodesDataModel.getRowCount()); this.gameCodesDataModel = new ListDataModel<GameCode>(gameBean.findUserCodes(user));
this.beginConversation(); System.out.println("codecount: " + gameCodesDataModel.getRowCount());
this.beginConversation();
}
} }
} }
public ListDataModel<Game> getGames() { public ListDataModel<Game> getGames() {
return gamesDataModel; return gamesDataModel;
} }
public ListDataModel<GameCode> getGameCodes() { public ListDataModel<GameCode> getGameCodes() {
return gameCodesDataModel; return gameCodesDataModel;
} }
public Game getCurrentGame() { public Game getCurrentGame() {
return this.currentGame; return this.currentGame;
} }
public void setCurrentGame(Game game) {
this.currentGame = game;
}
public String saveCurrentGame() { public String saveCurrentGame() {
gameBean.saveOrCreateGame(currentGame); gameBean.saveOrCreateGame(currentGame);
return null; return null;
} }
public String generateSelectedToAllPlaces() { public String generateSelectedToAllPlaces() {
if(gamesDataModel != null && gamesDataModel.isRowAvailable()) { if (gamesDataModel != null && gamesDataModel.isRowAvailable()) {
Game game = gamesDataModel.getRowData(); Game game = gamesDataModel.getRowData();
gameBean.generateCodesForAllPlaces(game); gameBean.generateCodesForAllPlaces(game);
} }
return null; return null;
} }
public String editSelected() { public String editSelected() {
if(gamesDataModel != null && gamesDataModel.isRowAvailable()) { /*if (gamesDataModel != null && gamesDataModel.isRowAvailable()) {
currentGame = gamesDataModel.getRowData(); currentGame = gamesDataModel.getRowData();
} }*/
return null; return null;
} }
public String openSelectedCode() { public String openSelectedCode() {
if(gameCodesDataModel != null && gameCodesDataModel.isRowAvailable()) { if (gameCodesDataModel != null && gameCodesDataModel.isRowAvailable()) {
GameCode code = gameCodesDataModel.getRowData(); GameCode code = gameCodesDataModel.getRowData();
if(!gameBean.accessCode(code, user)) { if (!gameBean.accessCode(code, user)) {
this.addFaceMessage("gamecode.out"); this.addFaceMessage("game.out");
} }
} }
return null; return null;
} }
public boolean isNoGameCodes() { public boolean isNoGameCodes() {
return (getGameCodes().getRowCount() <= 0); return (getGameCodes().getRowCount() <= 0);
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!