Browse Source

work on connection go to spa

Simon 2 years ago
parent
commit
3b5a9c3a99
7 changed files with 318 additions and 0 deletions
  1. 56 0
      comm.go
  2. 29 0
      gui/indexExam.html
  3. 18 0
      gui/src/App.vue
  4. 25 0
      gui/src/main.js
  5. 28 0
      gui/src/mainEx.js
  6. 138 0
      index.html
  7. 24 0
      main.js

+ 56 - 0
comm.go

@@ -0,0 +1,56 @@
+package main
+
+import (
+	"fmt"
+	"log"
+	"net/http"
+	"time"
+)
+
+var Port = ":3001"
+
+func main() {
+
+	http.HandleFunc("/", ServeFiles)
+	fmt.Println("Serving @ : ", "http://127.0.0.1"+Port)
+	log.Fatal(http.ListenAndServe(Port, nil))
+}
+
+func ServeFiles(w http.ResponseWriter, r *http.Request) {
+
+	switch r.Method {
+
+	case "GET":
+
+		path := r.URL.Path
+
+		fmt.Println("path before: ", path)
+
+		if path == "/" {
+
+			path = "index.html"
+		} else {
+			path = "/home/simon/goCode/AnonymousTopicBasedPubSubCommunicationforMicroblogging/main.js"
+		}
+
+		fmt.Println("path after: ", path)
+
+		http.ServeFile(w, r, path)
+
+	case "POST":
+
+		r.ParseMultipartForm(0)
+
+		message := r.FormValue("message")
+
+		fmt.Println("----------------------------------")
+		fmt.Println("Message from Client: ", message)
+		// respond to client's request
+		fmt.Fprintf(w, "Server: %s \n", message+" | "+time.Now().Format(time.RFC3339))
+
+	default:
+		fmt.Fprintf(w, "Request type other than GET or POST not supported")
+
+	}
+
+}

+ 29 - 0
gui/indexExam.html

@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Home</title>
+</head>
+<body style="background-color: #cccccc;">
+
+    <div id="formBody" style="display: flex;justify-content: center;align-items: center;height: 90vh;">
+
+    <form method="POST" id="inputForm">
+
+        <label for="message">Message</label>
+        <input id="message" name="message" value="hello!!!" type="text">
+        <button type="submit" style="width:100px;">Go ...</button>
+    </form>     
+
+
+    </div>
+
+    <div id="serverMessageBox" style="text-align: center;">
+
+
+    </div>
+    
+</body>
+<script src="/static/main.js"></script>
+</html>

+ 18 - 0
gui/src/App.vue

@@ -57,6 +57,23 @@
     </ul>
   </div>
 </div>
+
+    <div id="formBody" style="display: flex;justify-content: center;align-items: center;height: 90vh;">
+
+    <form method="POST" id="inputForm">
+
+        <label for="message">Message</label>
+        <input id="message" name="message" value="app.vue" type="text">
+        <button type="submit" style="width:100px;">Go ...</button>
+    </form>     
+
+
+    </div>
+
+    <div id="serverMessageBox" style="text-align: center;">
+
+
+    </div>
  
 </template>
 
