index-app.js 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664
  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. let headerGUI = new Header();
  62. headerGUI.init();
  63. //add HTML
  64. let entry = document.createElement("div");
  65. entry.setAttribute("id", 'app');
  66. document.body.appendChild(entry);
  67. let divs = ['appGUI', 'userLobby', 'main', 'worldsGUI', 'lab'];
  68. divs.forEach(el => {
  69. let appEl = document.createElement("div");
  70. appEl.setAttribute("id", el);
  71. entry.appendChild(appEl);
  72. })
  73. document.querySelector("#worldsGUI").$cell({
  74. id: "worldsGUI",
  75. $cell: true,
  76. $type: "div",
  77. _comps: [],
  78. _wcards: {},
  79. $components: [],
  80. _refresh: function (comps) {
  81. //do update;
  82. //this._userAlias = user;
  83. this._comps = comps;
  84. this.$components = this._comps;
  85. },
  86. $init: function () {
  87. console.log('init comp...');
  88. },
  89. $update: function () {
  90. //do update;
  91. console.log('update me');
  92. }
  93. });
  94. //init CELL
  95. let userGUI = {
  96. $type: "div",
  97. id: "userGUI",
  98. // style:"background-color: #ffeb3b",
  99. class: "mdc-layout-grid mdc-layout-grid--align-left",
  100. _status: "Welcome!",
  101. $init: function () {
  102. //this._status = "Welcome!"
  103. //this._status = 'Welcome!';
  104. //userEl.style.backgroundColor = '#e6e6e6';
  105. self.initUser();
  106. this._refresh(); //$update();
  107. },
  108. $update: function () {},
  109. _refresh: function () {
  110. var gui = {};
  111. if (_LCSDB.user().is) {
  112. gui = [
  113. window._app.widgets.buttonRaised(
  114. {
  115. "label": 'Sign OUT',
  116. "onclick": function (e) {
  117. _LCSDB.user().leave();
  118. setTimeout(() => {
  119. //window.sessionStorage.removeItem('alias');
  120. //window.sessionStorage.removeItem('tmp');
  121. window.location.reload(true);
  122. }, 1);
  123. }
  124. }),
  125. {
  126. $type: "p"
  127. },
  128. window._app.widgets.buttonStroked(
  129. {
  130. "label": 'PROFILE',
  131. "onclick": function (e) {
  132. e.preventDefault();
  133. //page("/profile")
  134. window.location.pathname = "/profile"
  135. }
  136. }),
  137. {
  138. $type: "p"
  139. },
  140. window._app.widgets.buttonStroked(
  141. {
  142. "label": 'My World protos',
  143. "onclick": function (e) {
  144. e.preventDefault();
  145. let alias = _LCSDB.user().is.alias;
  146. window.location.pathname = '/' + alias + '/worlds/protos'
  147. //page('/' + alias + '/worlds/protos');
  148. //_app.indexApp.getWorldsProtosFromUserDB(alias);
  149. }
  150. }),
  151. window._app.widgets.buttonStroked(
  152. {
  153. "label": 'My World states',
  154. "onclick": function (e) {
  155. e.preventDefault();
  156. let alias = _LCSDB.user().is.alias;
  157. window.location.pathname = '/' + alias + '/worlds/states'
  158. //page('/' + alias + '/worlds/states');
  159. // page.redirect('/' + alias + '/worlds/states');
  160. //_app.indexApp.getWorldsFromUserDB(alias);
  161. }
  162. })
  163. ]
  164. }
  165. this.$components = [
  166. {
  167. $type: "h1",
  168. class: "mdc-typography--headline3",
  169. $text: this._status
  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, self.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 allWorldsProtosForUser(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: 'Worlds for user: ' + 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. async allWorldsStatesForUser(userAlias, worldName, elID) {
  238. let userPub = await _app.helpers.getUserPub(userAlias);
  239. //let db = _LCSDB.user(userPub);
  240. let doc = elID ? document.querySelector("#" + elID): document.querySelector("#worldsGUI");
  241. var worlds = {};
  242. if(userPub) {
  243. if(!worldName){
  244. worlds = this.createWorldsGUI('state', userAlias, userPub)
  245. } else {
  246. worlds = this.createWorldsGUI('state', userAlias, userPub, worldName)
  247. }
  248. } else {
  249. worlds = {
  250. $type: 'div',
  251. $text: 'Could not find user with name: ' + userAlias,
  252. class: "mdc-typography--headline4"
  253. }
  254. }
  255. let components = [
  256. {
  257. $type: "div",
  258. class: "mdc-layout-grid",
  259. $components: [
  260. {
  261. $type: "div",
  262. class: "mdc-layout-grid__inner",
  263. $components: [
  264. {
  265. $type: "div",
  266. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  267. $components: [
  268. {
  269. $type: "h1",
  270. class: "mdc-typography--headline4",
  271. $text: 'States for ' + userAlias
  272. }
  273. ]
  274. },
  275. {
  276. $type: "div",
  277. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  278. $components: [].concat(worlds)
  279. }
  280. ]
  281. }
  282. ]
  283. }
  284. ]
  285. doc._refresh(components);
  286. }
  287. authGUI(){
  288. let alias = _LCSDB.user().is.alias;
  289. let userEl = document.querySelector('#userGUI');
  290. userEl._status = 'Welcome ' + alias + '!';
  291. //userEl.style.backgroundColor = '#e6e6e6';
  292. userEl._refresh(); //$update();
  293. //_LCSDB.user().get('profile').once(function (data) { console.log(data) })
  294. let el = document.getElementById("loginGUI");
  295. if (el) {
  296. el.remove();
  297. }
  298. _LCSDB.user().get('profile').not(function (key) {
  299. let profile = { 'alias': alias };
  300. _LCSDB.user().get('profile').put(profile);
  301. })
  302. // not load proxy by default
  303. // _LCSDB.user().get('proxy').not(res=>{
  304. // console.log('user has no proxy');
  305. // window._app.loadProxyDefaults();
  306. // });
  307. let actionsGUI = document.querySelector('#worldActionsGUI');
  308. if (actionsGUI)
  309. actionsGUI._refresh();
  310. new Noty({
  311. text: alias + ' is succesfully authenticated!',
  312. timeout: 2000,
  313. theme: 'mint',
  314. layout: 'bottomRight',
  315. type: 'success'
  316. }).show();
  317. if(this.entry == 'index'){
  318. //change for LiveCoding.space to 'app'
  319. //this.initWorldsProtosListForUserNew(alias);
  320. this.allWorldsProtosForUser(alias)
  321. }
  322. }
  323. initUser() {
  324. let self = this;
  325. if(_LCSDB.user().is) {
  326. self.authGUI()
  327. } else {
  328. _LCSDB.on('auth', function (ack) {
  329. if (ack.sea.pub) {
  330. self.authGUI();
  331. }
  332. console.log(_LCSDB.user().is);
  333. });
  334. }
  335. }
  336. getLookWorlds(){
  337. let self = this;
  338. let lookWorlds =
  339. {
  340. $type: "div",
  341. id: "lookWorlds",
  342. class: "mdc-layout-grid mdc-layout-grid--align-left",
  343. _status: '',
  344. $init: function () {
  345. this._status = "init";
  346. },
  347. $update: function () {
  348. //change for LiveCoding.space site 'app'
  349. let defaultName = '';
  350. let guiForAll = [
  351. {
  352. $type: "div",
  353. style: "margin-top: 20px;",
  354. _userName: null,
  355. _userNameField: null,
  356. $components:
  357. [
  358. _app.widgets.inputTextFieldOutlined({
  359. "id": 'worldsUserName',
  360. "label": 'Enter user name',
  361. "value": defaultName,
  362. "type": "text",
  363. "init": function () {
  364. this._userNameField = new mdc.textField.MDCTextField(this);
  365. }
  366. }),
  367. _app.widgets.p,
  368. // {
  369. // $type: "a",
  370. // class: "mdc-button mdc-button--raised mdc-card__action actionButton",
  371. // $text: 'World Protos', //self.language.t('set proxy'),//"clone",
  372. // onclick: function (e) {
  373. // //console.log('clone');
  374. // let searchName = this._userNameField.value;
  375. // self.initWorldsProtosListForUser(searchName);
  376. // }
  377. // },
  378. // {
  379. // $type: "a",
  380. // class: "mdc-button mdc-button--raised mdc-card__action actionButton",
  381. // $text: 'World States', //self.language.t('set proxy'),//"clone",
  382. // onclick: function (e) {
  383. // //console.log('clone');
  384. // let searchName = this._userNameField.value;
  385. // self.initWorldsStatesListForUser(searchName);
  386. // }
  387. // }
  388. _app.widgets.buttonRaised(
  389. {
  390. "label": 'World Protos',
  391. "onclick": function (e) {
  392. e.preventDefault();
  393. //page("/app/worlds/protos")
  394. let searchName = this._userNameField.value;
  395. if(searchName !== "")
  396. window.location.pathname = "/"+searchName+"/worlds/protos"
  397. //_app.indexApp.getAppDetailsFromDefaultDB('protos');
  398. }
  399. }),
  400. _app.widgets.space,
  401. _app.widgets.buttonRaised(
  402. {
  403. "label": 'World States',
  404. "onclick": function (e) {
  405. e.preventDefault();
  406. //page("/app/worlds/states")
  407. let searchName = this._userNameField.value;
  408. if(searchName !== "")
  409. window.location.pathname = "/"+searchName+"/worlds/states"
  410. //_app.indexApp.getAppDetailsFromDefaultDB('states');
  411. }
  412. })
  413. ]
  414. },
  415. // window._app.widgets.buttonStroked(
  416. // {
  417. // "label": 'Default World Protos',
  418. // "onclick": function (e) {
  419. // e.preventDefault();
  420. // //page("/app/worlds/protos")
  421. // window.location.pathname = "/app/worlds/protos"
  422. // //_app.indexApp.getAppDetailsFromDefaultDB('protos');
  423. // }
  424. // }),
  425. // window._app.widgets.buttonStroked(
  426. // {
  427. // "label": 'Default World States',
  428. // "onclick": function (e) {
  429. // e.preventDefault();
  430. // //page("/app/worlds/states")
  431. // window.location.pathname = "/app/worlds/states"
  432. // //_app.indexApp.getAppDetailsFromDefaultDB('states');
  433. // }
  434. // })
  435. ];
  436. this.$components = [
  437. {
  438. $type: "h1",
  439. class: "mdc-typography--headline4",
  440. $text: "Looking for Worlds made by other Users!"
  441. }
  442. ].concat(guiForAll, _app.widgets.p, _app.widgets.divider)
  443. }
  444. }
  445. return lookWorlds
  446. }
  447. getLoginGUI(){
  448. let self = this;
  449. let loginGUI =
  450. {
  451. $type: "div",
  452. id: "loginGUI",
  453. //style:"background-color: #efefef",
  454. class: "mdc-layout-grid mdc-layout-grid--align-left",
  455. _alias: null,
  456. _pass: null,
  457. _passField: null,
  458. _aliasField: null,
  459. _initData: function () {
  460. this._alias = '';
  461. this._pass = '';
  462. // if (window.sessionStorage.getItem('alias')) {
  463. // this._alias = window.sessionStorage.getItem('alias')
  464. // }
  465. // if (window.sessionStorage.getItem('tmp')) {
  466. // this._pass = window.sessionStorage.getItem('tmp')
  467. // }
  468. },
  469. $init: function () {
  470. this._initData();
  471. },
  472. $update: function () {
  473. this.$components = [
  474. {
  475. $type: "div",
  476. class: "mdc-layout-grid__inner",
  477. $components: [
  478. {
  479. $type: "div",
  480. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  481. $components: [
  482. {
  483. $type: "span",
  484. class: "mdc-typography--headline5",
  485. $text: "Login: "
  486. },
  487. window._app.widgets.inputTextFieldOutlined({
  488. "id": 'aliasInput',
  489. "label": "Login",
  490. "value": this._alias,
  491. "type": "text",
  492. "init": function () {
  493. this._aliasField = new mdc.textField.MDCTextField(this);
  494. }
  495. }),
  496. ]
  497. },
  498. {
  499. $type: "div",
  500. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  501. $components: [
  502. {
  503. $type: "span",
  504. class: "mdc-typography--headline5",
  505. $text: "Password: "
  506. },
  507. window._app.widgets.inputTextFieldOutlined({
  508. "id": 'passwordInput',
  509. "label": "Password",
  510. "value": this._pass,
  511. "type": "password",
  512. "init": function () {
  513. this._passField = new mdc.textField.MDCTextField(this);
  514. }
  515. }),
  516. ]
  517. },
  518. {
  519. $type: "div",
  520. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  521. $components: [
  522. window._app.widgets.buttonRaised(
  523. {
  524. "label": 'Sign UP',
  525. "onclick": function (e) {
  526. e.preventDefault();
  527. let alias = this._aliasField.value;
  528. let pass = this._passField.value
  529. if (pass.length < 7) {
  530. new Noty({
  531. text: "Your passphrase needs to be longer than 7 letters",
  532. timeout: 2000,
  533. theme: 'mint',
  534. layout: 'bottomRight',
  535. type: 'error'
  536. }).show();
  537. } else {
  538. //
  539. _LCSDB.user().create(alias, pass,
  540. function (ack) {
  541. if (!ack.wait) { }
  542. if (ack.err) {
  543. console.log(ack.err)
  544. return ack.err
  545. };
  546. if (ack.pub) {
  547. let userObj = {
  548. 'alias': alias,
  549. 'pub': ack.pub
  550. };
  551. _LCSDB.get('users').get(alias).put(userObj);
  552. }
  553. _LCSDB.user().auth(alias, pass);
  554. });
  555. }
  556. }
  557. }),
  558. _app.widgets.space,
  559. window._app.widgets.buttonRaised(
  560. {
  561. "label": 'Sign IN',
  562. "onclick": function (e) {
  563. e.preventDefault();
  564. let alias = this._aliasField.value;
  565. let pass = this._passField.value
  566. _app.helpers.authUser(alias, pass);
  567. // _LCSDB.user().auth.call(_LCSDB, alias, pass
  568. // // , function(ack) {
  569. // // if (ack.err) {
  570. // // new Noty({
  571. // // text: ack.err,
  572. // // timeout: 2000,
  573. // // theme: 'mint',
  574. // // layout: 'bottomRight',
  575. // // type: 'error'
  576. // // }).show();
  577. // // }
  578. // //}
  579. // );
  580. }
  581. })
  582. ]
  583. }
  584. ]
  585. }
  586. ]
  587. }
  588. }
  589. return loginGUI
  590. }
  591. initUserGUI() {
  592. let self = this;
  593. let lookWorlds =
  594. {
  595. $type: "div",
  596. id: "lookWorlds",
  597. class: "mdc-layout-grid mdc-layout-grid--align-left",
  598. _status: '',
  599. $init: function () {
  600. this._status = "init";
  601. },
  602. $update: function () {
  603. //change for LiveCoding.space site 'app'
  604. let defaultName = '';
  605. let guiForAll = [
  606. {
  607. $type: "div",
  608. style: "margin-top: 20px;",
  609. _userName: null,
  610. _userNameField: null,
  611. $components:
  612. [
  613. _app.widgets.inputTextFieldOutlined({
  614. "id": 'worldsUserName',
  615. "label": 'Enter user name',
  616. "value": defaultName,
  617. "type": "text",
  618. "init": function () {
  619. this._userNameField = new mdc.textField.MDCTextField(this);
  620. }
  621. }),
  622. _app.widgets.p,
  623. // {
  624. // $type: "a",
  625. // class: "mdc-button mdc-button--raised mdc-card__action actionButton",
  626. // $text: 'World Protos', //self.language.t('set proxy'),//"clone",
  627. // onclick: function (e) {
  628. // //console.log('clone');
  629. // let searchName = this._userNameField.value;
  630. // self.initWorldsProtosListForUser(searchName);
  631. // }
  632. // },
  633. // {
  634. // $type: "a",
  635. // class: "mdc-button mdc-button--raised mdc-card__action actionButton",
  636. // $text: 'World States', //self.language.t('set proxy'),//"clone",
  637. // onclick: function (e) {
  638. // //console.log('clone');
  639. // let searchName = this._userNameField.value;
  640. // self.initWorldsStatesListForUser(searchName);
  641. // }
  642. // }
  643. _app.widgets.buttonRaised(
  644. {
  645. "label": 'World Protos',
  646. "onclick": function (e) {
  647. e.preventDefault();
  648. //page("/app/worlds/protos")
  649. let searchName = this._userNameField.value;
  650. if(searchName !== "")
  651. window.location.pathname = "/"+searchName+"/worlds/protos"
  652. //_app.indexApp.getAppDetailsFromDefaultDB('protos');
  653. }
  654. }),
  655. _app.widgets.space,
  656. _app.widgets.buttonRaised(
  657. {
  658. "label": 'World States',
  659. "onclick": function (e) {
  660. e.preventDefault();
  661. //page("/app/worlds/states")
  662. let searchName = this._userNameField.value;
  663. if(searchName !== "")
  664. window.location.pathname = "/"+searchName+"/worlds/states"
  665. //_app.indexApp.getAppDetailsFromDefaultDB('states');
  666. }
  667. })
  668. ]
  669. },
  670. // window._app.widgets.buttonStroked(
  671. // {
  672. // "label": 'Default World Protos',
  673. // "onclick": function (e) {
  674. // e.preventDefault();
  675. // //page("/app/worlds/protos")
  676. // window.location.pathname = "/app/worlds/protos"
  677. // //_app.indexApp.getAppDetailsFromDefaultDB('protos');
  678. // }
  679. // }),
  680. // window._app.widgets.buttonStroked(
  681. // {
  682. // "label": 'Default World States',
  683. // "onclick": function (e) {
  684. // e.preventDefault();
  685. // //page("/app/worlds/states")
  686. // window.location.pathname = "/app/worlds/states"
  687. // //_app.indexApp.getAppDetailsFromDefaultDB('states');
  688. // }
  689. // })
  690. ];
  691. this.$components = [
  692. {
  693. $type: "h1",
  694. class: "mdc-typography--headline4",
  695. $text: "Looking for Worlds made by other Users!"
  696. }
  697. ].concat(guiForAll, _app.widgets.p, _app.widgets.divider)
  698. }
  699. }
  700. let connectionSettings = {
  701. id: 'connectionSettings',
  702. $type: 'div',
  703. class: "mdc-layout-grid mdc-layout-grid--align-left",
  704. $components: [
  705. _app.widgets.emptyDiv,
  706. window._app.widgets.buttonRaised(
  707. {
  708. "label": 'Connection settings',
  709. "onclick": function (e) {
  710. e.preventDefault();
  711. window.location.pathname = '/settings';
  712. }
  713. }), _app.widgets.emptyDiv
  714. ]
  715. }
  716. let luminaryFeature = {
  717. $cell: true,
  718. $type: 'div',
  719. class: "mdc-layout-grid mdc-layout-grid--align-left",
  720. _luminarySwitch: null,
  721. $components: [
  722. {
  723. $type: "p",
  724. class: "mdc-typography--headline5",
  725. $text: "Use Krestianstvo Luminary (experimental)"
  726. },
  727. {
  728. $type: 'p'
  729. },
  730. _app.widgets.switch({
  731. 'id': 'forceLuminary',
  732. 'init': function () {
  733. this._switch = new mdc.switchControl.MDCSwitch(this);
  734. let config = localStorage.getItem('lcs_config');
  735. this._switch.checked = JSON.parse(config).luminary;
  736. // this._replaceSwitch = this._switch;
  737. },
  738. 'onchange': function (e) {
  739. if (this._switch) {
  740. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  741. if (chkAttr) {
  742. let config = JSON.parse(localStorage.getItem('lcs_config'));
  743. config.luminary = true;
  744. localStorage.setItem('lcs_config', JSON.stringify(config));
  745. window.location.reload(true);
  746. //this._switch.checked = false;
  747. } else {
  748. let config = JSON.parse(localStorage.getItem('lcs_config'));
  749. config.luminary = false;
  750. localStorage.setItem('lcs_config', JSON.stringify(config));
  751. window.location.reload(true);
  752. }
  753. }
  754. }
  755. }
  756. ),
  757. {
  758. $type: 'label',
  759. for: 'input-forceLuminary',
  760. $text: 'Off / On'
  761. }
  762. ]
  763. }
  764. return [luminaryFeature, connectionSettings, _app.widgets.divider]
  765. }
  766. refresh() {
  767. // socket.emit('getWebAppUpdate', "");
  768. }
  769. parseOnlineData(data) {
  770. let parcedData = _app.parseAppInstancesData(data);
  771. //if (Object.entries(parcedData).length !== 0)
  772. let onlineGUIs = document.querySelectorAll('.online');
  773. onlineGUIs.forEach(function (item) {
  774. item._refresh(parcedData)
  775. });
  776. }
  777. createWorldCard(worldType, userAlias, userPub, worldName, id, type, cb) {
  778. let self = this;
  779. let db = _LCSDB.user(userPub);
  780. let onlineGUI = {
  781. $cell: true,
  782. id: "onlineGUI_" + id,
  783. class: "online",
  784. $type: "div",
  785. _instances: {},
  786. _worldListItem: function (m) {
  787. return {
  788. $type: "li",
  789. class: "mdc-list-item",
  790. $components: [
  791. {
  792. $type: "span",
  793. class: "world-link mdc-list-item__text",
  794. $components: [
  795. {
  796. $type: "span",
  797. class: "mdc-list-item__primary-text",
  798. $components: [
  799. {
  800. $type: "a",
  801. $text: m[0],
  802. //target: "_blank",
  803. // href: window.location.protocol + "//" + window.location.host + "/" + m[1].user + m[0],
  804. onclick: function (e) {
  805. self.checkForManualSettings();
  806. window.location.pathname = "/" + m[1].user + m[0];
  807. //self.refresh();
  808. }
  809. },
  810. ]
  811. },
  812. {
  813. $type: "span",
  814. class: "mdc-list-item__secondary-text",
  815. $text: _app.isLuminary ? _LangManager.language.t('users') + Object.keys(m[1].clients).length : _LangManager.language.t('users') + m[1].clients
  816. }
  817. ]
  818. }
  819. ]
  820. }
  821. },
  822. $components: [],
  823. _refresh: function (data) {
  824. if (data) {
  825. if (Object.entries(data).length !== 0) {
  826. if (this._worldInfo) {
  827. let insts = Object.entries(data).filter(el => el[0] == this._worldInfo.worldName);
  828. if (insts.length !== 0)
  829. this._instances = insts[0][1];
  830. }
  831. } else {
  832. this._instances = {}
  833. }
  834. }
  835. },
  836. $init: function () {
  837. if (_app.isLuminary) {
  838. let luminaryPath = _app.luminaryPath;
  839. let ref = _LCSDB.get(luminaryPath);
  840. setInterval(function () {
  841. ref.get('allclients').once().map().once(res => {
  842. if (res) {
  843. if (res.id) {
  844. let clientTime = Gun.state.is(res, 'live');
  845. let now = Gun.time.is();
  846. if (now - clientTime < 10000) {
  847. let instance = res.user + res.instance;
  848. //let data = JSON.stringify({[res.instance]: {instance: instance, clients: {}, user: res.user, loadInfo: {}}});
  849. //console.log(data);
  850. if (!self.instances[res.instance]) {
  851. self.instances[res.instance] = { id: res.instance, instance: instance, clients: { [res.id]: res }, user: res.user, loadInfo: {} }
  852. } else {
  853. self.instances[res.instance].clients[res.id] = res
  854. }
  855. let data = JSON.stringify(self.instances);
  856. self.parseOnlineData(data);
  857. } else {
  858. if (self.instances[res.instance]) {
  859. delete self.instances[res.instance].clients[res.id];
  860. if (Object.keys(self.instances[res.instance].clients).length == 0) {
  861. delete self.instances[res.instance];
  862. self.parseOnlineData(JSON.stringify({}));
  863. }
  864. }
  865. //ref.get('instances').get(res.instance).get(res.id).put(null);
  866. }
  867. }
  868. }
  869. }
  870. )
  871. }, 5000);
  872. }
  873. this._refresh();
  874. },
  875. $update: function () {
  876. if (this._instances) {
  877. let cardListData = Object.entries(this._instances).filter(el => el[1].user == this._worldInfo.userAlias);
  878. this.$components = [
  879. {
  880. $type: "hr",
  881. class: "mdc-list-divider"
  882. }
  883. ].concat(cardListData.map(this._worldListItem))
  884. }
  885. }
  886. }
  887. return {
  888. $cell: true,
  889. id: 'worldCard_' + id,
  890. $type: "div",
  891. _worldName: "",
  892. _worldInfo: {},
  893. _refresh: function (data) {
  894. this._worldInfo = data;
  895. this.$components = [this._updateCard()]
  896. },
  897. $init: function () {
  898. this._worldName = worldName;
  899. if(type == 'min') {
  900. if(worldType == 'proto') {
  901. db.get('worlds').get(this._worldName).path('info_json').on((res)=>{
  902. console.log(res);
  903. let worldDesc = JSON.parse(res);
  904. let root = Object.keys(worldDesc)[0];
  905. var appInfo = worldDesc[root]['en'];
  906. let langID = localStorage.getItem('krestianstvo_locale');
  907. if (langID) {
  908. appInfo = worldDesc[root][langID]
  909. }
  910. let doc = {
  911. 'worldName': this._worldName,
  912. 'created': undefined,
  913. 'modified': undefined,
  914. 'type': 'proto',
  915. 'userAlias': userAlias,
  916. 'info': appInfo
  917. }
  918. this._refresh(doc);
  919. //callback
  920. if(cb)
  921. cb(doc);
  922. })
  923. } else if (worldType == 'state'){
  924. let pathName = 'savestate_/' + this._worldName.protoName+ '/' + this._worldName.stateName + '_info_vwf_json';
  925. db.get('documents').get(this._worldName.protoName).path(pathName).on((res)=>{
  926. console.log(res);
  927. let worldDesc = JSON.parse(res);
  928. let root = Object.keys(worldDesc)[0];
  929. var appInfo = worldDesc[root]['en'];
  930. let langID = localStorage.getItem('krestianstvo_locale');
  931. if (langID) {
  932. appInfo = worldDesc[root][langID]
  933. }
  934. let doc = {
  935. 'worldName': this._worldName.protoName + '/load/' + this._worldName.stateName,
  936. 'created': undefined,
  937. 'modified': undefined,
  938. 'type': 'saveState',
  939. 'userAlias': userAlias,
  940. 'info': appInfo
  941. }
  942. this._refresh(doc);
  943. //callback
  944. if(cb)
  945. cb(doc);
  946. })
  947. }
  948. } else if (type == 'full'){
  949. if(worldType == 'proto') {
  950. db.get('worlds').get(this._worldName).on((res)=>{
  951. console.log(res);
  952. let worldDesc = JSON.parse(res['info_json']);
  953. let root = Object.keys(worldDesc)[0];
  954. var appInfo = worldDesc[root]['en'];
  955. let langID = localStorage.getItem('krestianstvo_locale');
  956. if (langID) {
  957. appInfo = worldDesc[root][langID]
  958. }
  959. let settings = worldDesc[root]['settings'];
  960. let doc = {
  961. 'worldName': this._worldName,
  962. 'created': res.created ? res.created : "",
  963. 'modified': res.modified ? res.modified : "",
  964. 'proxy': res.proxy,
  965. 'type': 'proto',
  966. 'userAlias': userAlias,
  967. 'info': appInfo,
  968. 'settings': settings
  969. }
  970. this._refresh(doc);
  971. //callback
  972. if(cb)
  973. cb(doc);
  974. })
  975. } else if (worldType == 'state') {
  976. let pathNameInfo = 'savestate_/' + this._worldName.protoName+ '/' + this._worldName.stateName + '_info_vwf_json';
  977. db.get('documents').get(this._worldName.protoName).path(pathNameInfo).on((res)=>{
  978. console.log(res);
  979. let worldDesc = JSON.parse(res);
  980. let root = Object.keys(worldDesc)[0];
  981. var appInfo = worldDesc[root]['en'];
  982. let langID = localStorage.getItem('krestianstvo_locale');
  983. if (langID) {
  984. appInfo = worldDesc[root][langID]
  985. }
  986. let settings = worldDesc[root]['settings'];
  987. let doc = {
  988. 'worldName': this._worldName.protoName + '/load/' + this._worldName.stateName,
  989. 'created': undefined,
  990. 'modified': undefined,
  991. 'type': 'saveState',
  992. 'userAlias': userAlias,
  993. 'info': appInfo,
  994. 'settings': settings
  995. }
  996. this._refresh(doc);
  997. //callback
  998. if(cb)
  999. cb(doc);
  1000. })
  1001. // let pathNameState = 'savestate_/' + this._worldName.protoName+ '/' + this._worldName.stateName + '_vwf_json';
  1002. // db.get('documents').get(this._worldName.protoName).path(pathNameState).on((res)=>{
  1003. // console.log(res);
  1004. // // let worldDesc = JSON.parse(res);
  1005. // // let root = Object.keys(worldDesc)[0];
  1006. // // var appInfo = worldDesc[root]['en'];
  1007. // // let langID = localStorage.getItem('krestianstvo_locale');
  1008. // // if (langID) {
  1009. // // appInfo = worldDesc[root][langID]
  1010. // // }
  1011. // let settings = worldDesc[root]['settings'];
  1012. // let doc = {
  1013. // 'worldName': this._worldName.protoName + '/load/' + this._worldName.stateName,
  1014. // 'created': res.created,
  1015. // 'modified': res.modified,
  1016. // 'type': 'saveState',
  1017. // 'userAlias': userAlias,
  1018. // 'info': appInfo,
  1019. // 'settings': settings
  1020. // }
  1021. // this._refresh(doc);
  1022. // //callback
  1023. // if(cb)
  1024. // cb(doc);
  1025. // })
  1026. }
  1027. }
  1028. },
  1029. $update: function () {
  1030. //this.$components = [this._updateCard()]
  1031. },
  1032. _updateComps: function () {
  1033. //console.log(this._worldInfo);
  1034. },
  1035. _updateCard: function () {
  1036. let desc = this._worldInfo;
  1037. if (!desc || Object.keys(desc).length == 0) {
  1038. return {
  1039. $type: "h1",
  1040. class: "mdc-typography--headline4",
  1041. $text: "ERROR: NO WORLD!"
  1042. }
  1043. }
  1044. let userGUI = [];
  1045. let online = [];
  1046. let cardInfo = {
  1047. "title": ""
  1048. };
  1049. if (type == "full") {
  1050. } else {
  1051. userGUI.push({
  1052. $type: "a",
  1053. class: "mdc-button mdc-button--compact mdc-card__action mdc-button--outlined",
  1054. $text: "Details",
  1055. onclick: function (e) {
  1056. e.preventDefault();
  1057. window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName + '/about'
  1058. }
  1059. });
  1060. }
  1061. userGUI.push({
  1062. $type: "a",
  1063. class: "mdc-button mdc-button--raised mdc-card__action ",
  1064. $text: _LangManager.language.t('start'),//"Start new",
  1065. //target: "_blank",
  1066. //href: "/" + desc.userAlias + '/' + desc.worldName,
  1067. onclick: function (e) {
  1068. self.checkForManualSettings();
  1069. window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName
  1070. //self.refresh();
  1071. }
  1072. });
  1073. let protoID = {}
  1074. if (desc.type == 'saveState') {
  1075. cardInfo.title = desc.worldName.split('/')[2];
  1076. let protoIDComp = {
  1077. $type: 'div',
  1078. $components: [
  1079. {
  1080. $type: "span",
  1081. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  1082. $text: 'proto: '
  1083. },
  1084. {
  1085. $type: "input",
  1086. type: "text",
  1087. disabled: "",
  1088. style: "font-size:18px",
  1089. value: desc.worldName.split('/')[0]
  1090. }
  1091. ]
  1092. }
  1093. Object.assign(protoID, protoIDComp)
  1094. }
  1095. if (desc.type == 'proto') {
  1096. cardInfo.title = desc.worldName;
  1097. // userGUI.push(
  1098. // {
  1099. // $type: "a",
  1100. // class: "mdc-button mdc-button--compact mdc-card__action",
  1101. // $text: "States",
  1102. // onclick: async function (e) {
  1103. // e.preventDefault();
  1104. // window.location.pathname = "/" + desc.userAlias + '/' + desc.worldName +'/about'
  1105. // //console.log('clone');
  1106. // // document.querySelector('#worldStatesGUI')._refresh({});
  1107. // // let data = await _app.getSaveStates(desc.userAlias, desc.worldName);
  1108. // // document.querySelector('#worldStatesGUI')._refresh(data);
  1109. // }
  1110. // }
  1111. // )
  1112. }
  1113. online.push(onlineGUI);
  1114. if(!desc.info){
  1115. desc.info = {
  1116. imgUrl: "/defaults/worlds/webrtc/webimg.jpg",
  1117. text: "..no text",
  1118. title: "..no title"
  1119. }
  1120. }
  1121. return {
  1122. $type: "div",
  1123. class: "mdc-card world-card",
  1124. $components: [
  1125. {
  1126. $type: "section",
  1127. class: "mdc-card__media world-card__16-9-media",
  1128. $init: function () {
  1129. if (desc.info.imgUrl !== "") {
  1130. this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3) ), url(' + desc.info.imgUrl + ')';
  1131. }
  1132. }
  1133. },
  1134. {
  1135. $type: "section",
  1136. class: "mdc-card__primary",
  1137. $components: [
  1138. {
  1139. $type: "h1",
  1140. class: "mdc-card__title mdc-card__title--large",
  1141. $text: desc.info.title
  1142. },
  1143. {
  1144. $type: "h2",
  1145. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  1146. $text: desc.info.text
  1147. },
  1148. {
  1149. $type: "span",
  1150. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  1151. $text: 'id: '
  1152. },
  1153. {
  1154. $type: "input",
  1155. type: "text",
  1156. disabled: "",
  1157. style: "font-size:18px",
  1158. value: cardInfo.title
  1159. },
  1160. {
  1161. $type: "p",
  1162. },
  1163. protoID,
  1164. {
  1165. $type: "p",
  1166. },
  1167. {
  1168. $type: "span",
  1169. class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  1170. $text: desc.created ? 'created: ' + (new Date(desc.created)).toUTCString() : ""
  1171. },
  1172. {
  1173. $type: "p",
  1174. }
  1175. // ,{
  1176. // $type: "span",
  1177. // class: "mdc-card__subtitle mdc-theme--text-secondary-on-background",
  1178. // $text: 'modified: ' + (new Date(desc[5])).toUTCString()
  1179. // }
  1180. ]
  1181. },
  1182. {
  1183. $type: "section",
  1184. class: "mdc-card__actions",
  1185. $components: [
  1186. ].concat(userGUI)
  1187. },
  1188. {
  1189. $type: "section",
  1190. class: "mdc-card__actions",
  1191. $components: [
  1192. {
  1193. $type: 'div',
  1194. $text: 'online now: '
  1195. }
  1196. ].concat(online)
  1197. }
  1198. ]
  1199. }
  1200. }
  1201. }
  1202. }
  1203. createWorldsGUI(worldType, userAlias, userPub, worldName) {
  1204. let self = this;
  1205. let db = _LCSDB.user(userPub);
  1206. var headerText = 'Worlds';
  1207. if(worldType == 'state' && !worldName){
  1208. headerText = 'All World States for ' + userAlias;
  1209. } else {
  1210. headerText = worldName ? 'States for ' + worldName : 'All Worlds Protos'
  1211. }
  1212. let id = worldName ? worldName + '_' + userAlias : "allWorlds_" + userAlias
  1213. //let headerText = worldName ? 'States for ' + worldName : 'All Worlds Protos'
  1214. let worldCards = {
  1215. $cell: true,
  1216. id: id,
  1217. $type: "div",
  1218. $components: [],
  1219. _cards: [],
  1220. // _states: {},
  1221. // _refresh: function (data) {
  1222. // this._states = data;
  1223. // },
  1224. $init: function () {
  1225. console.log('init lab...');
  1226. if(worldType == 'proto'){
  1227. db.get('worlds')
  1228. .map()
  1229. .on((res,k)=>{
  1230. console.log('From world: ', k);
  1231. //let doc = document.querySelector('#'+ k);
  1232. let cardID = userAlias + '_' + k;
  1233. let doc = this._cards.filter(el=> el.$components[0].id == 'worldCard_'+ cardID)[0];
  1234. if(!doc) {
  1235. doc = this._makeWorldCard(k, cardID);
  1236. this._cards.push(doc);
  1237. }
  1238. })
  1239. } else if(worldType == 'state') {
  1240. //get states
  1241. if(!worldName) {
  1242. console.log('get states');
  1243. db.get('documents')
  1244. .map()
  1245. .on((res,k)=>{
  1246. if( k !== 'id'){
  1247. console.log('From world: ', k);
  1248. let worldStatesInfo = Object.entries(res).filter(el=>el[0].includes('_info_vwf_json'));
  1249. worldStatesInfo.map(el=>{
  1250. let saveName = el[0].split('/')[2].replace('_info_vwf_json', "");
  1251. let cardID = userAlias + '_' + saveName + '_' + k;
  1252. console.log(cardID, ' - ', el);
  1253. let doc = this._cards.filter(el=> el.$components[0].id == 'worldCard_'+ cardID)[0];
  1254. if(!doc) {
  1255. doc = this._makeWorldCard({protoName: k, stateName: saveName}, cardID);
  1256. this._cards.push(doc);
  1257. }
  1258. })
  1259. //let saveName = el.stateName.split('/')[2].replace('_info_vwf_json', "");
  1260. }
  1261. //let doc = document.querySelector('#'+ k);
  1262. // let doc = this._cards.filter(el=> el.$components[0].id == 'worldCard_'+ userAlias + '_' + k)[0];
  1263. // if(!doc) {
  1264. // doc = this._makeWorldCard(k);
  1265. // this._cards.push(doc);
  1266. // }
  1267. })
  1268. } else {
  1269. console.log('get states for ' + worldName);
  1270. db.get('documents')
  1271. .map((res, k) => {if (k == worldName) return res})
  1272. .on((res,k)=>{
  1273. if( k !== 'id'){
  1274. console.log('From world: ', k);
  1275. let worldStatesInfo = Object.entries(res).filter(el=>el[0].includes('_info_vwf_json'));
  1276. worldStatesInfo.map(el=>{
  1277. let saveName = el[0].split('/')[2].replace('_info_vwf_json', "");
  1278. let cardID = userAlias + '_' + saveName + '_' + k;
  1279. console.log(cardID, ' - ', el);
  1280. let doc = this._cards.filter(el=> el.$components[0].id == 'worldCard_'+ cardID)[0];
  1281. if(!doc) {
  1282. doc = this._makeWorldCard({protoName: k, stateName: saveName}, cardID);
  1283. this._cards.push(doc);
  1284. }
  1285. })
  1286. //let saveName = el.stateName.split('/')[2].replace('_info_vwf_json', "");
  1287. }
  1288. //let doc = document.querySelector('#'+ k);
  1289. // let doc = this._cards.filter(el=> el.$components[0].id == 'worldCard_'+ userAlias + '_' + k)[0];
  1290. // if(!doc) {
  1291. // doc = this._makeWorldCard(k);
  1292. // this._cards.push(doc);
  1293. // }
  1294. })
  1295. }
  1296. }
  1297. //this._refresh();
  1298. },
  1299. _makeWorldCard: function (worldID, cardID) {
  1300. //let cardID = userAlias + '_' + worldID//data[1].userAlias + '_' + data[1].worldName + '_' + data[0];
  1301. let card = self.createWorldCard(worldType, userAlias, userPub, worldID, cardID, 'min');
  1302. //card._refresh(data[1]);
  1303. //card._worldInfo = data[1];
  1304. //card._updateComps();
  1305. return {
  1306. $cell: true,
  1307. $type: "div",
  1308. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  1309. $components: [card]
  1310. }
  1311. },
  1312. $update: function () {
  1313. // let cards = Object.entries(this._states)
  1314. // .filter(el => Object.keys(el[1]).length !== 0)
  1315. // .sort(function (el1, el2) {
  1316. // return parseInt(el2[1].created) - parseInt(el1[1].created)
  1317. // })
  1318. // .map(this._makeWorldCard);
  1319. this.$components = [
  1320. {
  1321. $type: "div",
  1322. class: "mdc-layout-grid",
  1323. $components: [
  1324. {
  1325. $type: "div",
  1326. class: "mdc-layout-grid__inner",
  1327. $components: [
  1328. {
  1329. $type: "div",
  1330. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1331. $components: [
  1332. {
  1333. $type: "H3",
  1334. $text: headerText
  1335. }
  1336. ]
  1337. }
  1338. ]
  1339. },
  1340. {
  1341. $type: "div",
  1342. class: "mdc-layout-grid__inner",
  1343. $components: this._cards
  1344. }
  1345. ]
  1346. }
  1347. ]
  1348. }
  1349. }
  1350. return worldCards
  1351. }
  1352. checkForManualSettings() {
  1353. console.log("check for manual settings");
  1354. let manualSettings = localStorage.getItem('lcs_app_manual_settings');
  1355. if (manualSettings) {
  1356. localStorage.removeItem('lcs_app_manual_settings');
  1357. }
  1358. let el = document.querySelector('#runWorldGUI');
  1359. if (el) {
  1360. if (el._arSwitch.checked) {
  1361. let arSettings = {
  1362. model: {
  1363. 'vwf/model/aframe': null
  1364. },
  1365. view: {
  1366. 'vwf/view/aframe': null,
  1367. 'vwf/view/editor-new': null
  1368. }
  1369. }
  1370. localStorage.setItem('lcs_app_manual_settings', JSON.stringify(arSettings));
  1371. }
  1372. if (el._turnArOnSwitch.checked) {
  1373. let arSettings = {
  1374. model: {
  1375. 'vwf/model/aframe': null
  1376. },
  1377. view: {
  1378. 'vwf/view/aframe': null,
  1379. 'vwf/view/aframe-ar-driver': null
  1380. }
  1381. }
  1382. localStorage.setItem('lcs_app_manual_settings', JSON.stringify(arSettings));
  1383. }
  1384. }
  1385. }
  1386. }
  1387. export { IndexApp as default }
  1388. //export {getAppDetails, generateFrontPage, setLanguage, initLocale};