Browse Source

html form

Martin Kunz 5 years ago
parent
commit
3fab7126a0

+ 11 - 7
src/main/java/com/acdp/transceivr/WebServer.java

@@ -21,7 +21,6 @@ public class WebServer {
     public void start() {
         port(port);
         staticFiles.location("/webroot");
-        get("/hello", (req, res) -> "Hello World");
         get("/zero", (req, res) -> {
             var os = res.raw().getOutputStream();
             var ba = new byte[1024];
@@ -42,12 +41,17 @@ public class WebServer {
             return ja.toString();
         });
         post("/xfer", (req, res) -> {
-            Transfer t = new Transfer(nextID++);
-            t.from = req.queryParams("from");
-            t.to = req.queryParams("to");
-            LoadTools.startTransfer(t);
-            uploads.put(t.id, t);
-            return "OK: " + t.id;
+            try {
+                Transfer t = new Transfer(nextID++);
+                t.from = req.queryParams("from");
+                t.to = req.queryParams("to");
+                LoadTools.startTransfer(t);
+                uploads.put(t.id, t);
+                return "OK: " + t.id;
+            }
+            catch (Exception e) {
+                return "FAILED: " + e.toString();
+            }
         });
     }
 

+ 14 - 0
src/main/resources/logback.xml

@@ -0,0 +1,14 @@
+<configuration>
+
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <!-- encoders are assigned the type
+             ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+        <encoder>
+            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+        </encoder>
+    </appender>
+
+    <root level="info">
+        <appender-ref ref="STDOUT" />
+    </root>
+</configuration>

+ 23 - 0
src/main/resources/webroot/index.html

@@ -22,6 +22,11 @@
 <body>
 
 <div id="app">
+    <input v-model="from" placeholder="from">
+    <input v-model="to" placeholder="to">
+    <button @click="send">Send</button>
+
+
     <table>
         <template v-for="(item, index) in transfers">
             <tr>
@@ -63,12 +68,30 @@ rate: {{ item.rate}}k/s
         data: {
             input: '',
             transfers: [],
+            from: '',
+            to: ''
         },
         created: function () {
             setInterval(this.update, 330);
         },
         watch: {},
         methods: {
+            send: function (ts) {
+                let data = new URLSearchParams();
+                data.append('from', this.from);
+                data.append('to', this.to);
+                fetch('/xfer', {
+                    method: "POST",
+                    body: data
+                }).then(response => {
+                    console.log(response);
+                })
+                .catch(error => {
+                    this.$data.log = [];
+                    console.log(error)
+                });
+
+            },
             ts2txt: function (ts) {
                 return moment(ts).format('YYYY-MM-DD hh:mm ss.SSS ')
             },