|
|
@ -5,6 +5,7 @@ import app.data.entity.Matchday; |
|
|
|
import app.navigation.Navigation; |
|
|
|
import app.navigation.components.button.NextMatchdayButton; |
|
|
|
import app.navigation.components.button.PrevMatchdayButton; |
|
|
|
import app.utils.ComponentUtils; |
|
|
|
import app.utils.EntityStringUtils; |
|
|
|
import app.utils.StringUtils; |
|
|
|
import app.utils.VaadinUtils; |
|
|
@ -21,33 +22,43 @@ import com.vaadin.flow.component.icon.VaadinIcon; |
|
|
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout; |
|
|
|
import com.vaadin.flow.component.orderedlayout.VerticalLayout; |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Calendar; |
|
|
|
import java.util.NoSuchElementException; |
|
|
|
|
|
|
|
public class MatchdayCard extends Div implements ContentConfigurable { |
|
|
|
|
|
|
|
private final Navigation navigation; |
|
|
|
|
|
|
|
private final Calendar calendar = Calendar.getInstance(); |
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM."); |
|
|
|
|
|
|
|
private final HorizontalLayout header = new HorizontalLayout(); |
|
|
|
private final Label headerLabel = new Label(); |
|
|
|
private final HorizontalLayout headerLabelLayout = new HorizontalLayout(); |
|
|
|
private final Grid<CalculatedMatch> grid = new Grid<>(); |
|
|
|
|
|
|
|
|
|
|
|
public MatchdayCard(Navigation navigation) { |
|
|
|
this.navigation = navigation; |
|
|
|
|
|
|
|
addClassName("card"); |
|
|
|
VerticalLayout inner = new VerticalLayout(); |
|
|
|
add(inner); |
|
|
|
inner.add(header, grid); |
|
|
|
add(new VerticalLayout(header, grid)); |
|
|
|
|
|
|
|
defineCalendar(); |
|
|
|
|
|
|
|
defineHeader(); |
|
|
|
defineGrid(); |
|
|
|
} |
|
|
|
|
|
|
|
private void defineCalendar() { |
|
|
|
calendar.setFirstDayOfWeek(Calendar.MONDAY); |
|
|
|
} |
|
|
|
|
|
|
|
private void defineHeader() { |
|
|
|
header.add(new PrevMatchdayButton(this.navigation), headerLabel, new NextMatchdayButton(this.navigation)); |
|
|
|
header.add(new PrevMatchdayButton(this.navigation), headerLabelLayout, new NextMatchdayButton(this.navigation)); |
|
|
|
header.setWidthFull(); |
|
|
|
|
|
|
|
headerLabel.addClassName("matchday-header-label"); |
|
|
|
headerLabelLayout.addClassName("matchday-header-label-layout"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -119,11 +130,29 @@ public class MatchdayCard extends Div implements ContentConfigurable { |
|
|
|
public void configureContent() { |
|
|
|
try { |
|
|
|
Matchday matchday = navigation.getSelectedMatchday().orElseThrow(); |
|
|
|
headerLabel.setText(String.format("Matchday %s", EntityStringUtils.getMatchdayString(matchday))); // TODO: add dates |
|
|
|
configureHeaderLabels(matchday); |
|
|
|
grid.setItems(navigation.getMatchService().getCalculatedMatches(matchday)); |
|
|
|
} catch (NoSuchElementException e) { |
|
|
|
removeAll(); |
|
|
|
add(navigation.getValidationLabel()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void configureHeaderLabels(Matchday matchday) { |
|
|
|
int week = matchday.getSeason().getWeekOfFirstMatchday() + matchday.getNumber() - 1; |
|
|
|
int firstDay = matchday.getSeason().getFirstWeekdayOfMatchday(); |
|
|
|
int lastDay = matchday.getSeason().getLastWeekdayOfMatchday(); |
|
|
|
|
|
|
|
calendar.set(Calendar.WEEK_OF_YEAR, week); |
|
|
|
|
|
|
|
calendar.set(Calendar.DAY_OF_WEEK, firstDay); |
|
|
|
String startDate = dateFormat.format(calendar.getTime()); |
|
|
|
|
|
|
|
calendar.set(Calendar.DAY_OF_WEEK, lastDay); |
|
|
|
String endDate = dateFormat.format(calendar.getTime()); |
|
|
|
|
|
|
|
String mainText = String.format("Matchday %s", EntityStringUtils.getMatchdayString(matchday)); |
|
|
|
String dateText = String.format("%s - %s", startDate, endDate); |
|
|
|
ComponentUtils.configureFormattedLabelWithParentheses(headerLabelLayout, mainText, dateText); |
|
|
|
} |
|
|
|
} |