Nikolay Suslov hace 4 años
padre
commit
22a177843c
Se han modificado 3 ficheros con 102 adiciones y 16 borrados
  1. 16 8
      public/app.js
  2. 60 5
      public/web/index-app.js
  3. 26 3
      public/web/world-app.js

+ 16 - 8
public/app.js

@@ -40,8 +40,9 @@ class App {
     this.reflectorClient = new ReflectorClient;
     this.config = {};
 
-    this.initDB();
-    this.initUser();
+    this.initDB()
+    new Promise(res=> {this.initUser(); res});
+    
 
     import('/lib/polyglot/language.js').then(res => {
       window._LangManager = new res.default;
@@ -207,7 +208,14 @@ class App {
   }
 
   initUser() {
-    _LCSDB.user().recall({ sessionStorage: 1 });
+
+    function recall() {
+      _LCSDB.user().recall({ sessionStorage: 1 })
+    }
+
+    setTimeout(
+      recall, 1000)
+
   }
 
 
@@ -1268,7 +1276,10 @@ class App {
 
   }
 
-  async generateFrontPage(infoEl) {
+  async generateFrontPage() {
+
+    let infoEl = document.createElement("div");
+    infoEl.setAttribute("id", "indexPage");
 
     let lang = _LangManager.locale;
 
@@ -1292,13 +1303,10 @@ class App {
 
     console.log("INDEX");
 
-    let infoEl = document.createElement("div");
-    infoEl.setAttribute("id", "indexPage");
-
     window._app.hideProgressBar();
     window._app.hideUIControl();
 
-   (new Promise(res => res(_app.generateFrontPage(infoEl)))).then(res=>{
+   (new Promise(res => res(_app.generateFrontPage()))).then(res=>{
 
 
     if (!_app.indexApp) {

+ 60 - 5
public/web/index-app.js

@@ -20,7 +20,7 @@ class IndexApp {
         }
 
         this.initHTML();
-        
+
 
     }
 
@@ -277,17 +277,22 @@ class IndexApp {
    
     }
 
-    async allWorldsStatesForUser(userAlias) {
+    async allWorldsStatesForUser(userAlias, worldName, elID) {
 
         let userPub = await _app.helpers.getUserPub(userAlias);
         //let db = _LCSDB.user(userPub);
 
-        let doc = document.querySelector("#worldsGUI");
+        let doc = elID ? document.querySelector("#" + elID): document.querySelector("#worldsGUI");
 
         var worlds = {};
 
         if(userPub) {
-        worlds = this.createWorldsGUI('state', userAlias, userPub, 'allStates') 
+            if(!worldName){
+                worlds = this.createWorldsGUI('state', userAlias, userPub) 
+            } else {
+                worlds = this.createWorldsGUI('state', userAlias, userPub, worldName) 
+            }
+        
         } else {
 
         worlds = {
@@ -1425,8 +1430,16 @@ class IndexApp {
 
         let db = _LCSDB.user(userPub);
 
+       var headerText = 'Worlds';
+
+        if(worldType == 'state' && !worldName){
+            headerText = 'All World States for ' + userAlias;
+        } else {
+            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 headerText = worldName ? 'States for ' + worldName : 'All Worlds Protos'
 
         let worldCards = {
             $cell: true,
@@ -1458,6 +1471,8 @@ class IndexApp {
                     })
                 } else if(worldType == 'state') {
                 //get states
+
+                if(!worldName) {
                     console.log('get states');
                 db.get('documents')
                     .map()
@@ -1494,6 +1509,46 @@ class IndexApp {
        
                     })
 
+                } else {
+
+                    console.log('get states for ' + worldName);
+                    db.get('documents')
+                        .map((res, k) => {if (k == worldName) return res})
+                        .on((res,k)=>{
+                            if( k !== 'id'){
+                                console.log('From world: ', k);
+    
+                                let worldStatesInfo = Object.entries(res).filter(el=>el[0].includes('_info_vwf_json'));
+                                worldStatesInfo.map(el=>{
+                                   
+                                    let saveName = el[0].split('/')[2].replace('_info_vwf_json', "");
+                                    let cardID = userAlias + '_' + saveName + '_' + k;
+                                    console.log(cardID, ' - ', el);
+    
+                                    let doc = this._cards.filter(el=> el.$components[0].id == 'worldCard_'+ cardID)[0];
+           
+                                    if(!doc) {
+                                        doc = this._makeWorldCard({protoName: k, stateName: saveName}, cardID);
+                                        this._cards.push(doc);
+                                    } 
+    
+                                })
+                                //let saveName = el.stateName.split('/')[2].replace('_info_vwf_json', "");
+    
+                            }
+                           
+                            //let doc = document.querySelector('#'+ k);
+                        //    let doc = this._cards.filter(el=> el.$components[0].id == 'worldCard_'+ userAlias + '_' + k)[0];
+           
+                        //     if(!doc) {
+                        //         doc = this._makeWorldCard(k);
+                        //         this._cards.push(doc);
+                        //     } 
+           
+                        })
+
+
+                }
 
                 }
              

+ 26 - 3
public/web/world-app.js

@@ -26,6 +26,29 @@ class WorldApp {
         el2.setAttribute("id", "worldStates");
         document.body.appendChild(el2);
 
+        document.querySelector("#worldStates").$cell({
+            id: "worldStates",
+            $cell: true,
+            $type: "div",
+            _comps: [],
+            _wcards: {},
+            $components: [],
+            _refresh: function (comps) {
+                //do update;
+                //this._userAlias = user;
+                this._comps = comps;
+                this.$components = this._comps;
+            },
+            $init: function () {
+                console.log('init comp...');
+            },
+
+            $update: function () {
+                //do update;
+                console.log('update me');
+            }
+        });
+
     }
 
 
@@ -528,6 +551,7 @@ class WorldApp {
         }
         })
 
+        document.querySelector("#aboutWorld")._refresh(worldCardGUI);
        
 
 
@@ -547,7 +571,7 @@ class WorldApp {
        
         //worldCardGUI._refresh(info);
         //worldCardGUI._updateComps();
-        document.querySelector("#aboutWorld")._refresh(worldCardGUI);
+        
         //document.querySelector("#aboutWorld")._refreshWorldComps(info);
 
       
@@ -569,8 +593,7 @@ class WorldApp {
     // })
 
     if (!saveName) {
-       // _app.indexApp.allWorldsStatesForUser(user.user, space)
-
+        _app.indexApp.allWorldsStatesForUser(user.user, space, 'worldStates')
     }
 
         // if (!saveName) {