Browse Source

fix bug

master
GAM 4 years ago
parent
commit
14eb2caf55
3 changed files with 20 additions and 12 deletions
  1. +5
    -1
      src/main/java/app/utils/ChessComUtils.java
  2. +9
    -1
      src/main/java/app/views/match/components/EditMatchCard.java
  3. +6
    -10
      src/main/java/app/views/match/components/utils/GameCardUtils.java

+ 5
- 1
src/main/java/app/utils/ChessComUtils.java View File

@ -6,6 +6,8 @@ import app.data.entity.Match;
import app.data.entity.Player;
import org.springframework.lang.NonNull;
import static app.utils.TimeControl.*;
public class ChessComUtils {
private static final String GAME_LINK = "https://www.chess.com/game/live/{gameId}";
@ -46,7 +48,9 @@ public class ChessComUtils {
public static boolean hasValidTimeControl(ChessComGame game) {
String timeControl = game.getTimeControl();
if (timeControl != null) {
return timeControl.equals("600") || timeControl.equals("300") || timeControl.equals("180");
return timeControl.equals(TEN_MINUTES.toSecondsString())
|| timeControl.equals(FIVE_MINUTES.toSecondsString())
|| timeControl.equals(THREE_MINUTES.toSecondsString());
}
return false;
}


+ 9
- 1
src/main/java/app/views/match/components/EditMatchCard.java View File

@ -178,12 +178,20 @@ public class EditMatchCard extends VerticalLayout {
}
private void addGamesToMatchFromFieldValues() {
for (TextField textField : tenMinuteTextFields) {
for (TextField textField : getAllTextfields()) {
Optional<Game> game = chessComService.getGame(textField.getValue(), match); // TODO: handle this when Optional is empty!
game.ifPresent(value -> match.getGames().add(value));
}
}
private List<TextField> getAllTextfields() {
List<TextField> list = new ArrayList<>();
list.addAll(tenMinuteTextFields);
list.addAll(fiveMinuteTextFields);
list.addAll(threeMinuteTextFields);
return list;
}
private void configureEditCancelButton() {
if (editCancelButtonRegistration != null) editCancelButtonRegistration.remove();
editCancelButtonRegistration = editCancelButton.addClickListener(createEditCancelButtonListener());


+ 6
- 10
src/main/java/app/views/match/components/utils/GameCardUtils.java View File

@ -5,6 +5,7 @@ import app.data.entity.Player;
import app.gameimage.GameImageUtils;
import app.utils.ChessComUtils;
import app.utils.EntityComponentUtils;
import app.utils.TimeControl;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.html.Div;
@ -85,26 +86,21 @@ public class GameCardUtils {
public static Div getTimeControlDiv(Game game) {
String timeControl = game.getGameInfo().getTimeControl();
TimeControl timeControl = TimeControl.fromSecondsString(game.getGameInfo().getTimeControl());
Icon icon;
String string;
switch (timeControl) {
case "600":
case TEN_MINUTES:
icon = new Icon(VaadinIcon.STOPWATCH);
string = "10 min";
break;
case "300":
case FIVE_MINUTES:
icon = new Icon(VaadinIcon.BOLT);
string = "5 min";
break;
case "180":
case THREE_MINUTES:
icon = new Icon(VaadinIcon.BOMB);
string = "3 min";
break;
default:
icon = new Icon(VaadinIcon.QUESTION);
string = String.format("Unknown Time Control: %s", timeControl);
break;
}
@ -114,7 +110,7 @@ public class GameCardUtils {
HorizontalLayout horizontalLayout = new HorizontalLayout();
horizontalLayout.setWidthFull();
horizontalLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.CENTER);
horizontalLayout.add(icon, new Label(string));
horizontalLayout.add(icon, new Label(timeControl.toPresentationString()));
div.add(horizontalLayout);


Loading…
Cancel
Save