123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482 |
- /*
- The MIT License (MIT)
- Copyright (c) 2014-2018 Nikolai Suslov and the Krestianstvo.org project contributors. (https://github.com/NikolaySuslov/livecodingspace/blob/master/LICENSE.md)
- */
- //import page from '/lib/page.mjs';
- import { Header } from '/web/header.js';
- class IndexApp {
- constructor(entry) {
- console.log("index app constructor");
- this.entry = entry;
- this.worlds = {};
- this.instances = {};
- if (!_app.isLuminary) {
- this.initReflectorConnection();
- }
- this.initHTML();
-
- }
- initReflectorConnection() {
- 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.parseOnlineData(msg)
- }
- socket.on('getWebAppUpdate', msg => parse.call(this, 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();
- });
- }
- 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', 'lab'];
- divs.forEach(el => {
- let appEl = document.createElement("div");
- appEl.setAttribute("id", el);
- entry.appendChild(appEl);
- })
- document.querySelector("#worldsGUI").$cell({
- id: "worldsGUI",
- $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');
- }
- });
- //init CELL
- let userGUI = {
- $type: "div",
- id: "userGUI",
- // style:"background-color: #ffeb3b",
- class: "mdc-layout-grid mdc-layout-grid--align-left",
- _status: "Welcome!",
- $init: function () {
- //this._status = "Welcome!"
- //this._status = 'Welcome!';
- //userEl.style.backgroundColor = '#e6e6e6';
- self.initUser();
- this._refresh(); //$update();
- },
- $update: function () {},
- _refresh: function () {
- var gui = {};
- if (_LCSDB.user().is) {
- gui = [
- window._app.widgets.buttonRaised(
- {
- "label": 'Sign OUT',
- "onclick": function (e) {
- _LCSDB.user().leave();
- setTimeout(() => {
- //window.sessionStorage.removeItem('alias');
- //window.sessionStorage.removeItem('tmp');
- window.location.reload(true);
- }, 1);
- }
- }),
- {
- $type: "p"
- },
- window._app.widgets.buttonStroked(
- {
- "label": 'PROFILE',
- "onclick": function (e) {
- e.preventDefault();
- //page("/profile")
- window.location.pathname = "/profile"
- }
- }),
- {
- $type: "p"
- },
- window._app.widgets.buttonStroked(
- {
- "label": 'My World protos',
- "onclick": function (e) {
- e.preventDefault();
- let alias = _LCSDB.user().is.alias;
- window.location.pathname = '/' + alias + '/worlds/protos'
- //page('/' + alias + '/worlds/protos');
- //_app.indexApp.getWorldsProtosFromUserDB(alias);
- }
- }),
- window._app.widgets.buttonStroked(
- {
- "label": 'My World states',
- "onclick": function (e) {
- e.preventDefault();
- let alias = _LCSDB.user().is.alias;
- window.location.pathname = '/' + alias + '/worlds/states'
- //page('/' + alias + '/worlds/states');
- // page.redirect('/' + alias + '/worlds/states');
- //_app.indexApp.getWorldsFromUserDB(alias);
- }
- })
- ]
- }
- this.$components = [
- {
- $type: "h1",
- class: "mdc-typography--headline3",
- $text: this._status
- }
- ].concat(gui)
- }
- }
- document.querySelector("#userLobby").$cell({
- id: "userLobby",
- $cell: true,
- $type: "div",
- $components: [],
- _comps: [],
- _refresh: function(){
- this.$components = this._comps.concat([userGUI, self.getLoginGUI(), _app.widgets.divider, self.getLookWorlds()]);
- },
- $init: function () {
- this._comps = self.initUserGUI()
- this._refresh();
- },
- $update: function () {
- }
- });
- }
- async allWorldsProtosForUser(userAlias) {
- let userPub = await _app.helpers.getUserPub(userAlias);
- //let db = _LCSDB.user(userPub);
-
- let doc = document.querySelector("#worldsGUI");
- var worlds = {};
- if(userPub) {
- worlds = this.createWorldsGUI(userAlias, userPub)
- } else {
- worlds = {
- $type: 'div',
- $text: 'Could not find user with name: ' + userAlias,
- class: "mdc-typography--headline4"
- }
- }
- let 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: "h1",
- class: "mdc-typography--headline4",
- $text: 'Worlds for user: ' + userAlias
- }
- ]
- },
- {
- $type: "div",
- class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
- $components: [worlds]
- }
- ]
- }
- ]
- }
- ];
- doc._refresh(components);
-
- }
- async allWorldsStatesForUser(userAlias) {
- let userPub = await _app.helpers.getUserPub(userAlias);
- //let db = _LCSDB.user(userPub);
- let doc = document.querySelector("#worldsGUI");
- 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 = [
- {
- $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 user: ' + userAlias
- }
- ]
- },
- {
- $type: "div",
- class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
- $components: [worlds]
- }
- ]
- }
- ]
- }
- ];
- doc._refresh(components);
-
- }
- async initWorldsStatesListForUser(userAlias) {
- let doc = document.querySelector("#worldsGUI");
- //doc.$components = [];
- let allInfo = await _app.getAllStateWorldsInfoForUser(userAlias);//await this.getWorldsProtosListForUser(userAlias);
- let worlds = this.createWorldsGUI(userAlias, 'allStates');
- worlds._refresh(allInfo);
- let 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: "h1",
- class: "mdc-typography--headline4",
- $text: 'States for ' + userAlias
- }
- ]
- },
- {
- $type: "div",
- class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
- $components: [].concat(worlds)
- }
- ]
- }
- ]
- }
- ]
- doc._refresh(components);
- //initiate update world cards
- doc._wcards = worlds;
- doc._wcards.$update();
- //console.log(allInfo);
- }
- authGUI(){
- let alias = _LCSDB.user().is.alias;
- let userEl = document.querySelector('#userGUI');
- userEl._status = 'Welcome ' + alias + '!';
- //userEl.style.backgroundColor = '#e6e6e6';
- userEl._refresh(); //$update();
- //_LCSDB.user().get('profile').once(function (data) { console.log(data) })
- let el = document.getElementById("loginGUI");
- if (el) {
- el.remove();
- }
- _LCSDB.user().get('profile').not(function (key) {
- let profile = { 'alias': alias };
- _LCSDB.user().get('profile').put(profile);
- })
- // not load proxy by default
- // _LCSDB.user().get('proxy').not(res=>{
- // console.log('user has no proxy');
- // window._app.loadProxyDefaults();
- // });
- let actionsGUI = document.querySelector('#worldActionsGUI');
- if (actionsGUI)
- actionsGUI._refresh();
- new Noty({
- text: alias + ' is succesfully authenticated!',
- timeout: 2000,
- theme: 'mint',
- layout: 'bottomRight',
- type: 'success'
- }).show();
- if(this.entry == 'index'){
- //change for LiveCoding.space to 'app'
- //this.initWorldsProtosListForUserNew(alias);
- this.allWorldsProtosForUser(alias)
- }
-
-
- }
- initUser() {
- let self = this;
- if(_LCSDB.user().is) {
- self.authGUI()
- } else {
- _LCSDB.on('auth', function (ack) {
- if (ack.sea.pub) {
- self.authGUI();
- }
- console.log(_LCSDB.user().is);
- });
- }
-
- }
- getLookWorlds(){
- let self = this;
- let lookWorlds =
- {
- $type: "div",
- id: "lookWorlds",
- class: "mdc-layout-grid mdc-layout-grid--align-left",
- _status: '',
- $init: function () {
- this._status = "init";
- },
- $update: function () {
- //change for LiveCoding.space site 'app'
- let defaultName = '';
- let guiForAll = [
- {
- $type: "div",
- style: "margin-top: 20px;",
- _userName: null,
- _userNameField: null,
- $components:
- [
- _app.widgets.inputTextFieldOutlined({
- "id": 'worldsUserName',
- "label": 'Enter user name',
- "value": defaultName,
- "type": "text",
- "init": function () {
- this._userNameField = new mdc.textField.MDCTextField(this);
- }
- }),
- _app.widgets.p,
- // {
- // $type: "a",
- // class: "mdc-button mdc-button--raised mdc-card__action actionButton",
- // $text: 'World Protos', //self.language.t('set proxy'),//"clone",
- // onclick: function (e) {
- // //console.log('clone');
- // let searchName = this._userNameField.value;
- // self.initWorldsProtosListForUser(searchName);
- // }
- // },
- // {
- // $type: "a",
- // class: "mdc-button mdc-button--raised mdc-card__action actionButton",
- // $text: 'World States', //self.language.t('set proxy'),//"clone",
- // onclick: function (e) {
- // //console.log('clone');
- // let searchName = this._userNameField.value;
- // self.initWorldsStatesListForUser(searchName);
- // }
- // }
- _app.widgets.buttonRaised(
- {
- "label": 'World Protos',
- "onclick": function (e) {
- e.preventDefault();
- //page("/app/worlds/protos")
- let searchName = this._userNameField.value;
- if(searchName !== "")
- window.location.pathname = "/"+searchName+"/worlds/protos"
- //_app.indexApp.getAppDetailsFromDefaultDB('protos');
- }
- }),
- _app.widgets.space,
- _app.widgets.buttonRaised(
- {
- "label": 'World States',
- "onclick": function (e) {
- e.preventDefault();
- //page("/app/worlds/states")
- let searchName = this._userNameField.value;
- if(searchName !== "")
- window.location.pathname = "/"+searchName+"/worlds/states"
- //_app.indexApp.getAppDetailsFromDefaultDB('states');
- }
- })
-
- ]
- },
- // window._app.widgets.buttonStroked(
- // {
- // "label": 'Default World Protos',
- // "onclick": function (e) {
- // e.preventDefault();
- // //page("/app/worlds/protos")
- // window.location.pathname = "/app/worlds/protos"
- // //_app.indexApp.getAppDetailsFromDefaultDB('protos');
- // }
- // }),
- // window._app.widgets.buttonStroked(
- // {
- // "label": 'Default World States',
- // "onclick": function (e) {
- // e.preventDefault();
- // //page("/app/worlds/states")
- // window.location.pathname = "/app/worlds/states"
- // //_app.indexApp.getAppDetailsFromDefaultDB('states');
- // }
- // })
- ];
- this.$components = [
- {
- $type: "h1",
- class: "mdc-typography--headline4",
- $text: "Looking for Worlds made by other Users!"
- }
- ].concat(guiForAll, _app.widgets.p, _app.widgets.divider)
- }
- }
- return lookWorlds
- }
- getLoginGUI(){
- let self = this;
- 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 {
- //
- _LCSDB.user().create(alias, pass,
- function (ack) {
- if (!ack.wait) { }
- if (ack.err) {
- console.log(ack.err)
- return ack.err
- };
- if (ack.pub) {
- let userObj = {
- 'alias': alias,
- 'pub': ack.pub
- };
- _LCSDB.get('users').get(alias).put(userObj);
- }
- _LCSDB.user().auth(alias, pass);
- });
- }
- }
- }),
- _app.widgets.space,
- window._app.widgets.buttonRaised(
- {
- "label": 'Sign IN',
- "onclick": function (e) {
- e.preventDefault();
- let alias = this._aliasField.value;
- let pass = this._passField.value
- _app.helpers.authUser(alias, pass);
- // _LCSDB.user().auth.call(_LCSDB, alias, pass
- // // , function(ack) {
- // // if (ack.err) {
- // // new Noty({
- // // text: ack.err,
- // // timeout: 2000,
- // // theme: 'mint',
- // // layout: 'bottomRight',
- // // type: 'error'
- // // }).show();
- // // }
- // //}
- // );
- }
- })
- ]
- }
- ]
- }
- ]
- }
- }
- return loginGUI
- }
- initUserGUI() {
- let self = this;
- let lookWorlds =
- {
- $type: "div",
- id: "lookWorlds",
- class: "mdc-layout-grid mdc-layout-grid--align-left",
- _status: '',
- $init: function () {
- this._status = "init";
- },
- $update: function () {
- //change for LiveCoding.space site 'app'
- let defaultName = '';
- let guiForAll = [
- {
- $type: "div",
- style: "margin-top: 20px;",
- _userName: null,
- _userNameField: null,
- $components:
- [
- _app.widgets.inputTextFieldOutlined({
- "id": 'worldsUserName',
- "label": 'Enter user name',
- "value": defaultName,
- "type": "text",
- "init": function () {
- this._userNameField = new mdc.textField.MDCTextField(this);
- }
- }),
- _app.widgets.p,
- // {
- // $type: "a",
- // class: "mdc-button mdc-button--raised mdc-card__action actionButton",
- // $text: 'World Protos', //self.language.t('set proxy'),//"clone",
- // onclick: function (e) {
- // //console.log('clone');
- // let searchName = this._userNameField.value;
- // self.initWorldsProtosListForUser(searchName);
- // }
- // },
- // {
- // $type: "a",
- // class: "mdc-button mdc-button--raised mdc-card__action actionButton",
- // $text: 'World States', //self.language.t('set proxy'),//"clone",
- // onclick: function (e) {
- // //console.log('clone');
- // let searchName = this._userNameField.value;
- // self.initWorldsStatesListForUser(searchName);
- // }
- // }
- _app.widgets.buttonRaised(
- {
- "label": 'World Protos',
- "onclick": function (e) {
- e.preventDefault();
- //page("/app/worlds/protos")
- let searchName = this._userNameField.value;
- if(searchName !== "")
- window.location.pathname = "/"+searchName+"/worlds/protos"
- //_app.indexApp.getAppDetailsFromDefaultDB('protos');
- }
- }),
- _app.widgets.space,
- _app.widgets.buttonRaised(
- {
- "label": 'World States',
- "onclick": function (e) {
- e.preventDefault();
- //page("/app/worlds/states")
- let searchName = this._userNameField.value;
- if(searchName !== "")
- window.location.pathname = "/"+searchName+"/worlds/states"
- //_app.indexApp.getAppDetailsFromDefaultDB('states');
- }
- })
-
- ]
- },
- // window._app.widgets.buttonStroked(
- // {
- // "label": 'Default World Protos',
- // "onclick": function (e) {
- // e.preventDefault();
- // //page("/app/worlds/protos")
- // window.location.pathname = "/app/worlds/protos"
- // //_app.indexApp.getAppDetailsFromDefaultDB('protos');
- // }
- // }),
- // window._app.widgets.buttonStroked(
- // {
- // "label": 'Default World States',
- // "onclick": function (e) {
- // e.preventDefault();
- // //page("/app/worlds/states")
- // window.location.pathname = "/app/worlds/states"
- // //_app.indexApp.getAppDetailsFromDefaultDB('states');
- // }
- // })
- ];
- this.$components = [
- {
- $type: "h1",
- class: "mdc-typography--headline4",
- $text: "Looking for Worlds made by other Users!"
- }
- ].concat(guiForAll, _app.widgets.p, _app.widgets.divider)
- }
- }
- let connectionSettings = {
- id: 'connectionSettings',
- $type: 'div',
- class: "mdc-layout-grid mdc-layout-grid--align-left",
- $components: [
- _app.widgets.emptyDiv,
- window._app.widgets.buttonRaised(
- {
- "label": 'Connection settings',
- "onclick": function (e) {
- e.preventDefault();
- window.location.pathname = '/settings';
- }
- }), _app.widgets.emptyDiv
- ]
- }
- let luminaryFeature = {
- $cell: true,
- $type: 'div',
- class: "mdc-layout-grid mdc-layout-grid--align-left",
- _luminarySwitch: null,
- $components: [
- {
- $type: "p",
- class: "mdc-typography--headline5",
- $text: "Use Krestianstvo Luminary (experimental)"
- },
- {
- $type: 'p'
- },
- _app.widgets.switch({
- 'id': 'forceLuminary',
- 'init': function () {
- this._switch = new mdc.switchControl.MDCSwitch(this);
- let config = localStorage.getItem('lcs_config');
- this._switch.checked = JSON.parse(config).luminary;
- // this._replaceSwitch = this._switch;
- },
- 'onchange': function (e) {
- if (this._switch) {
- let chkAttr = this._switch.checked;//this.getAttribute('checked');
- if (chkAttr) {
- let config = JSON.parse(localStorage.getItem('lcs_config'));
- config.luminary = true;
- localStorage.setItem('lcs_config', JSON.stringify(config));
- window.location.reload(true);
- //this._switch.checked = false;
- } else {
- let config = JSON.parse(localStorage.getItem('lcs_config'));
- config.luminary = false;
- localStorage.setItem('lcs_config', JSON.stringify(config));
- window.location.reload(true);
- }
- }
- }
- }
- ),
- {
- $type: 'label',
- for: 'input-forceLuminary',
- $text: 'Off / On'
- }
- ]
- }
- return [luminaryFeature, connectionSettings, _app.widgets.divider]
- }
- refresh() {
- // socket.emit('getWebAppUpdate', "");
- }
- parseOnlineData(data) {
- let parcedData = _app.parseAppInstancesData(data);
- //if (Object.entries(parcedData).length !== 0)
- let onlineGUIs = document.querySelectorAll('.online');
- onlineGUIs.forEach(function (item) {
- item._refresh(parcedData)
- });
- }
- createWorldCard(userAlias, userPub, worldName, id, type, cb) {
- let self = this;
- let db = _LCSDB.user(userPub);
- 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.checkForManualSettings();
- window.location.pathname = "/" + m[1].user + m[0];
- //self.refresh();
- }
- },
- ]
- },
- {
- $type: "span",
- class: "mdc-list-item__secondary-text",
- $text: _app.isLuminary ? _LangManager.language.t('users') + Object.keys(m[1].clients).length : _LangManager.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 = {}
- }
- }
- },
- $init: function () {
- if (_app.isLuminary) {
- let luminaryPath = _app.luminaryPath;
- let ref = _LCSDB.get(luminaryPath);
- setInterval(function () {
- ref.get('allclients').once().map().once(res => {
- if (res) {
- if (res.id) {
- let clientTime = Gun.state.is(res, 'live');
- let now = Gun.time.is();
- if (now - clientTime < 10000) {
- let instance = res.user + res.instance;
- //let data = JSON.stringify({[res.instance]: {instance: instance, clients: {}, user: res.user, loadInfo: {}}});
- //console.log(data);
- if (!self.instances[res.instance]) {
- self.instances[res.instance] = { id: res.instance, instance: instance, clients: { [res.id]: res }, user: res.user, loadInfo: {} }
- } else {
- self.instances[res.instance].clients[res.id] = res
- }
- let data = JSON.stringify(self.instances);
- self.parseOnlineData(data);
- } else {
- if (self.instances[res.instance]) {
- delete self.instances[res.instance].clients[res.id];
- if (Object.keys(self.instances[res.instance].clients).length == 0) {
- delete self.instances[res.instance];
- self.parseOnlineData(JSON.stringify({}));
- }
- }
- //ref.get('instances').get(res.instance).get(res.id).put(null);
- }
- }
- }
- }
- )
- }, 5000);
- }
- 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))
- }
- }
- }
- return {
- $cell: true,
- id: 'worldCard_' + id,
- $type: "div",
- _worldName: "",
- _worldInfo: {},
- _refresh: function (data) {
- this._worldInfo = data;
- this.$components = [this._updateCard()]
- },
- $init: function () {
- this._worldName = worldName;
- if(type == 'min') {
- db.get('worlds').get(this._worldName).path('info_json').on((res)=>{
- console.log(res);
- let worldDesc = JSON.parse(res);
-
- let root = Object.keys(worldDesc)[0];
- var appInfo = worldDesc[root]['en'];
-
- let langID = localStorage.getItem('krestianstvo_locale');
- if (langID) {
- appInfo = worldDesc[root][langID]
- }
- let doc = {
- 'worldName': this._worldName,
- 'created': undefined,
- 'modified': undefined,
- 'type': 'proto',
- 'userAlias': userAlias,
- 'info': appInfo
- }
- this._refresh(doc);
-
- //callback
- if(cb)
- cb(doc);
- })
- } else if (type == 'full'){
- db.get('worlds').get(this._worldName).on((res)=>{
- console.log(res);
- let worldDesc = JSON.parse(res['info_json']);
-
-
- let root = Object.keys(worldDesc)[0];
- var appInfo = worldDesc[root]['en'];
-
- let langID = localStorage.getItem('krestianstvo_locale');
- if (langID) {
- appInfo = worldDesc[root][langID]
- }
-
- let settings = worldDesc[root]['settings'];
- let doc = {
- 'worldName': this._worldName,
- 'created': res.created ? res.created : "",
- 'modified': res.modified ? res.modified : "",
- 'proxy': res.proxy,
- 'type': 'proto',
- 'userAlias': userAlias,
- 'info': appInfo,
- 'settings': settings
- }
- this._refresh(doc);
- //callback
- if(cb)
- cb(doc);
- })
- }
- },
- $update: function () {
- //this.$components = [this._updateCard()]
- },
- _updateComps: function () {
- //console.log(this._worldInfo);
-
- },
- _updateCard: function () {
- let desc = this._worldInfo;
- if (!desc || Object.keys(desc).length == 0) {
- return {
- $type: "h1",
- class: "mdc-typography--headline4",
- $text: "ERROR: NO WORLD!"
- }
- }
- let userGUI = [];
- let online = [];
- let cardInfo = {
- "title": ""
- };
- if (type == "full") {
- } 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'
- }
- });
- }
- userGUI.push({
- $type: "a",
- class: "mdc-button mdc-button--raised mdc-card__action ",
- $text: _LangManager.language.t('start'),//"Start new",
- //target: "_blank",
- //href: "/" + desc.userAlias + '/' + desc.worldName,
- onclick: function (e) {
- self.checkForManualSettings();
- window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName
- //self.refresh();
- }
- });
- if (desc.type == 'saveState') {
- cardInfo.title = desc.worldName.split('/')[2];
- }
- if (desc.type == 'proto') {
- cardInfo.title = desc.worldName;
- // 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);
- if(!desc.info){
- desc.info = {
- imgUrl: "/defaults/worlds/webrtc/webimg.jpg",
- text: "..no text",
- title: "..no title"
- }
- }
- return {
- $type: "div",
- class: "mdc-card world-card",
- $components: [
- {
- $type: "section",
- class: "mdc-card__media world-card__16-9-media",
- $init: function () {
- 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 + ')';
- }
- }
- },
- {
- $type: "section",
- class: "mdc-card__primary",
- $components: [
- {
- $type: "h1",
- class: "mdc-card__title mdc-card__title--large",
- $text: desc.info.title
- },
- {
- $type: "h2",
- class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
- $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: desc.created ? 'created: ' + (new Date(desc.created)).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: [
- ].concat(userGUI)
- },
- {
- $type: "section",
- class: "mdc-card__actions",
- $components: [
- {
- $type: 'div',
- $text: 'online now: '
- }
- ].concat(online)
- }
- ]
- }
- }
- }
- }
- createWorldsGUI(userAlias, userPub, worldName) {
- let self = this;
- let db = _LCSDB.user(userPub);
- 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: [],
- _cards: [],
- _states: {},
- _refresh: function (data) {
- this._states = data
- },
- $init: async 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._cards.filter(el=> el.$components[0].id == 'worldCard_'+ userAlias + '_' + k)[0];
-
- if(!doc) {
- doc = this._makeWorldCard(k);
- this._cards.push(doc);
- }
-
- })
- //this._refresh();
- },
- _makeWorldCard: function (worldName) {
- let cardID = userAlias + '_' + worldName//data[1].userAlias + '_' + data[1].worldName + '_' + data[0];
- let card = self.createWorldCard(userAlias, userPub, worldName, cardID, 'min');
- //card._refresh(data[1]);
- //card._worldInfo = data[1];
- //card._updateComps();
- return {
- $cell: true,
- $type: "div",
- class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
- $components: [card]
- }
- },
- $update: function () {
- // let cards = 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);
- 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: this._cards
- }
- ]
- }
- ]
- }
- }
- return worldCards
- }
- checkForManualSettings() {
- console.log("check for manual settings");
- let manualSettings = localStorage.getItem('lcs_app_manual_settings');
- if (manualSettings) {
- localStorage.removeItem('lcs_app_manual_settings');
- }
- let el = document.querySelector('#runWorldGUI');
- if (el) {
- if (el._arSwitch.checked) {
- let arSettings = {
- model: {
- 'vwf/model/aframe': null
- },
- view: {
- 'vwf/view/aframe': null,
- 'vwf/view/editor-new': null
- }
- }
- localStorage.setItem('lcs_app_manual_settings', JSON.stringify(arSettings));
- }
- if (el._turnArOnSwitch.checked) {
- let arSettings = {
- model: {
- 'vwf/model/aframe': null
- },
- view: {
- 'vwf/view/aframe': null,
- 'vwf/view/aframe-ar-driver': null
- }
- }
- localStorage.setItem('lcs_app_manual_settings', JSON.stringify(arSettings));
- }
- }
- }
- }
- export { IndexApp as default }
- //export {getAppDetails, generateFrontPage, setLanguage, initLocale};
|