wip: MiscPresenter

This commit is contained in:
Sohaib Baig committed 2026-04-13 14:29:48 +02:00
1 parent 265d9c38f6
commit 05cb006f6c
12 files changed
+100 -92

No files matched your search

@@ -6,10 +6,11 @@ public class FavoritesResult implements Result {
private FavoriteBoatClassesDTO favoriteBoatClasses;
private FavoriteCompetitorsDTO favoriteCompetitors;
private boolean isSubscribedToFeatureAndCommunityUpdates;
protected FavoritesResult() {}
public FavoritesResult(FavoriteBoatClassesDTO favoriteBoatClasses, FavoriteCompetitorsDTO favoriteCompetitors) {
public FavoritesResult(FavoriteBoatClassesDTO favoriteBoatClasses, FavoriteCompetitorsDTO favoriteCompetitors, boolean isSubscribedToFeatureAndCommunityUpdates) {
this.favoriteBoatClasses = favoriteBoatClasses;
this.favoriteCompetitors = favoriteCompetitors;
}
@@ -22,4 +23,8 @@ public class FavoritesResult implements Result {
return favoriteCompetitors;
}
public boolean getIsSubscribedToFeatureAndCommunityUpdates() {
return isSubscribedToFeatureAndCommunityUpdates;
}
}
@@ -25,7 +25,12 @@ public class GetFavoritesAction implements SailingAction<FavoritesResult> {
@Override
@GwtIncompatible
public FavoritesResult execute(SailingDispatchContext ctx) throws DispatchException {
return new FavoritesResult(getFavoriteBoatClasses(ctx), getFavoriteCompetitors(ctx));
return new FavoritesResult(getFavoriteBoatClasses(ctx), getFavoriteCompetitors(ctx),
getDidOptOutOfFeatureAndCommunityEmails(ctx));
}
private boolean getDidOptOutOfFeatureAndCommunityEmails(SailingDispatchContext ctx) {
return ctx.getSecurityService().getCurrentUser().getDidOptOutOfFeatureAndCommunityEmails();
}
@GwtIncompatible
@@ -1,22 +0,0 @@
package com.sap.sailing.gwt.home.communication.user.profile;
import com.google.gwt.core.shared.GwtIncompatible;
import com.google.gwt.user.client.rpc.IsSerializable;
import com.sap.sailing.gwt.home.communication.SailingAction;
import com.sap.sailing.gwt.home.communication.SailingDispatchContext;
import com.sap.sse.gwt.dispatch.shared.commands.BooleanResult;
import com.sap.sse.gwt.dispatch.shared.commands.HasWriteAction;
import com.sap.sse.gwt.dispatch.shared.exceptions.DispatchException;
public class GetMiscEmailPreferencesAction implements SailingAction<BooleanResult>, HasWriteAction, IsSerializable {
// @GwtIncompatible
public GetMiscEmailPreferencesAction() {
}
@Override
@GwtIncompatible
public BooleanResult execute(SailingDispatchContext ctx) throws DispatchException {
final boolean didOptOut = ctx.getSecurityService().getCurrentUser().getDidOptOutOfFeatureAndCommunityEmails();
return new BooleanResult(!didOptOut);
}
}
@@ -6,7 +6,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlowPanel;
import com.sap.sailing.gwt.home.shared.partials.checkboxtile.CheckBoxTile;
import com.sap.sailing.gwt.home.shared.partials.labeledbox.LabeledBox;
import com.sap.sailing.gwt.home.shared.places.user.profile.preferences.UserPreferencesView;
import com.sap.sailing.gwt.home.shared.places.user.profile.preferences.MiscPreferencesPresenter;
import com.sap.sailing.gwt.ui.client.StringMessages;
import com.sap.sse.gwt.client.Notification;
import com.sap.sse.gwt.client.Notification.NotificationType;
@@ -14,19 +14,23 @@ import com.sap.sse.gwt.dispatch.shared.commands.VoidResult;
public class MiscellaneousDisplayImpl {
public final LabeledBox selectionUi;
private final CheckBoxTile featureAndCommunityUpdates;
public MiscellaneousDisplayImpl(final UserPreferencesView.Presenter presenter) {
public MiscellaneousDisplayImpl(final MiscPreferencesPresenter presenter) {
presenter.registerDisplay(this);
// compose ui
final String securityUpdatesTitle = StringMessages.INSTANCE.securityUpdates();
final CheckBoxTile securityUpdates = new CheckBoxTile(securityUpdatesTitle, true, null);
final CheckBoxTile featureAndCommunityUpdates = composeFeatureAndCommunityUpdatesTile(presenter);
featureAndCommunityUpdates = composeFeatureAndCommunityUpdatesTile(presenter);
final FlowPanel tileList = new FlowPanel();
tileList.add(securityUpdates);
tileList.add(featureAndCommunityUpdates);
final String boxTitle = StringMessages.INSTANCE.miscellaneous();
selectionUi = new LabeledBox(boxTitle, tileList);
// fire init call
presenter.initIsSubscribedToFeatureAndCommunityUpdates(featureAndCommunityUpdates);
}
public void setIsSubscribedToFeatureAndCommunityUpdates(final boolean b, final boolean fireChangeHandlers) {
featureAndCommunityUpdates.setValue(b, fireChangeHandlers);
}
private AsyncCallback<VoidResult> wrapCallbackWithToastResponse(final boolean isNowTrue,
@@ -56,10 +60,10 @@ public class MiscellaneousDisplayImpl {
return callbackWrappedWithToastNotification;
}
private CheckBoxTile composeFeatureAndCommunityUpdatesTile(final UserPreferencesView.Presenter presenter) {
private CheckBoxTile composeFeatureAndCommunityUpdatesTile(final MiscPreferencesPresenter presenter) {
final BiConsumer<Boolean, AsyncCallback<VoidResult>> onToggle = (isNowTrue, callback) -> {
final AsyncCallback<VoidResult> wrappedCallback = wrapCallbackWithToastResponse(isNowTrue, callback);
presenter.setIsSubscribedToFeatureAndCommunityUpdates(isNowTrue, wrappedCallback);
presenter.updateIsSubscribedToFeatureAndCommunityUpdates(isNowTrue, wrappedCallback);
};
final String title = StringMessages.INSTANCE.featureAndCommunityUpdates();
return new CheckBoxTile(title, false, onToggle);
@@ -0,0 +1,14 @@
package com.sap.sailing.gwt.home.shared.places.user.profile.preferences;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.sap.sailing.gwt.home.shared.partials.multiselection.MiscellaneousDisplayImpl;
import com.sap.sse.gwt.dispatch.shared.commands.VoidResult;
public interface MiscPreferencesPresenter {
public void registerDisplay(MiscellaneousDisplayImpl display);
public void updateIsSubscribedToFeatureAndCommunityUpdates(final boolean b, final AsyncCallback<VoidResult> callback);
/** get value via dispatch method, set first correct value onto checkbox */
public void initIsSubscribedToFeatureAndCommunityUpdates(final boolean b);
}
@@ -48,7 +48,7 @@ public class UserPreferences extends Composite implements UserPreferencesView {
flagImageResolver).selectionUi;
favoriteBoatClassesSelctionUi = new BoatClassDisplayImpl(
presenter.getFavoriteBoatClassesDataProvider()).selectionUi;
miscUi = (new MiscellaneousDisplayImpl(presenter)).selectionUi;
miscUi = (new MiscellaneousDisplayImpl(presenter.getMiscPresenter())).selectionUi;
initWidget(uiBinder.createAndBindUi(this));
// TODO hide notificationsTextUi if the user's mail address is already verified
}
@@ -9,16 +9,14 @@ import com.sap.sailing.gwt.home.communication.user.profile.FavoriteBoatClassesDT
import com.sap.sailing.gwt.home.communication.user.profile.FavoriteCompetitorsDTO;
import com.sap.sailing.gwt.home.communication.user.profile.FavoritesResult;
import com.sap.sailing.gwt.home.communication.user.profile.GetFavoritesAction;
import com.sap.sailing.gwt.home.communication.user.profile.GetMiscEmailPreferencesAction;
import com.sap.sailing.gwt.home.communication.user.profile.SaveFavoriteBoatClassesAction;
import com.sap.sailing.gwt.home.communication.user.profile.SaveFavoriteCompetitorsAction;
import com.sap.sailing.gwt.home.communication.user.profile.SaveMiscEmailPreferences;
import com.sap.sailing.gwt.home.shared.app.ClientFactoryWithDispatch;
import com.sap.sailing.gwt.home.shared.partials.checkboxtile.CheckBoxTile;
import com.sap.sailing.gwt.home.shared.partials.multiselection.AbstractSuggestedBoatClassMultiSelectionPresenter;
import com.sap.sailing.gwt.home.shared.partials.multiselection.AbstractSuggestedCompetitorMultiSelectionPresenter;
import com.sap.sailing.gwt.home.shared.partials.multiselection.MiscellaneousDisplayImpl;
import com.sap.sailing.gwt.ui.client.refresh.ErrorAndBusyClientFactory;
import com.sap.sse.gwt.dispatch.shared.commands.BooleanResult;
import com.sap.sse.gwt.dispatch.shared.commands.VoidResult;
/**
@@ -34,6 +32,7 @@ public class UserPreferencesPresenter<C extends ClientFactoryWithDispatch & Erro
private final BoatClassSelectionPresenter boatClassSelectionPresenter = new BoatClassSelectionPresenterImpl();
final CompetitorSelectionPresenter competitorPresenter;
private final MiscPreferencesPresenter miscPresenter = new MiscPresenterImpl();
private final C clientFactory;
public UserPreferencesPresenter(C clientFactory) {
@@ -57,11 +56,38 @@ public class UserPreferencesPresenter<C extends ClientFactoryWithDispatch & Erro
final FavoriteBoatClassesDTO favoriteBoatClasses = result.getFavoriteBoatClasses();
boatClassSelectionPresenter.initNotifications(favoriteBoatClasses.isNotifyAboutUpcomingRaces(),
favoriteBoatClasses.isNotifyAboutResults(), favoriteBoatClasses.getSelectedBoatClasses());
miscPresenter.initIsSubscribedToFeatureAndCommunityUpdates(result.getIsSubscribedToFeatureAndCommunityUpdates());
}
};
clientFactory.getDispatch().execute(new GetFavoritesAction(), callback);
}
@Override
public MiscPreferencesPresenter getMiscPresenter() {
return miscPresenter;
}
private class MiscPresenterImpl implements MiscPreferencesPresenter {
MiscellaneousDisplayImpl display;
@Override
public void registerDisplay(MiscellaneousDisplayImpl display) {
this.display = display;
}
@Override
public void initIsSubscribedToFeatureAndCommunityUpdates(final boolean b) {
if (display != null) {
display.setIsSubscribedToFeatureAndCommunityUpdates(b, false);
}
}
@Override
public void updateIsSubscribedToFeatureAndCommunityUpdates(final boolean b, final AsyncCallback<VoidResult> callback) {
clientFactory.getDispatch().execute(new SaveMiscEmailPreferences(b), callback);
}
}
@Override
public BoatClassSelectionPresenter getFavoriteBoatClassesDataProvider() {
return boatClassSelectionPresenter;
@@ -108,11 +134,7 @@ public class UserPreferencesPresenter<C extends ClientFactoryWithDispatch & Erro
if (selectionCallback != null) {
persistResults(display.getNotifyAboutUpcomingRaces(), display.getNotifyAboutResults(),
selectionCallback, selectedItems);
} else {
throw new RuntimeException("set the selection callback first");
}
} else {
throw new RuntimeException("attach a display to this presenter");
}
}
@@ -130,28 +152,6 @@ public class UserPreferencesPresenter<C extends ClientFactoryWithDispatch & Erro
}
}
@Override
public void setIsSubscribedToFeatureAndCommunityUpdates(final Boolean b, final AsyncCallback<VoidResult> callback) {
clientFactory.getDispatch().execute(new SaveMiscEmailPreferences(b), callback);
}
/** get value via dispatch method, set first correct value onto checkbox */
@Override
public void initIsSubscribedToFeatureAndCommunityUpdates(final CheckBoxTile ui) {
final AsyncCallback<BooleanResult> callback = new AsyncCallback<BooleanResult>() {
@Override
public void onFailure(Throwable caught) {
clientFactory.createErrorView("Error while loading miscellaneous email subscriptions!", caught);
}
@Override
public void onSuccess(BooleanResult result) {
ui.setValue(result.getValue());
}
};
clientFactory.getDispatch().execute(new GetMiscEmailPreferencesAction(), callback);
}
private class CompetitorSelectionPresenterImpl
extends AbstractSuggestedCompetitorMultiSelectionPresenter<CompetitorSelectionPresenter.Display>
implements CompetitorSelectionPresenter {
@@ -168,11 +168,7 @@ public class UserPreferencesPresenter<C extends ClientFactoryWithDispatch & Erro
.toArray()[0];
if (selectionCallback != null) {
persistResults(display.getIsNotify(), selectionCallback, selectedItems);
} else {
throw new RuntimeException("set the selection callback first");
}
} else {
throw new RuntimeException("attach a display to this presenter");
}
}
@@ -1,10 +1,7 @@
package com.sap.sailing.gwt.home.shared.places.user.profile.preferences;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.IsWidget;
import com.sap.sailing.gwt.home.shared.partials.checkboxtile.CheckBoxTile;
import com.sap.sailing.gwt.home.shared.partials.multiselection.SuggestedMultiSelectionPresenter;
import com.sap.sse.gwt.dispatch.shared.commands.VoidResult;
/**
* Interface for the user preferences UI. To support desktop as well as mobile version, an
@@ -31,11 +28,9 @@ public interface UserPreferencesView extends IsWidget {
BoatClassSelectionPresenter getFavoriteBoatClassesDataProvider();
void setIsSubscribedToFeatureAndCommunityUpdates(final Boolean b, final AsyncCallback<VoidResult> callback);
void initIsSubscribedToFeatureAndCommunityUpdates(final CheckBoxTile featureAndCommunityUpdates);
CompetitorSelectionPresenter getFavoriteCompetitorsDataProvider();
MiscPreferencesPresenter getMiscPresenter();
}
}
@@ -2565,6 +2565,16 @@ public interface StringMessages extends com.sap.sse.gwt.client.StringMessages,
String youWillNowReceiveNotificationsForFavoriteCompetitors();
String youWillNotReceiveNotificationsForFavoriteCompetitorsAnymore();
String failedToSetStatusOfNotificationsForFavoriteCompetitors();
String youWillNowReceiveNotificationsForFavoriteBoatClassUpcomingRaces();
String youWillNotReceiveUpdatesOnUpcomingRacesForYourFavoredBoatClassesAnymore();
String failedToSetStatusOfUpdatesOnUpcomingRacesForYourFavoredBoatClasses();
String youWillNowReceiveUpdatesOnNewResultsForYourFavoredBoatClasses();
String youWillNotReceiveNotificationsForFavoriteBoatClassNewResultsAnymore();
String failedToSetStatusOfUpdatesOnNewResultsForYourFavoredBoatClasses();
String failedToModifyFavoriteCompetitors();
String favoriteCompetitorsModifiedSuccessfully();
String failedToModifyFavoredBoatClasses();
String succesfullyModifiedFavoredBoatClasses();
String revokeExplicitTrackingTimes();
String confirmRevokeExplicitTrackingTimes(String leaderboardName);
String errorRevokingExplicitTrackingTimes(String leaderboardName, String message);
@@ -2574,4 +2584,5 @@ public interface StringMessages extends com.sap.sse.gwt.client.StringMessages,
String notRevokedTrackingTimesBecauseOfMissingStartOrFinishTime();
String noRegattaLeaderboard(String leaderboardName);
String noAutomatedTrackingTimes(String leaderboardName);
String unknownError(String name);
String unknownError(String name);
}
@@ -2600,6 +2600,16 @@ youWillNotReceiveFeatureAndCommunityUpdatesAnymore=You will not receive feature
failedToSetStatusOfFeatureAndCommunityUpdates=Failed to set status of feature and community updates
failedToSetStatusOfNotificationsForFavoriteCompetitors=Failed to set status of notifications for favorite competitors
youWillNowReceiveNotificationsForFavoriteCompetitors=You will now receive notifications for favorite competitors
failedToSetStatusOfUpdatesOnUpcomingRacesForYourFavoredBoatClasses=Failed to set status of notifications for upcoming races of your favored boat classes
youWillNowReceiveNotificationsForFavoriteBoatClassUpcomingRaces=You will now receive notifications for upcoming races of your favored boat classes
youWillNotReceiveUpdatesOnUpcomingRacesForYourFavoredBoatClassesAnymore=You will not receive notifications for upcoming races of your favored boat classes anymore
failedToSetStatusOfUpdatesOnNewResultsForYourFavoredBoatClasses=Failed to set status of notifications for new results of your favored boat classes
youWillNowReceiveUpdatesOnNewResultsForYourFavoredBoatClasses=You will now receive notifications for new results of your favored boat classes
youWillNotReceiveNotificationsForFavoriteBoatClassNewResultsAnymore=You will not receive notifications for new results of your favored boat classes anymore
failedToModifyFavoriteCompetitors=Failed to modify favorite competitors
favoriteCompetitorsModifiedSuccessfully=Favorite competitors modified successfully
failedToModifyFavoredBoatClasses=Failed to modify favorite boat classes
succesfullyModifiedFavoredBoatClasses=Successfully modified favored boat classes
youWillNotReceiveNotificationsForFavoriteCompetitorsAnymore=You will not receive notifications for favorite competitors anymore
revokeExplicitTrackingTimes=Revoke explicit tracking times for races with valid start and finishing times
confirmRevokeExplicitTrackingTimes=Really revoke explicit tracking times for all races of leaderboard {0} that have valid start and finishing times?
@@ -2596,6 +2596,15 @@ failedToSetStatusOfNotificationsForFavoriteCompetitors=Status der Benachrichtigu
youWillNowReceiveNotificationsForFavoriteCompetitors=Sie erhalten nun Benachrichtigungen für Ihre bevorzugten Teilnehmer.
youWillNotReceiveNotificationsForFavoriteCompetitorsAnymore=Sie erhalten keine Benachrichtigungen mehr für Ihre Lieblingskonkurrenten.
failedToSetStatusOfUpdatesOnUpcomingRacesForYourFavoredBoatClasses=Fehler beim Festlegen des Benachrichtigungsstatus für bevorstehende Rennen Ihrer bevorzugten Bootsklasse
youWillNowReceiveNotificationsForFavoriteBoatClassUpcomingRaces=Sie erhalten nun Benachrichtigungen für anstehende Rennen Ihrer bevorzugten Bootsklasse.
youWillNotReceiveUpdatesOnUpcomingRacesForYourFavoredBoatClassesAnymore=Sie erhalten keine Benachrichtigungen mehr für bevorstehende Rennen Ihrer bevorzugten Bootsklasse.
failedToSetStatusOfUpdatesOnNewResultsForYourFavoredBoatClasses=Fehler beim Festlegen des Benachrichtigungsstatus für neue Ergebnisse Ihrer bevorzugten Bootsklasse
youWillNowReceiveUpdatesOnNewResultsForYourFavoredBoatClasses=Sie erhalten nun Benachrichtigungen über neue Ergebnisse Ihrer bevorzugten Bootsklasse.
youWillNotReceiveNotificationsForFavoriteBoatClassNewResultsAnymore=Sie erhalten keine Benachrichtigungen mehr über neue Ergebnisse Ihrer bevorzugten Bootsklasse.
failedToModifyFavoriteCompetitors=Fehler beim Setzen der Teilnemer-Favoriten
favoriteCompetitorsModifiedSuccessfully=Teilnehmer-Favoriten erfolgreich aktualisiert
failedToModifyFavoredBoatClasses=Die bevorzugten Bootsklassen konnten nicht angepasst werden.
succesfullyModifiedFavoredBoatClasses=Die bevorzugten Bootsklassen wurden erfolgreich angepasst.
revokeExplicitTrackingTimes=Explizite Tracking-Zeiten zurücksetzen für Rennen mit gültigen Start- und Endzeitpunkten
confirmRevokeExplicitTrackingTimes=Wirklich explizite Tracking-Zeiten zurücksetzen für Rennen mit gültigen Start- und Endzeitpunkten der Rangliste {0}?
errorRevokingExplicitTrackingTimes=Fehler beim Zurücksetzen expliziter Tracking-Zeiten für Rennen mit gültigen Start- und Endzeitpunkten der Rangliste {0}: {1}
@@ -1,19 +0,0 @@
package com.sap.sse.gwt.dispatch.shared.commands;
import com.sap.sse.gwt.shared.DTO;
public class BooleanResult implements DTO, Result {
private boolean value;
@Deprecated // Used for GWT serialization only
BooleanResult() {
}
public BooleanResult(final boolean b) {
this.value = b;
}
public boolean getValue() {
return value;
}
}