123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056 |
- import page from '/lib/page.mjs';
- class IndexApp {
- constructor() {
- console.log("app constructor");
- this.worlds = {};
- this.language = _LangManager.language;
- this.options = {
- query: 'pathname=' + window.location.pathname.slice(1,
- window.location.pathname.lastIndexOf("/")),
- secure: window.location.protocol === "https:",
- reconnection: false,
- path: '',
- transports: ['websocket']
- }
- //window.location.host
- var socket = io.connect(window._app.reflectorHost, this.options);
- const parse = (msg) => {
- this.parseAppInstancesData(msg)
- }
- socket.on('getWebAppUpdate', msg => parse.call(self, msg));
- socket.on("connect", function () {
- let noty = new Noty({
- text: 'Connected to Reflector!',
- timeout: 2000,
- theme: 'mint',
- layout: 'bottomRight',
- type: 'success'
- });
- noty.show();
- })
- socket.on('connect_error', function (err) {
- console.log(err);
- var errDiv = document.createElement("div");
- errDiv.innerHTML = "<div class='vwf-err' style='z-index: 10; position: absolute; top: 80px; right: 50px'>Connection error to Reflector!" + err + "</div>";
- document.querySelector('body').appendChild(errDiv);
- let noty = new Noty({
- text: 'Connection error to Reflector! ' + err,
- theme: 'mint',
- layout: 'bottomRight',
- type: 'error'
- });
- noty.show();
- });
- }
- async generateFrontPage() {
- let infoEl = document.createElement("div");
- infoEl.setAttribute("id", "info");
- let lang = _LangManager.locale;
- let infoElHTML = await _app.helpers.getHtmlText('/web/locale/' + lang + '/index.html');
- infoEl.innerHTML = infoElHTML;
- document.body.appendChild(infoEl);
- document.querySelector('#ruLang').addEventListener('click', function (e) {
- _LangManager.locale = 'ru';
- window.location.reload(true);
- });
- document.querySelector('#enLang').addEventListener('click', function (e) {
- _LangManager.locale = 'en';
- window.location.reload(true);
- });
- }
- async initApp() {
- let appEl = document.createElement("div");
- appEl.setAttribute("id", "app");
- let appElHTML = await _app.helpers.getHtmlText('/web/app.html');
- appEl.innerHTML = appElHTML;
- document.body.appendChild(appEl);
- this.initUser();
- this.initUserGUI();
- this.initWorldsListGUI();
- //this.getAppDetailsFromDB();
- }
- initUser() {
- _LCSDB.on('auth', (ack) => {
- if (ack.pub) {
- let alias = _LCSUSER.is.alias;
- let userEl = document.querySelector('#userGUI');
- userEl._status = 'Welcome ' + alias + '!';
- //userEl.style.backgroundColor = '#e6e6e6';
- userEl.$update();
- document.querySelector('#worldGUI').$update();
- document.querySelector('#main').$update();
- _LCSUSER.get('profile').once(function (data) { console.log(data) })
- var el = document.getElementById("loginGUI");
- if (el) {
- el.remove();
- }
- _LCSUSER.get('profile').not(function (key) {
- let profile = { 'alias': alias };
- _LCSUSER.get('profile').put(profile);
- })
- new Noty({
- text: alias + ' is succesfully authenticated!',
- timeout: 2000,
- theme: 'mint',
- layout: 'bottomRight',
- type: 'success'
- }).show();
- //this.getAppDetailsFromUserDB();
- }
- console.log(_LCSUSER.is);
- });
- }
- initUserGUI() {
- let worldGUI =
- {
- $type: "div",
- id: "worldGUI",
- class: "mdc-layout-grid mdc-layout-grid--align-left",
- _status: '',
- $init: function () {
- this._status = "init";
- },
- $update: function () {
- let guiForAll = [
- window._app.widgets.buttonStroked(
- {
- "label": 'Default World Protos',
- "onclick": function (e) {
- e.preventDefault();
- _app.indexApp.getAppDetailsFromDefaultDB('protos');
- }
- }),
- window._app.widgets.buttonStroked(
- {
- "label": 'Default World States',
- "onclick": function (e) {
- e.preventDefault();
- _app.indexApp.getAppDetailsFromDefaultDB('states');
- }
- })
- ];
- var guiUser = [];
- if (_LCSUSER.is) {
- guiUser = []
- }
- this.$components = [
- {
- $type: "h1",
- class: "mdc-typography--headline4",
- $text: "Worlds list"
- }
- ].concat(guiForAll).concat(guiUser)
- }
- }
- let userGUI =
- {
- $type: "div",
- id: "userGUI",
- // style:"background-color: #ffeb3b",
- class: "mdc-layout-grid mdc-layout-grid--align-left",
- _status: "",
- $init: function () {
- this._status = "Welcome!"
- },
- $update: function () {
- var gui = {};
- if (_LCSUSER.is) {
- gui = [
- window._app.widgets.buttonRaised(
- {
- "label": 'Sign OUT',
- "onclick": function (e) {
- _LCSUSER.leave().then(ack => {
- if (ack.ok == 0) {
- window.sessionStorage.removeItem('alias');
- window.sessionStorage.removeItem('tmp');
- window.location.reload(true);
- }
- });
- }
- }),
- {
- $type: "p"
- },
- window._app.widgets.buttonStroked(
- {
- "label": 'PROFILE',
- "onclick": function (e) {
- e.preventDefault();
- window.location.pathname = "/profile"
- }
- }),
- {
- $type: "p"
- },
- window._app.widgets.buttonStroked(
- {
- "label": 'My World protos',
- "onclick": function (e) {
- e.preventDefault();
- let alias = _LCSUSER.is.alias;
- page.redirect('/' + alias + '/worlds/protos');
- //_app.indexApp.getWorldsProtosFromUserDB(alias);
- }
- }),
- window._app.widgets.buttonStroked(
- {
- "label": 'My World states',
- "onclick": function (e) {
- e.preventDefault();
- let alias = _LCSUSER.is.alias;
- page.redirect('/' + alias + '/worlds/states');
- //_app.indexApp.getWorldsFromUserDB(alias);
- }
- })
- ]
- }
- this.$components = [
- window._app.widgets.buttonRaised(
- {
- "label": 'Connection settings',
- "onclick": function (e) {
- e.preventDefault();
- window.location.pathname = '/settings';
- }
- }),
- {
- $type: "h1",
- class: "mdc-typography--headline3",
- $text: this._status
- }
- ].concat(gui)
- }
- }
-
- let loginGUI =
- {
- $type: "div",
- id: "loginGUI",
- //style:"background-color: #efefef",
- class: "mdc-layout-grid mdc-layout-grid--align-left",
- _alias: null,
- _pass: null,
- _passField: null,
- _aliasField: null,
- _initData: function () {
- this._alias = '';
- this._pass = '';
- // if (window.sessionStorage.getItem('alias')) {
- // this._alias = window.sessionStorage.getItem('alias')
- // }
- // if (window.sessionStorage.getItem('tmp')) {
- // this._pass = window.sessionStorage.getItem('tmp')
- // }
- },
- $init: function () {
- this._initData();
- },
- $update: function () {
- this.$components = [
- {
- $type: "div",
- class: "mdc-layout-grid__inner",
- $components: [
- {
- $type: "div",
- class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
- $components: [
- {
- $type: "span",
- class: "mdc-typography--headline5",
- $text: "Login: "
- },
- window._app.widgets.inputTextFieldOutlined({
- "id": 'aliasInput',
- "label": "Login",
- "value": this._alias,
- "type": "text",
- "init": function() {
- this._aliasField = new mdc.textField.MDCTextField(this);
- }
- }),
- ]
- },
- {
- $type: "div",
- class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
- $components: [
- {
- $type: "span",
- class: "mdc-typography--headline5",
- $text: "Password: "
- },
- window._app.widgets.inputTextFieldOutlined({
- "id": 'passwordInput',
- "label": "Password",
- "value": this._pass,
- "type": "password",
- "init": function() {
- this._passField = new mdc.textField.MDCTextField(this);
- }
- }),
- ]
- },
- {
- $type: "div",
- class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
- $components: [
- window._app.widgets.buttonRaised(
- {
- "label": 'Sign UP',
- "onclick": function (e) {
- e.preventDefault();
- let alias = this._aliasField.value;
- let pass = this._passField.value
- if (pass.length < 7) {
- new Noty({
- text: "Your passphrase needs to be longer than 7 letters",
- timeout: 2000,
- theme: 'mint',
- layout: 'bottomRight',
- type: 'error'
- }).show();
- } else {
- //
- _LCSUSER.create(alias, pass,
- (ack) => {
- if (!ack.wait) { }
- if (ack.err) {
- console.log(ack.err)
- return ack.err
- };
- if (ack.pub) {
- _LCSUSER.auth(alias, pass);
- _LCSDB.get('users').get(alias).put({
- 'alias': alias,
- 'pub': ack.pub
- });
- }
- });
- }
- }
- }),
- {
- $type: "span",
- $text: " "
- },
- window._app.widgets.buttonRaised(
- {
- "label": 'Sign IN',
- "onclick": function (e) {
- e.preventDefault();
- _LCSUSER.auth(this._aliasField.value, this._passField.value, ack => {
- if (ack.err) {
- new Noty({
- text: ack.err,
- timeout: 2000,
- theme: 'mint',
- layout: 'bottomRight',
- type: 'error'
- }).show();
- }
- });
- }
- })
-
- ]
- }
- ]
- }
- ]
- }
- }
- document.querySelector("#userLobby").$cell({
- id: "userLobby",
- $cell: true,
- $type: "div",
- $components: [
-
- userGUI, loginGUI, _app.widgets.divider, worldGUI]
- }
- );
- }
- parseAppInstancesData(data) {
- if (data == "{}") {
- var el = document.querySelector(".instance");
- if (el) {
- var topEl = el.parentNode;
- topEl.removeChild(el);
- }
- // let removeElements = elms => Array.from(elms).forEach(el => el.remove());
- }
- let jsonObj = JSON.parse(data);
- var parsed = {};
- for (var prop in jsonObj) {
- var name = prop.split('/')[1];
- if (parsed[name]) {
- parsed[name][prop] = jsonObj[prop];
- } else {
- parsed[name] = {};
- parsed[name][prop] = jsonObj[prop];
- }
- }
- //console.log(parsed);
- if (Object.entries(this.worlds).length !== 0)
- document.querySelector("#main")._emptyLists();
- for (var prop in parsed) {
- var name = prop;
- let obj = Object.entries(parsed[prop]);
- var lists = {};
- obj.forEach(el => {
- let sotSave = prop;
- if (el[1].loadInfo['save_name']) {
- let saveName = prop + '/load/' + el[1].loadInfo.save_name;
- if (!lists[saveName])
- lists[saveName] = {};
- lists[saveName][el[0]] = el[1]
- } else {
- if (!lists[name])
- lists[name] = {};
- lists[name][el[0]] = el[1]
- }
- });
- // console.log(lists);
- Object.entries(lists).forEach(list => {
- let element = document.getElementById(list[0] + 'List');
- if (element) {
- element._setListData(list[1]);
- }
- })
- }
- // console.log(data)
- }
- initWorldsListGUI() {
- var self = this;
- let worldsListGUI = {
- $cell: true,
- $type: "div",
- id: "main",
- _status: "",
- _jsonData: {},
- _emptyLists: function () {
- Object.entries(this._jsonData).forEach(function (element) {
- //console.log(element);
- let el = document.getElementById(element[0] + 'List');
- if (el)
- el._setListData({});
- });
- },
- $init: function () {
- this._jsonData = {} //data//JSON.parse(data);
- },
- _makeWorldCard: function (m) {
- let langID = localStorage.getItem('krestianstvo_locale');
- var appInfo = m
- if (langID) {
- if (m[1][langID]) {
- appInfo = [m[0], m[1][langID], m[1].user, m[1].type, m[1].created, m[1].modified]
- }
- }
- return {
- $cell: true,
- $type: "div",
- class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
- $components: [
- this._worldCardDef(appInfo)
- ]
- }
- },
- $update: function () {
- this.$components = [
- {
- $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: "H3",
- $text: this._status
- }
- ]
- }
- ]
- },
- {
- $type: "div",
- class: "mdc-layout-grid__inner",
- $components: Object.entries(this._jsonData).sort(function(el1, el2){
- return parseInt(el2[1].created) - parseInt(el1[1].created)
- }).map(this._makeWorldCard)
- }
- ]
- },
- ]
- },
- _worldCardDef: function (desc) {
- let userGUI = [];
- let cardInfo = {
- "title": ""
- };
- if (desc[3] == 'saveState') {
- cardInfo.title = desc[0].split('/')[2];
- }
- if (desc[3] == 'proto') {
- cardInfo.title = desc[0];
- userGUI.push(
- {
- $type: "a",
- class: "mdc-button mdc-button--compact mdc-card__action",
- $text: "States",
- onclick: function (e) {
- //console.log('clone');
- self.showOnlySaveStates(desc[0], desc[2]);
- //self.refresh();
- }
- }
- )
- }
- if (_LCSUSER.is) {
- if (_LCSUSER.is.alias == desc[2]) {
- userGUI.push(
- {
- $type: "a",
- class: "mdc-button mdc-button--compact mdc-card__action",
- $text: "Edit info",
- //href: "/" + desc[2] + '/worlds/' + desc[0] + '/edit', ///:user/worlds/:name/edit
- onclick: function (e) {
- //'/:user/:type/:name/edit/:file'
- if (desc[3] == 'proto') {
- window.location.pathname = "/" + desc[2] + '/proto/' + desc[0] + '/edit/info_json'
- } else if (desc[3] == 'saveState') {
- let names = desc[0].split('/');
- let filename = ('savestate_/' + names[0] + '/' + names[2] + '_info_vwf_json').split('/').join("~");
- window.location.pathname = "/" + desc[2] + '/state/' + names[0] + '/edit/' + filename;
- }
- //self.refresh();
- }
- }
- );
- if (desc[3] == 'proto') {
- userGUI.push(
- {
- $type: "a",
- class: "mdc-button mdc-button--compact mdc-card__action",
- $text: "Edit proto",
- //href: "/" + desc[2] + '/worlds/' + desc[0] + '/edit', ///:user/worlds/:name/edit
- onclick: function (e) {
- window.location.pathname = "/" + desc[2] + '/proto/' + desc[0] + '/edit/index_vwf_yaml'
- }
- }
- );
- userGUI.push(
- {
- $type: "a",
- class: "mdc-button mdc-button--compact mdc-card__action",
- $text: "Delete",
- //href: "/" + desc[2] + '/worlds/' + desc[0] + '/edit', ///:user/worlds/:name/edit
- onclick: function (e) {
- _app.deleteWorld(desc[0], 'proto');
- }
- }
- );
- }
- if(desc[3] == 'saveState'){
- userGUI.push(
- {
- $type: "a",
- class: "mdc-button mdc-button--compact mdc-card__action",
- $text: "Delete",
- //href: "/" + desc[2] + '/worlds/' + desc[0] + '/edit', ///:user/worlds/:name/edit
- onclick: function (e) {
- _app.deleteWorld(desc[0], 'state');
- }
- }
- );
- }
- }
- if (desc[3] == 'proto') {
- userGUI.push(
- {
- $type: "a",
- class: "mdc-button mdc-button--compact mdc-card__action",
- $text: self.language.t('clone proto'),//"clone",
- onclick: function (e) {
- //console.log('clone');
- _app.cloneWorldPrototype(desc[0], desc[2]);
- //self.refresh();
- }
- }
- )
- } else if (desc[3] == 'saveState') {
-
- // userGUI.push(
- // {
- // $type: "a",
- // class: "mdc-button mdc-button--compact mdc-card__action mdc-button--outlined",
- // $text: "Clone",
- // onclick: function (e) {
- // //console.log('clone');
- // //self.cloneWorldState(desc[0], desc[2]);
- // //self.refresh();
- // }
- // })
- }
- }
- return {
- $cell: true,
- $type: "div",
- class: "mdc-card world-card",
- _appInfo: desc,
- $components: [
- {
- $type: "section",
- class: "mdc-card__media world-card__16-9-media",
- $init: function () {
- if (desc[1].imgUrl !== "") {
- this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3) ), url(' + desc[1].imgUrl + ')';
- }
- }
- },
- {
- $type: "section",
- class: "mdc-card__primary",
- $components: [
- {
- $type: "h1",
- class: "mdc-card__title mdc-card__title--large",
- $text: desc[1].title
- },
- {
- $type: "h2",
- class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
- $text: desc[1].text
- },
- {
- $type: "span",
- class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
- $text: 'id: '
- },
- {
- $type: "input",
- type: "text",
- disabled: "",
- style: "font-size:18px",
- value: cardInfo.title
- },
- {
- $type: "p",
- },
- {
- $type: "span",
- class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
- $text: 'created: ' + (new Date(desc[4])).toUTCString()
- },
- {
- $type: "p",
- }
- // ,{
- // $type: "span",
- // class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
- // $text: 'modified: ' + (new Date(desc[5])).toUTCString()
- // }
- ]
- },
- {
- $type: "section",
- class: "mdc-card__actions",
- $components: [
- {
- $type: "a",
- class: "mdc-button mdc-button--compact mdc-card__action mdc-button--outlined",
- $text: self.language.t('start'),//"Start new",
- target: "_blank",
- href: "/" + desc[2] + '/' + desc[0],
- onclick: function (e) {
- self.refresh();
- }
- }
- ].concat(userGUI)
- },
- {
- $type: "section",
- class: "mdc-card__actions",
- $components: [
- {
- $type: "ul",
- _listData: {},
- _setListData: function (data) {
- this._listData = data;
- },
- class: "mdc-list mdc-list--two-line",
- 'aria-orientation': "vertical",
- id: desc[0] + 'List',
- $update: function () {
- var connectText = {}
- let cardListData = Object.entries(this._listData).filter(el => el[1].user == this._appInfo[2]);
- if (cardListData.length !== 0) {
- connectText = {
- // $type: "span",
- // class: "mdc-theme--text-secondary",
- // $text: "...or connect to:"
- }
- }
- this.$components = [
- {
- $type: "hr",
- class: "mdc-list-divider"
- }
- ].concat(cardListData.map(this._worldListItem))
- // [connectText]
- // }].concat(Object.entries(this._listData).map(this._worldListItem))
- },
- _worldListItem: function (m) {
- return {
- $type: "li",
- class: "mdc-list-item",
- $components: [
- {
- $type: "span",
- class: "world-link mdc-list-item__text",
- $components: [
- {
- $type: "span",
- class: "mdc-list-item__primary-text",
- $components: [
- {
- $type: "a",
- $text: m[0],
- target: "_blank",
- href: window.location.protocol + "//" + window.location.host + "/" + m[1].user + m[0],
- onclick: function (e) {
- //self.refresh();
- }
- },
- ]
- },
- {
- $type: "span",
- class: "mdc-list-item__secondary-text",
- $text: self.language.t('users') + m[1].clients
- }
- ]
- }
- ]
- }
- }
- }
- ]
- }
- ]
- }
- }
- }
- document.querySelector("#main").$cell({
- $cell: true,
- $type: "div",
- $components: [worldsListGUI]
- })
- }
- async showOnlySaveStates(index, userAlias) {
- 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;
- }
- this.worlds = {};
- document.querySelector("#main")._jsonData = Object.assign({}, this.worlds);
- document.querySelector("#main")._status = "Save states of the World: " + index + ' for user: ' + userAlias;
- document.querySelector("#main").$update();
- //let userAlias = _LCSUSER.is.alias;
- db.get('documents').get(index).once(save => {
- if (save) {
- let saves = Object.keys(save).filter(el => el.includes('_info_vwf_json'));
- console.log(saves);
- if (saves) {
- saves.forEach(el => {
- db.get('documents').get(index).get(el).once(res => {
- if (res) {
- let created = res.created ? res.created: res.modified;
- let fileName = el.split('/')[2].replace('_info_vwf_json', "");
- let world = JSON.parse(res.file);
- let root = Object.keys(world)[0];
- world[root].user = userAlias;
- world[root].type = 'saveState';
- world[root].created = created;
- world[root].modified = res.modified;
- this.worlds[index + '/load/' + fileName] = world[root];
- document.querySelector("#main")._jsonData = Object.assign({}, this.worlds);
- }
- })
- })
- }
- }
- })
- }
- async getWorldsProtosFromUserDB(userAlias) {
- let userPub = await _LCSDB.get('users').get(userAlias).get('pub').once().then();
- console.log('get user worlds for: ' + userAlias);
- this.worlds = {};
- document.querySelector("#main")._jsonData = Object.assign({}, this.worlds);
- if (!userPub) {
- document.querySelector("#main")._status = "no such user";
- document.querySelector("#main").$update();
- }
- if (userPub) {
- document.querySelector("#main")._status = "Worlds protos for: " + userAlias;
- document.querySelector("#main").$update();
- var db = _LCSDB.user(userPub);
- if (_LCSUSER.is) {
- if (_LCSUSER.is.alias == userAlias)
- db = _LCSUSER;
- }
- db.get('worlds').map().once((w, index) => {
- if (w) {
- db.get('worlds').get(index).get('info_json').once(res => {
- if (res && res !== 'null') {
- if (res.file && res.file !== 'null') {
- let created = res.created ? res.created: res.modified;
- let world = JSON.parse(res.file);
- let root = Object.keys(world)[0];
- world[root].user = userAlias;
- world[root].type = 'proto';
- world[root].created = created;
- world[root].modified = res.modified;
- this.worlds[index] = world[root];
- document.querySelector("#main")._jsonData = Object.assign({}, this.worlds);
- }
- }
- })
- }
- })
- }
- }
- async getWorldsFromUserDB(userAlias) {
- let userPub = await _LCSDB.get('users').get(userAlias).get('pub').once().then();
- console.log('get user worlds for: ' + userAlias);
- this.worlds = {};
- document.querySelector("#main")._jsonData = Object.assign({}, this.worlds);
- if (!userPub) {
- document.querySelector("#main")._status = "no such user";
- document.querySelector("#main").$update();
- }
- if (userPub) {
- document.querySelector("#main")._status = "Worlds states for: " + userAlias;
- document.querySelector("#main").$update();
- var db = _LCSDB.user(userPub);
- if (_LCSUSER.is) {
- if (_LCSUSER.is.alias == userAlias)
- db = _LCSUSER;
- }
- db.get('worlds').map().once((w, index) => {
- if (w) {
- db.get('documents').get(index).once(save => {
- if (save) {
- let saves = Object.keys(save).filter(el => el.includes('_info_vwf_json'));
- console.log(saves);
- if (saves) {
- saves.forEach(el => {
- db.get('documents').get(index).get(el).once(res => {
- if (res ) {
- if(res.file && res.file !== "null") {
- let created = res.created ? res.created: res.modified;
- let fileName = el.split('/')[2].replace('_info_vwf_json', "");
- let world = JSON.parse(res.file);
- let root = Object.keys(world)[0];
- world[root].user = userAlias;
- world[root].type = 'saveState';
- world[root].created = created;
- world[root].modified = res.modified;
- this.worlds[index + '/load/' + fileName] = world[root];
- document.querySelector("#main")._jsonData = Object.assign({}, this.worlds);
- }
- }
- })
- })
- }
- }
- })
- }
- })
- }
- }
- async getAppDetailsFromDefaultDB(type) {
- let defaultUserPUB = await _LCSDB.get('lcs/app').path('pub').once().then();
- var userAlias = await _LCSDB.user(defaultUserPUB).get('alias').once().then();
- page.redirect('/' + userAlias + '/worlds/' + type);
- }
- async getAppDetailsFromDB() {
- let defaultUserPUB = await _LCSDB.get('lcs/app').path('pub').once().then();
- var userAlias = await _LCSDB.user(defaultUserPUB).get('alias').once().then();
- if (userAlias)
- this.getWorldsProtosFromUserDB(userAlias);
- }
- refresh() {
- // socket.emit('getWebAppUpdate', "");
- }
- }
- export { IndexApp }
- //export {getAppDetails, generateFrontPage, setLanguage, initLocale};
|