From 5408a63a330cf867aed2fc9bd37a590e0febf6a2 Mon Sep 17 00:00:00 2001
From: Nils G <nils.gondermann@ruhr-uni-bochum.de>
Date: Mon, 6 Apr 2020 16:18:43 +0200
Subject: [PATCH] Added in-browser protocol debug tool

---
 controllers/debug.py   |  3 +++
 views/debug/index.html | 44 ++++++++++++++++++++++++++++++++++++++++++
 views/layout.html      | 10 ++++++++++
 3 files changed, 57 insertions(+)
 create mode 100644 controllers/debug.py
 create mode 100644 views/debug/index.html
 create mode 100644 views/layout.html

diff --git a/controllers/debug.py b/controllers/debug.py
new file mode 100644
index 0000000..00e415c
--- /dev/null
+++ b/controllers/debug.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+# try something like
+def index(): return dict(message="hello from debug.py")
\ No newline at end of file
diff --git a/views/debug/index.html b/views/debug/index.html
new file mode 100644
index 0000000..934b6e0
--- /dev/null
+++ b/views/debug/index.html
@@ -0,0 +1,44 @@
+{{extend 'layout.html'}}
+<h1>
+    JSON debug
+</h1>
+<table>
+    <tr>
+        <td>
+            <u>You</u><br>
+            <form>
+                URL: <input type="text" name="url" id="url" value="{{=URL('room','create')}}"><br>
+                <textarea rows=20 cols=60 id="input" placeholder="Your JSON parameters"></textarea><br>
+                <input type="submit">
+            </form>
+        </td>
+        <td style="vertical-align: top">
+            <u>Server</u><br>
+            Status-Code<input type="text" id="status" readonly=""><br>
+            <textarea readonly="" rows=20 cols=60 id="server" placeholder="Server Response"></textarea><br>
+        </td>
+    </tr>
+</table>
+<script type="text/javascript">
+    $('form').submit(function(){
+
+        $.ajax({
+            type: 'POST',
+            url: $("#url").val(),
+            dataType: 'json',
+            data: $('#input').val(),
+            contentType : 'application/json',
+            success: function(data) {
+               $("#status").val("200");
+               $("#server").val(JSON.stringify(data, null, 4));
+            },
+            error: function(xhr, statusText, errorThrown){
+                $("#status").val(xhr.status);
+                $("#server").val(errorThrown);
+            }
+        });
+
+        return (false);
+
+    });
+</script>
diff --git a/views/layout.html b/views/layout.html
new file mode 100644
index 0000000..ded03bf
--- /dev/null
+++ b/views/layout.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+    <head>
+        <meta charset="utf-8">
+        <meta name="viewport" content="width=device-width, initial-scale=1.0">
+        <script src="{{=URL('static','js/jquery.js')}}" type="text/javascript"></script>
+    </head>
+    <body>
+        {{include}}
+    </body>
+</html>
-- 
GitLab