index-app.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. /*
  2. The MIT License (MIT)
  3. Copyright (c) 2014-2018 Nikolai Suslov and the Krestianstvo.org project contributors. (https://github.com/NikolaySuslov/livecodingspace/blob/master/LICENSE.md)
  4. */
  5. //import page from '/lib/page.mjs';
  6. import { Header } from '/web/header.js';
  7. class IndexApp {
  8. constructor() {
  9. console.log("app constructor");
  10. this.worlds = {};
  11. //this.language = _LangManager.language;
  12. this.options = {
  13. query: 'pathname=' + window.location.pathname.slice(1,
  14. window.location.pathname.lastIndexOf("/")),
  15. secure: window.location.protocol === "https:",
  16. reconnection: false,
  17. path: '',
  18. transports: ['websocket']
  19. }
  20. //window.location.host
  21. var socket = io.connect(window._app.reflectorHost, this.options);
  22. const parse = (msg) => {
  23. this.parseOnlineData(msg)
  24. }
  25. socket.on('getWebAppUpdate', msg => parse.call(this, msg));
  26. socket.on("connect", function () {
  27. let noty = new Noty({
  28. text: 'Connected to Reflector!',
  29. timeout: 2000,
  30. theme: 'mint',
  31. layout: 'bottomRight',
  32. type: 'success'
  33. });
  34. noty.show();
  35. })
  36. socket.on('connect_error', function (err) {
  37. console.log(err);
  38. var errDiv = document.createElement("div");
  39. errDiv.innerHTML = "<div class='vwf-err' style='z-index: 10; position: absolute; top: 80px; right: 50px'>Connection error to Reflector!" + err + "</div>";
  40. document.querySelector('body').appendChild(errDiv);
  41. let noty = new Noty({
  42. text: 'Connection error to Reflector! ' + err,
  43. theme: 'mint',
  44. layout: 'bottomRight',
  45. type: 'error'
  46. });
  47. noty.show();
  48. });
  49. }
  50. initHTML() {
  51. let self = this;
  52. //first init from _app
  53. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="/web/index-app.css">';
  54. let headerGUI = new Header();
  55. headerGUI.init();
  56. //add HTML
  57. let entry = document.createElement("div");
  58. entry.setAttribute("id", 'app');
  59. document.body.appendChild(entry);
  60. let divs = ['appGUI', 'userLobby', 'main', 'worldsGUI'];
  61. divs.forEach(el => {
  62. let appEl = document.createElement("div");
  63. appEl.setAttribute("id", el);
  64. entry.appendChild(appEl);
  65. })
  66. //init CELL
  67. document.querySelector("#userLobby").$cell({
  68. id: "userLobby",
  69. $cell: true,
  70. $type: "div",
  71. $components: [],
  72. $update: function () {
  73. this.$components = self.initUserGUI()
  74. }
  75. });
  76. document.querySelector("#worldsGUI").$cell({
  77. id: 'worldsGUI',
  78. $cell: true,
  79. $type: "div",
  80. $components: [],
  81. _comps: [],
  82. _refresh: async function (data, fn) {
  83. _app.showProgressBar();
  84. this._comps = await fn.call(self, data);
  85. this.$update();
  86. _app.hideProgressBar();
  87. },
  88. $update: async function () {
  89. this.$components = this._comps
  90. }
  91. });
  92. }
  93. async generateFrontPage() {
  94. let infoEl = document.createElement("div");
  95. infoEl.setAttribute("id", "indexPage");
  96. let lang = _LangManager.locale;
  97. let infoElHTML = await _app.helpers.getHtmlText('/web/locale/' + lang + '/index.html');
  98. infoEl.innerHTML = infoElHTML;
  99. document.body.appendChild(infoEl);
  100. document.querySelector('#ruLang').addEventListener('click', function (e) {
  101. _LangManager.locale = 'ru';
  102. window.location.reload(true);
  103. });
  104. document.querySelector('#enLang').addEventListener('click', function (e) {
  105. _LangManager.locale = 'en';
  106. window.location.reload(true);
  107. });
  108. }
  109. initApp() {
  110. // let appElHTML = await _app.helpers.getHtmlText('/web/app.html');
  111. // appEl.innerHTML = appElHTML;
  112. // document.body.appendChild(appEl);
  113. this.initUser();
  114. document.querySelector("#userLobby").$update();
  115. //this.initWorldsListGUI();
  116. //this.getAppDetailsFromDB();
  117. }
  118. async initWorldsProtosListForUser(userAlias) {
  119. document.querySelector("#worldsGUI").$components = [];
  120. await document.querySelector("#worldsGUI")._refresh(userAlias, this.getWorldsProtosListForUser);
  121. }
  122. async initWorldsStatesListForUser(userAlias) {
  123. document.querySelector("#worldsGUI").$components = [];
  124. await document.querySelector("#worldsGUI")._refresh(userAlias, this.getWorldsStatesListForUser);
  125. }
  126. async getWorldsStatesListForUser(userAlias) {
  127. let worldsGUI = [];
  128. let worlds = this.createWorldsGUI(userAlias, 'allStates' );
  129. await _app.getAllStateWorldsInfoForUser(userAlias, function (data) {
  130. let doc = document.querySelector("#allStates_" + userAlias);
  131. if (doc) {
  132. Object.assign(doc._states, data);
  133. doc.$update();
  134. }
  135. }
  136. );
  137. worldsGUI.push(worlds);
  138. // Object.entries(data).forEach(el => {
  139. // let worlds = this.createWorldsGUI(userAlias, el[0]);
  140. // worlds._states = el[1];
  141. // worlds.$update();
  142. // worldsGUI.push(worlds);
  143. // })
  144. return [
  145. {
  146. $type: "div",
  147. class: "mdc-layout-grid",
  148. $components: [
  149. {
  150. $type: "div",
  151. class: "mdc-layout-grid__inner",
  152. $components: [
  153. {
  154. $type: "div",
  155. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  156. $components: [
  157. {
  158. $type: "h1",
  159. class: "mdc-typography--headline4",
  160. $text: 'States for ' + userAlias
  161. }
  162. ]
  163. },
  164. {
  165. $type: "div",
  166. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  167. $components: [].concat(worldsGUI)
  168. }
  169. ]
  170. }
  171. ]
  172. }
  173. ]
  174. }
  175. async getWorldsProtosListForUser(userAlias) {
  176. let worldsGUI = [];
  177. //let data = await _app.getAllProtoWorldsInfoForUser(userAlias);
  178. let worlds = this.createWorldsGUI(userAlias);
  179. await _app.getAllProtoWorldsInfoForUser(userAlias, function (data) {
  180. let doc = document.querySelector("#allWorlds_" + userAlias);
  181. if (doc) {
  182. Object.assign(doc._states, data);
  183. doc.$update();
  184. }
  185. })
  186. //worlds._states = data;
  187. //worlds.$update();
  188. worldsGUI.push(worlds);
  189. return [
  190. {
  191. $type: "div",
  192. class: "mdc-layout-grid",
  193. $components: [
  194. {
  195. $type: "div",
  196. class: "mdc-layout-grid__inner",
  197. $components: [
  198. {
  199. $type: "div",
  200. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  201. $components: [
  202. {
  203. $type: "h1",
  204. class: "mdc-typography--headline4",
  205. $text: 'Worlds for ' + userAlias
  206. }
  207. ]
  208. },
  209. {
  210. $type: "div",
  211. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  212. $components: [].concat(worldsGUI)
  213. },
  214. ]
  215. }
  216. ]
  217. }
  218. ]
  219. }
  220. initUser() {
  221. _LCSDB.on('auth', function(ack) {
  222. if (ack.sea.pub) {
  223. let alias = _LCSDB.user().is.alias;
  224. let userEl = document.querySelector('#userGUI');
  225. userEl._status = 'Welcome ' + alias + '!';
  226. //userEl.style.backgroundColor = '#e6e6e6';
  227. userEl.$update();
  228. // document.querySelector('#worldGUI').$update();
  229. // document.querySelector('#main').$update();
  230. _LCSDB.get('users').get(alias).not(function(res) {
  231. let userObj = {
  232. alias: alias,
  233. pub: ack.sea.pub
  234. }
  235. _LCSDB.get('users').get(alias).put(userObj);
  236. })
  237. _LCSDB.user().get('profile').once(function (data) { console.log(data) })
  238. let el = document.getElementById("loginGUI");
  239. if (el) {
  240. el.remove();
  241. }
  242. _LCSDB.user().get('profile').not(function (key) {
  243. let profile = { 'alias': alias };
  244. _LCSDB.user().get('profile').put(profile);
  245. })
  246. let actionsGUI = document.querySelector('#worldActionsGUI');
  247. if (actionsGUI)
  248. actionsGUI._refresh();
  249. new Noty({
  250. text: alias + ' is succesfully authenticated!',
  251. timeout: 2000,
  252. theme: 'mint',
  253. layout: 'bottomRight',
  254. type: 'success'
  255. }).show();
  256. //this.getAppDetailsFromUserDB();
  257. }
  258. console.log(_LCSDB.user().is);
  259. });
  260. }
  261. initUserGUI() {
  262. let worldGUI =
  263. {
  264. $type: "div",
  265. id: "worldGUI",
  266. class: "mdc-layout-grid mdc-layout-grid--align-left",
  267. _status: '',
  268. $init: function () {
  269. this._status = "init";
  270. },
  271. $update: function () {
  272. let guiForAll = [
  273. window._app.widgets.buttonStroked(
  274. {
  275. "label": 'Default World Protos',
  276. "onclick": function (e) {
  277. e.preventDefault();
  278. //page("/app/worlds/protos")
  279. window.location.pathname = "/app/worlds/protos"
  280. //_app.indexApp.getAppDetailsFromDefaultDB('protos');
  281. }
  282. }),
  283. window._app.widgets.buttonStroked(
  284. {
  285. "label": 'Default World States',
  286. "onclick": function (e) {
  287. e.preventDefault();
  288. //page("/app/worlds/states")
  289. window.location.pathname = "/app/worlds/states"
  290. //_app.indexApp.getAppDetailsFromDefaultDB('states');
  291. }
  292. })
  293. ];
  294. var guiUser = [];
  295. if (_LCSDB.user().is) {
  296. guiUser = []
  297. }
  298. this.$components = [
  299. {
  300. $type: "h1",
  301. class: "mdc-typography--headline4",
  302. $text: "Worlds list"
  303. }
  304. ].concat(guiForAll).concat(guiUser)
  305. }
  306. }
  307. let userGUI =
  308. {
  309. $type: "div",
  310. id: "userGUI",
  311. // style:"background-color: #ffeb3b",
  312. class: "mdc-layout-grid mdc-layout-grid--align-left",
  313. _status: "",
  314. $init: function () {
  315. this._status = "Welcome!"
  316. },
  317. $update: function () {
  318. var gui = {};
  319. if (_LCSDB.user().is) {
  320. gui = [
  321. window._app.widgets.buttonRaised(
  322. {
  323. "label": 'Sign OUT',
  324. "onclick": function (e) {
  325. _LCSDB.user().leave();
  326. setTimeout(() =>
  327. {
  328. //window.sessionStorage.removeItem('alias');
  329. //window.sessionStorage.removeItem('tmp');
  330. window.location.reload(true);
  331. }, 1);
  332. }
  333. }),
  334. {
  335. $type: "p"
  336. },
  337. window._app.widgets.buttonStroked(
  338. {
  339. "label": 'PROFILE',
  340. "onclick": function (e) {
  341. e.preventDefault();
  342. //page("/profile")
  343. window.location.pathname = "/profile"
  344. }
  345. }),
  346. {
  347. $type: "p"
  348. },
  349. window._app.widgets.buttonStroked(
  350. {
  351. "label": 'My World protos',
  352. "onclick": function (e) {
  353. e.preventDefault();
  354. let alias = _LCSDB.user().is.alias;
  355. window.location.pathname = '/' + alias + '/worlds/protos'
  356. //page('/' + alias + '/worlds/protos');
  357. //_app.indexApp.getWorldsProtosFromUserDB(alias);
  358. }
  359. }),
  360. window._app.widgets.buttonStroked(
  361. {
  362. "label": 'My World states',
  363. "onclick": function (e) {
  364. e.preventDefault();
  365. let alias = _LCSDB.user().is.alias;
  366. window.location.pathname = '/' + alias + '/worlds/states'
  367. //page('/' + alias + '/worlds/states');
  368. // page.redirect('/' + alias + '/worlds/states');
  369. //_app.indexApp.getWorldsFromUserDB(alias);
  370. }
  371. })
  372. ]
  373. }
  374. this.$components = [
  375. window._app.widgets.buttonRaised(
  376. {
  377. "label": 'Connection settings',
  378. "onclick": function (e) {
  379. e.preventDefault();
  380. window.location.pathname = '/settings';
  381. }
  382. }),
  383. {
  384. $type: "h1",
  385. class: "mdc-typography--headline3",
  386. $text: this._status
  387. }
  388. ].concat(gui)
  389. }
  390. }
  391. let loginGUI =
  392. {
  393. $type: "div",
  394. id: "loginGUI",
  395. //style:"background-color: #efefef",
  396. class: "mdc-layout-grid mdc-layout-grid--align-left",
  397. _alias: null,
  398. _pass: null,
  399. _passField: null,
  400. _aliasField: null,
  401. _initData: function () {
  402. this._alias = '';
  403. this._pass = '';
  404. // if (window.sessionStorage.getItem('alias')) {
  405. // this._alias = window.sessionStorage.getItem('alias')
  406. // }
  407. // if (window.sessionStorage.getItem('tmp')) {
  408. // this._pass = window.sessionStorage.getItem('tmp')
  409. // }
  410. },
  411. $init: function () {
  412. this._initData();
  413. },
  414. $update: function () {
  415. this.$components = [
  416. {
  417. $type: "div",
  418. class: "mdc-layout-grid__inner",
  419. $components: [
  420. {
  421. $type: "div",
  422. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  423. $components: [
  424. {
  425. $type: "span",
  426. class: "mdc-typography--headline5",
  427. $text: "Login: "
  428. },
  429. window._app.widgets.inputTextFieldOutlined({
  430. "id": 'aliasInput',
  431. "label": "Login",
  432. "value": this._alias,
  433. "type": "text",
  434. "init": function () {
  435. this._aliasField = new mdc.textField.MDCTextField(this);
  436. }
  437. }),
  438. ]
  439. },
  440. {
  441. $type: "div",
  442. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  443. $components: [
  444. {
  445. $type: "span",
  446. class: "mdc-typography--headline5",
  447. $text: "Password: "
  448. },
  449. window._app.widgets.inputTextFieldOutlined({
  450. "id": 'passwordInput',
  451. "label": "Password",
  452. "value": this._pass,
  453. "type": "password",
  454. "init": function () {
  455. this._passField = new mdc.textField.MDCTextField(this);
  456. }
  457. }),
  458. ]
  459. },
  460. {
  461. $type: "div",
  462. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  463. $components: [
  464. window._app.widgets.buttonRaised(
  465. {
  466. "label": 'Sign UP',
  467. "onclick": function (e) {
  468. e.preventDefault();
  469. let alias = this._aliasField.value;
  470. let pass = this._passField.value
  471. if (pass.length < 7) {
  472. new Noty({
  473. text: "Your passphrase needs to be longer than 7 letters",
  474. timeout: 2000,
  475. theme: 'mint',
  476. layout: 'bottomRight',
  477. type: 'error'
  478. }).show();
  479. } else {
  480. //
  481. _LCSDB.user().create(alias, pass,
  482. function(ack) {
  483. if (!ack.wait) { }
  484. if (ack.err) {
  485. console.log(ack.err)
  486. return ack.err
  487. };
  488. if (ack.pub) {
  489. let userObj = {
  490. 'alias': alias,
  491. 'pub': ack.pub
  492. };
  493. _LCSDB.get('users').get(alias).put(userObj);
  494. }
  495. _LCSDB.user().auth(alias, pass);
  496. });
  497. }
  498. }
  499. }),
  500. {
  501. $type: "span",
  502. $text: " "
  503. },
  504. window._app.widgets.buttonRaised(
  505. {
  506. "label": 'Sign IN',
  507. "onclick": function (e) {
  508. e.preventDefault();
  509. _LCSDB.user().auth(this._aliasField.value, this._passField.value, function(ack) {
  510. if (ack.err) {
  511. new Noty({
  512. text: ack.err,
  513. timeout: 2000,
  514. theme: 'mint',
  515. layout: 'bottomRight',
  516. type: 'error'
  517. }).show();
  518. }
  519. });
  520. }
  521. })
  522. ]
  523. }
  524. ]
  525. }
  526. ]
  527. }
  528. }
  529. // document.querySelector("#userLobby").$cell({
  530. // id: "userLobby",
  531. // $cell: true,
  532. // $type: "div",
  533. // $components: [
  534. // userGUI, loginGUI, _app.widgets.divider, worldGUI]
  535. // }
  536. // );
  537. return [userGUI, loginGUI, _app.widgets.divider, worldGUI]
  538. }
  539. refresh() {
  540. // socket.emit('getWebAppUpdate', "");
  541. }
  542. parseOnlineData(data) {
  543. let parcedData = _app.parseAppInstancesData(data);
  544. //if (Object.entries(parcedData).length !== 0)
  545. let onlineGUIs = document.querySelectorAll('.online');
  546. onlineGUIs.forEach(function (item) {
  547. item._refresh(parcedData)
  548. });
  549. }
  550. createWorldCard(id, type) {
  551. let self = this;
  552. let onlineGUI = {
  553. $cell: true,
  554. id: "onlineGUI_" + id,
  555. class: "online",
  556. $type: "div",
  557. _instances: {},
  558. _worldListItem: function (m) {
  559. return {
  560. $type: "li",
  561. class: "mdc-list-item",
  562. $components: [
  563. {
  564. $type: "span",
  565. class: "world-link mdc-list-item__text",
  566. $components: [
  567. {
  568. $type: "span",
  569. class: "mdc-list-item__primary-text",
  570. $components: [
  571. {
  572. $type: "a",
  573. $text: m[0],
  574. //target: "_blank",
  575. // href: window.location.protocol + "//" + window.location.host + "/" + m[1].user + m[0],
  576. onclick: function (e) {
  577. self.checkForManualSettings();
  578. window.location.pathname = "/" + m[1].user + m[0];
  579. //self.refresh();
  580. }
  581. },
  582. ]
  583. },
  584. {
  585. $type: "span",
  586. class: "mdc-list-item__secondary-text",
  587. $text: _LangManager.language.t('users') + m[1].clients
  588. }
  589. ]
  590. }
  591. ]
  592. }
  593. },
  594. $components: [],
  595. _refresh: function (data) {
  596. if (data) {
  597. if (Object.entries(data).length !== 0) {
  598. if (this._worldInfo) {
  599. let insts = Object.entries(data).filter(el => el[0] == this._worldInfo.worldName);
  600. if (insts.length !== 0)
  601. this._instances = insts[0][1];
  602. }
  603. } else {
  604. this._instances = {}
  605. }
  606. }
  607. },
  608. $init: function () {
  609. this._refresh();
  610. },
  611. $update: function () {
  612. if (this._instances) {
  613. let cardListData = Object.entries(this._instances).filter(el => el[1].user == this._worldInfo.userAlias);
  614. this.$components = [
  615. {
  616. $type: "hr",
  617. class: "mdc-list-divider"
  618. }
  619. ].concat(cardListData.map(this._worldListItem))
  620. }
  621. }
  622. }
  623. return {
  624. $cell: true,
  625. id: 'worldCard_' + id,
  626. $type: "div",
  627. _worldInfo: {},
  628. _refresh: function (data) {
  629. this._worldInfo = data
  630. },
  631. // _getWorldInfo: async function () {
  632. // //get space for user
  633. // let info = await _app.getWorldInfo(user, space);
  634. // this._refresh(info);
  635. // },
  636. // _getStateInfo: async function () {
  637. // //get space for user
  638. // let info = await _app.getStateInfo(user, space, saveName);
  639. // this._refresh(info);
  640. // },
  641. $init: function () {
  642. //get space for user
  643. // if (!saveName) {
  644. // this._getWorldInfo();
  645. // } else {
  646. // this._getStateInfo();
  647. // }
  648. },
  649. $update: function () {
  650. //console.log(this._worldInfo);
  651. this.$components = [this._updateCard()]
  652. },
  653. $components: [],
  654. _updateCard: function () {
  655. let desc = this._worldInfo;
  656. if (!desc || Object.keys(desc).length == 0) {
  657. return {
  658. $type: "h1",
  659. class: "mdc-typography--headline4",
  660. $text: "ERROR: NO WORLD!"
  661. }
  662. }
  663. let userGUI = [];
  664. let online = [];
  665. let cardInfo = {
  666. "title": ""
  667. };
  668. if (type == "full") {
  669. } else {
  670. userGUI.push({
  671. $type: "a",
  672. class: "mdc-button mdc-button--compact mdc-card__action mdc-button--outlined",
  673. $text: "Details",
  674. onclick: function (e) {
  675. e.preventDefault();
  676. window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName + '/about'
  677. }
  678. });
  679. }
  680. userGUI.push({
  681. $type: "a",
  682. class: "mdc-button mdc-button--raised mdc-card__action ",
  683. $text: _LangManager.language.t('start'),//"Start new",
  684. //target: "_blank",
  685. //href: "/" + desc.userAlias + '/' + desc.worldName,
  686. onclick: function (e) {
  687. self.checkForManualSettings();
  688. window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName
  689. //self.refresh();
  690. }
  691. });
  692. if (desc.type == 'saveState') {
  693. cardInfo.title = desc.worldName.split('/')[2];
  694. }
  695. if (desc.type == 'proto') {
  696. cardInfo.title = desc.worldName;
  697. // userGUI.push(
  698. // {
  699. // $type: "a",
  700. // class: "mdc-button mdc-button--compact mdc-card__action",
  701. // $text: "States",
  702. // onclick: async function (e) {
  703. // e.preventDefault();
  704. // window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName +'/about'
  705. // //console.log('clone');
  706. // // document.querySelector('#worldStatesGUI')._refresh({});
  707. // // let data = await _app.getSaveStates(desc.userAlias, desc.worldName);
  708. // // document.querySelector('#worldStatesGUI')._refresh(data);
  709. // }
  710. // }
  711. // )
  712. }
  713. online.push(onlineGUI);
  714. return {
  715. $cell: true,
  716. $type: "div",
  717. class: "mdc-card world-card",
  718. $components: [
  719. {
  720. $type: "section",
  721. class: "mdc-card__media world-card__16-9-media",
  722. $init: function () {
  723. if (desc.info.imgUrl !== "") {
  724. this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3) ), url(' + desc.info.imgUrl + ')';
  725. }
  726. }
  727. },
  728. {
  729. $type: "section",
  730. class: "mdc-card__primary",
  731. $components: [
  732. {
  733. $type: "h1",
  734. class: "mdc-card__title mdc-card__title--large",
  735. $text: desc.info.title
  736. },
  737. {
  738. $type: "h2",
  739. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  740. $text: desc.info.text
  741. },
  742. {
  743. $type: "span",
  744. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  745. $text: 'id: '
  746. },
  747. {
  748. $type: "input",
  749. type: "text",
  750. disabled: "",
  751. style: "font-size:18px",
  752. value: cardInfo.title
  753. },
  754. {
  755. $type: "p",
  756. },
  757. {
  758. $type: "span",
  759. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  760. $text: 'created: ' + (new Date(desc.created)).toUTCString()
  761. },
  762. {
  763. $type: "p",
  764. }
  765. // ,{
  766. // $type: "span",
  767. // class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  768. // $text: 'modified: ' + (new Date(desc[5])).toUTCString()
  769. // }
  770. ]
  771. },
  772. {
  773. $type: "section",
  774. class: "mdc-card__actions",
  775. $components: [
  776. ].concat(userGUI)
  777. },
  778. {
  779. $type: "section",
  780. class: "mdc-card__actions",
  781. $components: [
  782. {
  783. $type: 'div',
  784. $text: 'online now: '
  785. }
  786. ].concat(online)
  787. }
  788. ]
  789. }
  790. }
  791. }
  792. }
  793. createWorldsGUI(userAlias, worldName) {
  794. let self = this;
  795. let id = worldName ? worldName + '_' + userAlias : "allWorlds_" + userAlias
  796. let headerText = worldName ? 'States for ' + worldName : 'All Worlds Protos'
  797. let worldCards = {
  798. $cell: true,
  799. id: id,
  800. $type: "div",
  801. $components: [],
  802. _states: {},
  803. _refresh: function (data) {
  804. this._states = data
  805. },
  806. $init: async function () {
  807. //this._refresh();
  808. },
  809. _makeWorldCard: function (data) {
  810. let cardID = data[1].userAlias + '_' + data[1].worldName + '_' + data[0];
  811. let card = self.createWorldCard(cardID, 'min');
  812. card._worldInfo = data[1];
  813. card.$update();
  814. return {
  815. $cell: true,
  816. $type: "div",
  817. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  818. $components: [
  819. card
  820. //self.createWorldCard(data[1].userAlias, data[1].worldName, data[0])
  821. //this._worldCardDef(appInfo)
  822. ]
  823. }
  824. //console.log(data);
  825. },
  826. $update: function () {
  827. let cards = Object.entries(this._states)
  828. .filter(el => Object.keys(el[1]).length !== 0)
  829. .sort(function (el1, el2) {
  830. return parseInt(el2[1].created) - parseInt(el1[1].created)
  831. })
  832. .map(this._makeWorldCard);
  833. this.$components = [
  834. {
  835. $type: "div",
  836. class: "mdc-layout-grid",
  837. $components: [
  838. {
  839. $type: "div",
  840. class: "mdc-layout-grid__inner",
  841. $components: [
  842. {
  843. $type: "div",
  844. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  845. $components: [
  846. {
  847. $type: "H3",
  848. $text: headerText
  849. }
  850. ]
  851. }
  852. ]
  853. },
  854. {
  855. $type: "div",
  856. class: "mdc-layout-grid__inner",
  857. $components: cards
  858. }
  859. ]
  860. }
  861. ]
  862. }
  863. }
  864. return worldCards
  865. }
  866. checkForManualSettings() {
  867. console.log("check for manual settings");
  868. let manualSettings = localStorage.getItem('lcs_app_manual_settings');
  869. if(manualSettings){
  870. localStorage.removeItem('lcs_app_manual_settings');
  871. }
  872. let el = document.querySelector('#runWorldGUI');
  873. if (el) {
  874. if (el._arSwitch.checked){
  875. let arSettings = {
  876. model:{
  877. 'vwf/model/aframe': null
  878. },
  879. view:{
  880. 'vwf/view/aframe' : null,
  881. 'vwf/view/editor-new': null
  882. }
  883. }
  884. localStorage.setItem('lcs_app_manual_settings', JSON.stringify(arSettings));
  885. }
  886. if (el._turnArOnSwitch.checked){
  887. let arSettings = {
  888. model:{
  889. 'vwf/model/aframe': null
  890. },
  891. view:{
  892. 'vwf/view/aframe' : null,
  893. 'vwf/view/aframe-ar-driver': null
  894. }
  895. }
  896. localStorage.setItem('lcs_app_manual_settings', JSON.stringify(arSettings));
  897. }
  898. }
  899. }
  900. }
  901. export { IndexApp as default }
  902. //export {getAppDetails, generateFrontPage, setLanguage, initLocale};