index-app.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  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.refresh();
  571. }
  572. },
  573. ]
  574. },
  575. {
  576. $type: "span",
  577. class: "mdc-list-item__secondary-text",
  578. $text: self.language.t('users') + m[1].clients
  579. }
  580. ]
  581. }
  582. ]
  583. }
  584. },
  585. $components: [],
  586. _refresh: function (data) {
  587. if (data) {
  588. if (Object.entries(data).length !== 0) {
  589. if (this._worldInfo) {
  590. let insts = Object.entries(data).filter(el => el[0] == this._worldInfo.worldName);
  591. if (insts.length !== 0)
  592. this._instances = insts[0][1];
  593. }
  594. } else {
  595. this._instances = {}
  596. }
  597. }
  598. },
  599. $init: function () {
  600. this._refresh();
  601. },
  602. $update: function () {
  603. if (this._instances) {
  604. let cardListData = Object.entries(this._instances).filter(el => el[1].user == this._worldInfo.userAlias);
  605. this.$components = [
  606. {
  607. $type: "hr",
  608. class: "mdc-list-divider"
  609. }
  610. ].concat(cardListData.map(this._worldListItem))
  611. }
  612. }
  613. }
  614. return {
  615. $cell: true,
  616. id: 'worldCard_' + id,
  617. $type: "div",
  618. _worldInfo: {},
  619. _refresh: function (data) {
  620. this._worldInfo = data
  621. },
  622. // _getWorldInfo: async function () {
  623. // //get space for user
  624. // let info = await _app.getWorldInfo(user, space);
  625. // this._refresh(info);
  626. // },
  627. // _getStateInfo: async function () {
  628. // //get space for user
  629. // let info = await _app.getStateInfo(user, space, saveName);
  630. // this._refresh(info);
  631. // },
  632. $init: function () {
  633. //get space for user
  634. // if (!saveName) {
  635. // this._getWorldInfo();
  636. // } else {
  637. // this._getStateInfo();
  638. // }
  639. },
  640. $update: function () {
  641. //console.log(this._worldInfo);
  642. this.$components = [this._updateCard()]
  643. },
  644. $components: [],
  645. _updateCard: function () {
  646. let desc = this._worldInfo;
  647. if (!desc || Object.keys(desc).length == 0) {
  648. return {
  649. $type: "h1",
  650. class: "mdc-typography--headline4",
  651. $text: "ERROR: NO WORLD!"
  652. }
  653. }
  654. let userGUI = [];
  655. let online = [];
  656. let cardInfo = {
  657. "title": ""
  658. };
  659. if (type == "full") {
  660. } else {
  661. userGUI.push({
  662. $type: "a",
  663. class: "mdc-button mdc-button--compact mdc-card__action mdc-button--outlined",
  664. $text: "Details",
  665. onclick: function (e) {
  666. e.preventDefault();
  667. window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName + '/about'
  668. }
  669. });
  670. }
  671. userGUI.push({
  672. $type: "a",
  673. class: "mdc-button mdc-button--raised mdc-card__action ",
  674. $text: self.language.t('start'),//"Start new",
  675. target: "_blank",
  676. href: "/" + desc.userAlias + '/' + desc.worldName,
  677. onclick: function (e) {
  678. //self.refresh();
  679. }
  680. });
  681. if (desc.type == 'saveState') {
  682. cardInfo.title = desc.worldName.split('/')[2];
  683. }
  684. if (desc.type == 'proto') {
  685. cardInfo.title = desc.worldName;
  686. // userGUI.push(
  687. // {
  688. // $type: "a",
  689. // class: "mdc-button mdc-button--compact mdc-card__action",
  690. // $text: "States",
  691. // onclick: async function (e) {
  692. // e.preventDefault();
  693. // window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName +'/about'
  694. // //console.log('clone');
  695. // // document.querySelector('#worldStatesGUI')._refresh({});
  696. // // let data = await _app.getSaveStates(desc.userAlias, desc.worldName);
  697. // // document.querySelector('#worldStatesGUI')._refresh(data);
  698. // }
  699. // }
  700. // )
  701. }
  702. online.push(onlineGUI);
  703. return {
  704. $cell: true,
  705. $type: "div",
  706. class: "mdc-card world-card",
  707. $components: [
  708. {
  709. $type: "section",
  710. class: "mdc-card__media world-card__16-9-media",
  711. $init: function () {
  712. if (desc.info.imgUrl !== "") {
  713. this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3) ), url(' + desc.info.imgUrl + ')';
  714. }
  715. }
  716. },
  717. {
  718. $type: "section",
  719. class: "mdc-card__primary",
  720. $components: [
  721. {
  722. $type: "h1",
  723. class: "mdc-card__title mdc-card__title--large",
  724. $text: desc.info.title
  725. },
  726. {
  727. $type: "h2",
  728. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  729. $text: desc.info.text
  730. },
  731. {
  732. $type: "span",
  733. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  734. $text: 'id: '
  735. },
  736. {
  737. $type: "input",
  738. type: "text",
  739. disabled: "",
  740. style: "font-size:18px",
  741. value: cardInfo.title
  742. },
  743. {
  744. $type: "p",
  745. },
  746. {
  747. $type: "span",
  748. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  749. $text: 'created: ' + (new Date(desc.created)).toUTCString()
  750. },
  751. {
  752. $type: "p",
  753. }
  754. // ,{
  755. // $type: "span",
  756. // class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  757. // $text: 'modified: ' + (new Date(desc[5])).toUTCString()
  758. // }
  759. ]
  760. },
  761. {
  762. $type: "section",
  763. class: "mdc-card__actions",
  764. $components: [
  765. ].concat(userGUI)
  766. },
  767. {
  768. $type: "section",
  769. class: "mdc-card__actions",
  770. $components: [
  771. {
  772. $type: 'div',
  773. $text: 'online now: '
  774. }
  775. ].concat(online)
  776. }
  777. ]
  778. }
  779. }
  780. }
  781. }
  782. createWorldsGUI(userAlias, worldName) {
  783. let self = this;
  784. let id = worldName ? worldName + '_' + userAlias : "allWorlds_" + userAlias
  785. let headerText = worldName ? 'States for ' + worldName : 'All Worlds Protos'
  786. let worldCards = {
  787. $cell: true,
  788. id: id,
  789. $type: "div",
  790. $components: [],
  791. _states: {},
  792. _refresh: function (data) {
  793. this._states = data
  794. },
  795. $init: async function () {
  796. //this._refresh();
  797. },
  798. _makeWorldCard: function (data) {
  799. let cardID = data[1].userAlias + '_' + data[1].worldName + '_' + data[0];
  800. let card = self.createWorldCard(cardID, 'min');
  801. card._worldInfo = data[1];
  802. card.$update();
  803. return {
  804. $cell: true,
  805. $type: "div",
  806. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  807. $components: [
  808. card
  809. //self.createWorldCard(data[1].userAlias, data[1].worldName, data[0])
  810. //this._worldCardDef(appInfo)
  811. ]
  812. }
  813. //console.log(data);
  814. },
  815. $update: function () {
  816. let cards = Object.entries(this._states)
  817. .filter(el => Object.keys(el[1]).length !== 0)
  818. .sort(function (el1, el2) {
  819. return parseInt(el2[1].created) - parseInt(el1[1].created)
  820. })
  821. .map(this._makeWorldCard);
  822. this.$components = [
  823. {
  824. $type: "div",
  825. class: "mdc-layout-grid",
  826. $components: [
  827. {
  828. $type: "div",
  829. class: "mdc-layout-grid__inner",
  830. $components: [
  831. {
  832. $type: "div",
  833. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  834. $components: [
  835. {
  836. $type: "H3",
  837. $text: headerText
  838. }
  839. ]
  840. }
  841. ]
  842. },
  843. {
  844. $type: "div",
  845. class: "mdc-layout-grid__inner",
  846. $components: cards
  847. }
  848. ]
  849. }
  850. ]
  851. }
  852. }
  853. return worldCards
  854. }
  855. }
  856. export { IndexApp }
  857. //export {getAppDetails, generateFrontPage, setLanguage, initLocale};