|
@ -7,6 +7,7 @@ import app.data.entity.Season; |
|
|
import app.data.service.MatchService; |
|
|
import app.data.service.MatchService; |
|
|
import app.data.service.MatchdayService; |
|
|
import app.data.service.MatchdayService; |
|
|
import app.data.service.SeasonService; |
|
|
import app.data.service.SeasonService; |
|
|
|
|
|
import app.navigation.service.NavigationLevel; |
|
|
import com.vaadin.flow.component.AbstractField; |
|
|
import com.vaadin.flow.component.AbstractField; |
|
|
import com.vaadin.flow.component.HasValue; |
|
|
import com.vaadin.flow.component.HasValue; |
|
|
import com.vaadin.flow.component.UI; |
|
|
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.HasUrlParameter; |
|
|
import com.vaadin.flow.router.WildcardParameter; |
|
|
import com.vaadin.flow.router.WildcardParameter; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.lang.NonNull; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
@ -41,9 +43,7 @@ public class Navigation implements HasUrlParameter<String> { |
|
|
private final Select<Matchday> matchdaySelect = new Select<>(); |
|
|
private final Select<Matchday> matchdaySelect = new Select<>(); |
|
|
private final Select<Match> matchSelect = 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(); |
|
|
private final ValidationLabel validationLabel = new ValidationLabel(); |
|
|
|
|
|
|
|
@ -69,32 +69,24 @@ public class Navigation implements HasUrlParameter<String> { |
|
|
this.onlyMatchdaysWithActivity = onlyMatchdaysWithActivity; |
|
|
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) { |
|
|
public void addRunnableToBeRunAfterSelection(Runnable runnable) { |
|
|
runnablesToBeRunAfterSelection.add(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() { |
|
|
private String getRoute() { |
|
@ -106,9 +98,9 @@ public class Navigation implements HasUrlParameter<String> { |
|
|
String seasonParam = null; |
|
|
String seasonParam = null; |
|
|
String matchdayParam = null; |
|
|
String matchdayParam = null; |
|
|
String matchParam = 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); |
|
|
String params = NavigationUtils.getWildcardParam(seasonParam, matchdayParam, matchParam); |
|
|
UI.getCurrent().getPage().getHistory().pushState(null, String.format("%s/%s", getRoute(), params)); |
|
|
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() { |
|
|
private HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<Select<Season>, Season>> seasonSelectValueChangeListener() { |
|
|
return event -> { |
|
|
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()); |
|
|
fillMatchdaySelectWithData(event.getValue()); |
|
|
autoselectMatchday(); |
|
|
autoselectMatchday(); |
|
|
return; |
|
|
return; |
|
@ -128,8 +120,8 @@ public class Navigation implements HasUrlParameter<String> { |
|
|
|
|
|
|
|
|
private HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<Select<Matchday>, Matchday>> matchdaySelectValueChangeListener() { |
|
|
private HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<Select<Matchday>, Matchday>> matchdaySelectValueChangeListener() { |
|
|
return event -> { |
|
|
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()); |
|
|
fillMatchSelectWithData(event.getValue()); |
|
|
autoselectMatch(); |
|
|
autoselectMatch(); |
|
|
return; |
|
|
return; |
|
@ -140,7 +132,7 @@ public class Navigation implements HasUrlParameter<String> { |
|
|
|
|
|
|
|
|
private HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<Select<Match>, Match>> matchSelectValueChangeListener() { |
|
|
private HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<Select<Match>, Match>> matchSelectValueChangeListener() { |
|
|
return event -> { |
|
|
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(); |
|
|
doPostSelectionStuff(); |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
@ -152,7 +144,7 @@ public class Navigation implements HasUrlParameter<String> { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void autoselectSeason() { |
|
|
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()) { |
|
|
if (seasonList.isEmpty()) { |
|
|
validationLabel.setText("No Seasons in List!"); |
|
|
validationLabel.setText("No Seasons in List!"); |
|
|
validationLabel.setValid(false); |
|
|
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! |
|
|
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()) { |
|
|
if (matchdayList.isEmpty()) { |
|
|
validationLabel.setText("No Matchdays in List!"); |
|
|
validationLabel.setText("No Matchdays in List!"); |
|
|
validationLabel.setValid(false); |
|
|
validationLabel.setValid(false); |
|
@ -174,7 +166,7 @@ public class Navigation implements HasUrlParameter<String> { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void autoselectMatch() { |
|
|
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()) { |
|
|
if (matchList.isEmpty()) { |
|
|
validationLabel.setText("No Matches in List!"); |
|
|
validationLabel.setText("No Matches in List!"); |
|
|
validationLabel.setValid(false); |
|
|
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) { |
|
|
private void navigate(Optional<String> seasonParam, Optional<String> matchdayParam, Optional<String> matchParam) { |
|
|
if (!seasonEnabled) return; |
|
|
|
|
|
|
|
|
if (!seasonEnabled()) return; |
|
|
Optional<Season> season = getSeasonFromParam(seasonParam); |
|
|
Optional<Season> season = getSeasonFromParam(seasonParam); |
|
|
if (season.isPresent()) seasonSelect.setValue(season.get()); |
|
|
if (season.isPresent()) seasonSelect.setValue(season.get()); |
|
|
else autoselectSeason(); |
|
|
else autoselectSeason(); |
|
|
|
|
|
|
|
|
if (!matchdayEnabled) return; |
|
|
|
|
|
|
|
|
if (!matchdayEnabled()) return; |
|
|
Optional<Matchday> matchday = getMatchdayFromParam(matchdayParam); |
|
|
Optional<Matchday> matchday = getMatchdayFromParam(matchdayParam); |
|
|
if (matchday.isPresent()) matchdaySelect.setValue(matchday.get()); |
|
|
if (matchday.isPresent()) matchdaySelect.setValue(matchday.get()); |
|
|
else autoselectMatchday(); |
|
|
else autoselectMatchday(); |
|
|
|
|
|
|
|
|
if (!matchEnabled) return; |
|
|
|
|
|
|
|
|
if (!matchEnabled()) return; |
|
|
Optional<Match> match = getMatchFromParam(matchParam); |
|
|
Optional<Match> match = getMatchFromParam(matchParam); |
|
|
if (match.isPresent()) matchSelect.setValue(match.get()); |
|
|
if (match.isPresent()) matchSelect.setValue(match.get()); |
|
|
else autoselectMatch(); |
|
|
else autoselectMatch(); |
|
|