|
|
@ -1,12 +1,12 @@ |
|
|
|
package app.navigation.regular; |
|
|
|
|
|
|
|
import app.components.label.ValidationLabel; |
|
|
|
import app.data.entity.Match; |
|
|
|
import app.data.entity.Matchday; |
|
|
|
import app.data.entity.Season; |
|
|
|
import app.data.service.MatchService; |
|
|
|
import app.data.service.MatchdayService; |
|
|
|
import app.data.service.SeasonService; |
|
|
|
import app.navigation.Navigation; |
|
|
|
import app.navigation.NavigationUtils; |
|
|
|
import app.utils.EntityStringUtils; |
|
|
|
import com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent; |
|
|
@ -14,7 +14,6 @@ import com.vaadin.flow.component.HasValue.ValueChangeListener; |
|
|
|
import com.vaadin.flow.component.UI; |
|
|
|
import com.vaadin.flow.component.select.Select; |
|
|
|
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; |
|
|
@ -25,13 +24,10 @@ import java.util.Map; |
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") |
|
|
|
public class RegularNavigation implements HasUrlParameter<String> { |
|
|
|
public class RegularNavigation extends Navigation { |
|
|
|
|
|
|
|
private String route; |
|
|
|
private boolean onlyMatchdaysWithActivity; |
|
|
|
|
|
|
|
private final List<Runnable> runnablesToBeRunAfterSelection = new ArrayList<>(); |
|
|
|
|
|
|
|
private final SeasonService seasonService; |
|
|
|
private final MatchdayService matchdayService; |
|
|
|
private final MatchService matchService; |
|
|
@ -46,10 +42,6 @@ public class RegularNavigation implements HasUrlParameter<String> { |
|
|
|
|
|
|
|
private RegularNavigationLevel regularNavigationLevel = RegularNavigationLevel.SEASON; |
|
|
|
|
|
|
|
private final ValidationLabel validationLabel = new ValidationLabel(); |
|
|
|
|
|
|
|
private boolean editFlag = false; |
|
|
|
|
|
|
|
public RegularNavigation(@Autowired SeasonService seasonService, |
|
|
|
@Autowired MatchdayService matchdayService, |
|
|
|
@Autowired MatchService matchService) { |
|
|
@ -68,10 +60,6 @@ public class RegularNavigation implements HasUrlParameter<String> { |
|
|
|
matchSelect.setItemLabelGenerator(EntityStringUtils::getMatchString); |
|
|
|
} |
|
|
|
|
|
|
|
public void setRoute(String route) { |
|
|
|
this.route = route; |
|
|
|
} |
|
|
|
|
|
|
|
public void setOnlyMatchdaysWithActivity(boolean onlyMatchdaysWithActivity) { |
|
|
|
this.onlyMatchdaysWithActivity = onlyMatchdaysWithActivity; |
|
|
|
} |
|
|
@ -96,12 +84,7 @@ public class RegularNavigation implements HasUrlParameter<String> { |
|
|
|
return this.regularNavigationLevel.compareTo(RegularNavigationLevel.MATCH) >= 0; |
|
|
|
} |
|
|
|
|
|
|
|
private String getRoute() { |
|
|
|
if (route != null) return route; |
|
|
|
throw new IllegalStateException("Route must be set!"); |
|
|
|
} |
|
|
|
|
|
|
|
private void updateUrl() { |
|
|
|
protected void updateUrl() { |
|
|
|
String seasonParam = null; |
|
|
|
String matchdayParam = null; |
|
|
|
String matchParam = null; |
|
|
@ -147,12 +130,6 @@ public class RegularNavigation implements HasUrlParameter<String> { |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private void doPostSelectionStuff() { |
|
|
|
validationLabel.setValid(true); |
|
|
|
updateUrl(); |
|
|
|
runnablesToBeRunAfterSelection.forEach(Runnable::run); |
|
|
|
} |
|
|
|
|
|
|
|
private void autoselectSeason() { |
|
|
|
if (!seasonEnabled()) |
|
|
|
throw new IllegalStateException("This method should not be called when season is not enabled!"); |
|
|
@ -164,7 +141,7 @@ public class RegularNavigation implements HasUrlParameter<String> { |
|
|
|
seasonSelect.setValue(seasonList.get(seasonList.size() - 1)); |
|
|
|
} |
|
|
|
|
|
|
|
private void autoselectMatchday() { // TODO: choose depending on date instead! |
|
|
|
private void autoselectMatchday() { |
|
|
|
if (!matchdayEnabled()) |
|
|
|
throw new IllegalStateException("This method should not be called when matchday is not enabled!"); |
|
|
|
if (matchdayList.isEmpty()) { |
|
|
@ -232,10 +209,6 @@ public class RegularNavigation implements HasUrlParameter<String> { |
|
|
|
else autoselectMatch(); |
|
|
|
} |
|
|
|
|
|
|
|
public ValidationLabel getValidationLabel() { |
|
|
|
return validationLabel; |
|
|
|
} |
|
|
|
|
|
|
|
public List<Season> getSeasonList() { |
|
|
|
return seasonList; |
|
|
|
} |
|
|
@ -284,18 +257,7 @@ public class RegularNavigation implements HasUrlParameter<String> { |
|
|
|
return matchService; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean editFlag() { |
|
|
|
return editFlag; |
|
|
|
} |
|
|
|
|
|
|
|
public void setEditFlag(boolean editFlag) { |
|
|
|
if (editFlag != this.editFlag) { |
|
|
|
this.editFlag = editFlag; |
|
|
|
updateUrl(); |
|
|
|
runnablesToBeRunAfterSelection.forEach(Runnable::run); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String getWildcardParam() { |
|
|
|
return NavigationUtils.getWildcardParam( |
|
|
|
editFlag, |
|
|
|