Skip to content

Commit 49630a3

Browse files
committed
IPTE-165: ON-OFF API Status
1 parent 4480dc8 commit 49630a3

File tree

2 files changed

+57
-8
lines changed

2 files changed

+57
-8
lines changed

src/main/java/de/doubleslash/keeptime/view/SettingsController.java

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package de.doubleslash.keeptime.view;
1818

1919
import java.io.File;
20+
import java.io.FileInputStream;
2021
import java.io.FileOutputStream;
2122
import java.io.IOException;
2223
import java.io.InputStream;
@@ -166,7 +167,7 @@ public class SettingsController {
166167
private TextField authName;
167168

168169
@FXML
169-
private PasswordField authPassword1;
170+
private PasswordField authPassword;
170171

171172
private ToggleGroup toggleGroup;
172173

@@ -185,6 +186,15 @@ public class SettingsController {
185186
@FXML
186187
private TextField authPort;
187188

189+
@FXML
190+
private Label labelPassword;
191+
192+
@FXML
193+
private Label labelPort;
194+
195+
@FXML
196+
private Label labelUsername;
197+
188198
private String propertiesFilePath = "application.properties";
189199

190200
private static final String GITHUB_PAGE = "https://www.github.com/doubleSlashde/KeepTime";
@@ -246,8 +256,41 @@ private void initialize() {
246256
radioApiOff.setToggleGroup(toggleGroup);
247257
radioApiOn.setToggleGroup(toggleGroup);
248258

249-
LOG.debug("saveButton.setOnAction");
259+
Properties properties = new Properties();
260+
User user;
261+
try (FileInputStream input = new FileInputStream(propertiesFilePath)) {
262+
properties.load(input);
263+
String apistatus = properties.getProperty("api");
264+
System.err.println(apistatus);
265+
266+
if (apistatus.equals("ON")) {
267+
radioApiOn.setSelected(true);
268+
radioApiOff.setSelected(false);
269+
authPort.setText(properties.getProperty("server.port"));
270+
authName.setText(properties.getProperty("authUsername"));
271+
// labelPort.setDisable(false);
272+
// labelUsername.setDisable(false);
273+
// labelPassword.setDisable(false);
274+
// authPort.setDisable(false);
275+
// authName.setDisable(false);
276+
// authPassword.setDisable(false);
277+
System.err.println("--------");
278+
} else if (apistatus.equals("OFF")) {
279+
radioApiOn.setSelected(false);
280+
radioApiOff.setSelected(true);
281+
// labelPort.setDisable(true);
282+
// labelUsername.setDisable(true);
283+
// labelPassword.setDisable(true);
284+
// authPort.setDisable(true);
285+
// authName.setDisable(true);
286+
// authPassword.setDisable(true);
287+
System.err.println("+++++++++");
288+
}
289+
} catch (IOException e) {
290+
e.printStackTrace();
291+
}
250292

293+
LOG.debug("saveButton.setOnAction");
251294
saveButton.setOnAction(ae -> {
252295
LOG.info("Save clicked");
253296

@@ -586,18 +629,24 @@ private void showLicense(final Licenses license) {
586629
}
587630

588631
private void handleApiOff() {
632+
Map<String, String> propertiesToUpdate = new HashMap<>();
589633
setWebApplicationType("none");
634+
propertiesToUpdate.put("api", "OFF");
635+
propertyWrite(propertiesToUpdate);
636+
590637
}
591638

592639
private void handleApiOn() {
593640
username = authName.getText();
594-
password = authPassword1.getText();
641+
password = authPassword.getText();
595642

596643
createAndSaveUser(username, password);
597644

598645
Map<String, String> propertiesToUpdate = new HashMap<>();
599646
propertiesToUpdate.put("spring.main.web-application-type", "");
600647
propertiesToUpdate.put("server.port", authPort.getText());
648+
propertiesToUpdate.put("api", "ON");
649+
propertiesToUpdate.put("authUsername", username);
601650

602651
propertyWrite(propertiesToUpdate);
603652
}

src/main/resources/layouts/settings.fxml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,24 +372,24 @@
372372
<content>
373373
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="420.0" prefWidth="407.0">
374374
<children>
375-
<Label layoutX="24.0" layoutY="169.0" text="Username:" />
375+
<Label fx:id="labelUsername" layoutX="24.0" layoutY="169.0" text="Username:" />
376376
<Label layoutX="14.0" layoutY="14.0" prefHeight="28.0" prefWidth="279.0" text="Rest API Authentication">
377377
<font>
378378
<Font name="System Bold" size="13.0" />
379379
</font>
380380
</Label>
381-
<Label layoutX="24.0" layoutY="219.0" text="Password:" />
382-
<TextField fx:id="authName" layoutX="97.0" layoutY="166.0" prefHeight="26.0" prefWidth="298.0" promptText="User" />
381+
<Label fx:id="labelPassword" layoutX="24.0" layoutY="219.0" text="Password:" />
382+
<TextField fx:id="authName" layoutX="97.0" layoutY="166.0" prefHeight="26.0" prefWidth="298.0" />
383383
<Label layoutX="24.0" layoutY="70.0" text="Auth" />
384-
<Label layoutX="26.0" layoutY="124.0" text="Port:" />
384+
<Label fx:id="labelPort" layoutX="26.0" layoutY="124.0" text="Port:" />
385385
<TextField fx:id="authPort" layoutX="97.0" layoutY="120.0" prefHeight="26.0" prefWidth="298.0" promptText="8080" />
386386
<RadioButton fx:id="radioApiOn" layoutX="88.0" layoutY="64.0" mnemonicParsing="false" text="ON">
387387
<toggleGroup>
388388
<ToggleGroup fx:id="authAPI" />
389389
</toggleGroup>
390390
</RadioButton>
391391
<RadioButton fx:id="radioApiOff" layoutX="219.0" layoutY="64.0" mnemonicParsing="false" text="OFF" toggleGroup="$authAPI" />
392-
<PasswordField fx:id="authPassword1" layoutX="97.0" layoutY="215.0" prefHeight="26.0" prefWidth="298.0" />
392+
<PasswordField fx:id="authPassword" layoutX="97.0" layoutY="215.0" prefHeight="26.0" prefWidth="298.0" />
393393
</children></AnchorPane>
394394
</content>
395395
<graphic>

0 commit comments

Comments
 (0)