index-app.js 36 KB

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