Browse Source

NavigationLevel

master
GAM 4 years ago
parent
commit
f016b3b993
9 changed files with 50 additions and 86 deletions
  1. +25
    -33
      src/main/java/app/navigation/Navigation.java
  2. +3
    -3
      src/main/java/app/navigation/components/NavigationHeader.java
  3. +1
    -1
      src/main/java/app/navigation/components/button/NextMatchdayButton.java
  4. +1
    -1
      src/main/java/app/navigation/components/button/PrevMatchdayButton.java
  5. +8
    -0
      src/main/java/app/navigation/service/NavigationLevel.java
  6. +2
    -10
      src/main/java/app/views/match/MatchView.java
  7. +3
    -15
      src/main/java/app/views/matchday/MatchdayView.java
  8. +5
    -13
      src/main/java/app/views/navigation/NavigationViewBase.java
  9. +2
    -10
      src/main/java/app/views/table/TableView.java

+ 25
- 33
src/main/java/app/navigation/Navigation.java View File

@ -7,6 +7,7 @@ import app.data.entity.Season;
import app.data.service.MatchService;
import app.data.service.MatchdayService;
import app.data.service.SeasonService;
import app.navigation.service.NavigationLevel;
import com.vaadin.flow.component.AbstractField;
import com.vaadin.flow.component.HasValue;
import com.vaadin.flow.component.UI;
@ -15,6 +16,7 @@ import com.vaadin.flow.router.BeforeEvent;
import com.vaadin.flow.router.HasUrlParameter;
import com.vaadin.flow.router.WildcardParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import java.util.ArrayList;
import java.util.List;
@ -41,9 +43,7 @@ public class Navigation implements HasUrlParameter<String> {
private final Select<Matchday> matchdaySelect = new Select<>();
private final Select<Match> matchSelect = new Select<>();
private boolean seasonEnabled = false;
private boolean matchdayEnabled = false;
private boolean matchEnabled = false;
private NavigationLevel navigationLevel = NavigationLevel.SEASON;
private final ValidationLabel validationLabel = new ValidationLabel();
@ -69,32 +69,24 @@ public class Navigation implements HasUrlParameter<String> {
this.onlyMatchdaysWithActivity = onlyMatchdaysWithActivity;
}
public void setSeasonEnabled(boolean seasonEnabled) {
this.seasonEnabled = seasonEnabled;
}
public void setMatchdayEnabled(boolean matchdayEnabled) {
this.matchdayEnabled = matchdayEnabled;
}
public void setMatchEnabled(boolean matchEnabled) {
this.matchEnabled = matchEnabled;
public void setNavigationLevel(@NonNull NavigationLevel navigationLevel) {
this.navigationLevel = navigationLevel;
}
public void addRunnableToBeRunAfterSelection(Runnable runnable) {
runnablesToBeRunAfterSelection.add(runnable);
}
public boolean isSeasonEnabled() {
return seasonEnabled;
public boolean seasonEnabled() {
return this.navigationLevel.compareTo(NavigationLevel.SEASON) >= 0;
}
public boolean isMatchdayEnabled() {
return matchdayEnabled;
public boolean matchdayEnabled() {
return this.navigationLevel.compareTo(NavigationLevel.MATCHDAY) >= 0;
}
public boolean isMatchEnabled() {
return matchEnabled;
public boolean matchEnabled() {
return this.navigationLevel.compareTo(NavigationLevel.MATCH) >= 0;
}
private String getRoute() {
@ -106,9 +98,9 @@ public class Navigation implements HasUrlParameter<String> {
String seasonParam = null;
String matchdayParam = null;
String matchParam = null;
if (seasonEnabled && seasonSelect.getOptionalValue().isPresent()) seasonParam = seasonSelect.getValue().toString();
if (matchdayEnabled && matchdaySelect.getOptionalValue().isPresent()) matchdayParam = matchdaySelect.getValue().toString();
if (matchEnabled && matchSelect.getOptionalValue().isPresent()) matchParam = matchSelect.getValue().toString();
if (seasonEnabled() && seasonSelect.getOptionalValue().isPresent()) seasonParam = seasonSelect.getValue().toString();
if (matchdayEnabled() && matchdaySelect.getOptionalValue().isPresent()) matchdayParam = matchdaySelect.getValue().toString();
if (matchEnabled() && matchSelect.getOptionalValue().isPresent()) matchParam = matchSelect.getValue().toString();
String params = NavigationUtils.getWildcardParam(seasonParam, matchdayParam, matchParam);
UI.getCurrent().getPage().getHistory().pushState(null, String.format("%s/%s", getRoute(), params));
@ -116,8 +108,8 @@ public class Navigation implements HasUrlParameter<String> {
private HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<Select<Season>, Season>> seasonSelectValueChangeListener() {
return event -> {
if (!seasonEnabled) throw new IllegalStateException("Cannot select season when it is not enabled!");
if (matchdayEnabled) {
if (!seasonEnabled()) throw new IllegalStateException("Cannot select season when it is not enabled!");
if (matchdayEnabled()) {
fillMatchdaySelectWithData(event.getValue());
autoselectMatchday();
return;
@ -128,8 +120,8 @@ public class Navigation implements HasUrlParameter<String> {
private HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<Select<Matchday>, Matchday>> matchdaySelectValueChangeListener() {
return event -> {
if (!matchdayEnabled) throw new IllegalStateException("Cannot select matchday when it is not enabled!");
if (matchEnabled) {
if (!matchdayEnabled()) throw new IllegalStateException("Cannot select matchday when it is not enabled!");
if (matchEnabled()) {
fillMatchSelectWithData(event.getValue());
autoselectMatch();
return;
@ -140,7 +132,7 @@ public class Navigation implements HasUrlParameter<String> {
private HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<Select<Match>, Match>> matchSelectValueChangeListener() {
return event -> {
if (!matchEnabled) throw new IllegalStateException("Cannot select match when it is not enabled!");
if (!matchEnabled()) throw new IllegalStateException("Cannot select match when it is not enabled!");
doPostSelectionStuff();
};
}
@ -152,7 +144,7 @@ public class Navigation implements HasUrlParameter<String> {
}
private void autoselectSeason() {
if (!seasonEnabled) throw new IllegalStateException("This method should not be called when season is not enabled!");
if (!seasonEnabled()) throw new IllegalStateException("This method should not be called when season is not enabled!");
if (seasonList.isEmpty()) {
validationLabel.setText("No Seasons in List!");
validationLabel.setValid(false);
@ -162,7 +154,7 @@ public class Navigation implements HasUrlParameter<String> {
}
private void autoselectMatchday() { // TODO: add date stuff and choose depending on date instead!
if (!matchdayEnabled) throw new IllegalStateException("This method should not be called when matchday is not enabled!");
if (!matchdayEnabled()) throw new IllegalStateException("This method should not be called when matchday is not enabled!");
if (matchdayList.isEmpty()) {
validationLabel.setText("No Matchdays in List!");
validationLabel.setValid(false);
@ -174,7 +166,7 @@ public class Navigation implements HasUrlParameter<String> {
}
private void autoselectMatch() {
if (!matchEnabled) throw new IllegalStateException("This method should not be called when match is not enabled!");
if (!matchEnabled()) throw new IllegalStateException("This method should not be called when match is not enabled!");
if (matchList.isEmpty()) {
validationLabel.setText("No Matches in List!");
validationLabel.setValid(false);
@ -210,17 +202,17 @@ public class Navigation implements HasUrlParameter<String> {
}
private void navigate(Optional<String> seasonParam, Optional<String> matchdayParam, Optional<String> matchParam) {
if (!seasonEnabled) return;
if (!seasonEnabled()) return;
Optional<Season> season = getSeasonFromParam(seasonParam);
if (season.isPresent()) seasonSelect.setValue(season.get());
else autoselectSeason();
if (!matchdayEnabled) return;
if (!matchdayEnabled()) return;
Optional<Matchday> matchday = getMatchdayFromParam(matchdayParam);
if (matchday.isPresent()) matchdaySelect.setValue(matchday.get());
else autoselectMatchday();
if (!matchEnabled) return;
if (!matchEnabled()) return;
Optional<Match> match = getMatchFromParam(matchParam);
if (match.isPresent()) matchSelect.setValue(match.get());
else autoselectMatch();


+ 3
- 3
src/main/java/app/navigation/components/NavigationHeader.java View File

@ -27,13 +27,13 @@ public class NavigationHeader extends HorizontalLayout {
private void configureChildren() {
removeAll();
if (navigation.isSeasonEnabled()) {
if (navigation.seasonEnabled()) {
add(seasonLabel, navigation.getSeasonSelect());
}
if (navigation.isMatchdayEnabled()) {
if (navigation.matchdayEnabled()) {
add(matchdayLabel, navigation.getMatchdaySelect());
}
if (navigation.isMatchEnabled()) {
if (navigation.matchEnabled()) {
add(matchLabel, navigation.getMatchSelect());
}
}


+ 1
- 1
src/main/java/app/navigation/components/button/NextMatchdayButton.java View File

@ -15,7 +15,7 @@ public class NextMatchdayButton extends Button {
public NextMatchdayButton(Navigation navigation) {
this.navigation = navigation;
if (!navigation.isMatchdayEnabled())
if (!navigation.matchdayEnabled())
throw new IllegalStateException("Cannot instantiate NextMatchdayButton when Matchdays are not enabled!");
setIcon(new Icon(VaadinIcon.ARROW_RIGHT));


+ 1
- 1
src/main/java/app/navigation/components/button/PrevMatchdayButton.java View File

@ -15,7 +15,7 @@ public class PrevMatchdayButton extends Button {
public PrevMatchdayButton(Navigation navigation) {
this.navigation = navigation;
if (!navigation.isMatchdayEnabled())
if (!navigation.matchdayEnabled())
throw new IllegalStateException("Cannot instantiate PrevMatchdayButton when Matchdays are not enabled!");
setIcon(new Icon(VaadinIcon.ARROW_LEFT));


+ 8
- 0
src/main/java/app/navigation/service/NavigationLevel.java View File

@ -0,0 +1,8 @@
package app.navigation.service;
public enum NavigationLevel {
NONE,
SEASON,
MATCHDAY,
MATCH
}

+ 2
- 10
src/main/java/app/views/match/MatchView.java View File

@ -3,6 +3,7 @@ package app.views.match;
import app.data.service.MatchService;
import app.data.service.MatchdayService;
import app.data.service.SeasonService;
import app.navigation.service.NavigationLevel;
import app.navigation.service.NavigationService;
import app.views.main.MainView;
import app.views.navigation.NavigationViewBase;
@ -20,7 +21,7 @@ public class MatchView extends NavigationViewBase {
public MatchView(@Autowired NavigationService navigationService,
@Autowired MatchService matchService) {
super(navigationService, true, true, true);
super(navigationService, "match", NavigationLevel.MATCH);
this.matchService = matchService;
addClassName("match-view");
@ -28,15 +29,6 @@ public class MatchView extends NavigationViewBase {
configureLayout();
}
///////////
// ROUTE //
///////////
@Override
public String getRoute() {
return "match";
}
////////////
// LAYOUT //
////////////


+ 3
- 15
src/main/java/app/views/matchday/MatchdayView.java View File

@ -1,6 +1,7 @@
package app.views.matchday;
import app.data.service.MatchService;
import app.navigation.service.NavigationLevel;
import app.navigation.service.NavigationService;
import app.views.main.MainView;
import app.views.matchday.components.MatchdayComponent;
@ -15,29 +16,16 @@ import org.springframework.beans.factory.annotation.Autowired;
@PageTitle("Schachliga DACH - Results - Matchdays")
public class MatchdayView extends NavigationViewBase {
private final MatchService matchService;
private MatchdayComponent matchdayComponent;
public MatchdayView(@Autowired NavigationService navigationService,
@Autowired MatchService matchService) {
super(navigationService, true, true, false);
this.matchService = matchService;
public MatchdayView(@Autowired NavigationService navigationService) {
super(navigationService, "matchday", NavigationLevel.MATCHDAY);
addClassName("matchday-view");
configureLayout();
}
///////////
// ROUTE //
///////////
@Override
public String getRoute() {
return "matchday";
}
////////////
// LAYOUT //
////////////


+ 5
- 13
src/main/java/app/views/navigation/NavigationViewBase.java View File

@ -2,6 +2,7 @@ package app.views.navigation;
import app.navigation.Navigation;
import app.navigation.components.NavigationHeader;
import app.navigation.service.NavigationLevel;
import app.navigation.service.NavigationService;
import com.vaadin.flow.component.orderedlayout.FlexComponent;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
@ -16,14 +17,11 @@ public abstract class NavigationViewBase extends VerticalLayout implements HasUr
protected final NavigationHeader navigationHeader;
protected NavigationViewBase(@Autowired NavigationService navigationService,
boolean seasonEnabled,
boolean matchdayEnabled,
boolean matchEnabled) {
String route,
NavigationLevel navigationLevel) {
this.navigation = navigationService.getNewNavigation();
navigation.setRoute(getRoute());
navigation.setSeasonEnabled(seasonEnabled);
navigation.setMatchdayEnabled(matchdayEnabled);
navigation.setMatchEnabled(matchEnabled);
navigation.setRoute(route);
navigation.setNavigationLevel(navigationLevel);
this.navigationHeader = new NavigationHeader(navigation);
@ -38,12 +36,6 @@ public abstract class NavigationViewBase extends VerticalLayout implements HasUr
navigation.addRunnableToBeRunAfterSelection(this::configureContent);
}
///////////
// ROUTE //
///////////
protected abstract String getRoute();
/////////////
// CONTENT //
/////////////


+ 2
- 10
src/main/java/app/views/table/TableView.java View File

@ -1,6 +1,7 @@
package app.views.table;
import app.data.service.PlayerService;
import app.navigation.service.NavigationLevel;
import app.navigation.service.NavigationService;
import app.views.main.MainView;
import app.views.navigation.NavigationViewBase;
@ -21,7 +22,7 @@ public class TableView extends NavigationViewBase {
public TableView(@Autowired NavigationService navigationService,
@Autowired PlayerService playerService) {
super(navigationService, true, true, false);
super(navigationService, "table", NavigationLevel.MATCHDAY);
this.playerService = playerService;
this.navigation.setOnlyMatchdaysWithActivity(true);
@ -31,15 +32,6 @@ public class TableView extends NavigationViewBase {
configureLayout();
}
///////////
// ROUTE //
///////////
@Override
public String getRoute() {
return "table";
}
////////////
// LAYOUT //
////////////


Loading…
Cancel
Save