Johann Woelper vor 7 Jahren
Ursprung
Commit
b4aecd9acc
4 geänderte Dateien mit 70 neuen und 123 gelöschten Zeilen
  1. 7 0
      Cargo.lock
  2. 2 1
      Cargo.toml
  3. 22 8
      src/main.rs
  4. 39 114
      static/index.html

+ 7 - 0
Cargo.lock

@@ -124,6 +124,11 @@ dependencies = [
  "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "json"
+version = "0.11.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
 [[package]]
 name = "language-tags"
 version = "0.2.2"
@@ -206,6 +211,7 @@ dependencies = [
 name = "objectstore"
 version = "0.1.0"
 dependencies = [
+ "json 0.11.13 (registry+https://github.com/rust-lang/crates.io-index)",
  "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "rocket 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "rocket_codegen 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -538,6 +544,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2"
 "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e"
 "checksum isatty 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6c324313540cd4d7ba008d43dc6606a32a5579f13cc17b2804c13096f0a5c522"
+"checksum json 0.11.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9ad0485404155f45cce53a40d4b2d6ac356418300daed05273d9e26f91c390be"
 "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a"
 "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
 "checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7"

+ 2 - 1
Cargo.toml

@@ -7,4 +7,5 @@ authors = ["Johann Woelper <woelper@gmail.com>"]
 rocket = "*"
 rocket_codegen = "*"
 lazy_static = "1.1.0"
-rocket_cors = "0.3.0"
+rocket_cors = "0.3.0"
+json = "*"

+ 22 - 8
src/main.rs

@@ -3,6 +3,7 @@
 
 #[macro_use] extern crate rocket;
 #[macro_use] extern crate lazy_static;
+#[macro_use] extern crate json;
 extern crate rocket_cors;
 
 use std::io::prelude::*;
@@ -36,10 +37,18 @@ fn get() -> String {
 //set the storage
 #[get("/<obj>")]
 fn set(obj: String) -> String {
-    let parsed = obj;
-    println!("GOT {:?}", parsed);
+
+    let json_result = json::parse(obj.to_owned().as_str());
+    match json_result {
+        Ok(j) => {
+            println!("{:?}", j)
+        },
+        Err(e) => println!("Invalid Json {:?}", e)
+    }
+
+    println!("GOT {:?}", obj);
     let mut data = OBJECT.lock().unwrap();
-    *data = parsed;
+    *data = obj;
     String::from("ok")
 }
 
@@ -72,11 +81,16 @@ fn disk_committer() {
 }
 
 fn read_db() {    
-    let mut f = File::open("db").expect("db file not found");
-    let mut contents = String::new();
-    f.read_to_string(&mut contents).expect("{}");
-    let mut data = OBJECT.lock().unwrap();
-    *data = contents;
+    let dbfile = File::open("db");
+    match dbfile {
+        Ok(mut f) => {
+            let mut contents = String::new();
+            f.read_to_string(&mut contents).expect("{}");
+            let mut data = OBJECT.lock().unwrap();
+            *data = contents;
+        },
+        Err(e) => println!("Could not load db file {:?}", e)
+    }
 }
 
 fn main() {

+ 39 - 114
static/index.html

@@ -12,138 +12,68 @@
         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;
     }
 </style>
 
-
-
 <div id="app">
-
-    <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
-        <header class="mdl-layout__header">
-            <div class="mdl-layout__header-row">
-                <!-- Title -->
-                <span class="mdl-layout-title">
-                    {{config.appname}}
-                </span>
-                <div class="mdl-layout-spacer"></div>
-
-
-                <!-- Add spacer, to align navigation to the right -->
-                <div class="mdl-layout-spacer"></div>
-                <!-- Navigation. We hide it in small screens. -->
-                <nav class="mdl-navigation mdl-layout--large-screen-only">
-                </nav>
-            </div>
-        </header>
-        <div class="mdl-layout__drawer">
-            <span class="mdl-layout-title">Title</span>
-            <nav class="mdl-navigation">
-            </nav>
-
-
-        </div>
-        <main class="mdl-layout__content">
-            <div class="page-content">
-
-                <div class="mdl-tabs mdl-js-tabs mdl-js-ripple-effect">
-                    <div class="mdl-tabs__tab-bar">
-                        <a href="#updates" class="mdl-tabs__tab is-active">updates</a>
-                        <a href="#summary" class="mdl-tabs__tab">summary</a>
-                        <a href="#debug" class="mdl-tabs__tab">debug</a>
-                    </div>
-
-                    <div class="mdl-tabs__panel is-active" id="updates">
-
-
-                        
-                        <div class="entry">
-
-                            <template v-for="studio in config.studios">
-                                <template v-for="member in studio">
-                                    <div>
-                                        <span style="width: 10em; display: inline-block">
-                                            {{member.name}}
-                                        </span>
-                                        <textarea cols="50" rows="5" v-model="member.task" placeholder="Enter updates"></textarea>
-
-                                    </div>
-                                </template>
-
-                            </template>
-                            
-                            
-                        </div>
-                        
-                        
-                    </div>
-                    <div class="mdl-tabs__panel" id="summary">
-                        <div class="entry">
-                            <span class="descriptor">Episode</span>
-                            <input type="number" v-model="config.released_episode">
-                        </div>
-                    </div>
-                    <div class="mdl-tabs__panel" id="debug">
-                        <pre>
-                            {{config.studios}}
-                        </pre>                        
-                    </div>
-    
- 
-                </div>
-
-            </div>
-        </main>
-    </div>
+    <button onclick="store.setter(app.config)">save</button>
+    <button onclick="store.getter()">load</button>
+    <pre>
+        {{config}}
+    </pre>
 </div>
 
 
 <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
 <script>
-var app = '';
-
-var store = {
-    server_url: "http://localhost:8000",
-    target: app.config,
-    setter: function (o) {
-        xhr = new XMLHttpRequest();
-        xhr.open('GET', this.server_url + '/set/' + encodeURIComponent(JSON.stringify(o)));
-        xhr.onload = function () {console.log(xhr.responseText);};
-        xhr.send();
-    },
-    getter: function () {
-        xhr = new XMLHttpRequest();
-        xhr.open('GET', this.server_url + '/get');
-        xhr.onload = function () {
-            var decodedResponse = this.responseText;
-            console.log(decodedResponse);
-            try {
-                var response = JSON.parse(decodedResponse);
-                app.config = response;
-            }
-            catch(err) {
-                console.warn("json could not be parsed:", this.responseText);
-            }
-            // return response;
-        };
-        xhr.send();
-    },
-};
+    var app = '';
+
+    var store = {
+        server_url: "http://localhost:8000",
+        target: app.config,
+        setter: function (o) {
+            xhr = new XMLHttpRequest();
+            xhr.open('GET', this.server_url + '/set/' + encodeURIComponent(JSON.stringify(o)));
+            xhr.onload = function () {
+                console.log(xhr.responseText);
+            };
+            xhr.send();
+        },
+        getter: function () {
+            xhr = new XMLHttpRequest();
+            xhr.open('GET', this.server_url + '/get');
+            xhr.onload = function () {
+                var decodedResponse = this.responseText;
+                console.log(decodedResponse);
+                try {
+                    var response = JSON.parse(decodedResponse);
+                    app.config = response;
+                } catch (err) {
+                    console.warn("json could not be parsed:", this.responseText);
+                }
+                // return response;
+            };
+            xhr.send();
+        },
+    };
 
 
-var app = new Vue({
+    var app = new Vue({
         el: '#app',
         data: {
             config: {
@@ -160,11 +90,6 @@ var app = new Vue({
             test: function () {},
         }
     })
-
-
-
-
-
 </script>
 <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">