Browse Source

Results Navigation

master
GAM 4 years ago
parent
commit
bb9169b8f0
2 changed files with 41 additions and 8 deletions
  1. +2
    -2
      src/main/java/app/views/main/MainView.java
  2. +39
    -6
      src/main/java/app/views/matchday/components/MatchdayComponent.java

+ 2
- 2
src/main/java/app/views/main/MainView.java View File

@ -103,8 +103,8 @@ public class MainView extends AppLayout {
// createTab("Credit Card Form", CreditCardFormView.class),
// createTab("Map", MapView.class),
createTab("Table", TableView.class),
createTab("Matchday", MatchdayView.class),
createTab("Match", MatchView.class)
createTab("Results", MatchdayView.class),
// createTab("Match", MatchView.class)
};
}


+ 39
- 6
src/main/java/app/views/matchday/components/MatchdayComponent.java View File

@ -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());
}


Loading…
Cancel
Save