Browse Source

Merge remote-tracking branch 'upstream/lcs2New'

Nikolay Suslov 6 years ago
parent
commit
86cdd9bc23
2 changed files with 220 additions and 97 deletions
  1. 102 2
      public/app.js
  2. 118 95
      public/web/index-app.js

+ 102 - 2
public/app.js

@@ -1610,7 +1610,60 @@ class App {
     // console.log(data)
   }
 
-  async getAllStateWorldsInfoForUser(userAlias) {
+  async getAllStateWorldsInfoForUser(userAlias, cb) {
+
+    let userPub = await _LCSDB.get('users').get(userAlias).get('pub').once().then();
+
+    var db = _LCSDB.user(userPub);
+
+    if (_LCSUSER.is) {
+      if (_LCSUSER.is.alias == userAlias)
+        db = _LCSUSER;
+    }
+
+
+    db.get('worlds').once().map().once((val, index)=>{
+      db.get('documents').get(index).once().map().once((res, datI)=>{
+
+        var doc = {};
+
+         if (datI.includes('_info_vwf_json')){
+
+          if (res && res !== 'null') {
+
+            if (res.file && res.file !== 'null') {
+  
+              let saveName = datI.split('/')[2].replace('_info_vwf_json', "");
+
+              let worldDesc = JSON.parse(res.file);
+              let root = Object.keys(worldDesc)[0];
+              var appInfo = worldDesc[root]['en'];
+  
+              let langID = localStorage.getItem('krestianstvo_locale');
+              if (langID) {
+                appInfo = worldDesc[root][langID]
+              }
+  
+              doc = {
+                'worldName': index + '/load/' + saveName,
+                'created': res.created ? res.created : res.modified,
+                'modified': res.modified,
+                'type': 'saveState',
+                'userAlias': userAlias,
+                'info': appInfo
+              }
+            }
+          }
+         }
+
+         if (Object.keys(doc).length !== 0)
+            cb({[doc.worldName]: doc})
+      })
+    })
+  }
+
+
+  async getAllStateWorldsInfoForUserPromise(userAlias) {
 
     let userPub = await _LCSDB.get('users').get(userAlias).get('pub').once().then();
 
@@ -1641,7 +1694,54 @@ class App {
   }
 
 
-  async getAllProtoWorldsInfoForUser(userAlias) {
+  async getAllProtoWorldsInfoForUser (userAlias, cb){
+
+    let userPub = await _LCSDB.get('users').get(userAlias).get('pub').once().then();
+
+    var db = _LCSDB.user(userPub);
+
+    if (_LCSUSER.is) {
+      if (_LCSUSER.is.alias == userAlias)
+        db = _LCSUSER;
+    }
+
+    db.get('worlds').once().map().once((val, index)=>{
+      db.get('worlds').get(index).get('info_json').once(res=>{
+        
+       var doc = {};
+
+        if (res && res !== 'null') {
+
+          if (res.file && res.file !== 'null') {
+
+            let worldDesc = JSON.parse(res.file);
+            let root = Object.keys(worldDesc)[0];
+            var appInfo = worldDesc[root]['en'];
+
+            let langID = localStorage.getItem('krestianstvo_locale');
+            if (langID) {
+              appInfo = worldDesc[root][langID]
+            }
+
+           doc = {
+              'worldName': index,
+              'created': res.created ? res.created : res.modified,
+              'modified': res.modified,
+              'type': 'proto',
+              'userAlias': userAlias,
+              'info': appInfo
+            }
+          }
+        }
+
+        if (Object.keys(doc).length !== 0)
+            cb({[index]: doc})
+      })
+    })
+
+  }
+
+  async getAllProtoWorldsInfoForUserPromise(userAlias) {
 
     let userPub = await _LCSDB.get('users').get(userAlias).get('pub').once().then();
 

+ 118 - 95
public/web/index-app.js

@@ -5,7 +5,7 @@ import { Header } from '/web/header.js';
 class IndexApp {
     constructor() {
         console.log("app constructor");
-        
+
 
         this.worlds = {};
         this.language = _LangManager.language;
@@ -73,19 +73,19 @@ class IndexApp {
         document.body.appendChild(entry);
 
         let divs = ['appGUI', 'userLobby', 'main', 'worldsGUI'];
-        divs.forEach(el=>{
+        divs.forEach(el => {
             let appEl = document.createElement("div");
             appEl.setAttribute("id", el);
             entry.appendChild(appEl);
         })
-        
+
         //init CELL
         document.querySelector("#userLobby").$cell({
             id: "userLobby",
             $cell: true,
             $type: "div",
             $components: [],
-            $update: function(){
+            $update: function () {
                 this.$components = self.initUserGUI()
             }
         });
@@ -96,13 +96,13 @@ class IndexApp {
             $type: "div",
             $components: [],
             _comps: [],
-            _refresh: async function(data, fn){
+            _refresh: async function (data, fn) {
                 _app.showProgressBar();
                 this._comps = await fn.call(self, data);
                 this.$update();
                 _app.hideProgressBar();
             },
-            $update: async function(){
+            $update: async function () {
                 this.$components = this._comps
             }
         });
@@ -133,7 +133,7 @@ class IndexApp {
 
     }
 
-   initApp() {
+    initApp() {
 
         // let appElHTML = await _app.helpers.getHtmlText('/web/app.html');
         // appEl.innerHTML = appElHTML;
@@ -147,107 +147,130 @@ class IndexApp {
 
     }
 
-    async initWorldsProtosListForUser (userAlias) {
+    async initWorldsProtosListForUser(userAlias) {
         document.querySelector("#worldsGUI").$components = [];
         await document.querySelector("#worldsGUI")._refresh(userAlias, this.getWorldsProtosListForUser);
-     }
+    }
 
-    async initWorldsStatesListForUser (userAlias) {
+    async initWorldsStatesListForUser(userAlias) {
         document.querySelector("#worldsGUI").$components = [];
         await document.querySelector("#worldsGUI")._refresh(userAlias, this.getWorldsStatesListForUser);
-     }
+    }
 
 
-    async getWorldsStatesListForUser (userAlias) {
+    async getWorldsStatesListForUser(userAlias) {
 
+        let self = this;
         let worldsGUI = [];
 
-        let data = await _app.getAllStateWorldsInfoForUser(userAlias);
 
-        Object.entries(data).forEach(el=>{
+        let worlds = self.createWorldsGUI(userAlias, 'allStates' );
 
-            let worlds = this.createWorldsGUI(userAlias, el[0]);
-            worlds._states = el[1];
-            worlds.$update();
+        await _app.getAllStateWorldsInfoForUser(userAlias,
+            function (data) {
+            let doc = document.querySelector("#allStates_" + userAlias);
+            if (doc) {
+                Object.assign(doc._states, data);
+                doc.$update();
+            }
+        }
+            );
             worldsGUI.push(worlds);
 
-        })
+        // Object.entries(data).forEach(el => {
 
-       
-        return [ 
-                {
-                    $type: "div",
-                    class: "mdc-layout-grid",
-                    $components: [
-                        {
-                            $type: "div",
-                            class: "mdc-layout-grid__inner",
-                            $components: [
-                                {
-                                    $type: "div",
-                                    class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
-                                    $components: [
-                                        {
-                                            $type: "h1",
-                                            class: "mdc-typography--headline4",
-                                            $text: 'States for ' + userAlias
-                                        }
-                                    ]
-                                },
-                                {
-                                    $type: "div",
-                                    class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
-                                    $components: [].concat(worldsGUI)
-                                }
-                            ]
-                        }
-                    ]
-                }
-            ]
+        //     let worlds = this.createWorldsGUI(userAlias, el[0]);
+        //     worlds._states = el[1];
+        //     worlds.$update();
+        //     worldsGUI.push(worlds);
+
+        // })
+
+
+        return [
+            {
+                $type: "div",
+                class: "mdc-layout-grid",
+                $components: [
+                    {
+                        $type: "div",
+                        class: "mdc-layout-grid__inner",
+                        $components: [
+                            {
+                                $type: "div",
+                                class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
+                                $components: [
+                                    {
+                                        $type: "h1",
+                                        class: "mdc-typography--headline4",
+                                        $text: 'States for ' + userAlias
+                                    }
+                                ]
+                            },
+                            {
+                                $type: "div",
+                                class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
+                                $components: [].concat(worldsGUI)
+                            }
+                        ]
+                    }
+                ]
+            }
+        ]
     }
 
-    async getWorldsProtosListForUser (userAlias) {
+    async getWorldsProtosListForUser(userAlias) {
 
 
-            let worldsGUI = [];
+        let worldsGUI = [];
 
-            let data = await _app.getAllProtoWorldsInfoForUser(userAlias);
+        //let data = await _app.getAllProtoWorldsInfoForUser(userAlias);
 
-            let worlds = this.createWorldsGUI(userAlias);
-            worlds._states = data;
-            worlds.$update();
-            worldsGUI.push(worlds);
-        
-            return [
+        let worlds = this.createWorldsGUI(userAlias);
+
+        await _app.getAllProtoWorldsInfoForUser(userAlias, function (data) {
+
+            let doc = document.querySelector("#allWorlds_" + userAlias);
+            if (doc) {
+                Object.assign(doc._states, data);
+                doc.$update();
+            }
+        })
+
+        //worlds._states = data;
+        //worlds.$update();
+        worldsGUI.push(worlds);
+
+        return [
+            {
+                $type: "div",
+                class: "mdc-layout-grid",
+                $components: [
                     {
                         $type: "div",
-                        class: "mdc-layout-grid",
+                        class: "mdc-layout-grid__inner",
                         $components: [
                             {
                                 $type: "div",
-                                class: "mdc-layout-grid__inner",
+                                class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
                                 $components: [
                                     {
-                                        $type: "div",
-                                        class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
-                                        $components: [
-                                            {
-                                                $type: "h1",
-                                                class: "mdc-typography--headline4",
-                                                $text: 'Worlds for ' + userAlias
-                                            }
-                                        ]
-                                    },
-                                    {
-                                        $type: "div",
-                                        class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
-                                        $components: [].concat(worldsGUI)
-                                    },
+                                        $type: "h1",
+                                        class: "mdc-typography--headline4",
+                                        $text: 'Worlds for ' + userAlias
+                                    }
                                 ]
-                            }
+                            },
+                            {
+                                $type: "div",
+                                class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
+                                $components: [].concat(worldsGUI)
+                            },
                         ]
                     }
                 ]
+            }
+        ]
     }
 
     initUser() {
@@ -324,7 +347,7 @@ class IndexApp {
                             "onclick": function (e) {
                                 e.preventDefault();
                                 page("/app/worlds/states")
-                               // window.location.pathname = "/app/worlds/states"
+                                // window.location.pathname = "/app/worlds/states"
                                 //_app.indexApp.getAppDetailsFromDefaultDB('states');
 
                             }
@@ -406,9 +429,9 @@ class IndexApp {
                                 "onclick": function (e) {
                                     e.preventDefault();
                                     let alias = _LCSUSER.is.alias;
-                                   // window.location.pathname = '/' + alias + '/worlds/states'
-                                   page('/' + alias + '/worlds/states');
-                                   // page.redirect('/' + alias + '/worlds/states');
+                                    // window.location.pathname = '/' + alias + '/worlds/states'
+                                    page('/' + alias + '/worlds/states');
+                                    // page.redirect('/' + alias + '/worlds/states');
                                     //_app.indexApp.getWorldsFromUserDB(alias);       
                                 }
                             })
@@ -431,7 +454,7 @@ class IndexApp {
                 ].concat(gui)
             }
         }
-    
+
         let loginGUI =
         {
             $type: "div",
@@ -476,9 +499,9 @@ class IndexApp {
                                         "label": "Login",
                                         "value": this._alias,
                                         "type": "text",
-                                        "init": function() {
-                                                    this._aliasField = new mdc.textField.MDCTextField(this);
-                                                }
+                                        "init": function () {
+                                            this._aliasField = new mdc.textField.MDCTextField(this);
+                                        }
                                     }),
                                 ]
                             },
@@ -496,7 +519,7 @@ class IndexApp {
                                         "label": "Password",
                                         "value": this._pass,
                                         "type": "password",
-                                        "init": function() {
+                                        "init": function () {
                                             this._passField = new mdc.textField.MDCTextField(this);
                                         }
                                     }),
@@ -567,7 +590,7 @@ class IndexApp {
                                                 });
                                             }
                                         })
-                                        
+
 
 
                                 ]
@@ -585,7 +608,7 @@ class IndexApp {
         //     $cell: true,
         //     $type: "div",
         //     $components: [ 
-               
+
         //         userGUI, loginGUI, _app.widgets.divider, worldGUI]
         // }
         // );
@@ -790,7 +813,7 @@ class IndexApp {
                     //             // document.querySelector('#worldStatesGUI')._refresh({});
                     //             // let data = await _app.getSaveStates(desc.userAlias, desc.worldName);
                     //             // document.querySelector('#worldStatesGUI')._refresh(data);
- 
+
                     //         }
                     //     }
                     // )
@@ -885,8 +908,8 @@ class IndexApp {
 
     createWorldsGUI(userAlias, worldName) {
         let self = this;
-        let id = worldName?worldName + '_' + userAlias: "allWorlds_" + userAlias
-        let headerText = worldName?'States for ' + worldName: 'All Worlds Protos'
+        let id = worldName ? worldName + '_' + userAlias : "allWorlds_" + userAlias
+        let headerText = worldName ? 'States for ' + worldName : 'All Worlds Protos'
 
         let worldCards = {
             $cell: true,
@@ -943,11 +966,11 @@ class IndexApp {
                                 $type: "div",
                                 class: "mdc-layout-grid__inner",
                                 $components: Object.entries(this._states)
-                                .filter(el =>Object.keys(el[1]).length !== 0)
-                                .sort(function (el1, el2) {
-                                    return parseInt(el2[1].created) - parseInt(el1[1].created)
-                                })
-                                .map(this._makeWorldCard)
+                                    .filter(el => Object.keys(el[1]).length !== 0)
+                                    .sort(function (el1, el2) {
+                                        return parseInt(el2[1].created) - parseInt(el1[1].created)
+                                    })
+                                    .map(this._makeWorldCard)
                             }
                         ]