Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Linnea Samila
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 7245a590
authored
Sep 13, 2013
by
Antti Tonkyra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tournament stuff, MessageHelper
1 parent
8e02a635
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
370 additions
and
52 deletions
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/TournamentBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/facade/TournamentFacade.java
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/TournamentBeanLocal.java
code/MoyaUtilities/src/main/java/fi/codecrew/moya/utilities/jsf/MessageHelper.java
code/MoyaWeb/WebContent/tournaments/admin/delete.xhtml
code/MoyaWeb/WebContent/tournaments/admin/edit.xhtml
code/MoyaWeb/WebContent/tournaments/admin/index.xhtml
code/MoyaWeb/WebContent/tournaments/index.xhtml
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/tournaments/TournamentDeleteView.java
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/tournaments/TournamentEditView.java
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/tournaments/TournamentListView.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/TournamentBean.java
View file @
7245a59
...
...
@@ -68,7 +68,28 @@ public class TournamentBean implements TournamentBeanLocal {
}
@Override
public
List
<
Tournament
>
getTournamentsInStatus
(
TournamentStatus
status
)
{
return
tournamentFacade
.
getTournamentsInStatus
(
status
);
}
@Override
public
List
<
Tournament
>
getActiveTournaments
()
{
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
);
}
}
code/MoyaBeans/ejbModule/fi/codecrew/moya/facade/TournamentFacade.java
View file @
7245a59
...
...
@@ -30,5 +30,14 @@ public class TournamentFacade extends IntegerPkGenericFacade<Tournament> {
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
();
}
}
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/TournamentBeanLocal.java
View file @
7245a59
...
...
@@ -4,6 +4,7 @@ import java.util.List;
import
javax.ejb.Local
;
import
fi.codecrew.moya.enums.TournamentStatus
;
import
fi.codecrew.moya.model.Tournament
;
import
fi.codecrew.moya.model.TournamentGame
;
import
fi.codecrew.moya.model.TournamentRule
;
...
...
@@ -19,5 +20,9 @@ public interface TournamentBeanLocal {
TournamentRule
findRule
(
Integer
id
);
void
createTournament
(
Tournament
tournament
);
List
<
Tournament
>
getActiveTournaments
();
List
<
Tournament
>
getTournamentsInStatus
(
TournamentStatus
status
);
Tournament
getTournamentById
(
Integer
tournamentId
);
void
editTournament
(
Tournament
tournament
);
void
deleteTournament
(
Tournament
tournament
);
}
code/MoyaUtilities/src/main/java/fi/codecrew/moya/utilities/jsf/MessageHelper.java
0 → 100644
View file @
7245a59
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
);
}
}
code/MoyaWeb/WebContent/tournaments/admin/delete.xhtml
0 → 100644
View file @
7245a59
<!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
code/MoyaWeb/WebContent/tournaments/admin/edit.xhtml
0 → 100644
View file @
7245a59
<!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
code/MoyaWeb/WebContent/tournaments/admin/index.xhtml
View file @
7245a59
...
...
@@ -5,58 +5,66 @@
<h:body>
<ui:composition
template=
"#{sessionHandler.template}"
>
<f:metadata>
<!-- <f:event type="preRenderView" listener="#{userOverviewView.initView()}" /> -->
</f:metadata>
<ui:define
name=
"content"
>
<h1>
#{i18n['tournaments.admin.title']}
</h1>
<p>
#{i18n['tournaments.admin.description']}
</p>
<h2>
#{i18n['tournaments.active_tournaments']}
</h2>
<p:dataTable
value=
"#{tournamentAdminView.activeTournaments}"
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.playerspermatch_slash_teamsize']}"
/>
</f:facet>
<h:outputText
value=
"#{tournament.playersPerMatch}/#{tournament.playersPerTeam}"
/>
</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:form>
<p:dataTable
value=
"#{tournamentAdminView.activeTournaments}"
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.playerspermatch_slash_teamsize']}"
/>
</f:facet>
<h:outputText
value=
"#{tournament.playersPerMatch}/#{tournament.playersPerTeam}"
/>
</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: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>
<p:commandButton
value=
"#{i18n['tournament.admin.create']}"
action=
"#{tournamentAdminView.create}"
/>
</h:form>
...
...
code/MoyaWeb/WebContent/tournaments/index.xhtml
View file @
7245a59
...
...
@@ -5,15 +5,54 @@
<h:body>
<ui:composition
template=
"#{sessionHandler.template}"
>
<f:metadata>
<
!-- <f:event type="preRenderView" listener="#{userOverviewView.initView()}" /> --
>
<
f:event
type=
"preRenderView"
listener=
"#{tournamentListView.initView()}"
/
>
</f:metadata>
<ui:define
name=
"content"
>
<h1>
Tournaments
</h1>
<h1>
#{i18n['tournaments.title']}
</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:composition>
</h:body>
...
...
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/tournaments/TournamentDeleteView.java
0 → 100644
View file @
7245a59
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"
;
}
}
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/tournaments/TournamentEditView.java
0 → 100644
View file @
7245a59
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
;
}
}
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/tournaments/TournamentListView.java
View file @
7245a59
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
;
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment