Skip to content

Commit

Permalink
#192 - Possibility to reset URL (delete parameters from URL) -Done (#193
Browse files Browse the repository at this point in the history
)

* initial work for #192

* #192 - Possibility to reset URL (delete parameters from URL) - Done
  • Loading branch information
FrankHossfeld authored May 11, 2021
1 parent a07c52c commit 2c82754
Show file tree
Hide file tree
Showing 40 changed files with 478 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import elemental2.dom.PopStateEvent;
import jsinterop.base.Js;

import javax.naming.spi.DirObjectFactory;
import java.util.*;

public class NaluPluginCoreWeb {
Expand Down Expand Up @@ -79,6 +80,7 @@ public static void getContextPath(ShellConfiguration shellConfiguration) {

@SuppressWarnings("StringSplitter")
public static NaluStartModel getNaluStartModel() {
Js.debugger();
Location location = Js.uncheckedCast(DomGlobal.location);
Map<String, String> queryParameters = new HashMap<>();
String search = location.search;
Expand Down Expand Up @@ -127,8 +129,23 @@ public static NaluStartModel getNaluStartModel() {
} else {
startRoute = "";
}
} return new NaluStartModel(startRoute,
queryParameters);
}

// in case we need to remove the parameter, update histry ...
if (PropertyFactory.get().isRemoveUrlParameterAtStart()) {
String href = location.href;
String newUrl = "";
if (href.contains("?")) {
newUrl = href.substring(0, href.indexOf("?"));
if (startRoute.length() > 0) {
newUrl = newUrl + "#" + startRoute;
DomGlobal.window.history.replaceState(newUrl, DomGlobal.document.title, newUrl);
}
}
}

return new NaluStartModel(startRoute,
queryParameters);
}

private static String getHashValue(String hash) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ public void generate(MetaModel metaModel)
metaModel);
generateIsStayOnSide(typeSpec,
metaModel);
generateIsRemoveUrlParameterAtStart(typeSpec,
metaModel);

JavaFile javaFile = JavaFile.builder(metaModel.getGenerateToPackage(),
typeSpec.build())
Expand Down Expand Up @@ -371,6 +373,17 @@ private void generateIsStayOnSide(TypeSpec.Builder typeSpec,
.build());
}

private void generateIsRemoveUrlParameterAtStart(TypeSpec.Builder typeSpec,
MetaModel metaModel) {
typeSpec.addMethod(MethodSpec.methodBuilder("isRemoveUrlParameterAtStart")
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.returns(boolean.class)
.addStatement("return $L",
metaModel.isRemoveUrlParameterAtStart() ? "true" : "false")
.build());
}

public static class Builder {

ProcessingEnvironment processingEnvironment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public class MetaModel {
/* does the context extends */
/* AbstractModuleContext? */
private boolean extendingIsModuleContext;
/* do we have to remove the URL parameter */
/* from the URL */
private boolean removeUrlParameterAtStart;

public MetaModel() {
this.modules = new ArrayList<>();
Expand All @@ -80,6 +83,7 @@ public MetaModel() {

this.applicationVersion = "APPLCIATIOPN-VERSION-NOT-AVAILABLE";
this.extendingIsModuleContext = false;
this.removeUrlParameterAtStart = false;
}

public ModuleModel getModuleModel() {
Expand Down Expand Up @@ -336,4 +340,12 @@ public String getIllegalRouteTarget() {
public void setIllegalRouteTarget(String illegalRouteTarget) {
this.illegalRouteTarget = illegalRouteTarget;
}

public boolean isRemoveUrlParameterAtStart() {
return removeUrlParameterAtStart;
}

public void setRemoveUrlParameterAtStart(boolean removeUrlParameterAtStart) {
this.removeUrlParameterAtStart = removeUrlParameterAtStart;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void scan()
}
metaModel.setStartRoute(applicationAnnotation.startRoute());
metaModel.setIllegalRouteTarget(applicationAnnotation.illegalRouteTarget());
metaModel.setRemoveUrlParameterAtStart(applicationAnnotation.removeUrlParameterAtStart());
metaModel.setUsingHash(applicationAnnotation.useHash());
metaModel.setUsingColonForParametersInUrl(applicationAnnotation.useColonForParametersInUrl());
metaModel.setStayOnSide(applicationAnnotation.stayOnSite());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,15 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,14 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,14 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,14 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,14 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,14 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,14 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,14 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,14 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,14 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,14 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,14 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,15 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,14 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ public boolean isStayOnSide() {
}

@Override
public PropertyFactory.ErrorHandlingMethod getErrorHandlingMethod() {
return PropertyFactory.ErrorHandlingMethod.ROUTING;
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,9 @@ public boolean isUsingColonForParametersInUrl() {
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,14 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,14 @@ public boolean isUsingHash() {
public boolean isUsingColonForParametersInUrl() {
return false;
}

@Override
public boolean isStayOnSide() {
return false;
}

@Override
public boolean isRemoveUrlParameterAtStart() {
return false;
}
}
Loading

0 comments on commit 2c82754

Please sign in to comment.