Commit d3bda6e2 by Antti Jaakkola

Merge branch 'devel' of codecrew.fi:bortal into devel

2 parents d3a4882c 863ae773
...@@ -28,6 +28,7 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -28,6 +28,7 @@ public class BootstrapBean implements BootstrapBeanLocal {
// {"Query1","Query2",...} // {"Query1","Query2",...}
dbUpdates.add(new String[] { "" }); // first version, no changes 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 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" }); // dbUpdates.add(new String[] { "ALTER TABLE users ALTER COLUMN birthday TYPE date" });
} }
......
...@@ -6,6 +6,7 @@ import javax.ejb.EJB; ...@@ -6,6 +6,7 @@ import javax.ejb.EJB;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import fi.codecrew.moya.facade.TournamentFacade;
import fi.codecrew.moya.facade.TournamentGameFacade; import fi.codecrew.moya.facade.TournamentGameFacade;
import fi.codecrew.moya.facade.TournamentRuleFacade; import fi.codecrew.moya.facade.TournamentRuleFacade;
import fi.codecrew.moya.model.Tournament; import fi.codecrew.moya.model.Tournament;
...@@ -21,6 +22,7 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -21,6 +22,7 @@ public class TournamentBean implements TournamentBeanLocal {
@EJB private TournamentRuleFacade tournamentRuleFacade; @EJB private TournamentRuleFacade tournamentRuleFacade;
@EJB private TournamentGameFacade tournamentGameFacade; @EJB private TournamentGameFacade tournamentGameFacade;
@EJB private TournamentFacade tournamentFacade;
/** /**
* Default constructor. * Default constructor.
...@@ -45,8 +47,8 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -45,8 +47,8 @@ public class TournamentBean implements TournamentBeanLocal {
} }
@Override @Override
public void createRule(TournamentRule tr) { public TournamentRule createRule(TournamentRule tr) {
tournamentRuleFacade.create(tr); return tournamentRuleFacade.create(tr);
} }
@Override @Override
...@@ -58,4 +60,9 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -58,4 +60,9 @@ public class TournamentBean implements TournamentBeanLocal {
public TournamentRule findRule(Integer id) { public TournamentRule findRule(Integer id) {
return tournamentRuleFacade.find(id); return tournamentRuleFacade.find(id);
} }
@Override
public void createTournament(Tournament tournament) {
tournamentFacade.create(tournament);
}
} }
...@@ -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.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;
...@@ -13,8 +14,9 @@ public interface TournamentBeanLocal { ...@@ -13,8 +14,9 @@ public interface TournamentBeanLocal {
List<TournamentGame> getGames(); List<TournamentGame> getGames();
List<TournamentRule> getRulesByGame(TournamentGame tg); List<TournamentRule> getRulesByGame(TournamentGame tg);
void createGame(TournamentGame tg); void createGame(TournamentGame tg);
void createRule(TournamentRule tr); TournamentRule createRule(TournamentRule tr);
TournamentGame findGame(Integer id); TournamentGame findGame(Integer id);
TournamentRule findRule(Integer id); TournamentRule findRule(Integer id);
void createTournament(Tournament tournament);
} }
...@@ -63,6 +63,17 @@ public class Tournament extends GenericEntity implements Serializable { ...@@ -63,6 +63,17 @@ public class Tournament extends GenericEntity implements Serializable {
@JoinColumn(name="game", nullable=false) @JoinColumn(name="game", nullable=false)
private TournamentGame tournamentGame; 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 @OneToMany
@OrderBy("id ASC") @OrderBy("id ASC")
private List<Tournament> subTournaments; private List<Tournament> subTournaments;
...@@ -116,4 +127,60 @@ public class Tournament extends GenericEntity implements Serializable { ...@@ -116,4 +127,60 @@ public class Tournament extends GenericEntity implements Serializable {
public void setTournamentGame(TournamentGame tournamentGame) { public void setTournamentGame(TournamentGame tournamentGame) {
this.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 { ...@@ -62,6 +62,14 @@ public class TournamentRule extends GenericEntity implements Serializable {
public void setRules(String rules) { public void setRules(String rules) {
this.rules = rules; this.rules = rules;
} }
public TournamentGame getTournamentGame() {
return tournamentGame;
}
public void setTournamentGame(TournamentGame tournamentGame) {
this.tournamentGame = tournamentGame;
}
} }
...@@ -98,8 +98,8 @@ ...@@ -98,8 +98,8 @@
<p:inputTextarea cols="50" rendered="#{productShopView.gatherBillInfo}" value="#{productShopView.otherInfo}" label="#{i18n['otherInfo']}" /> <!-- <p:inputTextarea cols="50" rendered="#{productShopView.gatherBillInfo}" value="#{productShopView.otherInfo}" label="#{i18n['otherInfo']}" /> -->
<br />
......
...@@ -16,13 +16,11 @@ ...@@ -16,13 +16,11 @@
<p:tab id="selectGame" title="#{i18n['tournaments.admin.select_a_game']}"> <p:tab id="selectGame" title="#{i18n['tournaments.admin.select_a_game']}">
<p:panel> <p:panel>
<h:messages errorClass="error" /> <h:messages errorClass="error" />
<h:panelGroup rendered="#{tournamentCreateView.tournamentGames.isEmpty() eq false}"> <h:panelGroup rendered="#{tournamentCreateView.tournamentGames.isEmpty() eq false}">
<h2>#{i18n['tournaments.admin.select_a_game']}</h2> <h2>#{i18n['tournaments.admin.select_a_game']}</h2>
<h:selectOneMenu value="#{tournamentCreateView.game}" converter="#{tournamentGameConverter}"> <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:selectOneMenu>
</h:panelGroup> </h:panelGroup>
...@@ -40,15 +38,13 @@ ...@@ -40,15 +38,13 @@
<p:tab id="selectRuleset" title="#{i18n['tournaments.admin.rules']}"> <p:tab id="selectRuleset" title="#{i18n['tournaments.admin.rules']}">
<p:panel> <p:panel>
<h:messages errorClass="error" /> <h:messages errorClass="error" />
<h:panelGroup rendered="#{tournamentCreateView.tournamentRules.isEmpty() eq false}"> <h:panelGroup rendered="#{tournamentCreateView.tournamentRules.isEmpty() eq false}">
<h2>#{i18n['tournaments.admin.select_a_ruleset']}</h2> <h2>#{i18n['tournaments.admin.select_a_ruleset']}</h2>
<h:selectOneMenu value="#{tournamentCreateView.rules}" converter="#{tournamentRuleConverter}"> <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:selectOneMenu>
</h:panelGroup> </h:panelGroup>
<br />
<h2>#{i18n['tournaments.admin.create_new_ruleset']}</h2> <h2>#{i18n['tournaments.admin.create_new_ruleset']}</h2>
<h:outputText value="#{i18n['tournaments.ruleset_name']}" /> <h:outputText value="#{i18n['tournaments.ruleset_name']}" />
...@@ -58,31 +54,65 @@ ...@@ -58,31 +54,65 @@
<br /> <br />
<h:outputText value="#{i18n['tournaments.ruleset_description']}" /> <h:outputText value="#{i18n['tournaments.ruleset_description']}" />
<br /> <br />
<p:inputTextarea value="#{tournamentCreateView.rulesetDescription}"/> <p:inputText value="#{tournamentCreateView.rulesetDescription}"/>
<br />
<h:outputText value="#{i18n['tournaments.ruleset_rules']}" />
<br />
<p:inputTextarea value="#{tournamentCreateView.rulesetRules}"/>
<br />
</p:panel> </p:panel>
</p:tab> </p:tab>
<p:tab id="selectRegTimes" title="#{i18n['tournaments.admin.set_time_constraints']}"> <p:tab id="selectRegTimes" title="#{i18n['tournaments.admin.set_time_constraints']}">
<p:panel> <p:panel>
<h:messages errorClass="error" /> <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:panelGrid columns="2">
<h:outputText value="#{i18n['tournaments.registration_opens']}" /> <h:outputText value="#{i18n['tournaments.registration_opens']}" />
<h:outputText value="#{i18n['tournaments.registration_closes']}" /> <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" value="#{tournamentCreateView.tournament.registrationOpensAt}"/>
<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.registrationClosesAt}"/>
</h:panelGrid> </h:panelGrid>
<h2>#{i18n['tournaments.admin.begin_time_constraints']}</h2> <h2>#{i18n['tournaments.admin.begin_time_constraints']}</h2>
<h:panelGrid> <h:panelGrid>
<h:outputText value="Start time" /> <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> </h:panelGrid>
<br />
</p:panel> </p:panel>
<div style="float: right;"> <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> </div>
</p:tab> </p:tab>
</p:wizard> </p:wizard>
</h:form> </h:form>
......
<!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: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 styleClass="bordertable" id="actionlogtable" value="#{actionLogMessageView.messages}" var="message" paginator="true" rows="30" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="10,20,30,50,100" > -->
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
...@@ -84,6 +84,7 @@ public class MenuView extends GenericCDIView { ...@@ -84,6 +84,7 @@ public class MenuView extends GenericCDIView {
} }
public void menuChangeEvent() { public void menuChangeEvent() {
layoutview.setPageName(menuChange);
navihandler.forward(menuChange); navihandler.forward(menuChange);
// super.navihandler.forward(menuChange); // super.navihandler.forward(menuChange);
} }
...@@ -233,6 +234,9 @@ public class MenuView extends GenericCDIView { ...@@ -233,6 +234,9 @@ public class MenuView extends GenericCDIView {
} }
public String getMenuChange() { public String getMenuChange() {
if (menuChange == null || menuChange.isEmpty()) {
menuChange = layoutview.getPagepath();
}
return menuChange; return menuChange;
} }
......
package fi.codecrew.moya.web.cdiview.menu; package fi.codecrew.moya.web.cdiview.menu;
import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import javax.ejb.EJB; import javax.ejb.EJB;
...@@ -77,19 +75,7 @@ public class PrimeMenuView extends GenericCDIView { ...@@ -77,19 +75,7 @@ public class PrimeMenuView extends GenericCDIView {
if (menuModel == null) if (menuModel == null)
{ {
menuModel = new DefaultMenuModel(); menuModel = new DefaultMenuModel();
Set<MenuNavigation> selectedSet = new HashSet<>(); MenuNavigation selectedTop = layoutview.getSelectedTopmenu();
final MenuNavigation thisPage = menubean.findNavigation(layoutview.getPagepath());
MenuNavigation selectedTop = thisPage;
while (selectedTop != null && selectedTop.getParent() != null) {
selectedTop = selectedTop.getParent();
selectedSet.add(selectedTop);
}
List<MenuNavigation> tops = menubean.getTopmenus();
if (!tops.contains(selectedTop) && !tops.isEmpty()) {
selectedTop = tops.get(0);
}
for (MenuNavigation m : selectedTop.getChildren()) { for (MenuNavigation m : selectedTop.getChildren()) {
if (m.getItem() != null && m.getChildren().isEmpty()) { if (m.getItem() != null && m.getChildren().isEmpty()) {
...@@ -99,8 +85,7 @@ public class PrimeMenuView extends GenericCDIView { ...@@ -99,8 +85,7 @@ public class PrimeMenuView extends GenericCDIView {
menuModel.addElement(menuitem); menuModel.addElement(menuitem);
} }
} else { } else {
Submenu subm = addSubmenu(m, layoutview.getSelectedSet());
Submenu subm = addSubmenu(m, selectedSet);
if (subm != null) { if (subm != null) {
menuModel.addElement(subm); menuModel.addElement(subm);
......
package fi.codecrew.moya.web.cdiview.tournaments;
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.model.Tournament;
@RequestScoped
@Named
public class TournamentAdminView {
@EJB private TournamentBeanLocal tournamentBean;
public List<Tournament> getActiveTournaments() {
return null;
}
}
...@@ -5,6 +5,8 @@ import java.util.List; ...@@ -5,6 +5,8 @@ import java.util.List;
import fi.codecrew.moya.beans.EventBeanLocal; import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.TournamentBeanLocal; 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.Role;
import fi.codecrew.moya.model.Tournament; import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.TournamentGame; import fi.codecrew.moya.model.TournamentGame;
...@@ -35,6 +37,9 @@ public class TournamentCreateView extends GenericCDIView { ...@@ -35,6 +37,9 @@ public class TournamentCreateView extends GenericCDIView {
private String rulesetName; private String rulesetName;
private String rulesetDescription; private String rulesetDescription;
private String rulesetRules;
private Integer backupPlayers;
@EJB TournamentBeanLocal tournamentBean; @EJB TournamentBeanLocal tournamentBean;
@EJB EventBeanLocal eventBean; @EJB EventBeanLocal eventBean;
...@@ -43,13 +48,20 @@ public class TournamentCreateView extends GenericCDIView { ...@@ -43,13 +48,20 @@ public class TournamentCreateView extends GenericCDIView {
if(tournament == null) { if(tournament == null) {
this.beginConversation(); this.beginConversation();
tournament = new Tournament(); tournament = new Tournament();
tournament.setPlayersPerMatch(0);
backupPlayers = 0;
tournamentGames = tournamentBean.getGames(); tournamentGames = tournamentBean.getGames();
} }
} }
public void save(ActionEvent actionEvent) { 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() { public List<TournamentGame> getTournamentGames() {
...@@ -63,6 +75,11 @@ public class TournamentCreateView extends GenericCDIView { ...@@ -63,6 +75,11 @@ public class TournamentCreateView extends GenericCDIView {
public void uploadListener(org.primefaces.event.FileUploadEvent event) { public void uploadListener(org.primefaces.event.FileUploadEvent event) {
System.out.println("ZZ"); System.out.println("ZZ");
} }
public TournamentType[] getTournamentTypes() {
TournamentType[] items = TournamentType.values();
return items;
}
public String onFlowProcess(FlowEvent event) { public String onFlowProcess(FlowEvent event) {
switch(event.getOldStep()) { switch(event.getOldStep()) {
...@@ -77,19 +94,22 @@ public class TournamentCreateView extends GenericCDIView { ...@@ -77,19 +94,22 @@ public class TournamentCreateView extends GenericCDIView {
tournamentBean.createGame(tg); tournamentBean.createGame(tg);
} }
tournamentRules = tournamentBean.getRulesByGame(this.getGame()); tournamentRules = tournamentBean.getRulesByGame(game);
System.out.println(tournamentRules);
break; break;
case "selectRuleset": case "selectRuleset":
if(rulesetName != null && rulesetName.length() > 0) { if(rulesetName != null && rulesetName.length() > 0) {
TournamentRule tr = new TournamentRule(); TournamentRule tr = new TournamentRule();
tr.setName(rulesetName); tr.setName(rulesetName);
tr.setDescription(rulesetDescription); tr.setDescription(rulesetDescription);
tr.setRules(rulesetRules);
tr.setTournamentGame(game);
rules = tournamentBean.createRule(tr);
tournamentBean.createRule(tr); tournamentRules = tournamentBean.getRulesByGame(game);
} }
break; break;
} }
System.out.println(event.getOldStep());
return event.getNewStep(); return event.getNewStep();
} }
...@@ -140,4 +160,28 @@ public class TournamentCreateView extends GenericCDIView { ...@@ -140,4 +160,28 @@ public class TournamentCreateView extends GenericCDIView {
public void setRulesetDescription(String rulesetDescription) { public void setRulesetDescription(String rulesetDescription) {
this.rulesetDescription = 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;
}
public String getRulesetRules() {
return rulesetRules;
}
public void setRulesetRules(String rulesetRules) {
this.rulesetRules = rulesetRules;
}
} }
package fi.codecrew.moya.web.helper; package fi.codecrew.moya.web.helper;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Set;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
...@@ -17,10 +21,12 @@ import org.slf4j.Logger; ...@@ -17,10 +21,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal; import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.MenuBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal; import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.enums.apps.ContentPermission; import fi.codecrew.moya.enums.apps.ContentPermission;
import fi.codecrew.moya.model.LanEventProperty; import fi.codecrew.moya.model.LanEventProperty;
import fi.codecrew.moya.model.LanEventPropertyKey; import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.MenuNavigation;
@Named @Named
@RequestScoped @RequestScoped
...@@ -37,6 +43,9 @@ public class LayoutView { ...@@ -37,6 +43,9 @@ public class LayoutView {
private StreamedContent headerimage; private StreamedContent headerimage;
private String headertext; private String headertext;
@EJB
private transient MenuBeanLocal menubean;
private static final Logger logger = LoggerFactory.getLogger(LayoutView.class); private static final Logger logger = LoggerFactory.getLogger(LayoutView.class);
public void init() { public void init() {
...@@ -48,6 +57,38 @@ public class LayoutView { ...@@ -48,6 +57,38 @@ public class LayoutView {
return permbean.hasPermission(ContentPermission.MANAGE_PAGES); return permbean.hasPermission(ContentPermission.MANAGE_PAGES);
} }
private Set<MenuNavigation> selectedSet;
public Set<MenuNavigation> getSelectedSet()
{
if (selectedSet == null) {
getSelectedTopmenu();
}
return selectedSet;
}
private MenuNavigation selectedTop;
public MenuNavigation getSelectedTopmenu()
{
if (selectedTop == null)
{
selectedSet = new HashSet<>();
selectedTop = menubean.findNavigation(getPagepath());
while (selectedTop != null && selectedTop.getParent() != null) {
selectedTop = selectedTop.getParent();
selectedSet.add(selectedTop);
}
List<MenuNavigation> tops = menubean.getTopmenus();
if (!tops.contains(selectedTop) && !tops.isEmpty()) {
selectedTop = tops.get(0);
}
selectedSet = Collections.unmodifiableSet(selectedSet);
}
return selectedTop;
}
public String getPagepath() { public String getPagepath() {
if (pagename == null) { if (pagename == null) {
HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest(); HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest();
...@@ -137,4 +178,9 @@ public class LayoutView { ...@@ -137,4 +178,9 @@ public class LayoutView {
public void setHeadertext(String headertext) { public void setHeadertext(String headertext) {
this.headertext = headertext; this.headertext = headertext;
} }
public void setPageName(String menuChange) {
this.pagename = menuChange;
selectedTop = null;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!