|
|
@ -2,6 +2,7 @@ package app.views.match.components; |
|
|
|
|
|
|
|
import app.data.entity.Game; |
|
|
|
import app.data.entity.Match; |
|
|
|
import app.data.entity.Match.State; |
|
|
|
import app.data.service.ChessComService; |
|
|
|
import app.data.service.MatchService; |
|
|
|
import app.gameimage.GameImageService; |
|
|
@ -23,6 +24,7 @@ import com.vaadin.flow.shared.Registration; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import static app.data.entity.Match.State.*; |
|
|
|
import static app.utils.TimeControl.*; |
|
|
|
import static com.vaadin.flow.component.button.ButtonVariant.LUMO_PRIMARY; |
|
|
|
|
|
|
@ -46,6 +48,14 @@ public class EditMatchCard extends VerticalLayout { |
|
|
|
private final Button chessComButton = new Button("Autofill with the latest games between the players", new Icon(VaadinIcon.MAGIC)); |
|
|
|
private Registration chessComButtonButtonRegistration; |
|
|
|
|
|
|
|
HorizontalLayout adminButtonLayout = new HorizontalLayout(); |
|
|
|
private Registration sixZeroButtonRegistration; |
|
|
|
private final Button sixZeroButton = new Button("6 - 0", new Icon(VaadinIcon.CHECK)); |
|
|
|
private Registration zeroSixButtonRegistration; |
|
|
|
private final Button zeroSixButton = new Button("0 - 6", new Icon(VaadinIcon.CHECK)); |
|
|
|
private Registration zeroZeroButtonRegistration; |
|
|
|
private final Button zeroZeroButton = new Button("0 - 0", new Icon(VaadinIcon.CHECK)); |
|
|
|
|
|
|
|
private Match match; |
|
|
|
|
|
|
|
public EditMatchCard(MatchNavigation matchNavigation, ChessComService chessComService, GameImageService gameImageService) { |
|
|
@ -70,6 +80,7 @@ public class EditMatchCard extends VerticalLayout { |
|
|
|
defineTextFields(); |
|
|
|
defineSubmitButton(); |
|
|
|
addSubmitAndCancelButtons(); |
|
|
|
addAdminButtons(); |
|
|
|
} |
|
|
|
|
|
|
|
private void defineTextFields() { |
|
|
@ -111,6 +122,16 @@ public class EditMatchCard extends VerticalLayout { |
|
|
|
add(buttonLayout); |
|
|
|
} |
|
|
|
|
|
|
|
private void addAdminButtons() { |
|
|
|
sixZeroButton.addThemeVariants(LUMO_PRIMARY); |
|
|
|
zeroSixButton.addThemeVariants(LUMO_PRIMARY); |
|
|
|
zeroZeroButton.addThemeVariants(LUMO_PRIMARY); |
|
|
|
|
|
|
|
adminButtonLayout.setAlignItems(Alignment.CENTER); |
|
|
|
adminButtonLayout.setJustifyContentMode(JustifyContentMode.CENTER); |
|
|
|
adminButtonLayout.add(sixZeroButton, zeroSixButton, zeroZeroButton); |
|
|
|
} |
|
|
|
|
|
|
|
///////////// |
|
|
|
// CONTENT // |
|
|
|
///////////// |
|
|
@ -124,6 +145,8 @@ public class EditMatchCard extends VerticalLayout { |
|
|
|
configureChessComButton(); |
|
|
|
configureEditSubmitButton(); |
|
|
|
configureEditCancelButton(); |
|
|
|
|
|
|
|
configureAdminButtons(); |
|
|
|
} |
|
|
|
|
|
|
|
private void clearTextFields() { |
|
|
@ -191,6 +214,42 @@ public class EditMatchCard extends VerticalLayout { |
|
|
|
editCancelButtonRegistration = editCancelButton.addClickListener(createEditCancelButtonListener()); |
|
|
|
} |
|
|
|
|
|
|
|
private void configureAdminButtons() { |
|
|
|
if (matchNavigation.adminFlag()) { |
|
|
|
configureSixZeroButton(); |
|
|
|
configureZeroSixButton(); |
|
|
|
configureZeroZeroButton(); |
|
|
|
add(adminButtonLayout); |
|
|
|
} |
|
|
|
else { |
|
|
|
remove(adminButtonLayout); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void configureSixZeroButton() { |
|
|
|
if (sixZeroButtonRegistration != null) sixZeroButtonRegistration.remove(); |
|
|
|
sixZeroButtonRegistration = sixZeroButton.addClickListener(event -> submitAdminDecision(SIX_ZERO)); |
|
|
|
} |
|
|
|
|
|
|
|
private void configureZeroSixButton() { |
|
|
|
if (zeroSixButtonRegistration != null) zeroSixButtonRegistration.remove(); |
|
|
|
zeroSixButtonRegistration = zeroSixButton.addClickListener(event -> submitAdminDecision(ZERO_SIX)); |
|
|
|
} |
|
|
|
|
|
|
|
private void configureZeroZeroButton() { |
|
|
|
if (zeroZeroButtonRegistration != null) zeroZeroButtonRegistration.remove(); |
|
|
|
zeroZeroButtonRegistration = zeroZeroButton.addClickListener(event -> submitAdminDecision(ZERO_ZERO)); |
|
|
|
} |
|
|
|
|
|
|
|
private void submitAdminDecision(State sixZero) { |
|
|
|
match.getGames().clear(); |
|
|
|
match.setState(sixZero); |
|
|
|
matchService.update(match); |
|
|
|
|
|
|
|
matchNavigation.setEditFlag(false); |
|
|
|
matchNavigation.setAdminFlag(false); |
|
|
|
} |
|
|
|
|
|
|
|
private ComponentEventListener<ClickEvent<Button>> createEditCancelButtonListener() { |
|
|
|
return event -> UI.getCurrent().navigate(String.format("matchday/%s", matchNavigation.getWildcardParam().replace("edit/", ""))); |
|
|
|
} |
|
|
|