Commit 7245a590 by Antti Tonkyra

Tournament stuff, MessageHelper

1 parent 8e02a635
...@@ -68,7 +68,28 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -68,7 +68,28 @@ public class TournamentBean implements TournamentBeanLocal {
} }
@Override @Override
public List<Tournament> getTournamentsInStatus(TournamentStatus status) {
return tournamentFacade.getTournamentsInStatus(status);
}
@Override
public List<Tournament> getActiveTournaments() { public List<Tournament> getActiveTournaments() {
return tournamentFacade.getTournamentsNotInStatus(TournamentStatus.COMPLETED); return tournamentFacade.getTournamentsNotInStatus(TournamentStatus.COMPLETED);
} }
@Override
public Tournament getTournamentById(Integer tournamentId) {
return tournamentFacade.find(tournamentId);
}
@Override
public void editTournament(Tournament tournament) {
tournamentFacade.merge(tournament);
}
@Override
public void deleteTournament(Tournament tournament) {
tournament = tournamentFacade.merge(tournament);
tournamentFacade.remove(tournament);
}
} }
...@@ -30,5 +30,14 @@ public class TournamentFacade extends IntegerPkGenericFacade<Tournament> { ...@@ -30,5 +30,14 @@ public class TournamentFacade extends IntegerPkGenericFacade<Tournament> {
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
} }
public List<Tournament> getTournamentsInStatus(TournamentStatus status) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Tournament> cq = cb.createQuery(Tournament.class);
Root<Tournament> root = cq.from(Tournament.class);
cq.where(cb.equal(root.get(Tournament_.tournamentStatus), status));
return getEm().createQuery(cq).getResultList();
}
} }
...@@ -4,6 +4,7 @@ import java.util.List; ...@@ -4,6 +4,7 @@ import java.util.List;
import javax.ejb.Local; import javax.ejb.Local;
import fi.codecrew.moya.enums.TournamentStatus;
import fi.codecrew.moya.model.Tournament; import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.TournamentGame; import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.TournamentRule; import fi.codecrew.moya.model.TournamentRule;
...@@ -19,5 +20,9 @@ public interface TournamentBeanLocal { ...@@ -19,5 +20,9 @@ public interface TournamentBeanLocal {
TournamentRule findRule(Integer id); TournamentRule findRule(Integer id);
void createTournament(Tournament tournament); void createTournament(Tournament tournament);
List<Tournament> getActiveTournaments(); List<Tournament> getActiveTournaments();
List<Tournament> getTournamentsInStatus(TournamentStatus status);
Tournament getTournamentById(Integer tournamentId);
void editTournament(Tournament tournament);
void deleteTournament(Tournament tournament);
} }
package fi.codecrew.moya.utilities.jsf;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import fi.codecrew.moya.utilities.I18n;
public class MessageHelper {
public static void msg(String message, FacesMessage.Severity severity) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(severity, I18n.get(message), null));
}
public static void err(String message) {
msg(message, FacesMessage.SEVERITY_ERROR);
}
public static void info(String message) {
msg(message, FacesMessage.SEVERITY_INFO);
}
public static void fatal(String message) {
msg(message, FacesMessage.SEVERITY_FATAL);
}
public static void warn(String message) {
msg(message, FacesMessage.SEVERITY_WARN);
}
}
<!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:users="http://java.sun.com/jsf/composite/cditools/user" xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
</f:metadata>
<ui:define name="content">
<h1>#{i18n['tournaments.admin.remove_title']}</h1>
<p>#{i18n['tournaments.admin.remove_confirmation_text']}</p>
<h:form>
<p:commandButton value="#{i18n['tournament.admin.delete_cancel']}" action="#{tournamentDeleteView.cancel}" />
<p:commandButton value="#{i18n['tournament.admin.delete_confirm']}" action="#{tournamentDeleteView.delete}" />
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!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:users="http://java.sun.com/jsf/composite/cditools/user" xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
</f:metadata>
<ui:define name="content">
<h1>#{i18n['tournaments.admin.create_tournament']}</h1>
<h:form>
<h2>#{i18n['tournaments.tournament_details']}</h2>
<h:panelGrid columns="2">
<h:outputText value="#{i18n['tournaments.tournament_name']}" />
<p:inputText value="#{tournamentEditView.tournament.tournamentName}" />
<h:outputText value="#{i18n['tournaments.max_participants']}" />
<h:panelGroup>
<p:inputText id="maxPartSlider" value="#{tournamentEditView.tournament.maxParticipants}" />
<p:slider for="maxPartSlider" />
</h:panelGroup>
</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" value="#{tournamentEditView.tournament.registrationOpensAt}"/>
<p:calendar stepHour="1" stepMinute="10" pattern="dd.MM.yyyy hh:mm" value="#{tournamentEditView.tournament.registrationClosesAt}"/>
</h:panelGrid>
<h2>#{i18n['tournaments.admin.begin_time_constraints']}</h2>
<h:panelGrid columns="2">
<h:outputText value="#{i18n['tournaments.start_time']}" />
<p:calendar stepHour="1" stepMinute="10" pattern="dd.MM.yyyy hh:mm" value="#{tournamentEditView.tournament.beginsAt}"/>
</h:panelGrid>
<p:commandButton value="#{i18n['tournaments.admin.cancel_edits']}" action="#{tournamentEditView.cancel}"/>
<p:commandButton value="#{i18n['tournaments.admin.edit_tournament']}" action="#{tournamentEditView.commit}"/>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
...@@ -5,58 +5,66 @@ ...@@ -5,58 +5,66 @@
<h:body> <h:body>
<ui:composition template="#{sessionHandler.template}"> <ui:composition template="#{sessionHandler.template}">
<f:metadata> <f:metadata>
<!-- <f:event type="preRenderView" listener="#{userOverviewView.initView()}" /> -->
</f:metadata> </f:metadata>
<ui:define name="content"> <ui:define name="content">
<h1>#{i18n['tournaments.admin.title']}</h1> <h1>#{i18n['tournaments.admin.title']}</h1>
<p>#{i18n['tournaments.admin.description']}</p> <p>#{i18n['tournaments.admin.description']}</p>
<h2>#{i18n['tournaments.active_tournaments']}</h2> <h2>#{i18n['tournaments.active_tournaments']}</h2>
<p:dataTable value="#{tournamentAdminView.activeTournaments}" var="tournament"> <h:form>
<p:column> <p:dataTable value="#{tournamentAdminView.activeTournaments}" var="tournament">
<f:facet name="header"> <p:column>
<h:outputText value="#{i18n['tournament.name']}" /> <f:facet name="header">
</f:facet> <h:outputText value="#{i18n['tournament.name']}" />
<h:outputText value="#{tournament.tournamentName}" /> </f:facet>
</p:column> <h:outputText value="#{tournament.tournamentName}" />
<p:column> </p:column>
<f:facet name="header"> <p:column>
<h:outputText value="#{i18n['tournament.status']}" /> <f:facet name="header">
</f:facet> <h:outputText value="#{i18n['tournament.status']}" />
<h:outputText value="#{i18n[tournament.tournamentStatus.i18nKey]}" /> </f:facet>
</p:column> <h:outputText value="#{i18n[tournament.tournamentStatus.i18nKey]}" />
<p:column> </p:column>
<f:facet name="header"> <p:column>
<h:outputText value="#{i18n['tournament.type']}" /> <f:facet name="header">
</f:facet> <h:outputText value="#{i18n['tournament.type']}" />
<h:outputText value="#{i18n[tournament.tournamentType.i18nKey]}" /> </f:facet>
</p:column> <h:outputText value="#{i18n[tournament.tournamentType.i18nKey]}" />
<p:column> </p:column>
<f:facet name="header"> <p:column>
<h:outputText value="#{i18n['tournament.fillamount']}" /> <f:facet name="header">
</f:facet> <h:outputText value="#{i18n['tournament.fillamount']}" />
<h:outputText value="#{tournament.participants.size()}/#{tournament.maxParticipants}" /> </f:facet>
</p:column> <h:outputText value="#{tournament.participants.size()}/#{tournament.maxParticipants}" />
<p:column> </p:column>
<f:facet name="header"> <p:column>
<h:outputText value="#{i18n['tournament.playerspermatch_slash_teamsize']}" /> <f:facet name="header">
</f:facet> <h:outputText value="#{i18n['tournament.playerspermatch_slash_teamsize']}" />
<h:outputText value="#{tournament.playersPerMatch}/#{tournament.playersPerTeam}" /> </f:facet>
</p:column> <h:outputText value="#{tournament.playersPerMatch}/#{tournament.playersPerTeam}" />
<p:column> </p:column>
<f:facet name="header"> <p:column>
<h:outputText value="#{i18n['tournament.game']}" /> <f:facet name="header">
</f:facet> <h:outputText value="#{i18n['tournament.game']}" />
<h:outputText value="#{tournament.tournamentGame.name}" /> </f:facet>
</p:column> <h:outputText value="#{tournament.tournamentGame.name}" />
<p:column> </p:column>
<f:facet name="header"> <p:column>
<h:outputText value="#{i18n['tournament.rules']}" /> <f:facet name="header">
</f:facet> <h:outputText value="#{i18n['tournament.rules']}" />
<h:outputText value="#{tournament.rules.name}" /> </f:facet>
</p:column> <h:outputText value="#{tournament.rules.name}" />
</p:dataTable> </p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.admin.control']}" />
</f:facet>
<p:commandButton value="#{i18n['tournament.admin.edit']}" action="#{tournamentEditView.showEdit(tournament.id)}"/>
<p:commandButton value="#{i18n['tournament.admin.delete']}" action="#{tournamentDeleteView.showConfirm(tournament.id)}"/>
</p:column>
</p:dataTable>
</h:form>
<h:form> <h:form>
<p:commandButton value="#{i18n['tournament.admin.create']}" action="#{tournamentAdminView.create}" /> <p:commandButton value="#{i18n['tournament.admin.create']}" action="#{tournamentAdminView.create}" />
</h:form> </h:form>
......
...@@ -5,15 +5,54 @@ ...@@ -5,15 +5,54 @@
<h:body> <h:body>
<ui:composition template="#{sessionHandler.template}"> <ui:composition template="#{sessionHandler.template}">
<f:metadata> <f:metadata>
<!-- <f:event type="preRenderView" listener="#{userOverviewView.initView()}" /> --> <f:event type="preRenderView" listener="#{tournamentListView.initView()}" />
</f:metadata> </f:metadata>
<ui:define name="content"> <ui:define name="content">
<h1>#{i18n['tournaments.title']}</h1>
<h1>Tournaments</h1> <p>#{i18n['tournaments.description']}</p>
<h:panelGroup rendered="#{not empty tournamentListView.setupPhaseTournaments}">
<h2>#{i18n['tournaments.open_tournaments']}</h2>
<p:dataTable value="#{tournamentListView.setupPhaseTournaments}" var="tournament">
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.name']}" />
</f:facet>
<h:outputText value="#{tournament.tournamentName}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.status']}" />
</f:facet>
<h:outputText value="#{i18n[tournament.tournamentStatus.i18nKey]}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.type']}" />
</f:facet>
<h:outputText value="#{i18n[tournament.tournamentType.i18nKey]}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.fillamount']}" />
</f:facet>
<h:outputText value="#{tournament.participants.size()}/#{tournament.maxParticipants}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.game']}" />
</f:facet>
<h:outputText value="#{tournament.tournamentGame.name}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.rules']}" />
</f:facet>
<h:outputText value="#{tournament.rules.name}" />
</p:column>
</p:dataTable>
</h:panelGroup>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
......
package fi.codecrew.moya.web.cdiview.tournaments;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedProperty;
import javax.inject.Named;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.utilities.I18n;
import fi.codecrew.moya.utilities.jsf.MessageHelper;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@ConversationScoped
public class TournamentDeleteView extends GenericCDIView {
private static final long serialVersionUID = 7283815262506163537L;
private Integer id = null;
@EJB private TournamentBeanLocal tournamentBean;
public String showConfirm(Integer id) {
this.beginConversation();
this.id = id;
return "/tournaments/admin/delete.xhtml";
}
public String delete() {
if(this.id != null) {
try {
tournamentBean.deleteTournament(tournamentBean.getTournamentById(this.id));
MessageHelper.info(I18n.get("tournament.admin.tournament_deleted_successfully"));
} catch(Exception e) {
MessageHelper.err(I18n.get("tournament.admin.tournament_delete_failed"));
}
} else {
MessageHelper.err(I18n.get("tournament.admin.tournament_delete_failed"));
}
this.endConversation();
return "/tournaments/admin/index.xhtml";
}
public String cancel() {
this.endConversation();
return "/tournaments/admin/index.xhtml";
}
}
package fi.codecrew.moya.web.cdiview.tournaments;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.utilities.I18n;
import fi.codecrew.moya.utilities.jsf.MessageHelper;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@ConversationScoped
public class TournamentEditView extends GenericCDIView {
@EJB private TournamentBeanLocal tournamentBean;
private Tournament tournament = null;
public String showEdit(Integer tournamentId) {
this.beginConversation();
this.setTournament(tournamentBean.getTournamentById(tournamentId));
return "/tournaments/admin/edit.xhtml";
}
public String commit() {
if(this.tournament != null) {
try {
this.tournamentBean.editTournament(tournament);
MessageHelper.info(I18n.get("tournament.admin.tournament_edited_successfully"));
} catch(Exception e) {
MessageHelper.err(I18n.get("tournament.admin.tournament_edit_failed"));
}
} else {
MessageHelper.err(I18n.get("tournament.admin.tournament_edit_failed"));
}
this.endConversation();
return "/tournaments/admin/index.xhtml";
}
public String cancel() {
this.endConversation();
return "/tournaments/admin/index.xhtml";
}
public Tournament getTournament() {
return tournament;
}
public void setTournament(Tournament tournament) {
this.tournament = tournament;
}
}
package fi.codecrew.moya.web.cdiview.tournaments; package fi.codecrew.moya.web.cdiview.tournaments;
public class TournamentListView { import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.enums.TournamentStatus;
import fi.codecrew.moya.model.Tournament;
@Named
@RequestScoped
public class TournamentListView {
@EJB private TournamentBeanLocal tournamentBean;
private List<Tournament> setupPhaseTournaments;
private List<Tournament> inProgressTournaments;
private List<Tournament> completedTournaments;
public void initView() {
setupPhaseTournaments = tournamentBean.getTournamentsInStatus(TournamentStatus.SETUP);
inProgressTournaments = tournamentBean.getTournamentsInStatus(TournamentStatus.IN_PROGRESS);
completedTournaments = tournamentBean.getTournamentsInStatus(TournamentStatus.COMPLETED);
}
public List<Tournament> getSetupPhaseTournaments() {
return setupPhaseTournaments;
}
public List<Tournament> getInProgressTournaments() {
return inProgressTournaments;
}
public List<Tournament> getCompletedTournaments() {
return completedTournaments;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!