|
|
@ -9,14 +9,17 @@ import app.utils.EntityStringUtils; |
|
|
|
import app.utils.StringUtils; |
|
|
|
import app.utils.VaadinUtils; |
|
|
|
import app.views.navigation.interfaces.ContentConfigurable; |
|
|
|
import com.vaadin.flow.component.UI; |
|
|
|
import com.vaadin.flow.component.button.Button; |
|
|
|
import com.vaadin.flow.component.button.ButtonVariant; |
|
|
|
import com.vaadin.flow.component.grid.ColumnTextAlign; |
|
|
|
import com.vaadin.flow.component.grid.Grid; |
|
|
|
import com.vaadin.flow.component.grid.GridVariant; |
|
|
|
import com.vaadin.flow.component.html.Div; |
|
|
|
import com.vaadin.flow.component.html.Label; |
|
|
|
import com.vaadin.flow.component.icon.VaadinIcon; |
|
|
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout; |
|
|
|
import com.vaadin.flow.component.orderedlayout.VerticalLayout; |
|
|
|
import com.vaadin.flow.function.ValueProvider; |
|
|
|
|
|
|
|
import java.util.NoSuchElementException; |
|
|
|
|
|
|
@ -53,31 +56,61 @@ public class MatchdayComponent extends Div implements ContentConfigurable { |
|
|
|
headerPlayer1.addClassName("column_header"); |
|
|
|
Label headerPlayer2 = new Label("Player 2"); |
|
|
|
headerPlayer2.addClassName("column_header"); |
|
|
|
Label headerResult = new Label("Result"); |
|
|
|
headerResult.addClassName("column_header"); |
|
|
|
|
|
|
|
grid.addColumn(VaadinUtils.getPlayerRenderer(CalculatedMatch::getPlayer1)) |
|
|
|
.setHeader(headerPlayer1) |
|
|
|
.setTextAlign(ColumnTextAlign.END) |
|
|
|
.setTextAlign(ColumnTextAlign.CENTER) |
|
|
|
.setWidth("13em") |
|
|
|
.setFlexGrow(1); |
|
|
|
|
|
|
|
grid.addColumn((ValueProvider<CalculatedMatch, String>) this::getResultString) |
|
|
|
grid.addColumn(calculatedMatch -> "vs.") |
|
|
|
.setHeader("vs.") |
|
|
|
.setTextAlign(ColumnTextAlign.CENTER) |
|
|
|
.setWidth("6em"); |
|
|
|
.setWidth("3em"); |
|
|
|
|
|
|
|
grid.addColumn(VaadinUtils.getPlayerRenderer(CalculatedMatch::getPlayer2)) |
|
|
|
.setHeader(headerPlayer2) |
|
|
|
.setTextAlign(ColumnTextAlign.START) |
|
|
|
.setTextAlign(ColumnTextAlign.CENTER) |
|
|
|
.setWidth("13em") |
|
|
|
.setFlexGrow(1); |
|
|
|
|
|
|
|
grid.setWidth("32em"); // TODO: find a way to set this dynamically based on column widths |
|
|
|
grid.addColumn(this::getResultString) |
|
|
|
.setHeader(headerResult) |
|
|
|
.setTextAlign(ColumnTextAlign.CENTER) |
|
|
|
.setWidth("6em"); |
|
|
|
|
|
|
|
grid.addComponentColumn(this::createButton) |
|
|
|
.setTextAlign(ColumnTextAlign.CENTER) |
|
|
|
.setWidth("3em"); |
|
|
|
|
|
|
|
grid.setWidth("38em"); // TODO: find a way to set this dynamically based on column widths |
|
|
|
grid.setHeightByRows(true); |
|
|
|
|
|
|
|
grid.addThemeVariants(GridVariant.LUMO_NO_BORDER, |
|
|
|
GridVariant.LUMO_NO_ROW_BORDERS, GridVariant.LUMO_ROW_STRIPES); |
|
|
|
} |
|
|
|
|
|
|
|
private Button createButton(CalculatedMatch match) { |
|
|
|
Button button = new Button(); |
|
|
|
button.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE); |
|
|
|
|
|
|
|
String seasonAndMatchdayParam = navigation.getWildcardParam(); |
|
|
|
String matchParam = EntityStringUtils.getMatchStringForURL(match.getMatch()); |
|
|
|
String targetWildcardParam = String.format("match/%s%s/", seasonAndMatchdayParam, matchParam); |
|
|
|
|
|
|
|
if (match.getScore1() == 0 && match.getScore2() == 0) { |
|
|
|
button.setIcon(VaadinIcon.PENCIL.create()); |
|
|
|
button.addClickListener(event -> UI.getCurrent().navigate(targetWildcardParam + "edit")); |
|
|
|
return button; |
|
|
|
} |
|
|
|
|
|
|
|
button.setIcon(VaadinIcon.EYE.create()); |
|
|
|
button.addClickListener(event -> UI.getCurrent().navigate(targetWildcardParam)); |
|
|
|
return button; |
|
|
|
} |
|
|
|
|
|
|
|
private String getResultString(CalculatedMatch match) { |
|
|
|
return StringUtils.getResultString(":", match.getScore1(), match.getScore2()); |
|
|
|
} |
|
|
|