index-app.js 36 KB

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