@@ -67,6 +84,7 @@ export default {
   components: { Tweet },
   data: function() {
     return {
+      url : "127.0.0.1:5555",
       tweetToSubmit: '',
       tweets : [
         {

+ 25 - 0
gui/src/main.js

@@ -2,3 +2,28 @@ import { createApp } from 'vue'
 import App from './App.vue'
 
 createApp(App).mount('#app')
+
+/*console.log("JS Loaded")
+
+const url = "127.0.0.1:5555"
+
+var inputForm = document.getElementById("inputForm")
+
+inputForm.addEventListener("submit", (e)=>{
+
+    //prevent auto submission
+    e.preventDefault()
+
+    const formdata = new FormData(inputForm)
+    fetch(url,{
+
+        method:"POST",
+        body:formdata,
+    }).then(
+        response => response.text()
+    ).then(
+        (data) => {console.log(data);document.getElementById("serverMessageBox").innerHTML=data}
+    ).catch(
+        error => console.error(error)
+    )
+})*/

+ 28 - 0
gui/src/mainEx.js

@@ -0,0 +1,28 @@
+console.log("JS Loaded")
+
+const url = "127.0.0.1:5555"
+
+var inputForm = document.getElementById("inputForm")
+
+inputForm.addEventListener("submit", (e)=>{
+
+    //prevent auto submission
+    e.preventDefault()
+
+    const formdata = new FormData(inputForm)
+    fetch(url,{
+
+        method:"POST",
+        body:formdata,
+    }).then(
+        response => response.text()
+    ).then(
+        (data) => {console.log(data);document.getElementById("serverMessageBox").innerHTML=data}
+    ).catch(
+        error => console.error(error)
+    )
+
+
+
+
+})

+ 138 - 0
index.html

@@ -0,0 +1,138 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Home</title>
+</head>
+<body style="background-color: #cccccc;">
+
+    <div id="formBody" style="display: flex;justify-content: center;align-items: center;height: 90vh;">
+
+    <form method="POST" id="inputForm">
+
+        <label for="message">Message</label>
+        <input id="message" name="message" value="hello!!!" type="text">
+        <button type="submit" style="width:100px;">Go ...</button>
+    </form>     
+
+
+    </div>
+
+    <div id="serverMessageBox" style="text-align: center;">
+
+
+    </div>
+    
+    <div class="container">
+        <div class="toppane">
+          <form>
+            <h1 style="font-size: large">Anonymous Topic Based PubSub Communication for Microblogging</h1>
+            <input type="text" ref="my_input" id="tweetInput">
+            <button @click.prevent="submitTweet()">Submit</button>
+            <br>
+            <h1 style="font-size: medium;">Input like: "text#topic1#topic2"</h1>
+      
+          </form>
+        </div>
+        <div class="leftpane">
+          <h1 style="font-size: large;text-align: center;">Topic list</h1>
+          <ol>
+            <li v-for="topic in topicList">
+              <input type="checkbox" :value="topic.topic" v-model="selectedTopics">
+              <label :for="topic.topic">{{topic.topic}}</label>
+            </li>
+          </ol>
+          <div class="impressum">
+            <h1 style="font-size: medium;"><br>This is the gui accompanying the thesis Anonymous Topic Based PubSub Communication for Microblogging.
+              <br><br>
+              <a href="https://arxiv.org/pdf/2108.08624.pdf" target="_blank"> You can find the paper the thesis is based upon here</a>
+            </h1>
+          </div>
+        </div>
+      
+        <div class="middlepane">
+          <h1 style="font-size: large;text-align: center;">Tweets</h1>
+          <ul>
+            <Tweet
+              v-for="(tweet, index) in tweets"
+              :key=index
+              :topics="tweet.topics"
+              :text="tweet.text"
+            ></Tweet>
+          </ul>
+        </div>
+      
+        <div class="rightpane">
+          <h1 style="font-size: large;text-align: center;">Topic list for archived tweets</h1>
+          <ol>
+            <li v-for="topic in topicListArchive">
+              <input type="checkbox" :value="topic.topic" v-model="selectedTopicsArchive">
+              <label :for="topic.topic">{{topic.topic}}</label>
+            </li>
+          </ol>
+          <br>
+          <ul>
+            <Tweet
+              v-for="(tweet, index) in tweetsArchive"
+              :key=index
+              :topics="tweet.topics"
+              :text="tweet.text"
+            ></Tweet>
+          </ul>
+        </div>
+      </div>
+</body>
+<script src="main.js"></script>
+</html>
+
+
+<style>
+    @import './assets/base.css';
+    
+    body, html {
+      width: 100%;
+      height: 100%;
+      margin: 0;
+    }
+    
+    .container {
+      width: 100%;
+      height: 100%;
+    }
+    
+    .leftpane {
+        width: 25%;
+        height: 100%;
+        float: left;
+        background-color: #0058b759;
+        border-collapse: collapse;
+    }
+    
+    .middlepane {
+        width: 50%;
+        height: 100%;
+        float: left;
+        border-collapse: collapse;
+    }
+    
+    .rightpane {
+      width: 25%;
+      height: 100%;
+      position: relative;
+      float: right;
+      background-color: #ffd700;
+      border-collapse: collapse;
+    }
+    
+    .toppane {
+      margin-top: 10px;
+      width: 100%;
+      height: 100px;
+      border-collapse: collapse;
+    }
+    
+    form {
+      text-align: center;
+    }
+    </style>

+ 24 - 0
main.js

@@ -0,0 +1,24 @@
+console.log("JS Loaded")
+
+const url = "127.0.0.1:3001"
+
+var inputForm = document.getElementById("inputForm")
+
+inputForm.addEventListener("submit", (e)=>{
+
+    //prevent auto submission
+    e.preventDefault()
+
+    const formdata = new FormData(inputForm)
+    fetch(url,{
+
+        method:"POST",
+        body:formdata,
+    }).then(
+        response => response.text()
+    ).then(
+        (data) => {console.log(data);document.getElementById("serverMessageBox").innerHTML=data}
+    ).catch(
+        error => console.error(error)
+    )
+})