index-app.js 36 KB

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