Nikolay Suslov пре 4 година
родитељ
комит
5cf31aef30
2 измењених фајлова са 72 додато и 179 уклоњено
  1. 50 40
      public/app.js
  2. 22 139
      public/web/index-app.js

+ 50 - 40
public/app.js

@@ -1735,27 +1735,32 @@ class App {
 
   async getProtoWorldFiles(userPub, worldName, date) {
 
-    let fileNamesAll = (await _LCSDB.user(userPub).get('worlds').get(worldName).promOnce()).data;
-    let worldFileNames = Object.keys(fileNamesAll).filter(el => (el !== '_') && (el !== 'owner') && (el !== 'parent') && (el !== 'featured') && (el !== 'published') && (el !== 'info_json') && (el !== '_config_yaml') && (el !== '_yaml') && (el !== '_html') && (el !== 'proxy'));
-
-    let worldObj = {};
-    for (var doc in worldFileNames) {
-      let fn = worldFileNames[doc];
-      let res = (await _LCSDB.user(userPub).get('worlds').get(worldName).get(fn).promOnce()).data;
-      // var data = {
-      //   'file': res.file,
-      //   'modified': res.modified,
-      //   'created': res.created
-      // }
-      // if (!date) {
-      //   data = {
-      //     'file': res.file
-      //   }
-      // }
-      worldObj[fn] = res;
-    }
-    console.log(worldObj);
-    return worldObj
+     return (new Promise(res=>_LCSDB.user(userPub).get('worlds').get(worldName).once(res))).then(res=>{
+      let worldFiles = Object.entries(res).filter(el => (el[0].includes('_json')) || (el[0].includes('_yaml')) || (el[0].includes('_html')) || (el[0].includes('_js')))
+      .filter(el => (el[0] !== 'info_json'));
+
+
+      console.log(worldFiles);
+      return worldFiles
+    });
+   
+    //let worldObj = {};
+    // for (var doc in worldFileNames) {
+    //   let fn = worldFileNames[doc];
+    //   let res = (await _LCSDB.user(userPub).get('worlds').get(worldName).get(fn).promOnce()).data;
+    //   // var data = {
+    //   //   'file': res.file,
+    //   //   'modified': res.modified,
+    //   //   'created': res.created
+    //   // }
+    //   // if (!date) {
+    //   //   data = {
+    //   //     'file': res.file
+    //   //   }
+    //   // }
+    //   worldObj[fn] = res;
+    // }
+
   }
 
   async cloneWorldPrototype(worldName, userName, newWorldName, stateFileName) {
@@ -1789,7 +1794,7 @@ class App {
       }
     }
 
-    var worldID = window._app.helpers.GenerateInstanceID().toString();
+    let worldID = window._app.helpers.GenerateInstanceID().toString();
     if (newWorldName) {
       worldID = newWorldName
     }
@@ -1970,6 +1975,9 @@ class App {
     }
 
     //var documents = this.db.user().get('documents');
+    _LCSDB.user().get('documents').not(res=>{
+    _LCSDB.user().get('documents').put({id:'documents'})
+  })
 
     var saveRevision = new Date().valueOf();
 
@@ -1993,7 +2001,7 @@ class App {
     //let objName = loadInfo[ 'save_name' ] +'/'+ "savestate_" + loadInfo[ 'save_revision' ];
     // "savestate_" + loadInfo[ 'save_revision' ] + '/' + loadInfo[ 'save_name' ] + '_vwf_json'
     var docName = 'savestate_/' + root + '/' + filename + '_vwf_json';
-    let myNewWorldState = _LCSDB.user().get('documents').get(root).get(docName).put({});
+    let myNewWorldState = _LCSDB.user().get('documents').get(root).get(docName).put({'id': docName});
     //_LCSDB.user().get('documents').get(root).get(docName).put(stateWithRev, function(res) {
     myNewWorldState.put(stateWithRev, function (res) {
       if (res) {
@@ -2013,32 +2021,34 @@ class App {
 
       if (file) {
 
-        let modified = saveRevision;
-        let newOwner = _LCSDB.user().is.pub;
-        let userName = _LCSDB.user().is.alias;
+        // let modified = saveRevision;
+        // let newOwner = _LCSDB.user().is.pub;
+        // let userName = _LCSDB.user().is.alias;
 
         let fileData = (typeof file == 'object') ? JSON.stringify(file) : file;
 
-        let obj = {
-          'parent': userName + '/' + root,
-          'owner': newOwner,
-          'file': fileData, //file, //JSON.stringify(file),
-          //'modified': modified,
-          'created': modified
+        // let obj = {
+        //   'parent': userName + '/' + root,
+        //   'owner': newOwner,
+        //   'file': fileData, //file, //JSON.stringify(file),
+        //   //'modified': modified,
+        //   'created': modified
 
-        }
+        // }
 
         let docInfoName = 'savestate_/' + root + '/' + filename + '_info_vwf_json';
 
-        _LCSDB.user().get('documents').get(root).get(docInfoName).get('file').not(function (res) {
-          _LCSDB.user().get('documents').get(root).get(docInfoName).put(obj);
-        });
+        _LCSDB.user().get('documents').get(root).get(docInfoName).put(fileData);
 
-        _LCSDB.user().get('documents').get(root).get(docInfoName).get('created').not(function (res) {
-          _LCSDB.user().get('documents').get(root).get(docInfoName).get('created').put(modified);
-        });
+        // _LCSDB.user().get('documents').get(root).get(docInfoName).get('file').not(function (res) {
+        //   _LCSDB.user().get('documents').get(root).get(docInfoName).put(obj);
+        // });
+
+        // _LCSDB.user().get('documents').get(root).get(docInfoName).get('created').not(function (res) {
+        //   _LCSDB.user().get('documents').get(root).get(docInfoName).get('created').put(modified);
+        // });
 
-        _LCSDB.user().get('documents').get(root).get(docInfoName).get('modified').put(modified);
+        // _LCSDB.user().get('documents').get(root).get(docInfoName).get('modified').put(modified);
 
       }
     });

+ 22 - 139
public/web/index-app.js

@@ -20,7 +20,7 @@ class IndexApp {
         }
 
         this.initHTML();
-        this.initUser();
+        
 
     }
 
@@ -129,7 +129,8 @@ class IndexApp {
             $init: function () {
                 //this._status = "Welcome!"
                 //this._status = 'Welcome!';
-                //userEl.style.backgroundColor = '#e6e6e6';   
+                //userEl.style.backgroundColor = '#e6e6e6';  
+                self.initUser(); 
                 this._refresh(); //$update();
             },
             $update: function () {},
@@ -238,7 +239,7 @@ class IndexApp {
 
         worlds = {
             $type: 'div',
-            $text:  'Couls not find user with name: ' + userAlias,
+            $text:  'Could not find user with name: ' + userAlias,
             class: "mdc-typography--headline4"
         }
     }
@@ -278,14 +279,25 @@ class IndexApp {
    
     }
 
+    async allWorldsStatesForUser(userAlias) {
+
+        let userPub = await _app.helpers.getUserPub(userAlias);
+        //let db = _LCSDB.user(userPub);
 
-    async initWorldsProtosListForUser(userAlias) {
         let doc = document.querySelector("#worldsGUI");
-        //doc.$components = [];
-        let allInfo = await _app.getAllProtoWorldsInfoForUser(userAlias);//await this.getWorldsProtosListForUser(userAlias);
 
-        let worlds = this.createWorldsGUI(userAlias);
-        worlds._refresh(allInfo);
+        var worlds = {};
+
+        if(userPub) {
+        worlds = this.createWorldsGUI(userAlias, userPub, 'allStates') 
+        } else {
+
+        worlds = {
+            $type: 'div',
+            $text:  'Could not find user with name: ' + userAlias,
+            class: "mdc-typography--headline4"
+        }
+    }
 
         let components = [
             {
@@ -318,16 +330,12 @@ class IndexApp {
             }
         ];
 
-
         doc._refresh(components);
+   
+    }
 
-        //initiate update world cards
-        doc._wcards = worlds;
-        doc._wcards.$update();
 
-        //console.log(allInfo);
 
-    }
 
     async initWorldsStatesListForUser(userAlias) {
 
@@ -428,133 +436,8 @@ class IndexApp {
         
     }
 
-    async initWorldsProtosListForUserNew (userAlias) {
-
-       let userPub = await _app.helpers.getUserPub(userAlias);
-       let db = _LCSDB.user(userPub);
-
-        document.querySelector("#lab").$cell({
-            id: "lab",
-            $cell: true,
-            $type: "div",
-            _createCard: function(data){
-
-                let card = {
-                    $type: "div",
-                    id: '#'+ data,
-                    _worldName: "",
-                    _worldInfo: "info",
-                    $init: function(){
-                        this._worldName = data;
-
-                        // _LCSDB.user().get('worlds')
-                        // .map((el,k)=>k === this._worldName? el : undefined) 
-                        // .get('info_json').once(
-                        //     res=>{
-                        //         console.log("New World: ", res);
-                        //         if(!res.file){
-                        //             _LCSDB.get(res['_']['#']).once(res=>{
-                        //                 console.log("New World force get: ", res);
-                        //             })
-                        //         }
-                        //     }
-                        // )
-
-
-                        db.get('worlds').get(this._worldName).once((res)=>{
-                            console.log(res);
-                            this._worldInfo = res['info_json'];
-                        })
-                    
-
-                  
-                        //     .map()
-                        // .on((res,k,n)=>{
-                        //     if(k == 'info_json'){
-                        //         console.log(res);
-                        //         this._worldInfo = res;
-                        //         //this.$update();
-                        //     }
-                        // })
-                    },
-                    $update: function(){
-                        
-                        this.$components = [
-                            {
-                                $type: "div",
-                                $text: this._worldName
-                            },
-                            {
-                                $type: "div",
-                                $text: this._worldInfo
-                            }
-                        ]
-                    }
-
-                }
-                return card
-            },
-            _comps: [],
-            $init: function () {
-                console.log('init lab...');
-
-                db.get('worlds')
-                .map()
-                .on((res,k)=>{
-                    console.log('From world: ', k);
-                    //let doc = document.querySelector('#'+ k);
-                   let doc = this._comps.filter(el=> el.id == '#'+ k)[0];
-
-                    if(!doc) {
-                        doc = this._createCard(k);
-                        this._comps.push(doc);
-                    } 
-
-                    // _LCSDB.get(res['info_json']).once((res)=>{
-                    //     console.log(res);
-                    //     doc._worldInfo = res.file
-                    // })
-                    //this._refresh();
-
-                })
-                // .map((k,r,n)=>{
-                //     if(r == 'info_json')
-                //         {
-                //         //console.log(r);
-                //         return k
-                //     }
-                // })
-                // .once((res,k,n)=>{
-                //     console.log(res);
-                //     if(doc)
-                //         doc._worldInfo = res.file
-                // })
-                // .map((k,r,n)=>{
-                //     if(r == 'file')
-                //         {
-                //         //console.log(r);
-                //         return k
-                //         }
-                //     })
-                //     .on((res,k,n)=>{
-                //         console.log('From info ', res);
-                //     })
-
-                // .map()
-                // .on((res,k)=>{
-                //     console.log(res);
-                // })
-            },
-            $update: function () {
-                //do update;
-                console.log('update me');
-                this.$components = this._comps;
-            }
-        });
 
 
-    }
-
     initUser() {
         let self = this;