Skip to content

Commit

Permalink
Fix sonar.
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanudrescu committed May 25, 2020
1 parent 6035938 commit e7a3a25
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import com.vaadin.flow.server.AppShellRegistry;
import com.vaadin.flow.server.VaadinService;
import com.vaadin.flow.server.communication.JavaScriptBootstrapHandler;
import elemental.json.JsonValue;

/**
* Custom UI for {@link JavaScriptBootstrapHandler}. This class is intended for
Expand All @@ -54,7 +53,6 @@ public class JavaScriptBootstrapUI extends UI {
public static final String SERVER_ROUTING = "clientRoutingMode";

static final String SERVER_CONNECTED = "this.serverConnected($0)";
static final String SERVER_CONNECTED_URL = "this.serverConnected($0, new URL($1, document.baseURI))";
static final String CLIENT_NAVIGATE_TO = "window.dispatchEvent(new CustomEvent('vaadin-router-go', {detail: new URL($0, document.baseURI)}))";

Element wrapperElement;
Expand Down Expand Up @@ -132,9 +130,7 @@ public void connectClient(String clientElementTag, String clientElementId,
if (getForwardToClientUrl() != null) {
navigateToClient(getForwardToClientUrl());
acknowledgeClient();

// TODO: Handle forward to server view.


} else if (isPostponed()) {
cancelClient();
} else {
Expand Down Expand Up @@ -162,10 +158,6 @@ public void connectClient(String clientElementTag, String clientElementId,
public void leaveNavigation(String route) {
navigateToPlaceholder(new Location(PathUtil.trimPath(route)));

// TODO: Handle forward to server view which may happen in a
// BeforeLeaveEvent or deny the forward or reroute to a server view in
// BeforeLeaveEvent.

// Inform the client whether the navigation should be postponed
if (isPostponed()) {
cancelClient();
Expand Down Expand Up @@ -224,23 +216,15 @@ void navigateToClient(String clientRoute) {
}

private void acknowledgeClient() {
serverConnected(false, null);
}

private void acknowledgeClient(String serverRoute) {
serverConnected(false, serverRoute);
serverConnected(false);
}

private void cancelClient() {
serverConnected(true, null);
serverConnected(true);
}

private void serverConnected(boolean cancel, String serverRoute) {
if (serverRoute == null) {
wrapperElement.executeJs(SERVER_CONNECTED, cancel);
} else {
wrapperElement.executeJs(SERVER_CONNECTED_URL, cancel, serverRoute);
}
private void serverConnected(boolean cancel) {
wrapperElement.executeJs(SERVER_CONNECTED, cancel);
}

private void navigateToPlaceholder(Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,29 +97,26 @@ protected Optional<Integer> handleTriggeredBeforeEvent(
}

@Override
protected boolean shouldPushHistoryState(NavigationEvent event, UI ui) {
protected boolean shouldPushHistoryState(NavigationEvent event) {
if (NavigationTrigger.CLIENT_SIDE.equals(event.getTrigger())) {
return true;
} else {
return super.shouldPushHistoryState(event, ui);
return super.shouldPushHistoryState(event);
}
}

@Override
protected void pushHistoryState(NavigationEvent event, UI ui) {
super.pushHistoryState(event, ui);
protected void pushHistoryState(NavigationEvent event) {
super.pushHistoryState(event);

if (ui instanceof JavaScriptBootstrapUI) {
JavaScriptBootstrapUI jsUI = (JavaScriptBootstrapUI) ui;
if (event.getUI() instanceof JavaScriptBootstrapUI) {
JavaScriptBootstrapUI jsUI = (JavaScriptBootstrapUI) event.getUI();

if (continueNavigationAction != null
// We're trying to navigate to a client view.
&& JavaScriptBootstrapUI.ClientViewPlaceholder.class
.isAssignableFrom(getNavigationState()
.getNavigationTarget())) {

// FIXME: This could be invoked from ClientViewPlaceholder or
// another client placeholder view type.
jsUI.navigateToClient(
event.getLocation().getPathWithQueryParameters());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@
*/
package com.vaadin.flow.router.internal;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import javax.servlet.http.HttpServletResponse;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasElement;
import com.vaadin.flow.component.UI;
Expand Down Expand Up @@ -57,11 +55,10 @@
import com.vaadin.flow.router.NavigationTrigger;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.PreserveOnRefresh;
import com.vaadin.flow.router.RouteParameters;
import com.vaadin.flow.router.Router;
import com.vaadin.flow.router.RouterLayout;
import com.vaadin.flow.router.RouteParameters;
import com.vaadin.flow.server.VaadinSession;

import elemental.json.JsonValue;

/**
Expand Down Expand Up @@ -270,20 +267,20 @@ private void pushHistoryStateIfNeeded(NavigationEvent event, UI ui) {
.getLastHandledLocation()
.getPathWithQueryParameters()))) {

if (shouldPushHistoryState(event, ui)) {
pushHistoryState(event, ui);
if (shouldPushHistoryState(event)) {
pushHistoryState(event);
}

ui.getInternals().setLastHandledNavigation(event.getLocation());
}
}

protected void pushHistoryState(NavigationEvent event, UI ui) {
protected void pushHistoryState(NavigationEvent event) {
// Enable navigating back
ui.getPage().getHistory().pushState(null, event.getLocation());
event.getUI().getPage().getHistory().pushState(null, event.getLocation());
}

protected boolean shouldPushHistoryState(NavigationEvent event, UI ui) {
protected boolean shouldPushHistoryState(NavigationEvent event) {
return NavigationTrigger.UI_NAVIGATE.equals(event.getTrigger());
}

Expand Down

0 comments on commit e7a3a25

Please sign in to comment.