|
@@ -1,8 +1,11 @@
|
|
|
import page from '/lib/page.mjs';
|
|
|
+import { Header } from '/web/header.js';
|
|
|
+
|
|
|
|
|
|
class IndexApp {
|
|
|
constructor() {
|
|
|
console.log("app constructor");
|
|
|
+
|
|
|
|
|
|
this.worlds = {};
|
|
|
this.language = _LangManager.language;
|
|
@@ -21,9 +24,9 @@ class IndexApp {
|
|
|
var socket = io.connect(window._app.reflectorHost, this.options);
|
|
|
|
|
|
const parse = (msg) => {
|
|
|
- this.parseAppInstancesData(msg)
|
|
|
+ this.parseOnlineData(msg)
|
|
|
}
|
|
|
- socket.on('getWebAppUpdate', msg => parse.call(self, msg));
|
|
|
+ socket.on('getWebAppUpdate', msg => parse.call(this, msg));
|
|
|
socket.on("connect", function () {
|
|
|
|
|
|
let noty = new Noty({
|
|
@@ -54,12 +57,63 @@ class IndexApp {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ initHTML() {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+
|
|
|
+ //first init from _app
|
|
|
+ document.querySelector('head').innerHTML += '<link rel="stylesheet" href="/web/index-app.css">';
|
|
|
+
|
|
|
+ let headerGUI = new Header();
|
|
|
+ headerGUI.init();
|
|
|
+
|
|
|
+ //add HTML
|
|
|
+ let entry = document.createElement("div");
|
|
|
+ entry.setAttribute("id", 'app');
|
|
|
+ document.body.appendChild(entry);
|
|
|
+
|
|
|
+ let divs = ['appGUI', 'userLobby', 'main', 'worldsGUI'];
|
|
|
+ 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(){
|
|
|
+ this.$components = self.initUserGUI()
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ document.querySelector("#worldsGUI").$cell({
|
|
|
+ id: 'worldsGUI',
|
|
|
+ $cell: true,
|
|
|
+ $type: "div",
|
|
|
+ $components: [],
|
|
|
+ _comps: [],
|
|
|
+ _refresh: async function(data, fn){
|
|
|
+ _app.showProgressBar();
|
|
|
+ this._comps = await fn.call(self, data);
|
|
|
+ this.$update();
|
|
|
+ _app.hideProgressBar();
|
|
|
+ },
|
|
|
+ $update: async function(){
|
|
|
+ this.$components = this._comps
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
async generateFrontPage() {
|
|
|
|
|
|
let infoEl = document.createElement("div");
|
|
|
- infoEl.setAttribute("id", "info");
|
|
|
+ infoEl.setAttribute("id", "indexPage");
|
|
|
|
|
|
let lang = _LangManager.locale;
|
|
|
|
|
@@ -79,22 +133,122 @@ class IndexApp {
|
|
|
|
|
|
}
|
|
|
|
|
|
- async initApp() {
|
|
|
-
|
|
|
- let appEl = document.createElement("div");
|
|
|
- appEl.setAttribute("id", "app");
|
|
|
+ initApp() {
|
|
|
|
|
|
- let appElHTML = await _app.helpers.getHtmlText('/web/app.html');
|
|
|
- appEl.innerHTML = appElHTML;
|
|
|
- document.body.appendChild(appEl);
|
|
|
+ // let appElHTML = await _app.helpers.getHtmlText('/web/app.html');
|
|
|
+ // appEl.innerHTML = appElHTML;
|
|
|
+ // document.body.appendChild(appEl);
|
|
|
|
|
|
this.initUser();
|
|
|
- this.initUserGUI();
|
|
|
- this.initWorldsListGUI();
|
|
|
+ document.querySelector("#userLobby").$update();
|
|
|
+
|
|
|
+ //this.initWorldsListGUI();
|
|
|
//this.getAppDetailsFromDB();
|
|
|
|
|
|
}
|
|
|
|
|
|
+ async initWorldsProtosListForUser (userAlias) {
|
|
|
+ document.querySelector("#worldsGUI").$components = [];
|
|
|
+ await document.querySelector("#worldsGUI")._refresh(userAlias, this.getWorldsProtosListForUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ async initWorldsStatesListForUser (userAlias) {
|
|
|
+ document.querySelector("#worldsGUI").$components = [];
|
|
|
+ await document.querySelector("#worldsGUI")._refresh(userAlias, this.getWorldsStatesListForUser);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ async getWorldsStatesListForUser (userAlias) {
|
|
|
+
|
|
|
+ let worldsGUI = [];
|
|
|
+
|
|
|
+ let data = await _app.getAllStateWorldsInfoForUser(userAlias);
|
|
|
+
|
|
|
+ Object.entries(data).forEach(el=>{
|
|
|
+
|
|
|
+ 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) {
|
|
|
+
|
|
|
+
|
|
|
+ let worldsGUI = [];
|
|
|
+
|
|
|
+ let data = await _app.getAllProtoWorldsInfoForUser(userAlias);
|
|
|
+
|
|
|
+ let worlds = this.createWorldsGUI(userAlias);
|
|
|
+ worlds._states = data;
|
|
|
+ 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: 'Worlds for ' + userAlias
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ $type: "div",
|
|
|
+ class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
|
|
|
+ $components: [].concat(worldsGUI)
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
|
|
|
initUser() {
|
|
|
|
|
@@ -107,8 +261,8 @@ class IndexApp {
|
|
|
userEl._status = 'Welcome ' + alias + '!';
|
|
|
//userEl.style.backgroundColor = '#e6e6e6';
|
|
|
userEl.$update();
|
|
|
- document.querySelector('#worldGUI').$update();
|
|
|
- document.querySelector('#main').$update();
|
|
|
+ // document.querySelector('#worldGUI').$update();
|
|
|
+ // document.querySelector('#main').$update();
|
|
|
|
|
|
_LCSUSER.get('profile').once(function (data) { console.log(data) })
|
|
|
|
|
@@ -122,6 +276,10 @@ class IndexApp {
|
|
|
_LCSUSER.get('profile').put(profile);
|
|
|
})
|
|
|
|
|
|
+ let actionsGUI = document.querySelector('#worldActionsGUI');
|
|
|
+ if (actionsGUI)
|
|
|
+ actionsGUI._refresh();
|
|
|
+
|
|
|
new Noty({
|
|
|
text: alias + ' is succesfully authenticated!',
|
|
|
timeout: 2000,
|
|
@@ -154,7 +312,9 @@ class IndexApp {
|
|
|
"label": 'Default World Protos',
|
|
|
"onclick": function (e) {
|
|
|
e.preventDefault();
|
|
|
- _app.indexApp.getAppDetailsFromDefaultDB('protos');
|
|
|
+ page("/app/worlds/protos")
|
|
|
+ //window.location.pathname = "/app/worlds/protos"
|
|
|
+ //_app.indexApp.getAppDetailsFromDefaultDB('protos');
|
|
|
|
|
|
}
|
|
|
}),
|
|
@@ -163,7 +323,9 @@ class IndexApp {
|
|
|
"label": 'Default World States',
|
|
|
"onclick": function (e) {
|
|
|
e.preventDefault();
|
|
|
- _app.indexApp.getAppDetailsFromDefaultDB('states');
|
|
|
+ page("/app/worlds/states")
|
|
|
+ // window.location.pathname = "/app/worlds/states"
|
|
|
+ //_app.indexApp.getAppDetailsFromDefaultDB('states');
|
|
|
|
|
|
}
|
|
|
})
|
|
@@ -220,6 +382,7 @@ class IndexApp {
|
|
|
"label": 'PROFILE',
|
|
|
"onclick": function (e) {
|
|
|
e.preventDefault();
|
|
|
+ //page("/profile")
|
|
|
window.location.pathname = "/profile"
|
|
|
}
|
|
|
}),
|
|
@@ -232,7 +395,8 @@ class IndexApp {
|
|
|
"onclick": function (e) {
|
|
|
e.preventDefault();
|
|
|
let alias = _LCSUSER.is.alias;
|
|
|
- page.redirect('/' + alias + '/worlds/protos');
|
|
|
+ //window.location.pathname = '/' + alias + '/worlds/protos'
|
|
|
+ page('/' + alias + '/worlds/protos');
|
|
|
//_app.indexApp.getWorldsProtosFromUserDB(alias);
|
|
|
}
|
|
|
}),
|
|
@@ -242,7 +406,9 @@ class IndexApp {
|
|
|
"onclick": function (e) {
|
|
|
e.preventDefault();
|
|
|
let alias = _LCSUSER.is.alias;
|
|
|
- page.redirect('/' + alias + '/worlds/states');
|
|
|
+ // window.location.pathname = '/' + alias + '/worlds/states'
|
|
|
+ page('/' + alias + '/worlds/states');
|
|
|
+ // page.redirect('/' + alias + '/worlds/states');
|
|
|
//_app.indexApp.getWorldsFromUserDB(alias);
|
|
|
}
|
|
|
})
|
|
@@ -265,7 +431,6 @@ class IndexApp {
|
|
|
].concat(gui)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
|
|
|
let loginGUI =
|
|
|
{
|
|
@@ -415,258 +580,237 @@ class IndexApp {
|
|
|
|
|
|
}
|
|
|
|
|
|
- document.querySelector("#userLobby").$cell({
|
|
|
- id: "userLobby",
|
|
|
- $cell: true,
|
|
|
- $type: "div",
|
|
|
- $components: [
|
|
|
+ // document.querySelector("#userLobby").$cell({
|
|
|
+ // id: "userLobby",
|
|
|
+ // $cell: true,
|
|
|
+ // $type: "div",
|
|
|
+ // $components: [
|
|
|
|
|
|
- userGUI, loginGUI, _app.widgets.divider, worldGUI]
|
|
|
- }
|
|
|
- );
|
|
|
- }
|
|
|
+ // userGUI, loginGUI, _app.widgets.divider, worldGUI]
|
|
|
+ // }
|
|
|
+ // );
|
|
|
|
|
|
- parseAppInstancesData(data) {
|
|
|
+ return [userGUI, loginGUI, _app.widgets.divider, worldGUI]
|
|
|
|
|
|
- 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);
|
|
|
+ refresh() {
|
|
|
+ // socket.emit('getWebAppUpdate', "");
|
|
|
+ }
|
|
|
|
|
|
- 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;
|
|
|
+ parseOnlineData(data) {
|
|
|
|
|
|
- if (el[1].loadInfo['save_name']) {
|
|
|
- let saveName = prop + '/load/' + el[1].loadInfo.save_name;
|
|
|
- if (!lists[saveName])
|
|
|
- lists[saveName] = {};
|
|
|
+ let parcedData = _app.parseAppInstancesData(data);
|
|
|
|
|
|
- lists[saveName][el[0]] = el[1]
|
|
|
- } else {
|
|
|
- if (!lists[name])
|
|
|
- lists[name] = {};
|
|
|
+ //if (Object.entries(parcedData).length !== 0)
|
|
|
+ let onlineGUIs = document.querySelectorAll('.online');
|
|
|
|
|
|
- lists[name][el[0]] = el[1]
|
|
|
+ onlineGUIs.forEach(function (item) {
|
|
|
+ item._refresh(parcedData)
|
|
|
+ });
|
|
|
|
|
|
- }
|
|
|
- });
|
|
|
+ }
|
|
|
|
|
|
- // console.log(lists);
|
|
|
+ createWorldCard(id, type) {
|
|
|
+ let self = this;
|
|
|
|
|
|
- Object.entries(lists).forEach(list => {
|
|
|
+ let onlineGUI = {
|
|
|
+ $cell: true,
|
|
|
+ id: "onlineGUI_" + id,
|
|
|
+ class: "online",
|
|
|
+ $type: "div",
|
|
|
+ _instances: {},
|
|
|
+ _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
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ $components: [],
|
|
|
+ _refresh: function (data) {
|
|
|
+ if (data) {
|
|
|
+ if (Object.entries(data).length !== 0) {
|
|
|
+ if (this._worldInfo) {
|
|
|
+ let insts = Object.entries(data).filter(el => el[0] == this._worldInfo.worldName);
|
|
|
+ if (insts.length !== 0)
|
|
|
+ this._instances = insts[0][1];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this._instances = {}
|
|
|
+ }
|
|
|
|
|
|
- let element = document.getElementById(list[0] + 'List');
|
|
|
- if (element) {
|
|
|
- element._setListData(list[1]);
|
|
|
}
|
|
|
- })
|
|
|
- }
|
|
|
- // console.log(data)
|
|
|
- }
|
|
|
|
|
|
+ },
|
|
|
+ $init: function () {
|
|
|
+ this._refresh();
|
|
|
+ },
|
|
|
+ $update: function () {
|
|
|
+ if (this._instances) {
|
|
|
+ let cardListData = Object.entries(this._instances).filter(el => el[1].user == this._worldInfo.userAlias);
|
|
|
+ this.$components = [
|
|
|
+ {
|
|
|
+ $type: "hr",
|
|
|
+ class: "mdc-list-divider"
|
|
|
+ }
|
|
|
+ ].concat(cardListData.map(this._worldListItem))
|
|
|
+ }
|
|
|
|
|
|
- initWorldsListGUI() {
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- var self = this;
|
|
|
- let worldsListGUI = {
|
|
|
|
|
|
+ return {
|
|
|
$cell: true,
|
|
|
+ id: 'worldCard_' + id,
|
|
|
$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({});
|
|
|
- });
|
|
|
+ _worldInfo: {},
|
|
|
+ _refresh: function (data) {
|
|
|
+ this._worldInfo = data
|
|
|
},
|
|
|
+ // _getWorldInfo: async function () {
|
|
|
+ // //get space for user
|
|
|
+ // let info = await _app.getWorldInfo(user, space);
|
|
|
+ // this._refresh(info);
|
|
|
+ // },
|
|
|
+ // _getStateInfo: async function () {
|
|
|
+ // //get space for user
|
|
|
+ // let info = await _app.getStateInfo(user, space, saveName);
|
|
|
+ // this._refresh(info);
|
|
|
+ // },
|
|
|
$init: function () {
|
|
|
- this._jsonData = {} //data//JSON.parse(data);
|
|
|
+ //get space for user
|
|
|
+ // if (!saveName) {
|
|
|
+ // this._getWorldInfo();
|
|
|
+ // } else {
|
|
|
+ // this._getStateInfo();
|
|
|
+ // }
|
|
|
},
|
|
|
- _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]
|
|
|
+ $update: function () {
|
|
|
+ //console.log(this._worldInfo);
|
|
|
+ this.$components = [this._updateCard()]
|
|
|
+ },
|
|
|
+ $components: [],
|
|
|
+ _updateCard: function () {
|
|
|
+
|
|
|
+ let desc = this._worldInfo;
|
|
|
+
|
|
|
+
|
|
|
+ if (!desc || Object.keys(desc).length == 0) {
|
|
|
+ return {
|
|
|
+ $type: "h1",
|
|
|
+ class: "mdc-typography--headline4",
|
|
|
+ $text: "ERROR: NO WORLD!"
|
|
|
}
|
|
|
}
|
|
|
- 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)
|
|
|
- }
|
|
|
- ]
|
|
|
|
|
|
- },
|
|
|
+ let userGUI = [];
|
|
|
+ let online = [];
|
|
|
|
|
|
+ let cardInfo = {
|
|
|
+ "title": ""
|
|
|
+ };
|
|
|
|
|
|
- ]
|
|
|
- },
|
|
|
- _worldCardDef: function (desc) {
|
|
|
|
|
|
- var userGUI = [];
|
|
|
+ if (type == "full") {
|
|
|
|
|
|
- if (desc[3] == 'proto') {
|
|
|
- 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();
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ userGUI.push({
|
|
|
+ $type: "a",
|
|
|
+ class: "mdc-button mdc-button--compact mdc-card__action mdc-button--outlined",
|
|
|
+ $text: "Details",
|
|
|
+ onclick: function (e) {
|
|
|
+ e.preventDefault();
|
|
|
+ window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName + '/about'
|
|
|
}
|
|
|
- )
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- if (_LCSUSER.is) {
|
|
|
+ userGUI.push({
|
|
|
+ $type: "a",
|
|
|
+ class: "mdc-button mdc-button--raised mdc-card__action ",
|
|
|
+ $text: self.language.t('start'),//"Start new",
|
|
|
+ target: "_blank",
|
|
|
+ href: "/" + desc.userAlias + '/' + desc.worldName,
|
|
|
+ onclick: function (e) {
|
|
|
+ //self.refresh();
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- 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'
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
+ if (desc.type == 'saveState') {
|
|
|
+ cardInfo.title = desc.worldName.split('/')[2];
|
|
|
+ }
|
|
|
|
|
|
- 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();
|
|
|
- }
|
|
|
- }
|
|
|
+ if (desc.type == 'proto') {
|
|
|
+ cardInfo.title = desc.worldName;
|
|
|
|
|
|
- )
|
|
|
- } 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();
|
|
|
- // }
|
|
|
- // })
|
|
|
- }
|
|
|
+ // userGUI.push(
|
|
|
+
|
|
|
+ // {
|
|
|
+ // $type: "a",
|
|
|
+ // class: "mdc-button mdc-button--compact mdc-card__action",
|
|
|
+ // $text: "States",
|
|
|
+ // onclick: async function (e) {
|
|
|
|
|
|
+ // e.preventDefault();
|
|
|
+ // window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName +'/about'
|
|
|
+ // //console.log('clone');
|
|
|
+
|
|
|
+ // // document.querySelector('#worldStatesGUI')._refresh({});
|
|
|
+ // // let data = await _app.getSaveStates(desc.userAlias, desc.worldName);
|
|
|
+ // // document.querySelector('#worldStatesGUI')._refresh(data);
|
|
|
+
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // )
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ online.push(onlineGUI);
|
|
|
+
|
|
|
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 + ')';
|
|
|
+ if (desc.info.imgUrl !== "") {
|
|
|
+ this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3) ), url(' + desc.info.imgUrl + ')';
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -677,20 +821,35 @@ class IndexApp {
|
|
|
{
|
|
|
$type: "h1",
|
|
|
class: "mdc-card__title mdc-card__title--large",
|
|
|
- $text: desc[1].title
|
|
|
+ $text: desc.info.title
|
|
|
},
|
|
|
{
|
|
|
$type: "h2",
|
|
|
class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
|
|
|
- $text: desc[1].text
|
|
|
+ $text: desc.info.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()
|
|
|
+ $text: 'created: ' + (new Date(desc.created)).toUTCString()
|
|
|
},
|
|
|
{
|
|
|
- $type: "p",
|
|
|
+ $type: "p",
|
|
|
}
|
|
|
// ,{
|
|
|
// $type: "span",
|
|
@@ -703,16 +862,7 @@ class IndexApp {
|
|
|
$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)
|
|
|
},
|
|
|
|
|
@@ -720,275 +870,95 @@ class IndexApp {
|
|
|
$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
|
|
|
- }
|
|
|
- ]
|
|
|
- }
|
|
|
- ]
|
|
|
- }
|
|
|
- }
|
|
|
+ $type: 'div',
|
|
|
+ $text: 'online now: '
|
|
|
}
|
|
|
- ]
|
|
|
+ ].concat(online)
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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) {
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
-
|
|
|
- })
|
|
|
+ createWorldsGUI(userAlias, worldName) {
|
|
|
+ let self = this;
|
|
|
+ let id = worldName?worldName + '_' + userAlias: "allWorlds_" + userAlias
|
|
|
+ let headerText = worldName?'States for ' + worldName: 'All Worlds Protos'
|
|
|
|
|
|
+ let worldCards = {
|
|
|
+ $cell: true,
|
|
|
+ id: id,
|
|
|
+ $type: "div",
|
|
|
+ $components: [],
|
|
|
+ _states: {},
|
|
|
+ _refresh: function (data) {
|
|
|
+ this._states = data
|
|
|
+ },
|
|
|
+ $init: async function () {
|
|
|
+ //this._refresh();
|
|
|
+ },
|
|
|
+ _makeWorldCard: function (data) {
|
|
|
+ let cardID = data[1].userAlias + '_' + data[1].worldName + '_' + data[0];
|
|
|
+ let card = self.createWorldCard(cardID, 'min');
|
|
|
+ card._worldInfo = data[1];
|
|
|
+ card.$update();
|
|
|
+ return {
|
|
|
+ $cell: true,
|
|
|
+ $type: "div",
|
|
|
+ class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
|
|
|
+ $components: [
|
|
|
+ card
|
|
|
+ //self.createWorldCard(data[1].userAlias, data[1].worldName, data[0])
|
|
|
+ //this._worldCardDef(appInfo)
|
|
|
+ ]
|
|
|
}
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- 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) {
|
|
|
-
|
|
|
- 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);
|
|
|
-
|
|
|
- }
|
|
|
- })
|
|
|
+ //console.log(data);
|
|
|
+ },
|
|
|
+ $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: headerText
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ $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)
|
|
|
}
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- 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', "");
|
|
|
+ return worldCards
|
|
|
}
|
|
|
|
|
|
|