Add LoadingLayer maintenance while switching tabs
This commit is contained in:
parent
df1f61a5d8
commit
c739f21337
4 changed files with 99 additions and 12 deletions
|
@ -188,9 +188,6 @@ public class DashboardController implements Initializable {
|
|||
responseArea.setMode(mode);
|
||||
});
|
||||
|
||||
errorTitle.setText("Oops... That's embarrassing!");
|
||||
errorDetails.setText("Something went wrong. Try to make another request.\nRestart Everest if that doesn't work.");
|
||||
|
||||
visualizer = new Visualizer();
|
||||
visualizerTab.setContent(visualizer);
|
||||
|
||||
|
@ -657,6 +654,9 @@ public class DashboardController implements Initializable {
|
|||
dashboardState.errorTitle = errorTitle.getText();
|
||||
dashboardState.errorDetails = errorDetails.getText();
|
||||
break;
|
||||
case LOADING:
|
||||
dashboardState.setRequestManager(requestManager);
|
||||
break;
|
||||
}
|
||||
|
||||
return dashboardState;
|
||||
|
|
|
@ -17,7 +17,20 @@
|
|||
package com.rohitawate.everest.controllers.state;
|
||||
|
||||
import com.rohitawate.everest.controllers.DashboardController.ResponseLayer;
|
||||
import com.rohitawate.everest.exceptions.RedirectException;
|
||||
import com.rohitawate.everest.exceptions.UnreliableResponseException;
|
||||
import com.rohitawate.everest.misc.Services;
|
||||
import com.rohitawate.everest.models.requests.EverestRequest;
|
||||
import com.rohitawate.everest.models.responses.EverestResponse;
|
||||
import com.rohitawate.everest.requestmanager.DataDispatchRequestManager;
|
||||
import com.rohitawate.everest.requestmanager.RequestManager;
|
||||
import javafx.concurrent.WorkerStateEvent;
|
||||
import javafx.event.Event;
|
||||
|
||||
import javax.ws.rs.ProcessingException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class DashboardState {
|
||||
|
@ -30,12 +43,40 @@ public class DashboardState {
|
|||
public String responseBody;
|
||||
public int responseTime;
|
||||
public int responseSize;
|
||||
public HashMap<String, String> responseHeaders;
|
||||
|
||||
// ErrorLayer parameters
|
||||
public String errorTitle;
|
||||
public String errorDetails;
|
||||
|
||||
public HashMap<String, String> responseHeaders;
|
||||
// ResponseLayer parameters
|
||||
private RequestManager requestManager;
|
||||
|
||||
public void setRequestManager(RequestManager manager) {
|
||||
this.requestManager = manager;
|
||||
requestManager.removeEventHandler(WorkerStateEvent.WORKER_STATE_SUCCEEDED, requestManager.getOnSucceeded());
|
||||
requestManager.removeEventHandler(WorkerStateEvent.WORKER_STATE_FAILED, requestManager.getOnFailed());
|
||||
|
||||
requestManager.setOnFailed(this::onRequestFailed);
|
||||
requestManager.setOnSucceeded(this::onRequestSucceeded);
|
||||
}
|
||||
|
||||
private void onRequestSucceeded(Event e) {
|
||||
this.visibleLayer = ResponseLayer.RESPONSE;
|
||||
EverestResponse response = requestManager.getValue();
|
||||
responseCode = response.getStatusCode();
|
||||
responseType = response.getMediaType().toString();
|
||||
responseTime = (int) response.getTime();
|
||||
responseSize = response.getSize();
|
||||
responseBody = response.getBody();
|
||||
|
||||
if (responseHeaders == null)
|
||||
responseHeaders = new HashMap<>();
|
||||
else
|
||||
responseHeaders.clear();
|
||||
|
||||
response.getHeaders().forEach((key, value) -> responseHeaders.put(key, value.get(0)));
|
||||
}
|
||||
|
||||
public DashboardState() {
|
||||
}
|
||||
|
@ -43,4 +84,44 @@ public class DashboardState {
|
|||
public DashboardState(ComposerState composer) {
|
||||
this.composer = composer;
|
||||
}
|
||||
|
||||
private void onRequestFailed(Event e) {
|
||||
this.visibleLayer = ResponseLayer.ERROR;
|
||||
Throwable throwable = requestManager.getException();
|
||||
Exception exception = (Exception) throwable;
|
||||
Services.loggingService.logWarning(this.composer.httpMethod + " request could not be processed.", exception, LocalDateTime.now());
|
||||
|
||||
if (throwable.getClass() == UnreliableResponseException.class) {
|
||||
UnreliableResponseException URE = (UnreliableResponseException) throwable;
|
||||
errorTitle = URE.getExceptionTitle();
|
||||
errorDetails = URE.getExceptionDetails();
|
||||
} else if (throwable.getClass() == ProcessingException.class) {
|
||||
errorTitle = "Everest couldn't connect.";
|
||||
errorDetails = "Either you are not connected to the Internet or the server is offline.";
|
||||
} else if (throwable.getClass() == RedirectException.class) {
|
||||
RedirectException redirect = (RedirectException) throwable;
|
||||
this.composer.target = redirect.getNewLocation();
|
||||
EverestRequest request = requestManager.getRequest();
|
||||
try {
|
||||
request.setTarget(redirect.getNewLocation());
|
||||
requestManager.restart();
|
||||
} catch (MalformedURLException MURLE) {
|
||||
Services.loggingService.logInfo("Invalid URL: " + this.composer.target, LocalDateTime.now());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (requestManager.getClass() == DataDispatchRequestManager.class) {
|
||||
if (throwable.getCause() != null && throwable.getCause().getClass() == IllegalArgumentException.class) {
|
||||
errorTitle = "Did you forget something?";
|
||||
errorDetails = "Please specify a body for your " + this.composer.httpMethod + " request.";
|
||||
} else if (throwable.getClass() == FileNotFoundException.class) {
|
||||
errorTitle = "File(s) not found:";
|
||||
errorDetails = throwable.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
requestManager.reset();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,10 @@ public abstract class RequestManager extends Service<EverestResponse> {
|
|||
appendHeaders();
|
||||
}
|
||||
|
||||
public EverestRequest getRequest() {
|
||||
return this.request;
|
||||
}
|
||||
|
||||
private void appendHeaders() {
|
||||
HashMap<String, String> headers = request.getHeaders();
|
||||
Map.Entry<String, String> mapEntry;
|
||||
|
|
|
@ -145,12 +145,12 @@
|
|||
</AnchorPane>
|
||||
<AnchorPane>
|
||||
<children>
|
||||
<VBox fx:id="responseBox" alignment="CENTER" AnchorPane.bottomAnchor="0.0"
|
||||
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<VBox fx:id="responseBox" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
|
||||
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<children>
|
||||
<StackPane VBox.vgrow="ALWAYS">
|
||||
<children>
|
||||
<VBox fx:id="responseLayer">
|
||||
<VBox fx:id="responseLayer" visible="false">
|
||||
<children>
|
||||
<HBox fx:id="responseDetails" alignment="CENTER_RIGHT" maxHeight="50.0"
|
||||
minHeight="50.0" spacing="30.0" VBox.vgrow="ALWAYS">
|
||||
|
@ -236,7 +236,7 @@
|
|||
</TabPane>
|
||||
</children>
|
||||
</VBox>
|
||||
<VBox fx:id="loadingLayer" alignment="CENTER" spacing="10.0">
|
||||
<VBox fx:id="loadingLayer" alignment="CENTER" spacing="10.0" visible="false">
|
||||
<children>
|
||||
<Label text="LOADING" textFill="WHITE">
|
||||
<font>
|
||||
|
@ -256,7 +256,7 @@
|
|||
</JFXButton>
|
||||
</children>
|
||||
</VBox>
|
||||
<VBox fx:id="promptLayer" alignment="CENTER" visible="false">
|
||||
<VBox fx:id="promptLayer" alignment="CENTER">
|
||||
<children>
|
||||
<Label text="Enter an address, select a method and hit send."
|
||||
textFill="WHITE">
|
||||
|
@ -275,13 +275,15 @@
|
|||
<Image url="@../../assets/Explosion.png"/>
|
||||
</image>
|
||||
</ImageView>
|
||||
<Label fx:id="errorTitle" text="Error title" textFill="WHITE">
|
||||
<Label fx:id="errorTitle" text="Oops... That's embarrassing!"
|
||||
textFill="WHITE">
|
||||
<font>
|
||||
<Font name="System Bold" size="32.0"/>
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="errorDetails" text="Error details" textAlignment="CENTER"
|
||||
textFill="#c3c3c3">
|
||||
<Label fx:id="errorDetails"
|
||||
text="Something went wrong. Try to make another request.Restart Everest if that doesn't work."
|
||||
textAlignment="CENTER" textFill="#c3c3c3">
|
||||
<font>
|
||||
<Font size="22.0"/>
|
||||
</font>
|
||||
|
|
Loading…
Reference in a new issue