|
|
@ -6,6 +6,7 @@ import app.data.entity.Match; |
|
|
|
import app.data.service.ChessComService; |
|
|
|
import app.data.service.GameInfoService; |
|
|
|
import app.data.service.GameService; |
|
|
|
import app.data.service.MatchService; |
|
|
|
import app.gameimage.GameImageService; |
|
|
|
import app.navigation.Navigation; |
|
|
|
import app.utils.ChessComUtils; |
|
|
@ -23,6 +24,7 @@ import com.vaadin.flow.component.orderedlayout.FlexComponent; |
|
|
|
import com.vaadin.flow.component.orderedlayout.FlexLayout; |
|
|
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout; |
|
|
|
import com.vaadin.flow.component.orderedlayout.VerticalLayout; |
|
|
|
import com.vaadin.flow.component.progressbar.ProgressBar; |
|
|
|
import com.vaadin.flow.component.textfield.TextField; |
|
|
|
import com.vaadin.flow.shared.Registration; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -36,6 +38,7 @@ public class MatchComponent extends Div implements ContentConfigurable { |
|
|
|
|
|
|
|
private final Navigation navigation; |
|
|
|
private final ChessComService chessComService; |
|
|
|
private final MatchService matchService; |
|
|
|
private final GameService gameService; |
|
|
|
private final GameInfoService gameInfoService; |
|
|
|
private final GameImageService gameImageService; |
|
|
@ -53,6 +56,7 @@ public class MatchComponent extends Div implements ContentConfigurable { |
|
|
|
// TODO: autocorrect "/live/game" to "/game/live/" |
|
|
|
private final Button editSubmitButton = new Button("Submit", new Icon(VaadinIcon.CHECK)); |
|
|
|
// TODO: disable when no 6 values in form, and make sure you don't freeze forever when there are wrong entries |
|
|
|
// TODO: use overlapping progress here |
|
|
|
private Registration editSubmitButtonRegistration; |
|
|
|
private final Button editCancelButton = new Button("Cancel", new Icon(VaadinIcon.CLOSE)); |
|
|
|
private Registration editCancelButtonRegistration; |
|
|
@ -62,11 +66,13 @@ public class MatchComponent extends Div implements ContentConfigurable { |
|
|
|
|
|
|
|
public MatchComponent(Navigation navigation, |
|
|
|
@Autowired ChessComService chessComService, |
|
|
|
@Autowired MatchService matchService, // TODO: get this stuff from navigation instead, or even better: Do it like PaussHFramework |
|
|
|
@Autowired GameService gameService, |
|
|
|
@Autowired GameInfoService gameInfoService, |
|
|
|
@Autowired GameImageService gameImageService) { |
|
|
|
this.navigation = navigation; |
|
|
|
this.chessComService = chessComService; |
|
|
|
this.matchService = matchService; |
|
|
|
this.gameService = gameService; |
|
|
|
this.gameInfoService = gameInfoService; |
|
|
|
this.gameImageService = gameImageService; |
|
|
@ -172,10 +178,14 @@ public class MatchComponent extends Div implements ContentConfigurable { |
|
|
|
|
|
|
|
if (chessComButtonButtonRegistration != null) chessComButtonButtonRegistration.remove(); |
|
|
|
chessComButtonButtonRegistration = chessComButton.addClickListener(event -> { |
|
|
|
ProgressBar progressBar = new ProgressBar(); |
|
|
|
progressBar.setIndeterminate(true); |
|
|
|
editLayout.add(progressBar); |
|
|
|
List<Game> gamesBetweenPlayers = chessComService.getLatestGamesBetweenPlayers(match, 6, 2); |
|
|
|
for (int i = 0; i < Math.min(gamesBetweenPlayers.size(), 6); i++) { |
|
|
|
editTextFields.get(i).setValue(ChessComUtils.getGameURL(gamesBetweenPlayers.get(i))); |
|
|
|
} |
|
|
|
editLayout.remove(progressBar); |
|
|
|
}); |
|
|
|
|
|
|
|
if (editSubmitButtonRegistration != null) editSubmitButtonRegistration.remove(); |
|
|
@ -185,7 +195,7 @@ public class MatchComponent extends Div implements ContentConfigurable { |
|
|
|
Optional<Game> game = chessComService.getGame(textField.getValue(), match); // TODO: handle this when Optional is empty! |
|
|
|
game.ifPresent(value -> match.getGames().add(value)); |
|
|
|
} |
|
|
|
match.getGames().forEach(game -> gameInfoService.update(game.getGameInfo())); |
|
|
|
matchService.update(match); |
|
|
|
match.getGames().forEach(gameImageService::createImageIfNotPresent); |
|
|
|
|
|
|
|
navigation.setEditFlag(false); |
|
|
|