index-app.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. // Copyright (c) 2018 Nikolai Suslov
  2. // Krestianstvo.org MIT license (https://github.com/NikolaySuslov/livecodingspace/blob/master/LICENSE.md)
  3. import page from '/lib/page.mjs';
  4. import { Header } from '/web/header.js';
  5. class IndexApp {
  6. constructor() {
  7. console.log("app constructor");
  8. this.worlds = {};
  9. this.language = _LangManager.language;
  10. this.options = {
  11. query: 'pathname=' + window.location.pathname.slice(1,
  12. window.location.pathname.lastIndexOf("/")),
  13. secure: window.location.protocol === "https:",
  14. reconnection: false,
  15. path: '',
  16. transports: ['websocket']
  17. }
  18. //window.location.host
  19. var socket = io.connect(window._app.reflectorHost, this.options);
  20. const parse = (msg) => {
  21. this.parseOnlineData(msg)
  22. }
  23. socket.on('getWebAppUpdate', msg => parse.call(this, msg));
  24. socket.on("connect", function () {
  25. let noty = new Noty({
  26. text: 'Connected to Reflector!',
  27. timeout: 2000,
  28. theme: 'mint',
  29. layout: 'bottomRight',
  30. type: 'success'
  31. });
  32. noty.show();
  33. })
  34. socket.on('connect_error', function (err) {
  35. console.log(err);
  36. var errDiv = document.createElement("div");
  37. errDiv.innerHTML = "<div class='vwf-err' style='z-index: 10; position: absolute; top: 80px; right: 50px'>Connection error to Reflector!" + err + "</div>";
  38. document.querySelector('body').appendChild(errDiv);
  39. let noty = new Noty({
  40. text: 'Connection error to Reflector! ' + err,
  41. theme: 'mint',
  42. layout: 'bottomRight',
  43. type: 'error'
  44. });
  45. noty.show();
  46. });
  47. }
  48. initHTML() {
  49. let self = this;
  50. //first init from _app
  51. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="/web/index-app.css">';
  52. let headerGUI = new Header();
  53. headerGUI.init();
  54. //add HTML
  55. let entry = document.createElement("div");
  56. entry.setAttribute("id", 'app');
  57. document.body.appendChild(entry);
  58. let divs = ['appGUI', 'userLobby', 'main', 'worldsGUI'];
  59. divs.forEach(el => {
  60. let appEl = document.createElement("div");
  61. appEl.setAttribute("id", el);
  62. entry.appendChild(appEl);
  63. })
  64. //init CELL
  65. document.querySelector("#userLobby").$cell({
  66. id: "userLobby",
  67. $cell: true,
  68. $type: "div",
  69. $components: [],
  70. $update: function () {
  71. this.$components = self.initUserGUI()
  72. }
  73. });
  74. document.querySelector("#worldsGUI").$cell({
  75. id: 'worldsGUI',
  76. $cell: true,
  77. $type: "div",
  78. $components: [],
  79. _comps: [],
  80. _refresh: async function (data, fn) {
  81. _app.showProgressBar();
  82. this._comps = await fn.call(self, data);
  83. this.$update();
  84. _app.hideProgressBar();
  85. },
  86. $update: async function () {
  87. this.$components = this._comps
  88. }
  89. });
  90. }
  91. async generateFrontPage() {
  92. let infoEl = document.createElement("div");
  93. infoEl.setAttribute("id", "indexPage");
  94. let lang = _LangManager.locale;
  95. let infoElHTML = await _app.helpers.getHtmlText('/web/locale/' + lang + '/index.html');
  96. infoEl.innerHTML = infoElHTML;
  97. document.body.appendChild(infoEl);
  98. document.querySelector('#ruLang').addEventListener('click', function (e) {
  99. _LangManager.locale = 'ru';
  100. window.location.reload(true);
  101. });
  102. document.querySelector('#enLang').addEventListener('click', function (e) {
  103. _LangManager.locale = 'en';
  104. window.location.reload(true);
  105. });
  106. }
  107. initApp() {
  108. // let appElHTML = await _app.helpers.getHtmlText('/web/app.html');
  109. // appEl.innerHTML = appElHTML;
  110. // document.body.appendChild(appEl);
  111. this.initUser();
  112. document.querySelector("#userLobby").$update();
  113. //this.initWorldsListGUI();
  114. //this.getAppDetailsFromDB();
  115. }
  116. async initWorldsProtosListForUser(userAlias) {
  117. document.querySelector("#worldsGUI").$components = [];
  118. await document.querySelector("#worldsGUI")._refresh(userAlias, this.getWorldsProtosListForUser);
  119. }
  120. async initWorldsStatesListForUser(userAlias) {
  121. document.querySelector("#worldsGUI").$components = [];
  122. await document.querySelector("#worldsGUI")._refresh(userAlias, this.getWorldsStatesListForUser);
  123. }
  124. async getWorldsStatesListForUser(userAlias) {
  125. let self = this;
  126. let worldsGUI = [];
  127. let worlds = self.createWorldsGUI(userAlias, 'allStates' );
  128. await _app.getAllStateWorldsInfoForUser(userAlias,
  129. 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.pub) {
  223. let alias = _LCSUSER.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. _LCSUSER.get('profile').once(function (data) { console.log(data) })
  231. let el = document.getElementById("loginGUI");
  232. if (el) {
  233. el.remove();
  234. }
  235. _LCSUSER.get('profile').not(function (key) {
  236. let profile = { 'alias': alias };
  237. _LCSUSER.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(_LCSUSER.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 (_LCSUSER.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 (_LCSUSER.is) {
  313. gui = [
  314. window._app.widgets.buttonRaised(
  315. {
  316. "label": 'Sign OUT',
  317. "onclick": function (e) {
  318. _LCSUSER.leave().then(ack => {
  319. if (ack.ok == 0) {
  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 = _LCSUSER.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 = _LCSUSER.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. _LCSUSER.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. _LCSUSER.auth(alias, pass);
  483. _LCSDB.get('users').get(alias).put({
  484. 'alias': alias,
  485. 'pub': ack.pub
  486. });
  487. }
  488. });
  489. }
  490. }
  491. }),
  492. {
  493. $type: "span",
  494. $text: " "
  495. },
  496. window._app.widgets.buttonRaised(
  497. {
  498. "label": 'Sign IN',
  499. "onclick": function (e) {
  500. e.preventDefault();
  501. _LCSUSER.auth(this._aliasField.value, this._passField.value, ack => {
  502. if (ack.err) {
  503. new Noty({
  504. text: ack.err,
  505. timeout: 2000,
  506. theme: 'mint',
  507. layout: 'bottomRight',
  508. type: 'error'
  509. }).show();
  510. }
  511. });
  512. }
  513. })
  514. ]
  515. }
  516. ]
  517. }
  518. ]
  519. }
  520. }
  521. // document.querySelector("#userLobby").$cell({
  522. // id: "userLobby",
  523. // $cell: true,
  524. // $type: "div",
  525. // $components: [
  526. // userGUI, loginGUI, _app.widgets.divider, worldGUI]
  527. // }
  528. // );
  529. return [userGUI, loginGUI, _app.widgets.divider, worldGUI]
  530. }
  531. refresh() {
  532. // socket.emit('getWebAppUpdate', "");
  533. }
  534. parseOnlineData(data) {
  535. let parcedData = _app.parseAppInstancesData(data);
  536. //if (Object.entries(parcedData).length !== 0)
  537. let onlineGUIs = document.querySelectorAll('.online');
  538. onlineGUIs.forEach(function (item) {
  539. item._refresh(parcedData)
  540. });
  541. }
  542. createWorldCard(id, type) {
  543. let self = this;
  544. let onlineGUI = {
  545. $cell: true,
  546. id: "onlineGUI_" + id,
  547. class: "online",
  548. $type: "div",
  549. _instances: {},
  550. _worldListItem: function (m) {
  551. return {
  552. $type: "li",
  553. class: "mdc-list-item",
  554. $components: [
  555. {
  556. $type: "span",
  557. class: "world-link mdc-list-item__text",
  558. $components: [
  559. {
  560. $type: "span",
  561. class: "mdc-list-item__primary-text",
  562. $components: [
  563. {
  564. $type: "a",
  565. $text: m[0],
  566. target: "_blank",
  567. href: window.location.protocol + "//" + window.location.host + "/" + m[1].user + m[0],
  568. onclick: function (e) {
  569. //self.refresh();
  570. }
  571. },
  572. ]
  573. },
  574. {
  575. $type: "span",
  576. class: "mdc-list-item__secondary-text",
  577. $text: self.language.t('users') + m[1].clients
  578. }
  579. ]
  580. }
  581. ]
  582. }
  583. },
  584. $components: [],
  585. _refresh: function (data) {
  586. if (data) {
  587. if (Object.entries(data).length !== 0) {
  588. if (this._worldInfo) {
  589. let insts = Object.entries(data).filter(el => el[0] == this._worldInfo.worldName);
  590. if (insts.length !== 0)
  591. this._instances = insts[0][1];
  592. }
  593. } else {
  594. this._instances = {}
  595. }
  596. }
  597. },
  598. $init: function () {
  599. this._refresh();
  600. },
  601. $update: function () {
  602. if (this._instances) {
  603. let cardListData = Object.entries(this._instances).filter(el => el[1].user == this._worldInfo.userAlias);
  604. this.$components = [
  605. {
  606. $type: "hr",
  607. class: "mdc-list-divider"
  608. }
  609. ].concat(cardListData.map(this._worldListItem))
  610. }
  611. }
  612. }
  613. return {
  614. $cell: true,
  615. id: 'worldCard_' + id,
  616. $type: "div",
  617. _worldInfo: {},
  618. _refresh: function (data) {
  619. this._worldInfo = data
  620. },
  621. // _getWorldInfo: async function () {
  622. // //get space for user
  623. // let info = await _app.getWorldInfo(user, space);
  624. // this._refresh(info);
  625. // },
  626. // _getStateInfo: async function () {
  627. // //get space for user
  628. // let info = await _app.getStateInfo(user, space, saveName);
  629. // this._refresh(info);
  630. // },
  631. $init: function () {
  632. //get space for user
  633. // if (!saveName) {
  634. // this._getWorldInfo();
  635. // } else {
  636. // this._getStateInfo();
  637. // }
  638. },
  639. $update: function () {
  640. //console.log(this._worldInfo);
  641. this.$components = [this._updateCard()]
  642. },
  643. $components: [],
  644. _updateCard: function () {
  645. let desc = this._worldInfo;
  646. if (!desc || Object.keys(desc).length == 0) {
  647. return {
  648. $type: "h1",
  649. class: "mdc-typography--headline4",
  650. $text: "ERROR: NO WORLD!"
  651. }
  652. }
  653. let userGUI = [];
  654. let online = [];
  655. let cardInfo = {
  656. "title": ""
  657. };
  658. if (type == "full") {
  659. } else {
  660. userGUI.push({
  661. $type: "a",
  662. class: "mdc-button mdc-button--compact mdc-card__action mdc-button--outlined",
  663. $text: "Details",
  664. onclick: function (e) {
  665. e.preventDefault();
  666. window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName + '/about'
  667. }
  668. });
  669. }
  670. userGUI.push({
  671. $type: "a",
  672. class: "mdc-button mdc-button--raised mdc-card__action ",
  673. $text: self.language.t('start'),//"Start new",
  674. target: "_blank",
  675. href: "/" + desc.userAlias + '/' + desc.worldName,
  676. onclick: function (e) {
  677. //self.refresh();
  678. }
  679. });
  680. if (desc.type == 'saveState') {
  681. cardInfo.title = desc.worldName.split('/')[2];
  682. }
  683. if (desc.type == 'proto') {
  684. cardInfo.title = desc.worldName;
  685. // userGUI.push(
  686. // {
  687. // $type: "a",
  688. // class: "mdc-button mdc-button--compact mdc-card__action",
  689. // $text: "States",
  690. // onclick: async function (e) {
  691. // e.preventDefault();
  692. // window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName +'/about'
  693. // //console.log('clone');
  694. // // document.querySelector('#worldStatesGUI')._refresh({});
  695. // // let data = await _app.getSaveStates(desc.userAlias, desc.worldName);
  696. // // document.querySelector('#worldStatesGUI')._refresh(data);
  697. // }
  698. // }
  699. // )
  700. }
  701. online.push(onlineGUI);
  702. return {
  703. $cell: true,
  704. $type: "div",
  705. class: "mdc-card world-card",
  706. $components: [
  707. {
  708. $type: "section",
  709. class: "mdc-card__media world-card__16-9-media",
  710. $init: function () {
  711. if (desc.info.imgUrl !== "") {
  712. this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3) ), url(' + desc.info.imgUrl + ')';
  713. }
  714. }
  715. },
  716. {
  717. $type: "section",
  718. class: "mdc-card__primary",
  719. $components: [
  720. {
  721. $type: "h1",
  722. class: "mdc-card__title mdc-card__title--large",
  723. $text: desc.info.title
  724. },
  725. {
  726. $type: "h2",
  727. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  728. $text: desc.info.text
  729. },
  730. {
  731. $type: "span",
  732. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  733. $text: 'id: '
  734. },
  735. {
  736. $type: "input",
  737. type: "text",
  738. disabled: "",
  739. style: "font-size:18px",
  740. value: cardInfo.title
  741. },
  742. {
  743. $type: "p",
  744. },
  745. {
  746. $type: "span",
  747. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  748. $text: 'created: ' + (new Date(desc.created)).toUTCString()
  749. },
  750. {
  751. $type: "p",
  752. }
  753. // ,{
  754. // $type: "span",
  755. // class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  756. // $text: 'modified: ' + (new Date(desc[5])).toUTCString()
  757. // }
  758. ]
  759. },
  760. {
  761. $type: "section",
  762. class: "mdc-card__actions",
  763. $components: [
  764. ].concat(userGUI)
  765. },
  766. {
  767. $type: "section",
  768. class: "mdc-card__actions",
  769. $components: [
  770. {
  771. $type: 'div',
  772. $text: 'online now: '
  773. }
  774. ].concat(online)
  775. }
  776. ]
  777. }
  778. }
  779. }
  780. }
  781. createWorldsGUI(userAlias, worldName) {
  782. let self = this;
  783. let id = worldName ? worldName + '_' + userAlias : "allWorlds_" + userAlias
  784. let headerText = worldName ? 'States for ' + worldName : 'All Worlds Protos'
  785. let worldCards = {
  786. $cell: true,
  787. id: id,
  788. $type: "div",
  789. $components: [],
  790. _states: {},
  791. _refresh: function (data) {
  792. this._states = data
  793. },
  794. $init: async function () {
  795. //this._refresh();
  796. },
  797. _makeWorldCard: function (data) {
  798. let cardID = data[1].userAlias + '_' + data[1].worldName + '_' + data[0];
  799. let card = self.createWorldCard(cardID, 'min');
  800. card._worldInfo = data[1];
  801. card.$update();
  802. return {
  803. $cell: true,
  804. $type: "div",
  805. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  806. $components: [
  807. card
  808. //self.createWorldCard(data[1].userAlias, data[1].worldName, data[0])
  809. //this._worldCardDef(appInfo)
  810. ]
  811. }
  812. //console.log(data);
  813. },
  814. $update: function () {
  815. this.$components = [
  816. {
  817. $type: "div",
  818. class: "mdc-layout-grid",
  819. $components: [
  820. {
  821. $type: "div",
  822. class: "mdc-layout-grid__inner",
  823. $components: [
  824. {
  825. $type: "div",
  826. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  827. $components: [
  828. {
  829. $type: "H3",
  830. $text: headerText
  831. }
  832. ]
  833. }
  834. ]
  835. },
  836. {
  837. $type: "div",
  838. class: "mdc-layout-grid__inner",
  839. $components: Object.entries(this._states)
  840. .filter(el => Object.keys(el[1]).length !== 0)
  841. .sort(function (el1, el2) {
  842. return parseInt(el2[1].created) - parseInt(el1[1].created)
  843. })
  844. .map(this._makeWorldCard)
  845. }
  846. ]
  847. }
  848. ]
  849. }
  850. }
  851. return worldCards
  852. }
  853. }
  854. export { IndexApp }
  855. //export {getAppDetails, generateFrontPage, setLanguage, initLocale};