Added ability to append query params

This commit is contained in:
Rohit Awate 2018-02-01 13:43:19 +05:30
parent 8db0594660
commit a8baf68ba3
7 changed files with 107 additions and 12 deletions

View file

@ -38,6 +38,8 @@ import javax.ws.rs.core.Response;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
public class DashboardController implements Initializable {
@ -48,7 +50,7 @@ public class DashboardController implements Initializable {
@FXML
private ComboBox<String> httpMethodBox;
@FXML
private VBox responseBox, loadingLayer, promptLayer;
private VBox responseBox, loadingLayer, promptLayer, paramsBox;
@FXML
private HBox responseDetails;
@FXML
@ -60,10 +62,12 @@ public class DashboardController implements Initializable {
@FXML
private TabPane requestOptionsTab;
@FXML
private Tab authTab, headersTab, bodyTab;
private Tab paramsTab, authTab, headersTab, bodyTab;
private JFXSnackbar snackBar;
private final String[] httpMethods = {"GET", "POST", "PUT", "DELETE", "PATCH"};
private List<StringKeyValueFieldController> paramsControllers;
private List<String> appendedParams;
private RequestManager requestManager;
private HeaderTabController headerTabController;
private BodyTabController bodyTabController;
@ -94,6 +98,10 @@ public class DashboardController implements Initializable {
httpMethodBox.getItems().addAll(httpMethods);
httpMethodBox.getSelectionModel().select(1);
paramsControllers = new ArrayList<>();
appendedParams = new ArrayList<>();
addParam();
snackBar = new JFXSnackbar(dashboard);
bodyTab.disableProperty().bind(Bindings.and(httpMethodBox.valueProperty().isNotEqualTo("POST"),
httpMethodBox.valueProperty().isNotEqualTo("PUT")));
@ -209,4 +217,33 @@ public class DashboardController implements Initializable {
responseArea.clear();
promptLayer.setVisible(true);
}
@FXML
private void appendParams() {
String pair, key, value;
for (StringKeyValueFieldController controller : paramsControllers) {
if (controller.isChecked()) {
key = controller.getHeader().getKey();
value = controller.getHeader().getValue();
pair = key + value;
if (!appendedParams.contains(pair)) {
addressField.appendText("?" + key + "=" + value + "&");
appendedParams.add(pair);
}
}
}
}
@FXML
private void addParam() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/dashboard/StringKeyValueField.fxml"));
Parent headerField = loader.load();
StringKeyValueFieldController controller = loader.getController();
paramsControllers.add(controller);
paramsBox.getChildren().add(headerField);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -32,6 +32,11 @@ public class StringKeyValueFieldController implements Initializable {
@FXML
private JFXCheckBox checkBox;
@Override
public void initialize(URL location, ResourceBundle resources) {
checkBox.disableProperty().bind(Bindings.or(keyField.textProperty().isEmpty(), valueField.textProperty().isEmpty()));
}
public Pair<String, String> getHeader() {
return new Pair<>(keyField.getText(), valueField.getText());
}
@ -39,9 +44,4 @@ public class StringKeyValueFieldController implements Initializable {
public boolean isChecked() {
return checkBox.isSelected();
}
@Override
public void initialize(URL location, ResourceBundle resources) {
checkBox.disableProperty().bind(Bindings.or(keyField.textProperty().isEmpty(), valueField.textProperty().isEmpty()));
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B

View file

@ -146,11 +146,11 @@
-fx-text-fill: white;
}
#addHeaderButton, #newStringKVButton {
#addHeaderButton, #newStringKVButton, #newParamButton {
-fx-background-color: orangered;
}
#newFileKVButton {
#newFileKVButton, #appendParamsButton {
-fx-background-color: #5d53b1;
}

View file

@ -16,7 +16,7 @@
~ limitations under the License.
-->
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
@ -83,6 +83,64 @@
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0">
<tabs>
<Tab fx:id="paramsTab" text="PARAMS">
<content>
<VBox>
<children>
<HBox alignment="CENTER" maxHeight="0.0" spacing="20.0"
VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets/>
</VBox.margin>
<children>
<JFXButton fx:id="newParamButton" onAction="#addParam"
text=" NEW PARAM" textFill="WHITE"
HBox.hgrow="ALWAYS">
<graphic>
<ImageView fitHeight="15.0" fitWidth="15.0"
pickOnBounds="true"
preserveRatio="true">
<image>
<Image url="@../../assets/Plus.png"/>
</image>
</ImageView>
</graphic>
<HBox.margin>
<Insets/>
</HBox.margin>
</JFXButton>
<JFXButton fx:id="appendParamsButton"
onAction="#appendParams" ripplerFill="WHITE"
text=" APPEND PARAMS" textFill="WHITE"
HBox.hgrow="ALWAYS">
<graphic>
<ImageView fitHeight="15.0" fitWidth="15.0"
pickOnBounds="true"
preserveRatio="true">
<image>
<Image url="@../../assets/CheckMark.png"/>
</image>
</ImageView>
</graphic>
<HBox.margin>
<Insets/>
</HBox.margin>
</JFXButton>
</children>
<padding>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0"/>
</padding>
</HBox>
<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER"
VBox.vgrow="ALWAYS">
<content>
<VBox fx:id="paramsBox" alignment="TOP_CENTER"/>
</content>
</ScrollPane>
</children>
</VBox>
</content>
</Tab>
<Tab fx:id="authTab" text="AUTHORIZATION"/>
<Tab fx:id="headersTab" text="HEADERS"/>
<Tab fx:id="bodyTab" text="BODY"/>

View file

@ -26,7 +26,7 @@
xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.rohitawate.restaurant.dashboard.FormDataTabController">
<children>
<HBox alignment="CENTER_LEFT" VBox.vgrow="NEVER">
<HBox alignment="CENTER" VBox.vgrow="NEVER">
<VBox.margin>
<Insets/>
</VBox.margin>

View file

@ -26,7 +26,7 @@
xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.rohitawate.restaurant.dashboard.HeaderTabController">
<children>
<HBox alignment="CENTER_LEFT" VBox.vgrow="NEVER">
<HBox alignment="CENTER" VBox.vgrow="NEVER">
<VBox.margin>
<Insets/>
</VBox.margin>