Johann Woelper 7 лет назад
Родитель
Сommit
91a4dcefbf
2 измененных файлов с 58 добавлено и 22 удалено
  1. 57 18
      index.html
  2. 1 4
      src/main.rs

+ 57 - 18
index.html

@@ -1,33 +1,30 @@
 <!doctype html>
 
+<head>
+    <meta charset="utf-8" />
+</head>
+
 <title>Level tool</title>
 <link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.red-blue.min.css" />
 <script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
 
 
-
 <style>
     .entry {
         width: 100%;
         background-color: aquamarine;
         padding: 2em;
     }
-
     .descriptor {
         display: inline-block;
         width: 5em;
     }
-
-
     .log {
         font-size: 0.8em;
         line-height: 1em;
         background-color: aliceblue;
         padding: 1em;
     }
-
-
-
     .json-tree-value-number {
         color: red;
     }
@@ -36,27 +33,69 @@
 
 
 <div id="app">
-
-    
     <main class="mdl-layout__content">
-
-
         <div class="page-content">
-            yo yo yo <br>
-        
-            hi {{config}}
-
-
+            yo yo yo
+            <br> hi {{config}}
+            <br>
             <a onclick="getData()">get</a>
-
+            <br>
+            <a onclick="setData()">set</a>
         </div>
     </main>
 </div>
 
+
 <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
 <!-- <link href="https://unpkg.com/vue-json-tree@0.3.3/dist/json-tree.css" rel="stylesheet"> -->
 <!-- <script src="https://unpkg.com/vue-json-tree@0.3.3/dist/json-tree.js"></script> -->
-<script src="app.js"></script>
+<script>
+    var app = new Vue({
+        el: '#app',
+        data: {
+            config: {
+                released_episode: 80,
+                last_diorama: 50,
+                available_dioramas: 0,
+                first_diorama: 6,
+                github_levels: [],
+                github_episodes: [],
+                github_success: false,
+                github_access_token: "ac4311edd3cc5acf4ccc321525a96a",
+            },
+        },
+        mounted: function () {},
+        watch: {},
+        computed: {
+            test: function () {},
+        }
+    })
+
+
+    function getData() {
+        var xhr = new XMLHttpRequest();
+        var url = "http://localhost:8000/get";
+        xhr.onreadystatechange = function () {
+            if (this.readyState == 4 && this.status == 200) {
+                var response = JSON.parse(JSON.parse(this.responseText));
+                app.config = response;
+            }
+        };
+        xhr.open("GET", url, true);
+        xhr.send();
+    }
+
+
+    function setData() {
+        xhr = new XMLHttpRequest();
+        xhr.open('GET', 'http://localhost:8000/set/' + encodeURI(JSON.stringify(app.config)));
+        // xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
+        xhr.onload = function () {
+            console.log(xhr.responseText);
+        };
+        xhr.send();
+    }
+</script>
 <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
 
 

+ 1 - 4
src/main.rs

@@ -23,11 +23,8 @@ fn get() -> String {
 
 #[get("/")]
 fn test() -> File {
-    let mut f = std::fs::File::open("index.html").unwrap();
+    let f = std::fs::File::open("index.html").unwrap();
     f
-//     let mut contents = String::new();
-//     f.read_to_string(&mut contents).unwrap();
-//     contents
 }
 
 #[get("/<obj>")]