index-app.js 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  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', (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.user().get('profile').once(function (data) { console.log(data) })
  231. let el = document.getElementById("loginGUI");
  232. if (el) {
  233. el.remove();
  234. }
  235. _LCSDB.user().get('profile').not(function (key) {
  236. let profile = { 'alias': alias };
  237. _LCSDB.user().get('profile').put(profile);
  238. })
  239. let actionsGUI = document.querySelector('#worldActionsGUI');
  240. if (actionsGUI)
  241. actionsGUI._refresh();
  242. new Noty({
  243. text: alias + ' is succesfully authenticated!',
  244. timeout: 2000,
  245. theme: 'mint',
  246. layout: 'bottomRight',
  247. type: 'success'
  248. }).show();
  249. //this.getAppDetailsFromUserDB();
  250. }
  251. console.log(_LCSDB.user().is);
  252. });
  253. }
  254. initUserGUI() {
  255. let worldGUI =
  256. {
  257. $type: "div",
  258. id: "worldGUI",
  259. class: "mdc-layout-grid mdc-layout-grid--align-left",
  260. _status: '',
  261. $init: function () {
  262. this._status = "init";
  263. },
  264. $update: function () {
  265. let guiForAll = [
  266. window._app.widgets.buttonStroked(
  267. {
  268. "label": 'Default World Protos',
  269. "onclick": function (e) {
  270. e.preventDefault();
  271. page("/app/worlds/protos")
  272. //window.location.pathname = "/app/worlds/protos"
  273. //_app.indexApp.getAppDetailsFromDefaultDB('protos');
  274. }
  275. }),
  276. window._app.widgets.buttonStroked(
  277. {
  278. "label": 'Default World States',
  279. "onclick": function (e) {
  280. e.preventDefault();
  281. page("/app/worlds/states")
  282. // window.location.pathname = "/app/worlds/states"
  283. //_app.indexApp.getAppDetailsFromDefaultDB('states');
  284. }
  285. })
  286. ];
  287. var guiUser = [];
  288. if (_LCSDB.user().is) {
  289. guiUser = []
  290. }
  291. this.$components = [
  292. {
  293. $type: "h1",
  294. class: "mdc-typography--headline4",
  295. $text: "Worlds list"
  296. }
  297. ].concat(guiForAll).concat(guiUser)
  298. }
  299. }
  300. let userGUI =
  301. {
  302. $type: "div",
  303. id: "userGUI",
  304. // style:"background-color: #ffeb3b",
  305. class: "mdc-layout-grid mdc-layout-grid--align-left",
  306. _status: "",
  307. $init: function () {
  308. this._status = "Welcome!"
  309. },
  310. $update: function () {
  311. var gui = {};
  312. if (_LCSDB.user().is) {
  313. gui = [
  314. window._app.widgets.buttonRaised(
  315. {
  316. "label": 'Sign OUT',
  317. "onclick": function (e) {
  318. _LCSDB.user().leave().then(ack => {
  319. if (ack.pub) {
  320. window.sessionStorage.removeItem('alias');
  321. window.sessionStorage.removeItem('tmp');
  322. window.location.reload(true);
  323. }
  324. });
  325. }
  326. }),
  327. {
  328. $type: "p"
  329. },
  330. window._app.widgets.buttonStroked(
  331. {
  332. "label": 'PROFILE',
  333. "onclick": function (e) {
  334. e.preventDefault();
  335. //page("/profile")
  336. window.location.pathname = "/profile"
  337. }
  338. }),
  339. {
  340. $type: "p"
  341. },
  342. window._app.widgets.buttonStroked(
  343. {
  344. "label": 'My World protos',
  345. "onclick": function (e) {
  346. e.preventDefault();
  347. let alias = _LCSDB.user().is.alias;
  348. //window.location.pathname = '/' + alias + '/worlds/protos'
  349. page('/' + alias + '/worlds/protos');
  350. //_app.indexApp.getWorldsProtosFromUserDB(alias);
  351. }
  352. }),
  353. window._app.widgets.buttonStroked(
  354. {
  355. "label": 'My World states',
  356. "onclick": function (e) {
  357. e.preventDefault();
  358. let alias = _LCSDB.user().is.alias;
  359. // window.location.pathname = '/' + alias + '/worlds/states'
  360. page('/' + alias + '/worlds/states');
  361. // page.redirect('/' + alias + '/worlds/states');
  362. //_app.indexApp.getWorldsFromUserDB(alias);
  363. }
  364. })
  365. ]
  366. }
  367. this.$components = [
  368. window._app.widgets.buttonRaised(
  369. {
  370. "label": 'Connection settings',
  371. "onclick": function (e) {
  372. e.preventDefault();
  373. window.location.pathname = '/settings';
  374. }
  375. }),
  376. {
  377. $type: "h1",
  378. class: "mdc-typography--headline3",
  379. $text: this._status
  380. }
  381. ].concat(gui)
  382. }
  383. }
  384. let loginGUI =
  385. {
  386. $type: "div",
  387. id: "loginGUI",
  388. //style:"background-color: #efefef",
  389. class: "mdc-layout-grid mdc-layout-grid--align-left",
  390. _alias: null,
  391. _pass: null,
  392. _passField: null,
  393. _aliasField: null,
  394. _initData: function () {
  395. this._alias = '';
  396. this._pass = '';
  397. // if (window.sessionStorage.getItem('alias')) {
  398. // this._alias = window.sessionStorage.getItem('alias')
  399. // }
  400. // if (window.sessionStorage.getItem('tmp')) {
  401. // this._pass = window.sessionStorage.getItem('tmp')
  402. // }
  403. },
  404. $init: function () {
  405. this._initData();
  406. },
  407. $update: function () {
  408. this.$components = [
  409. {
  410. $type: "div",
  411. class: "mdc-layout-grid__inner",
  412. $components: [
  413. {
  414. $type: "div",
  415. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  416. $components: [
  417. {
  418. $type: "span",
  419. class: "mdc-typography--headline5",
  420. $text: "Login: "
  421. },
  422. window._app.widgets.inputTextFieldOutlined({
  423. "id": 'aliasInput',
  424. "label": "Login",
  425. "value": this._alias,
  426. "type": "text",
  427. "init": function () {
  428. this._aliasField = new mdc.textField.MDCTextField(this);
  429. }
  430. }),
  431. ]
  432. },
  433. {
  434. $type: "div",
  435. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  436. $components: [
  437. {
  438. $type: "span",
  439. class: "mdc-typography--headline5",
  440. $text: "Password: "
  441. },
  442. window._app.widgets.inputTextFieldOutlined({
  443. "id": 'passwordInput',
  444. "label": "Password",
  445. "value": this._pass,
  446. "type": "password",
  447. "init": function () {
  448. this._passField = new mdc.textField.MDCTextField(this);
  449. }
  450. }),
  451. ]
  452. },
  453. {
  454. $type: "div",
  455. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  456. $components: [
  457. window._app.widgets.buttonRaised(
  458. {
  459. "label": 'Sign UP',
  460. "onclick": function (e) {
  461. e.preventDefault();
  462. let alias = this._aliasField.value;
  463. let pass = this._passField.value
  464. if (pass.length < 7) {
  465. new Noty({
  466. text: "Your passphrase needs to be longer than 7 letters",
  467. timeout: 2000,
  468. theme: 'mint',
  469. layout: 'bottomRight',
  470. type: 'error'
  471. }).show();
  472. } else {
  473. //
  474. _LCSDB.user().create(alias, pass,
  475. (ack) => {
  476. if (!ack.wait) { }
  477. if (ack.err) {
  478. console.log(ack.err)
  479. return ack.err
  480. };
  481. if (ack.pub) {
  482. let users = _LCSDB.get('users');
  483. users.get(alias).put({
  484. 'alias': alias,
  485. 'pub': ack.pub
  486. });
  487. _LCSDB.user().auth(alias, pass);
  488. }
  489. });
  490. }
  491. }
  492. }),
  493. {
  494. $type: "span",
  495. $text: " "
  496. },
  497. window._app.widgets.buttonRaised(
  498. {
  499. "label": 'Sign IN',
  500. "onclick": function (e) {
  501. e.preventDefault();
  502. _LCSDB.user().auth(this._aliasField.value, this._passField.value, ack => {
  503. if (ack.err) {
  504. new Noty({
  505. text: ack.err,
  506. timeout: 2000,
  507. theme: 'mint',
  508. layout: 'bottomRight',
  509. type: 'error'
  510. }).show();
  511. }
  512. });
  513. }
  514. })
  515. ]
  516. }
  517. ]
  518. }
  519. ]
  520. }
  521. }
  522. // document.querySelector("#userLobby").$cell({
  523. // id: "userLobby",
  524. // $cell: true,
  525. // $type: "div",
  526. // $components: [
  527. // userGUI, loginGUI, _app.widgets.divider, worldGUI]
  528. // }
  529. // );
  530. return [userGUI, loginGUI, _app.widgets.divider, worldGUI]
  531. }
  532. refresh() {
  533. // socket.emit('getWebAppUpdate', "");
  534. }
  535. parseOnlineData(data) {
  536. let parcedData = _app.parseAppInstancesData(data);
  537. //if (Object.entries(parcedData).length !== 0)
  538. let onlineGUIs = document.querySelectorAll('.online');
  539. onlineGUIs.forEach(function (item) {
  540. item._refresh(parcedData)
  541. });
  542. }
  543. createWorldCard(id, type) {
  544. let self = this;
  545. let onlineGUI = {
  546. $cell: true,
  547. id: "onlineGUI_" + id,
  548. class: "online",
  549. $type: "div",
  550. _instances: {},
  551. _worldListItem: function (m) {
  552. return {
  553. $type: "li",
  554. class: "mdc-list-item",
  555. $components: [
  556. {
  557. $type: "span",
  558. class: "world-link mdc-list-item__text",
  559. $components: [
  560. {
  561. $type: "span",
  562. class: "mdc-list-item__primary-text",
  563. $components: [
  564. {
  565. $type: "a",
  566. $text: m[0],
  567. //target: "_blank",
  568. // href: window.location.protocol + "//" + window.location.host + "/" + m[1].user + m[0],
  569. onclick: function (e) {
  570. self.checkForManualSettings();
  571. window.location.pathname = "/" + m[1].user + m[0];
  572. //self.refresh();
  573. }
  574. },
  575. ]
  576. },
  577. {
  578. $type: "span",
  579. class: "mdc-list-item__secondary-text",
  580. $text: self.language.t('users') + m[1].clients
  581. }
  582. ]
  583. }
  584. ]
  585. }
  586. },
  587. $components: [],
  588. _refresh: function (data) {
  589. if (data) {
  590. if (Object.entries(data).length !== 0) {
  591. if (this._worldInfo) {
  592. let insts = Object.entries(data).filter(el => el[0] == this._worldInfo.worldName);
  593. if (insts.length !== 0)
  594. this._instances = insts[0][1];
  595. }
  596. } else {
  597. this._instances = {}
  598. }
  599. }
  600. },
  601. $init: function () {
  602. this._refresh();
  603. },
  604. $update: function () {
  605. if (this._instances) {
  606. let cardListData = Object.entries(this._instances).filter(el => el[1].user == this._worldInfo.userAlias);
  607. this.$components = [
  608. {
  609. $type: "hr",
  610. class: "mdc-list-divider"
  611. }
  612. ].concat(cardListData.map(this._worldListItem))
  613. }
  614. }
  615. }
  616. return {
  617. $cell: true,
  618. id: 'worldCard_' + id,
  619. $type: "div",
  620. _worldInfo: {},
  621. _refresh: function (data) {
  622. this._worldInfo = data
  623. },
  624. // _getWorldInfo: async function () {
  625. // //get space for user
  626. // let info = await _app.getWorldInfo(user, space);
  627. // this._refresh(info);
  628. // },
  629. // _getStateInfo: async function () {
  630. // //get space for user
  631. // let info = await _app.getStateInfo(user, space, saveName);
  632. // this._refresh(info);
  633. // },
  634. $init: function () {
  635. //get space for user
  636. // if (!saveName) {
  637. // this._getWorldInfo();
  638. // } else {
  639. // this._getStateInfo();
  640. // }
  641. },
  642. $update: function () {
  643. //console.log(this._worldInfo);
  644. this.$components = [this._updateCard()]
  645. },
  646. $components: [],
  647. _updateCard: function () {
  648. let desc = this._worldInfo;
  649. if (!desc || Object.keys(desc).length == 0) {
  650. return {
  651. $type: "h1",
  652. class: "mdc-typography--headline4",
  653. $text: "ERROR: NO WORLD!"
  654. }
  655. }
  656. let userGUI = [];
  657. let online = [];
  658. let cardInfo = {
  659. "title": ""
  660. };
  661. if (type == "full") {
  662. } else {
  663. userGUI.push({
  664. $type: "a",
  665. class: "mdc-button mdc-button--compact mdc-card__action mdc-button--outlined",
  666. $text: "Details",
  667. onclick: function (e) {
  668. e.preventDefault();
  669. window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName + '/about'
  670. }
  671. });
  672. }
  673. userGUI.push({
  674. $type: "a",
  675. class: "mdc-button mdc-button--raised mdc-card__action ",
  676. $text: self.language.t('start'),//"Start new",
  677. //target: "_blank",
  678. //href: "/" + desc.userAlias + '/' + desc.worldName,
  679. onclick: function (e) {
  680. self.checkForManualSettings();
  681. window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName
  682. //self.refresh();
  683. }
  684. });
  685. if (desc.type == 'saveState') {
  686. cardInfo.title = desc.worldName.split('/')[2];
  687. }
  688. if (desc.type == 'proto') {
  689. cardInfo.title = desc.worldName;
  690. // userGUI.push(
  691. // {
  692. // $type: "a",
  693. // class: "mdc-button mdc-button--compact mdc-card__action",
  694. // $text: "States",
  695. // onclick: async function (e) {
  696. // e.preventDefault();
  697. // window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName +'/about'
  698. // //console.log('clone');
  699. // // document.querySelector('#worldStatesGUI')._refresh({});
  700. // // let data = await _app.getSaveStates(desc.userAlias, desc.worldName);
  701. // // document.querySelector('#worldStatesGUI')._refresh(data);
  702. // }
  703. // }
  704. // )
  705. }
  706. online.push(onlineGUI);
  707. return {
  708. $cell: true,
  709. $type: "div",
  710. class: "mdc-card world-card",
  711. $components: [
  712. {
  713. $type: "section",
  714. class: "mdc-card__media world-card__16-9-media",
  715. $init: function () {
  716. if (desc.info.imgUrl !== "") {
  717. this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3) ), url(' + desc.info.imgUrl + ')';
  718. }
  719. }
  720. },
  721. {
  722. $type: "section",
  723. class: "mdc-card__primary",
  724. $components: [
  725. {
  726. $type: "h1",
  727. class: "mdc-card__title mdc-card__title--large",
  728. $text: desc.info.title
  729. },
  730. {
  731. $type: "h2",
  732. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  733. $text: desc.info.text
  734. },
  735. {
  736. $type: "span",
  737. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  738. $text: 'id: '
  739. },
  740. {
  741. $type: "input",
  742. type: "text",
  743. disabled: "",
  744. style: "font-size:18px",
  745. value: cardInfo.title
  746. },
  747. {
  748. $type: "p",
  749. },
  750. {
  751. $type: "span",
  752. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  753. $text: 'created: ' + (new Date(desc.created)).toUTCString()
  754. },
  755. {
  756. $type: "p",
  757. }
  758. // ,{
  759. // $type: "span",
  760. // class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  761. // $text: 'modified: ' + (new Date(desc[5])).toUTCString()
  762. // }
  763. ]
  764. },
  765. {
  766. $type: "section",
  767. class: "mdc-card__actions",
  768. $components: [
  769. ].concat(userGUI)
  770. },
  771. {
  772. $type: "section",
  773. class: "mdc-card__actions",
  774. $components: [
  775. {
  776. $type: 'div',
  777. $text: 'online now: '
  778. }
  779. ].concat(online)
  780. }
  781. ]
  782. }
  783. }
  784. }
  785. }
  786. createWorldsGUI(userAlias, worldName) {
  787. let self = this;
  788. let id = worldName ? worldName + '_' + userAlias : "allWorlds_" + userAlias
  789. let headerText = worldName ? 'States for ' + worldName : 'All Worlds Protos'
  790. let worldCards = {
  791. $cell: true,
  792. id: id,
  793. $type: "div",
  794. $components: [],
  795. _states: {},
  796. _refresh: function (data) {
  797. this._states = data
  798. },
  799. $init: async function () {
  800. //this._refresh();
  801. },
  802. _makeWorldCard: function (data) {
  803. let cardID = data[1].userAlias + '_' + data[1].worldName + '_' + data[0];
  804. let card = self.createWorldCard(cardID, 'min');
  805. card._worldInfo = data[1];
  806. card.$update();
  807. return {
  808. $cell: true,
  809. $type: "div",
  810. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  811. $components: [
  812. card
  813. //self.createWorldCard(data[1].userAlias, data[1].worldName, data[0])
  814. //this._worldCardDef(appInfo)
  815. ]
  816. }
  817. //console.log(data);
  818. },
  819. $update: function () {
  820. let cards = Object.entries(this._states)
  821. .filter(el => Object.keys(el[1]).length !== 0)
  822. .sort(function (el1, el2) {
  823. return parseInt(el2[1].created) - parseInt(el1[1].created)
  824. })
  825. .map(this._makeWorldCard);
  826. this.$components = [
  827. {
  828. $type: "div",
  829. class: "mdc-layout-grid",
  830. $components: [
  831. {
  832. $type: "div",
  833. class: "mdc-layout-grid__inner",
  834. $components: [
  835. {
  836. $type: "div",
  837. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  838. $components: [
  839. {
  840. $type: "H3",
  841. $text: headerText
  842. }
  843. ]
  844. }
  845. ]
  846. },
  847. {
  848. $type: "div",
  849. class: "mdc-layout-grid__inner",
  850. $components: cards
  851. }
  852. ]
  853. }
  854. ]
  855. }
  856. }
  857. return worldCards
  858. }
  859. checkForManualSettings() {
  860. console.log("check for manual settings");
  861. let manualSettings = localStorage.getItem('lcs_app_manual_settings');
  862. if(manualSettings){
  863. localStorage.removeItem('lcs_app_manual_settings');
  864. }
  865. let el = document.querySelector('#runWorldGUI');
  866. if (el) {
  867. if (el._settingsSwitch.checked){
  868. console.log("NEED TO LOAD MANUAL SETTINGS!!");
  869. let arSettings = {
  870. model:{
  871. 'vwf/model/aframe': null
  872. },
  873. view:{
  874. 'vwf/view/aframe' : null,
  875. 'vwf/view/aframe-arjs': null,
  876. 'vwf/view/editor-new': null
  877. }
  878. }
  879. localStorage.setItem('lcs_app_manual_settings', JSON.stringify(arSettings));
  880. }
  881. }
  882. }
  883. }
  884. export { IndexApp }
  885. //export {getAppDetails, generateFrontPage, setLanguage, initLocale};