Races list - Added switch to change between old and new Races list

in regattas races tab view
This commit is contained in:
Benjamin Barth committed 2015-07-09 16:47:14 +02:00
1 parent 2674718962
commit 827c98bfc6
2 files changed
+79 -20

No files matched your search

@@ -1,6 +1,9 @@
package com.sap.sailing.gwt.home.client.place.event.regatta.tabs;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Display;
@@ -27,20 +30,26 @@ import com.sap.sailing.gwt.home.client.place.event.partials.racelist.RaceListCol
import com.sap.sailing.gwt.home.client.place.event.partials.racelist.RaceListContainer;
import com.sap.sailing.gwt.home.client.place.event.partials.racelist.RaceListDataUtil;
import com.sap.sailing.gwt.home.client.place.event.partials.racelist.SortableRaceListColumn;
import com.sap.sailing.gwt.home.client.place.event.partials.regattaraces.EventRegattaRaces;
import com.sap.sailing.gwt.home.client.place.event.regatta.EventRegattaView.Presenter;
import com.sap.sailing.gwt.home.client.place.event.regatta.RegattaTabView;
import com.sap.sailing.gwt.ui.client.StringMessages;
import com.sap.sailing.gwt.ui.shared.LeaderboardGroupDTO;
import com.sap.sailing.gwt.ui.shared.RaceGroupDTO;
import com.sap.sailing.gwt.ui.shared.StrippedLeaderboardDTO;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
import com.sap.sailing.gwt.ui.shared.dispatch.event.GetRaceListViewAction;
import com.sap.sailing.gwt.ui.shared.dispatch.event.RaceListRaceDTO;
import com.sap.sailing.gwt.ui.shared.dispatch.event.RaceListViewDTO;
import com.sap.sailing.gwt.ui.shared.dispatch.regatta.RegattaProgressDTO;
import com.sap.sse.common.Util.Triple;
/**
* Created by pgtaboada on 25.11.14.
*/
public class RegattaRacesTabView extends Composite implements RegattaTabView<RegattaRacesPlace> {
private static final boolean SHOW_NEW_RACES_LIST = true;
private static final StringMessages I18N = StringMessages.INSTANCE;
private enum Navigation implements ListNavigationAction {
@@ -77,6 +86,7 @@ public class RegattaRacesTabView extends Composite implements RegattaTabView<Reg
@UiField(provided = true) ListNavigationPanel<Navigation> listNavigationPanelUi;
@UiField FlowPanel listFormatContainerUi;
@UiField FlowPanel compFormatContainerUi;
@UiField SimplePanel oldContentContainer;
private RacesListLive liveRacesList;
private RaceListFinishedRaces finishedRacesList;
@@ -101,26 +111,57 @@ public class RegattaRacesTabView extends Composite implements RegattaTabView<Reg
@Override
public void start(RegattaRacesPlace myPlace, final AcceptsOneWidget contentArea) {
listNavigationPanelUi.removeFromParent(); // TODO temporary removed
// listNavigationPanelUi.addAction(Navigation.SORT_LIST_FORMAT, true);
// listNavigationPanelUi.addAction(Navigation.COMPETITION_FORMAT, false);
GetRaceListViewAction action = new GetRaceListViewAction(myPlace.getCtx().getEventDTO().getId(), myPlace.getRegattaId());
currentPresenter.getDispatch().execute(action, new AsyncCallback<ResultWithTTL<RaceListViewDTO>>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(ResultWithTTL<RaceListViewDTO> result) {
regattaInfoContainerUi.setWidget(getRegattaInformation(result.getDto().getProgress()));
liveRacesList.setListData(result.getDto().getLiveRaces());
finishedRacesList.setListData(result.getDto().getFinishedRaces());
// for (RaceListSeriesDTO series : result.getDto().getRacesForCompetitionFormat()) {
// compFormatContainerUi.add(new RegattaCompetitionSeries(currentPresenter, series));
// }
contentArea.setWidget(RegattaRacesTabView.this);
}
});
if (SHOW_NEW_RACES_LIST) {
listNavigationPanelUi.removeFromParent(); // TODO temporary removed
// listNavigationPanelUi.addAction(Navigation.SORT_LIST_FORMAT, true);
// listNavigationPanelUi.addAction(Navigation.COMPETITION_FORMAT, false);
GetRaceListViewAction action = new GetRaceListViewAction(myPlace.getCtx().getEventDTO().getId(), myPlace.getRegattaId());
currentPresenter.getDispatch().execute(action, new AsyncCallback<ResultWithTTL<RaceListViewDTO>>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(ResultWithTTL<RaceListViewDTO> result) {
regattaInfoContainerUi.setWidget(getRegattaInformation(result.getDto().getProgress()));
liveRacesList.setListData(result.getDto().getLiveRaces());
finishedRacesList.setListData(result.getDto().getFinishedRaces());
// for (RaceListSeriesDTO series : result.getDto().getRacesForCompetitionFormat()) {
// compFormatContainerUi.add(new RegattaCompetitionSeries(currentPresenter, series));
// }
contentArea.setWidget(RegattaRacesTabView.this);
}
});
oldContentContainer.removeFromParent();
} else {
regattaInfoContainerUi.removeFromParent();
listFormatContainerUi.removeFromParent();
compFormatContainerUi.removeFromParent();
// TODO: understand, and than move this into appropiate place (probably context)
final String selectedRegattaId = myPlace.getCtx().getRegattaId();
currentPresenter.ensureRegattaStructure(new AsyncCallback<List<RaceGroupDTO>>() {
@Override
public void onSuccess(List<RaceGroupDTO> raceGroups) {
if (raceGroups.size() > 0) {
Map<String, Triple<RaceGroupDTO, StrippedLeaderboardDTO, LeaderboardGroupDTO>> rs = getRegattaStructure();
Triple<RaceGroupDTO, StrippedLeaderboardDTO, LeaderboardGroupDTO> selectedRegatta = rs .get(selectedRegattaId);
EventRegattaRaces regattaRaces = new EventRegattaRaces(currentPresenter);
oldContentContainer.setWidget(regattaRaces);
regattaRaces.setRaces(selectedRegatta.getC(), false, selectedRegatta.getB(), selectedRegatta.getA());
contentArea.setWidget(RegattaRacesTabView.this);
} else {
// createEventWithoutRegattasView(event, panel);
}
}
@Override
public void onFailure(Throwable caught) {
// createErrorView(
// "Error while loading the regatta structure with service getRegattaStructureOfEvent()",
// caught, panel);
}
});
}
}
private Widget getRegattaInformation(RegattaProgressDTO regattaProgress) {
@@ -142,6 +183,23 @@ public class RegattaRacesTabView extends Composite implements RegattaTabView<Reg
public Class<RegattaRacesPlace> getPlaceClassForActivation() {
return RegattaRacesPlace.class;
}
private Map<String, Triple<RaceGroupDTO, StrippedLeaderboardDTO, LeaderboardGroupDTO>> getRegattaStructure() {
Map<String, Triple<RaceGroupDTO, StrippedLeaderboardDTO, LeaderboardGroupDTO>> result = new HashMap<>();
Map<String, RaceGroupDTO> raceGroupsMap = new HashMap<>();
for (RaceGroupDTO raceGroup : currentPresenter.getCtx().getRaceGroups()) {
raceGroupsMap.put(raceGroup.getName(), raceGroup);
}
for (LeaderboardGroupDTO leaderboardGroup : currentPresenter.getCtx().getLeaderboardGroups()) {
for (StrippedLeaderboardDTO leaderboard : leaderboardGroup.getLeaderboards()) {
String leaderboardName = leaderboard.name;
result.put(leaderboardName, new Triple<RaceGroupDTO, StrippedLeaderboardDTO, LeaderboardGroupDTO>(
raceGroupsMap.get(leaderboardName), leaderboard, leaderboardGroup));
}
}
return result;
}
private class RegattaRacesTabViewNavigationSelectionCallback implements SelectionCallback<Navigation> {
@Override
@@ -16,5 +16,6 @@
<g:FlowPanel addStyleNames="{res.mediaCss.small12} {res.mediaCss.columns} {style.listContainer}" ui:field="listFormatContainerUi" />
<g:FlowPanel addStyleNames="{res.mediaCss.small12} {res.mediaCss.columns}" ui:field="compFormatContainerUi" />
</div>
<g:SimplePanel ui:field="oldContentContainer"/>
</g:HTMLPanel>
</ui:UiBinder>