Browse Source

diff to last matchday

master
GAM 4 years ago
parent
commit
541be93990
3 changed files with 45 additions and 7 deletions
  1. +17
    -3
      src/main/java/app/data/service/PlayerService.java
  2. +2
    -0
      src/main/java/app/utils/VaadinUtils.java
  3. +26
    -4
      src/main/java/app/views/table/components/TableCard.java

+ 17
- 3
src/main/java/app/data/service/PlayerService.java View File

@ -34,7 +34,7 @@ public class PlayerService extends CrudService<Player, Integer> {
} }
public List<PlayerForTable> getPlayersForTable(Matchday matchday) { public List<PlayerForTable> getPlayersForTable(Matchday matchday) {
return new PlayerForTableProvider(matchday).getPlayersForTableSorted();
return new PlayerForTableProvider(matchday).getPlayersForTableSorted(true);
} }
private class PlayerForTableProvider { private class PlayerForTableProvider {
@ -52,7 +52,7 @@ public class PlayerService extends CrudService<Player, Integer> {
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
private List<PlayerForTable> getPlayersForTableSorted() {
private List<PlayerForTable> getPlayersForTableSorted(boolean calcDiffToLastMatchday) {
List<PlayerForTable> playerForTableList = players.stream() List<PlayerForTable> playerForTableList = players.stream()
.map(this::getPlayerForTable) .map(this::getPlayerForTable)
.sorted(Comparator.comparingDouble(PlayerForTable::getGamePointsForSelf).reversed()) .sorted(Comparator.comparingDouble(PlayerForTable::getGamePointsForSelf).reversed())
@ -78,7 +78,21 @@ public class PlayerService extends CrudService<Player, Integer> {
currentPlayer.setPlace(i + 1 - offset); currentPlayer.setPlace(i + 1 - offset);
currentPlayer.setPlaceString(offset == 0 ? String.valueOf(i + 1) : ""); currentPlayer.setPlaceString(offset == 0 ? String.valueOf(i + 1) : "");
} }
// TODO: add diff to last matchday
if (calcDiffToLastMatchday) {
if (matchdays.size() < 2) {
playerForTableList.forEach(playerForTable -> playerForTable.setPlaceDiffToLastMatchday(Integer.MAX_VALUE));
} else {
List<PlayerForTable> lastMatchdayList = new PlayerForTableProvider(matchdays.get(matchdays.size() - 2)).getPlayersForTableSorted(false);
for (PlayerForTable playerForTable : playerForTableList) {
int placeLastMatchday = lastMatchdayList.stream()
.filter(playerForTableLastMatchday -> playerForTable.getPlayer().equals(playerForTableLastMatchday.getPlayer()))
.findFirst()
.map(PlayerForTable::getPlace)
.orElseThrow();
playerForTable.setPlaceDiffToLastMatchday(placeLastMatchday - playerForTable.getPlace());
}
}
}
return playerForTableList; return playerForTableList;
} }


+ 2
- 0
src/main/java/app/utils/VaadinUtils.java View File

@ -1,6 +1,7 @@
package app.utils; package app.utils;
import app.data.entity.Player; import app.data.entity.Player;
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.data.renderer.TemplateRenderer; import com.vaadin.flow.data.renderer.TemplateRenderer;
import com.vaadin.flow.function.ValueProvider; import com.vaadin.flow.function.ValueProvider;
@ -24,4 +25,5 @@ public class VaadinUtils {
return TemplateRenderer.<SOURCE>of(StringUtils.getBoldHtmlString(itemString)) return TemplateRenderer.<SOURCE>of(StringUtils.getBoldHtmlString(itemString))
.withProperty(string, stringProvider); .withProperty(string, stringProvider);
} }
} }

+ 26
- 4
src/main/java/app/views/table/components/TableCard.java View File

@ -12,6 +12,10 @@ import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.grid.GridVariant; import com.vaadin.flow.component.grid.GridVariant;
import com.vaadin.flow.component.html.Div; import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Label; import com.vaadin.flow.component.html.Label;
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.orderedlayout.FlexComponent;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -59,10 +63,9 @@ public class TableCard extends Div implements ContentConfigurable {
Label headerDiff = new Label("Diff"); Label headerDiff = new Label("Diff");
grid.addColumn(VaadinUtils.getBoldStringRenderer(PlayerForTable::getPlaceString))
grid.addComponentColumn(this::getPlaceColumnItem)
.setHeader(headerPlace) .setHeader(headerPlace)
.setTextAlign(ColumnTextAlign.CENTER)
// .setClassNameGenerator(playerForTable -> "leftmost-column-cell")
.setTextAlign(ColumnTextAlign.START)
.setWidth("5em"); .setWidth("5em");
grid.addColumn(VaadinUtils.getPlayerRenderer(PlayerForTable::getPlayer)) grid.addColumn(VaadinUtils.getPlayerRenderer(PlayerForTable::getPlayer))
@ -105,13 +108,32 @@ public class TableCard extends Div implements ContentConfigurable {
.setTextAlign(ColumnTextAlign.CENTER) .setTextAlign(ColumnTextAlign.CENTER)
.setWidth("5em"); .setWidth("5em");
grid.setWidth("51em");
grid.setWidth("55em");
grid.setHeightByRows(true); grid.setHeightByRows(true);
grid.addThemeVariants(GridVariant.LUMO_NO_BORDER, grid.addThemeVariants(GridVariant.LUMO_NO_BORDER,
GridVariant.LUMO_NO_ROW_BORDERS, GridVariant.LUMO_ROW_STRIPES); GridVariant.LUMO_NO_ROW_BORDERS, GridVariant.LUMO_ROW_STRIPES);
} }
private Icon getPlaceDiffIcon(PlayerForTable playerForTable) {
int placeDiff = playerForTable.getPlaceDiffToLastMatchday();
if (placeDiff < -1) return VaadinIcon.ANGLE_DOUBLE_DOWN.create();
if (placeDiff == -1) return VaadinIcon.ANGLE_DOWN.create();
if (placeDiff == 0) return VaadinIcon.MINUS.create();
if (placeDiff == 1) return VaadinIcon.ANGLE_UP.create();
return VaadinIcon.ANGLE_DOUBLE_UP.create();
}
private HorizontalLayout getPlaceColumnItem(PlayerForTable playerForTable) {
Label label = new Label(playerForTable.getPlaceString());
Icon icon = getPlaceDiffIcon(playerForTable);
icon.setSize("1em");
HorizontalLayout horizontalLayout = new HorizontalLayout(label, icon);
horizontalLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.BETWEEN);
horizontalLayout.setAlignItems(FlexComponent.Alignment.CENTER);
return horizontalLayout;
}
private String getResultString(PlayerForTable player) { private String getResultString(PlayerForTable player) {
return StringUtils.getResultString(":", player.getGamePointsForSelf(), player.getGamePointsForOpponents()); return StringUtils.getResultString(":", player.getGamePointsForSelf(), player.getGamePointsForOpponents());
} }


Loading…
Cancel
Save