Browse Source

fix app users

Nikolay Suslov 6 years ago
parent
commit
633c06f4ea

+ 29 - 8
public/app.js

@@ -85,6 +85,9 @@ class App {
       window._LCS_SYS_USER = undefined;
       window._LCS_WORLD_USER = undefined;
 
+      _LCSDB.get('lcs/app').load();
+      _LCSDB.get('users').load();
+
       _LCSDB.get('lcs/app').get('pub').once(res => {
 
         if (res) {
@@ -805,11 +808,20 @@ class App {
 
   async setUserPaths(user) {
 
-    await _LCSDB.get('users').get(user).get('pub').once(res => {
+     await _LCSDB.get('users').get(user).get('pub').once(res => {
       if (res)
-        window._LCS_WORLD_USER = _LCSDB.user(res);
+        window._LCS_WORLD_USER = {
+          alias: user,
+          pub: res
+        }   
     }).then();
 
+
+    // await _LCSDB.get('users').get(user).get('pub').once(res => {
+    //   if (res)
+    //     window._LCS_WORLD_USER = _LCSDB.user(res);
+    // }).then();
+
   }
 
   async HandleParsableRequestGenID(ctx) {
@@ -911,8 +923,10 @@ class App {
       if (!dataJson.path['instance']) return undefined;
     }
 
-    let userAlias = await _LCS_WORLD_USER.get('alias').once().then();
-    let userPub = await _LCSDB.get('users').get(userAlias).get('pub').once().then();
+    //let userAlias = await _LCS_WORLD_USER.get('alias').once().then();
+    // let userPub = await _LCSDB.get('users').get(userAlias).get('pub').once().then();
+    let userAlias = _LCS_WORLD_USER.alias;
+    let userPub = _LCS_WORLD_USER.pub;
 
     let loadInfo = await this.getLoadInformation(dataJson);
     let saveInfo = await this.loadSaveObject(loadInfo);
@@ -949,15 +963,18 @@ class App {
   // an empty array).
 
   async lookupSaveRevisions(public_path, save_name) {
+
+    let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);
+
     var result = [];
     var states = [];
     let docName = 'savestate_/' + public_path + '/' + save_name + '_vwf_json';
 
-    let revs = await _LCS_WORLD_USER.get('documents').get(public_path).get(docName).get('revs').once().then();
+    let revs = await userDB.get('documents').get(public_path).get(docName).get('revs').once().then();
     if (revs) {
       for (const res of Object.keys(revs)) {
         if (res !== '_') {
-          let el = await _LCS_WORLD_USER.get('documents').get(public_path).get(docName).get('revs').get(res).once().then();
+          let el = await userDB.get('documents').get(public_path).get(docName).get('revs').get(res).once().then();
           if (el)
             result.push(parseInt(el.revision));
         }
@@ -1010,6 +1027,8 @@ class App {
 
     //let objName = loadInfo[ 'save_name' ] +'/'+ "savestate_" + loadInfo[ 'save_revision' ];
 
+    let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);
+
     if (!loadInfo.save_name) {
       return undefined
     }
@@ -1022,7 +1041,7 @@ class App {
 
     let worldName = this.helpers.appPath //loadInfo[ 'application_path' ].slice(1);
 
-    let saveObject = await _LCS_WORLD_USER.get('documents').get(worldName).get(objName).get('revs').get(objNameRev).once().then();
+    let saveObject = await userDB.get('documents').get(worldName).get(objName).get('revs').get(objNameRev).once().then();
     let saveInfo = saveObject ? JSON.parse(saveObject.jsonState) : saveObject;
 
     return saveInfo;
@@ -1428,7 +1447,9 @@ class App {
   async loadSavedState(filename, applicationpath, revision) {
     console.log("Loading: " + filename);
 
-    let userName = await _LCS_WORLD_USER.get('alias').once().then();
+    let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);
+
+    let userName = await userDB.get('alias').once().then();
 
     if (revision) {
       window.location.pathname = '/' + userName + applicationpath + '/load/' + filename + '/' + revision + '/';

+ 6 - 2
public/helpers.js

@@ -93,10 +93,12 @@ class Helpers {
 
     async IsFileExist(path) {
 
+        let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);
+
         var seperatorFixedPath = path.slice(1);//path.replace(/\//g, '/');
         let worldName = seperatorFixedPath.split('/')[0];
         let fileName = seperatorFixedPath.replace(worldName + '/', "");
-        let doc = await _LCS_WORLD_USER.get('worlds').get(worldName).get(fileName).once().then();
+        let doc = await userDB.get('worlds').get(worldName).get(fileName).once().then();
         if (doc) {
             return true
         }
@@ -105,8 +107,10 @@ class Helpers {
 
     async IsExist(path) {
 
+        let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);
+        
         var seperatorFixedPath = path.slice(1);//path.replace(/\//g, '/');
-        let doc = await _LCS_WORLD_USER.get('worlds').get(seperatorFixedPath).once().then();
+        let doc = await userDB.get('worlds').get(seperatorFixedPath).once().then();
         if (doc) {
             return true
         }

+ 9 - 3
public/vwf.js

@@ -480,7 +480,9 @@ Copyright (c) 2014-2018 Nikolai Suslov and the Krestianstvo.org project contribu
             let appName = JSON.parse(localStorage.getItem('lcs_app')).path.application.split(".").join("_");
             let dbPath = appName + '_config_yaml';
            
-            _LCS_WORLD_USER.get('worlds').get(path.slice(1)).get(dbPath).get('file').load(res => {
+            let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);
+
+            userDB.get('worlds').get(path.slice(1)).get(dbPath).get('file').load(res => {
                 
                 var conf = "";
 
@@ -4886,6 +4888,8 @@ if ( ! childComponent.source ) {
 
 
             var fileName = "";
+            let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);    
+                
 
                 if(dbName.includes("vwf_example_com")){
                     //userDB = await window._LCS_SYS_USER.get('proxy').then();
@@ -4900,7 +4904,7 @@ if ( ! childComponent.source ) {
                     let worldName = dbName.split('/')[0];
                     //userDB = await window._LCS_WORLD_USER.get('worlds').path(worldName).then();
                    fileName = dbName.replace(worldName + '/', "");
-                   window._LCS_WORLD_USER.get('worlds').path(worldName).get(fileName).get('file').load(r=>{
+                   userDB.get('worlds').path(worldName).get(fileName).get('file').load(r=>{
                     //console.log(r);
                     parseComp(r);
 
@@ -4962,6 +4966,8 @@ if ( ! childComponent.source ) {
                 //var userDB = window._LCS_WORLD_USER.get('worlds').get(worldName);
                 var fileName = "";
 
+                let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);  
+
                 if(dbName.includes("vwf_example_com")){
                     //userDB = window._LCS_SYS_USER.get('proxy');
                     fileName = dbName;
@@ -4972,7 +4978,7 @@ if ( ! childComponent.source ) {
  
                 } else {
                     fileName = dbName.replace(worldName + '/', "");
-                    window._LCS_WORLD_USER.get('worlds').path(worldName).get(fileName).get('file').load(r=>{
+                    userDB.get('worlds').path(worldName).get(fileName).get('file').load(r=>{
                         //console.log(r);
                         parseComp(r);
     

+ 2 - 2
public/vwf/model/aframe.js

@@ -596,8 +596,8 @@ define(["module", "vwf/model", "vwf/utility"], function (module, model, utility)
                                 let worldName = path.slice(1);
                                 let dbPath = propertyValue.split(".").join("_");
 
-
-                                _LCS_WORLD_USER.get('worlds').get(worldName).get(dbPath).get('file').load(response => {
+                                let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);
+                                userDB.get('worlds').get(worldName).get(dbPath).get('file').load(response => {
                                     if (response) {
                                         console.log(JSON.parse(response));
                                         let assets = JSON.parse(response);

+ 2 - 2
public/vwf/view/document.js

@@ -56,8 +56,8 @@ define( [ "module", "vwf/view", "vwf/utility"], function( module, view, utility)
                let appName = JSON.parse(localStorage.getItem('lcs_app')).path.application.split(".").join("_");
                let dbPath = appName + '_html';
               let worldName = path.slice(1);
-   
-               _LCS_WORLD_USER.get('worlds').get(worldName).get(dbPath).once().then(res => {
+              let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);
+              userDB.get('worlds').get(worldName).get(dbPath).once().then(res => {
                    
                    var responseText = "";
                    

+ 2 - 1
public/vwf/view/editor-new.js

@@ -2951,8 +2951,9 @@ define([
                     this.style.visibility = 'hidden';
                     let fileName = 'appui_js';
                     let worldName = self.helpers.getRoot(true).root;//url.split('/')[0];
+                    let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);
 
-                    _LCS_WORLD_USER.get('worlds').get(worldName).get(fileName).once(res => {
+                    userDB.get('worlds').get(worldName).get(fileName).once(res => {
 
                         this._importScript(res.file);
                     })

+ 8 - 0
public/web/index-app.js

@@ -291,6 +291,14 @@ class IndexApp {
                 // document.querySelector('#worldGUI').$update();
                 // document.querySelector('#main').$update();
 
+                _LCSDB.get('users').get(alias).not(res => {
+                    let userObj = {
+                        alias: alias,
+                        pub: ack.sea.pub
+                    }
+                    _LCSDB.get('users').get(alias).put(userObj);
+                  })
+
                 _LCSDB.user().get('profile').once(function (data) { console.log(data) })
 
                 let el = document.getElementById("loginGUI");