Skip to content

Commit

Permalink
Add option to open link in browser for HTML responses and minor impro…
Browse files Browse the repository at this point in the history
…vements
  • Loading branch information
RohitAwate committed Jul 1, 2018
1 parent e1e282c commit c86f180
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
Expand All @@ -52,9 +54,11 @@
import javax.ws.rs.ProcessingException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.awt.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.time.LocalDateTime;
import java.util.ArrayList;
Expand Down Expand Up @@ -154,31 +158,33 @@ public void initialize(URL url, ResourceBundle rb) {
responseArea.selectAll();
responseArea.copy();
responseArea.deselect();
snackbar.show("Response rawBody copied to clipboard.", 5000);
snackbar.show("Response body copied to clipboard.", 5000);
});

responseTypeBox.getItems().addAll("JSON", "XML", "HTML", "PLAIN TEXT");

responseTypeBox.valueProperty().addListener(change -> {
String type = responseTypeBox.getValue();
try {
switch (type) {
case "JSON":
HighlightMode mode;
switch (type) {
case "JSON":
try {
JsonNode node = EverestUtilities.jsonMapper.readTree(responseArea.getText());
responseArea.setText(EverestUtilities.jsonMapper.writeValueAsString(node), HighlightMode.JSON);
break;
case "XML":
responseArea.setText(responseArea.getText(), HighlightMode.XML);
break;
case "HTML":
responseArea.setText(responseArea.getText(), HighlightMode.HTML);
break;
default:
responseArea.setText(responseArea.getText(), HighlightMode.PLAIN);
}
} catch (IOException e) {
Services.loggingService.logWarning("Response could not be parsed.", e, LocalDateTime.now());
} catch (IOException e) {
Services.loggingService.logWarning("Response could not be parsed.", e, LocalDateTime.now());
}
return;
case "XML":
mode = HighlightMode.XML;
break;
case "HTML":
mode = HighlightMode.XML;
break;
default:
mode = HighlightMode.PLAIN;
}
responseArea.setMode(mode);
});

errorTitle.setText("Oops... That's embarrassing!");
Expand Down Expand Up @@ -427,6 +433,18 @@ private void prettifyResponseBody(EverestResponse response) {
case "text/html":
responseTypeBox.setValue("HTML");
responseArea.setText(responseBody, HighlightMode.HTML);
if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
snackbar.show("Open link in browser?", "YES", 5000, e -> {
snackbar.close();
new Thread(() -> {
try {
Desktop.getDesktop().browse(new URI(addressField.getText()));
} catch (Exception ex) {
Services.loggingService.logWarning("Invalid URL encountered while opening in browser.", ex, LocalDateTime.now());
}
}).start();
});
}
break;
default:
responseTypeBox.setValue("PLAIN TEXT");
Expand Down Expand Up @@ -566,6 +584,16 @@ public DashboardState getState() {
* @param state - State of the dashboard
*/
public void setState(DashboardState state) {
/*
The only value from a set of constants in the state.json file is the httpMethod
which, if manipulated to a non-standard value by the user, would still
be loaded into the httpMethodBox, causing severe errors while making requests.
To prevent this, we check if it is a standard value (GET, POST, PUT, PATCH or DELETE) and
only then proceed to applying the rest of the state values to the Dashboard.
This is an extreme case, but still something to be taken care of.
*/
boolean validMethod = false;
for (String method : httpMethods) {
if (state.httpMethod.equals(method))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private List<HistoryItemController> getSearchResults(String searchString) {

int relativityIndex = controller.getRelativityIndex(searchString);

// Split the string into words and get total relativity index as sum of individual indices.
// Split the string into words and get total relativity index as the sum of individual indices.
String words[] = searchString.split("\\s");
for (String word : words)
relativityIndex += controller.getRelativityIndex(word);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void createBugReporter() {
} catch (IOException e) {
e.printStackTrace();
}
Services.loggingService.logInfo("BugReporter was copied to installation folder.", LocalDateTime.now());
Services.loggingService.logInfo("BugReporter was copied to installation directory.", LocalDateTime.now());

}).start();
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/css/Adreana.css
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
}

.visualizerLabel {
-fx-font-family: "Liberation Mono", monospace;
-fx-font-family: "Liberation Mono", "Consolas", "Courier New", "Monaco", "DejaVu Sans Mono", monospace;
}

.visualizerRootLabel {
Expand Down Expand Up @@ -374,3 +374,8 @@
-fx-text-fill: white;
-fx-alignment: center;
}

.jfx-snackbar-action .text {
-fx-fill: azure;
-fx-font-weight: bold;
}
10 changes: 5 additions & 5 deletions src/main/resources/css/syntax/Moondust.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* limitations under the License.
*/

/*General rules for EverestCodeArea*/
/* General rules for EverestCodeArea */

.everest-code-area {
-fx-background-color: #282828;
}

.everest-code-area .text {
-fx-fill: #ababab;
-fx-font-family: "Liberation Mono", monospace;
-fx-font-family: "Liberation Mono", "Consolas", "Courier New", "Monaco", "DejaVu Sans Mono", monospace;
-fx-font-size: 17px;
}

Expand All @@ -34,7 +34,7 @@
-fx-fill: azure !important;
}

/*Common to JSON and XML*/
/* Common to JSON and XML */

.xml_bracket,
.json_curly {
Expand All @@ -52,7 +52,7 @@
-fx-fill: cornflowerblue !important;
}

/*JSON-specific*/
/* JSON-specific */

.json_array {
-fx-fill: limegreen !important;
Expand All @@ -68,7 +68,7 @@
-fx-font-weight: bold;
}

/*XML-specific*/
/* XML-specific */

.xml_attribute {
-fx-fill: darkviolet !important;
Expand Down

0 comments on commit c86f180

Please sign in to comment.