Commit 695806c2 by Antti Tonkyra

tournament creation

1 parent c5592bac
eclipse.preferences.version=1
encoding/<project>=UTF-8
......@@ -28,6 +28,7 @@ public class BootstrapBean implements BootstrapBeanLocal {
// {"Query1","Query2",...}
dbUpdates.add(new String[] { "" }); // first version, no changes
dbUpdates.add(new String[] { "ALTER TABLE tournaments ADD COLUMN game integer NOT NULL REFERENCES tournament_games(id)" });
dbUpdates.add(new String[] { "ALTER TABLE tournaments ADD COLUMN rules integer NOT NULL REFERENCES tournament_rules(id)" });
// dbUpdates.add(new String[] { "ALTER TABLE users ALTER COLUMN birthday TYPE date" });
}
......
......@@ -6,6 +6,7 @@ import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import fi.codecrew.moya.facade.TournamentFacade;
import fi.codecrew.moya.facade.TournamentGameFacade;
import fi.codecrew.moya.facade.TournamentRuleFacade;
import fi.codecrew.moya.model.Tournament;
......@@ -21,6 +22,7 @@ public class TournamentBean implements TournamentBeanLocal {
@EJB private TournamentRuleFacade tournamentRuleFacade;
@EJB private TournamentGameFacade tournamentGameFacade;
@EJB private TournamentFacade tournamentFacade;
/**
* Default constructor.
......@@ -45,8 +47,8 @@ public class TournamentBean implements TournamentBeanLocal {
}
@Override
public void createRule(TournamentRule tr) {
tournamentRuleFacade.create(tr);
public TournamentRule createRule(TournamentRule tr) {
return tournamentRuleFacade.create(tr);
}
@Override
......@@ -58,4 +60,9 @@ public class TournamentBean implements TournamentBeanLocal {
public TournamentRule findRule(Integer id) {
return tournamentRuleFacade.find(id);
}
@Override
public void createTournament(Tournament tournament) {
tournamentFacade.create(tournament);
}
}
......@@ -4,6 +4,7 @@ import java.util.List;
import javax.ejb.Local;
import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.TournamentRule;
......@@ -13,8 +14,9 @@ public interface TournamentBeanLocal {
List<TournamentGame> getGames();
List<TournamentRule> getRulesByGame(TournamentGame tg);
void createGame(TournamentGame tg);
void createRule(TournamentRule tr);
TournamentRule createRule(TournamentRule tr);
TournamentGame findGame(Integer id);
TournamentRule findRule(Integer id);
void createTournament(Tournament tournament);
}
......@@ -63,6 +63,17 @@ public class Tournament extends GenericEntity implements Serializable {
@JoinColumn(name="game", nullable=false)
private TournamentGame tournamentGame;
@JoinColumn(name="rules", nullable=false)
private TournamentRule rules;
public TournamentRule getRules() {
return rules;
}
public void setRules(TournamentRule rules) {
this.rules = rules;
}
@OneToMany
@OrderBy("id ASC")
private List<Tournament> subTournaments;
......@@ -116,4 +127,60 @@ public class Tournament extends GenericEntity implements Serializable {
public void setTournamentGame(TournamentGame tournamentGame) {
this.tournamentGame = tournamentGame;
}
public LanEvent getLanEvent() {
return lanEvent;
}
public void setLanEvent(LanEvent lanEvent) {
this.lanEvent = lanEvent;
}
public Date getBeginsAt() {
return beginsAt;
}
public void setBeginsAt(Date beginsAt) {
this.beginsAt = beginsAt;
}
public TournamentStatus getTournamentStatus() {
return tournamentStatus;
}
public void setTournamentStatus(TournamentStatus tournamentStatus) {
this.tournamentStatus = tournamentStatus;
}
public TournamentMatch getTournamentRoot() {
return tournamentRoot;
}
public void setTournamentRoot(TournamentMatch tournamentRoot) {
this.tournamentRoot = tournamentRoot;
}
public Integer getPlayersPerMatch() {
return playersPerMatch;
}
public void setPlayersPerMatch(Integer playersPerMatch) {
this.playersPerMatch = playersPerMatch;
}
public Integer getPlayersPerTeam() {
return playersPerTeam;
}
public void setPlayersPerTeam(Integer playersPerTeam) {
this.playersPerTeam = playersPerTeam;
}
public List<Tournament> getSubTournaments() {
return subTournaments;
}
public void setSubTournaments(List<Tournament> subTournaments) {
this.subTournaments = subTournaments;
}
}
......@@ -62,6 +62,14 @@ public class TournamentRule extends GenericEntity implements Serializable {
public void setRules(String rules) {
this.rules = rules;
}
public TournamentGame getTournamentGame() {
return tournamentGame;
}
public void setTournamentGame(TournamentGame tournamentGame) {
this.tournamentGame = tournamentGame;
}
}
......@@ -16,13 +16,11 @@
<p:tab id="selectGame" title="#{i18n['tournaments.admin.select_a_game']}">
<p:panel>
<h:messages errorClass="error" />
<h:panelGroup rendered="#{tournamentCreateView.tournamentGames.isEmpty() eq false}">
<h2>#{i18n['tournaments.admin.select_a_game']}</h2>
<h:selectOneMenu value="#{tournamentCreateView.game}" converter="#{tournamentGameConverter}">
<f:selectItems var="game" itemLabel="#{game.name}" value="#{tournamentCreateView.tournamentGames}" itemValue="#{game.id}" />
<f:selectItems var="game" itemLabel="#{game.name}" value="#{tournamentCreateView.tournamentGames}" itemValue="#{game}" />
</h:selectOneMenu>
</h:panelGroup>
......@@ -40,15 +38,13 @@
<p:tab id="selectRuleset" title="#{i18n['tournaments.admin.rules']}">
<p:panel>
<h:messages errorClass="error" />
<h:messages errorClass="error" />
<h:panelGroup rendered="#{tournamentCreateView.tournamentRules.isEmpty() eq false}">
<h2>#{i18n['tournaments.admin.select_a_ruleset']}</h2>
<h:selectOneMenu value="#{tournamentCreateView.rules}" converter="#{tournamentRuleConverter}">
<f:selectItems var="rule" itemLabel="#{rule.name}" value="#{tournamentCreateView.tournamentRules}" itemValue="#{rule.id}" />
<f:selectItems var="rule" itemLabel="#{rule.name}" value="#{tournamentCreateView.tournamentRules}" itemValue="#{rule}" />
</h:selectOneMenu>
</h:panelGroup>
<br />
<h2>#{i18n['tournaments.admin.create_new_ruleset']}</h2>
<h:outputText value="#{i18n['tournaments.ruleset_name']}" />
......@@ -65,22 +61,48 @@
<p:tab id="selectRegTimes" title="#{i18n['tournaments.admin.set_time_constraints']}">
<p:panel>
<h:messages errorClass="error" />
<h2>#{i18n['tournaments.admin.registration_time_constraints']}</h2>
<h2>#{i18n['tournaments.tournament_details']}</h2>
<h:outputText value="#{i18n['tournaments.tournament_name']}" />
<br />
<p:inputText value="#{tournamentCreateView.tournament.tournamentName}" />
<br />
<h:outputText value="#{i18n['tournaments.tournament_type']}"/>
<br />
<h:selectOneMenu value="#{tournamentCreateView.tournament.tournamentType}">
<f:selectItems value="#{tournamentCreateView.tournamentTypes}" var="val" itemLabel="val" />
</h:selectOneMenu>
<h:outputText value="#{i18n['tournaments.players_per_match']}" />
<h:panelGrid columns="1" style="margin-bottom:10px">
<p:inputText id="playerSlider" value="#{tournamentCreateView.tournament.playersPerMatch}" />
<p:slider for="playerSlider" />
</h:panelGrid>
<h:outputText value="#{i18n['tournaments.backup_players']}" />
<h:panelGrid columns="1" style="margin-bottom:10px">
<p:inputText id="playerBackupSlider" value="#{tournamentCreateView.backupPlayers}" />
<p:slider for="playerBackupSlider" />
</h:panelGrid>
<h2>#{i18n['tournaments.admin.registration_time_constraints']}</h2>
<h:panelGrid columns="2">
<h:outputText value="#{i18n['tournaments.registration_opens']}" />
<h:outputText value="#{i18n['tournaments.registration_closes']}" />
<p:calendar stepHour="1" stepMinute="10" pattern="dd.MM.yyyy hh:mm" />
<p:calendar stepHour="1" stepMinute="10" pattern="dd.MM.yyyy hh:mm" />
<p:calendar stepHour="1" stepMinute="10" pattern="dd.MM.yyyy hh:mm" value="#{tournamentCreateView.tournament.registrationOpensAt}"/>
<p:calendar stepHour="1" stepMinute="10" pattern="dd.MM.yyyy hh:mm" value="#{tournamentCreateView.tournament.registrationClosesAt}"/>
</h:panelGrid>
<h2>#{i18n['tournaments.admin.begin_time_constraints']}</h2>
<h:panelGrid>
<h:outputText value="Start time" />
<p:calendar stepHour="1" stepMinute="10" pattern="dd.MM.yyyy hh:mm" />
<p:calendar stepHour="1" stepMinute="10" pattern="dd.MM.yyyy hh:mm" value="#{tournamentCreateView.tournament.beginsAt}"/>
</h:panelGrid>
</p:panel>
<div style="float: right;">
<p:commandButton icon="apply" value="#{i18n['tournaments.admin.create_tournament']}" />
<p:commandButton icon="apply" value="#{i18n['tournaments.admin.create_tournament']}" actionListener="#{tournamentCreateView.save}"/>
</div>
</p:tab>
</p:wizard>
......
......@@ -5,6 +5,8 @@ import java.util.List;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.enums.TournamentStatus;
import fi.codecrew.moya.enums.TournamentType;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.TournamentGame;
......@@ -36,6 +38,8 @@ public class TournamentCreateView extends GenericCDIView {
private String rulesetName;
private String rulesetDescription;
private Integer backupPlayers;
@EJB TournamentBeanLocal tournamentBean;
@EJB EventBeanLocal eventBean;
......@@ -43,13 +47,20 @@ public class TournamentCreateView extends GenericCDIView {
if(tournament == null) {
this.beginConversation();
tournament = new Tournament();
tournament.setPlayersPerMatch(0);
backupPlayers = 0;
tournamentGames = tournamentBean.getGames();
}
}
public void save(ActionEvent actionEvent) {
tournament.setPlayersPerTeam(tournament.getPlayersPerMatch() + backupPlayers);
tournament.setLanEvent(eventBean.getCurrentEvent());
tournament.setTournamentStatus(TournamentStatus.SETUP);
tournament.setTournamentGame(game);
tournament.setRules(rules);
tournamentBean.createTournament(tournament);
}
public List<TournamentGame> getTournamentGames() {
......@@ -63,6 +74,11 @@ public class TournamentCreateView extends GenericCDIView {
public void uploadListener(org.primefaces.event.FileUploadEvent event) {
System.out.println("ZZ");
}
public TournamentType[] getTournamentTypes() {
TournamentType[] items = TournamentType.values();
return items;
}
public String onFlowProcess(FlowEvent event) {
switch(event.getOldStep()) {
......@@ -77,19 +93,21 @@ public class TournamentCreateView extends GenericCDIView {
tournamentBean.createGame(tg);
}
tournamentRules = tournamentBean.getRulesByGame(this.getGame());
tournamentRules = tournamentBean.getRulesByGame(game);
System.out.println(tournamentRules);
break;
case "selectRuleset":
if(rulesetName != null && rulesetName.length() > 0) {
TournamentRule tr = new TournamentRule();
tr.setName(rulesetName);
tr.setDescription(rulesetDescription);
tr.setRules(rulesetDescription);
tr.setTournamentGame(game);
rules = tournamentBean.createRule(tr);
tournamentBean.createRule(tr);
tournamentRules = tournamentBean.getRulesByGame(game);
}
break;
}
System.out.println(event.getOldStep());
return event.getNewStep();
}
......@@ -140,4 +158,20 @@ public class TournamentCreateView extends GenericCDIView {
public void setRulesetDescription(String rulesetDescription) {
this.rulesetDescription = rulesetDescription;
}
public Tournament getTournament() {
return tournament;
}
public void setTournament(Tournament tournament) {
this.tournament = tournament;
}
public Integer getBackupPlayers() {
return backupPlayers;
}
public void setBackupPlayers(Integer backupPlayers) {
this.backupPlayers = backupPlayers;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!