widgets.js 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612
  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. /*
  6. * Cell widgets
  7. */
  8. class Widgets {
  9. constructor() {
  10. console.log("widget constructor")
  11. }
  12. get divider(){
  13. return {
  14. $cell: true,
  15. $type: "hr",
  16. class: "mdc-list-divider"
  17. }
  18. }
  19. get emptyDiv(){
  20. return {
  21. $type: "div",
  22. style: "padding-bottom: 30px;"
  23. }
  24. }
  25. get break(){
  26. return {
  27. $type: "br"
  28. }
  29. }
  30. get space() {
  31. return {
  32. $type: "span",
  33. $text: " "
  34. }
  35. }
  36. get p(){
  37. return {
  38. $type: "p"
  39. }
  40. }
  41. inputTextFieldOutlined(obj){
  42. function initFunc() {
  43. new mdc.textField.MDCTextField.attachTo(this);
  44. }
  45. let inputType = obj.type ? obj.type: 'text';
  46. let init = obj.init ? obj.init: initFunc;
  47. let style = obj.style ? obj.style: "";
  48. let fieldStyle = obj.fieldStyle ? obj.fieldStyle: "";
  49. return {
  50. $cell: true,
  51. $type: "div",
  52. class: "mdc-text-field mdc-text-field--outlined mdc-text-field--dense",
  53. style: style,
  54. $init: init,
  55. $components:[
  56. {
  57. $type: "input",
  58. type: inputType,
  59. id: obj.id,
  60. class: "mdc-text-field__input",
  61. value: obj.value,
  62. onchange: obj.change,
  63. style: obj.fieldStyle
  64. },
  65. {
  66. $type: "div",
  67. class: "mdc-notched-outline",
  68. $components:[
  69. {
  70. $type: "div",
  71. class: "mdc-notched-outline__leading"
  72. },
  73. {
  74. $type: "div",
  75. class: "mdc-notched-outline__notch",
  76. $components:[
  77. {
  78. $type: "label",
  79. class: "mdc-floating-label",
  80. for: obj.id,
  81. $text: obj.label
  82. }
  83. ]
  84. },
  85. {
  86. $type: "div",
  87. class: "mdc-notched-outline__trailing"
  88. }
  89. ]
  90. }
  91. ]
  92. //onclick: obj.onclick
  93. }
  94. }
  95. inputTextFieldStandart(obj){
  96. var propValue = obj.value;
  97. if (_app.helpers.testJSON(obj.value)){
  98. propValue = JSON.parse(obj.value);
  99. } else {
  100. propValue = obj.value;
  101. }
  102. return {
  103. $cell: true,
  104. $type: "div",
  105. class: "mdc-text-field text-field mdc-ripple-upgraded",
  106. _mdc: null,
  107. $init: function(){
  108. //new mdc.mdc.notchedOutline.MDCNotchedOutline(document.querySelector('.mdc-notched-outline'));
  109. this._mdc = new mdc.textField.MDCTextField.attachTo(this);
  110. },
  111. $components:[
  112. {
  113. $type: "input",
  114. type: "text",
  115. id: obj.id,
  116. class: "mdc-text-field__input",
  117. value: propValue,
  118. onchange: obj.change
  119. },
  120. {
  121. $type: "label",
  122. class: "mdc-floating-label",
  123. for: obj.id,
  124. $text: obj.label
  125. },
  126. {
  127. $type: "div",
  128. class: "mdc-line-ripple"
  129. }
  130. ]
  131. //onclick: obj.onclick
  132. }
  133. }
  134. headerH3(headertype, label, cssclass) {
  135. return {
  136. $cell: true,
  137. $type: headertype,
  138. class: cssclass,
  139. $text: label
  140. }
  141. }
  142. simpleCard(obj){
  143. let style = 'background-image: url(' + obj.imgSrc + '); background-size: cover; background-repeat: no-repeat; height:' + obj.imgHeight + ';';
  144. var addonClass = obj.addonClass;
  145. if (!addonClass){
  146. addonClass = ''
  147. }
  148. return {
  149. $cell: true,
  150. $type: "div",
  151. $components:[
  152. {
  153. $cell: true,
  154. $type: "div",
  155. class: "mdc-card" +' '+ addonClass,
  156. onclick: obj.onclickfunc,
  157. $components:[
  158. {
  159. $cell: true,
  160. $type: "section",
  161. class: "mdc-card__media",
  162. style: style
  163. },
  164. {
  165. $cell: true,
  166. $type: "section",
  167. class: "mdc-card__supporting-text",
  168. $text: obj.text
  169. }
  170. ]
  171. }
  172. ]
  173. }
  174. }
  175. listDivider() {
  176. return {
  177. $cell: true,
  178. $type: "hr",
  179. class: "mdc-list-divider mdc-list-divider--inset"
  180. }
  181. }
  182. createListItem(obj) {
  183. return {
  184. $cell: true,
  185. $type: "li",
  186. class: "mdc-list-item",
  187. $components: [
  188. {
  189. $cell: true,
  190. $type: "span",
  191. class: "mdc-list-item__graphic",
  192. $components: [
  193. {
  194. $cell: true,
  195. class: "createItems",
  196. $type: "img",
  197. src: obj.imgSrc,
  198. onclick: obj.onclickfunc
  199. }
  200. ]
  201. },
  202. {
  203. $cell: true,
  204. $type: "span",
  205. class: "mdc-list-item__text",
  206. $text: obj.title
  207. // $components: [
  208. // {
  209. // $text: obj.title
  210. // },
  211. // {
  212. // $cell: true,
  213. // $type: "span",
  214. // class: "mdc-list-item__secondary-text",
  215. // $text: obj.subTitle
  216. // }
  217. // ]
  218. }
  219. ]
  220. }
  221. }
  222. createCard(obj){
  223. return {
  224. $cell: true,
  225. $type: "div",
  226. $components:[
  227. {
  228. $cell: true,
  229. $type: "div",
  230. class: "mdc-card",
  231. $components:[
  232. {
  233. $cell: true,
  234. $type: "div",
  235. class: "mdc-card__horizontal-block",
  236. $components:[
  237. {
  238. $cell: true,
  239. $type: "section",
  240. class: "mdc-card__primary",
  241. $components:[
  242. {
  243. $cell: true,
  244. $type: "h1",
  245. class: "mdc-card__title mdc-card__title--large",
  246. $text: obj.title
  247. },
  248. {
  249. $cell: true,
  250. $type: "h2",
  251. class: "mdc-card__subtitle",
  252. $text: obj.subTitle
  253. }
  254. ]
  255. },
  256. {
  257. $cell: true,
  258. $type: "img",
  259. class: "",
  260. src: obj.imgSrc
  261. }
  262. ]
  263. },
  264. {
  265. $cell: true,
  266. $type: "section",
  267. class: "mdc-card__actions",
  268. $components:[
  269. {
  270. $cell: true,
  271. $type: "button",
  272. class: "mdc-button mdc-button--compact mdc-card__action",
  273. $text: obj.actionLabel
  274. }
  275. ]
  276. }
  277. ]
  278. }
  279. ]
  280. }
  281. }
  282. buttonStroked(obj){
  283. let initFun = obj.init ? obj.init: function(){}
  284. return {
  285. $cell: true,
  286. $type: "button",
  287. class: "mdc-button mdc-button--outlined",
  288. $text: obj.label,
  289. onclick: obj.onclick,
  290. $init: initFun
  291. }
  292. }
  293. buttonRaised(obj){
  294. let initFun = obj.init ? obj.init: function(){}
  295. return {
  296. $cell: true,
  297. $type: "button",
  298. class: "mdc-button mdc-button--raised mdc-ripple-upgraded",
  299. $text: obj.label,
  300. onclick: obj.onclick,
  301. $init: initFun
  302. }
  303. }
  304. buttonSimple(obj){
  305. return {
  306. $cell: true,
  307. $type: "button",
  308. class: "mdc-button",
  309. $components: [
  310. {
  311. $type: "span",
  312. class: "mdc-button__label",
  313. $text: obj.label
  314. }
  315. ],
  316. onclick: obj.onclick
  317. }
  318. }
  319. sliderDiscrete(obj) {
  320. return {
  321. $cell: true,
  322. $type: "div",
  323. class: "mdc-slider mdc-slider--discrete",
  324. role: "slider",
  325. 'aria-valuemin': obj.min,
  326. 'aria-valuemax': obj.max,
  327. 'aria-label': obj.label,
  328. $init: obj.init,
  329. $components: [
  330. {
  331. $cell: true,
  332. $type: "div",
  333. class: "mdc-slider__track-container",
  334. $components: [
  335. {
  336. $cell: true,
  337. $type: "div",
  338. class: "mdc-slider__track",
  339. }
  340. ]
  341. },
  342. {
  343. $cell: true,
  344. $type: "div",
  345. class: "mdc-slider__thumb-container",
  346. $components: [
  347. {
  348. $cell: true,
  349. $type: "div",
  350. class: "mdc-slider__pin",
  351. $components: [
  352. {
  353. $cell: true,
  354. $type: "span",
  355. class: "mdc-slider__pin-value-marker",
  356. }
  357. ]
  358. },
  359. {
  360. $cell: true,
  361. $type: "svg",
  362. class: "mdc-slider__thumb",
  363. width: 21,
  364. height: 21,
  365. $components: [
  366. {
  367. $cell: true,
  368. $type: "circle",
  369. cx: 10.5,
  370. cy: 10.5,
  371. r: 7.875
  372. }
  373. ]
  374. },
  375. {
  376. $cell: true,
  377. $type: "div",
  378. class: "mdc-slider__focus-ring"
  379. }
  380. ]
  381. }
  382. ]
  383. }
  384. }
  385. sliderContinuous(obj) {
  386. return {
  387. $cell: true,
  388. $type: "div",
  389. class: "mdc-slider",
  390. role: "slider",
  391. tabindex: 0,
  392. 'id': obj.id,
  393. 'aria-valuemin': obj.min,
  394. 'aria-valuemax': obj.max,
  395. 'aria-label': obj.label,
  396. 'aria-valuenow': obj.value,
  397. 'data-step': obj.step,
  398. $init: obj.init,
  399. $components: [
  400. {
  401. $cell: true,
  402. $type: "div",
  403. class: "mdc-slider__track-container",
  404. $components: [
  405. {
  406. $cell: true,
  407. $type: "div",
  408. class: "mdc-slider__track",
  409. }
  410. ]
  411. },
  412. {
  413. $cell: true,
  414. $type: "div",
  415. class: "mdc-slider__thumb-container",
  416. $components: [
  417. {
  418. $cell: true,
  419. $type: "svg",
  420. class: "mdc-slider__thumb",
  421. width: 21,
  422. height: 21,
  423. $components: [
  424. {
  425. $cell: true,
  426. $type: "circle",
  427. cx: 10.5,
  428. cy: 10.5,
  429. r: 7.875
  430. }
  431. ]
  432. },
  433. {
  434. $cell: true,
  435. $type: "div",
  436. class: "mdc-slider__focus-ring"
  437. }
  438. ]
  439. }
  440. ]
  441. }
  442. }
  443. textField(obj) {
  444. return {
  445. class: "mdc-text-field",
  446. style: "width: 100%",
  447. $cell: true,
  448. $type: "div",
  449. $components: [
  450. {
  451. class: "mdc-text-field__input prop-text-field-input",
  452. id: obj.id,
  453. $cell: true,
  454. $type: "input",
  455. type: "text",
  456. value: obj.value,
  457. onchange: obj.funconchange
  458. }
  459. ]
  460. }
  461. }
  462. icontoggle(obj) {
  463. var addClass = "";
  464. if (obj.styleClass){
  465. addClass = obj.styleClass;
  466. }
  467. return {
  468. $type: "button",
  469. class: addClass + " mdc-icon-button",
  470. //$text: obj.label,
  471. id: obj.id,
  472. //'data-toggle-on': obj.on,
  473. // 'data-toggle-off': obj.off,
  474. 'aria-pressed': obj.state,
  475. 'aria-hidden': true,
  476. $init: obj.init,
  477. $components:[
  478. {
  479. $type: "i",
  480. class: "material-icons mdc-icon-button__icon mdc-icon-button__icon--on",
  481. $text: JSON.parse(obj.on).content
  482. },
  483. {
  484. $type: "i",
  485. class: "material-icons mdc-icon-button__icon",
  486. $text: JSON.parse(obj.off).content
  487. },
  488. ]
  489. }
  490. }
  491. floatActionButton(obj) {
  492. var addClass = "";
  493. if (obj.styleClass){
  494. addClass = obj.styleClass;
  495. }
  496. return {
  497. $cell: true,
  498. $type: "button",
  499. class: "mdc-fab material-icons " + addClass,
  500. onclick: obj.onclickfunc,
  501. $components:[
  502. {
  503. $cell: true,
  504. $type: "span",
  505. class: "mdc-fab__icon",
  506. $text: obj.label
  507. }
  508. ]
  509. }
  510. }
  511. iconButton(obj) {
  512. var addClass = "";
  513. if (obj.styleClass){
  514. addClass = obj.styleClass;
  515. }
  516. return {
  517. $cell: true,
  518. $type: "button",
  519. class: "mdc-button " + addClass,
  520. onclick: obj.onclick,
  521. $components:[
  522. {
  523. $cell: true,
  524. $type: "i",
  525. class: "material-icons mdc-button__icon",
  526. $text: obj.label
  527. }
  528. ]
  529. }
  530. }
  531. imageButton(obj){
  532. return {
  533. $cell: true,
  534. $type: "button",
  535. class: "mdc-button mdc-button--compact",
  536. onclick: obj.onclickfunc,
  537. $components:[
  538. {
  539. $cell: true,
  540. class: obj.styleClass,
  541. $type: "img",
  542. src: obj.imgSrc
  543. }
  544. ]
  545. }
  546. }
  547. listTitle(obj){
  548. return {
  549. $type: "div",
  550. class: "mdc-layout-grid__inner",
  551. $components: [
  552. {
  553. $type: "div",
  554. class: "mdc-layout-grid__cell",
  555. $components: [
  556. {
  557. $type: "h3",
  558. class: "",
  559. $text: obj.text
  560. }
  561. ]
  562. }
  563. ]
  564. }
  565. }
  566. gridListItem(obj) {
  567. return {
  568. $type: "div",
  569. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2 tooltip " + obj.styleClass,
  570. $components:[
  571. {
  572. class: "tooltiptext",
  573. $type: "span",
  574. $text: obj.title
  575. },
  576. {
  577. $type: "div",
  578. style: "background-color: transparent;",
  579. $components:[
  580. {
  581. class: "",
  582. $type: "div",
  583. 'aria-label': obj.title,
  584. alt: obj.title,
  585. style: "background-image: url("+ obj.imgSrc + "); background-size: cover; background-repeat: no-repeat; height: "+ obj.imgSize + "; width: " + obj.imgSize + ";",
  586. onclick: obj.onclickfunc,
  587. }
  588. ]
  589. }
  590. ]
  591. }
  592. }
  593. switch(obj) {
  594. return {
  595. $cell: true,
  596. $type: "div",
  597. class: "mdc-switch",
  598. _switch: null,
  599. id: obj.id,
  600. $init: obj.init,
  601. //function(){
  602. // new mdc.switchControl.MDCSwitch(this);
  603. // },
  604. $components: [
  605. {
  606. $type: "div",
  607. class: "mdc-switch__track",
  608. },
  609. {
  610. $type: "div",
  611. class: "mdc-switch__thumb-underlay",
  612. $components:[
  613. {
  614. $type: "div",
  615. class: "mdc-switch__thumb",
  616. $components:[
  617. {
  618. $type: "input",
  619. type: "checkbox",
  620. class: "mdc-switch__native-control",
  621. id: 'input-' + obj.id,
  622. //$init: obj.init,
  623. //id: "basic-switch",
  624. onchange: obj.onchange,
  625. role: "switch"
  626. }
  627. ]
  628. }
  629. ]
  630. }
  631. // {
  632. // $type: "div",
  633. // class: "mdc-switch__background",
  634. // $components: [
  635. // {
  636. // $type: "div",
  637. // class: "mdc-switch__knob"
  638. // }
  639. // ]
  640. // }
  641. ]
  642. }
  643. }
  644. connectionSettingsGUI() {
  645. let connectionSettings = {
  646. id: 'connectionSettings',
  647. $type: 'div',
  648. $components: [
  649. _app.widgets.emptyDiv,
  650. window._app.widgets.buttonRaised(
  651. {
  652. "label": 'Connection settings',
  653. "onclick": function (e) {
  654. e.preventDefault();
  655. window.location.pathname = '/settings';
  656. }
  657. }), _app.widgets.emptyDiv
  658. ]
  659. }
  660. return connectionSettings
  661. }
  662. debugGUI() {
  663. let self = this;
  664. let debug6DoF = {
  665. $cell: true,
  666. $components: [
  667. {
  668. $type: "p",
  669. class: "mdc-typography--headline5",
  670. $text: "Debug 6DoF mode (for using with WebXR emulator)"
  671. },
  672. {
  673. $type: 'p'
  674. },
  675. _app.widgets.switch({
  676. 'id': 'forceDebug6DoF',
  677. 'init': function () {
  678. this._switch = new mdc.switchControl.MDCSwitch(this);
  679. let config = localStorage.getItem('lcs_config');
  680. this._switch.checked = JSON.parse(config).d6DoF;
  681. // this._replaceSwitch = this._switch;
  682. },
  683. 'onchange': function (e) {
  684. if (this._switch) {
  685. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  686. if (chkAttr) {
  687. let config = JSON.parse(localStorage.getItem('lcs_config'));
  688. config.d6DoF = true;
  689. localStorage.setItem('lcs_config', JSON.stringify(config));
  690. //this._switch.checked = false;
  691. } else {
  692. let config = JSON.parse(localStorage.getItem('lcs_config'));
  693. config.d6DoF = false;
  694. localStorage.setItem('lcs_config', JSON.stringify(config));
  695. }
  696. }
  697. }
  698. }
  699. ),
  700. {
  701. $type: 'label',
  702. for: 'input-forceDebug6DoF',
  703. $text: 'On / Off'
  704. }
  705. ]
  706. }
  707. let debug3DoF = {
  708. $cell: true,
  709. $components: [
  710. {
  711. $type: "p",
  712. class: "mdc-typography--headline5",
  713. $text: "Debug 3DoF mode (for using with WebXR emulator)"
  714. },
  715. {
  716. $type: 'p'
  717. },
  718. _app.widgets.switch({
  719. 'id': 'forceDebug3DoF',
  720. 'init': function () {
  721. this._switch = new mdc.switchControl.MDCSwitch(this);
  722. let config = localStorage.getItem('lcs_config');
  723. this._switch.checked = JSON.parse(config).d3DoF;
  724. // this._replaceSwitch = this._switch;
  725. },
  726. 'onchange': function (e) {
  727. if (this._switch) {
  728. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  729. if (chkAttr) {
  730. let config = JSON.parse(localStorage.getItem('lcs_config'));
  731. config.d3DoF = true;
  732. localStorage.setItem('lcs_config', JSON.stringify(config));
  733. //this._switch.checked = false;
  734. } else {
  735. let config = JSON.parse(localStorage.getItem('lcs_config'));
  736. config.d3DoF = false;
  737. localStorage.setItem('lcs_config', JSON.stringify(config));
  738. }
  739. }
  740. }
  741. }
  742. ),
  743. {
  744. $type: 'label',
  745. for: 'input-forceDebug3DoF',
  746. $text: 'On / Off'
  747. }
  748. ]
  749. }
  750. let allGUI =
  751. {
  752. $type: "div",
  753. id: "allGUI",
  754. //style:"background-color: #efefef",
  755. class: "mdc-layout-grid mdc-layout-grid--align-left",
  756. _d3DoF: null,
  757. _d6DoF: null,
  758. _initData: function () {
  759. let config = JSON.parse(localStorage.getItem('lcs_config'));
  760. if (config.d3DoF) {
  761. this._d3DoF = config.d3DoF
  762. }
  763. if (config.d6DoF) {
  764. this._d6DoF =config.d6DoF
  765. }
  766. this._refresh();
  767. },
  768. $init: function () {
  769. this._initData();
  770. },
  771. _refresh: function () {
  772. this.$components = [
  773. {
  774. $type: "div",
  775. class: "mdc-layout-grid__inner",
  776. $components: [
  777. {
  778. $type: "div",
  779. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  780. $components: [
  781. {
  782. $type: "h4",
  783. class: "mdc-typography--headline4",
  784. $text: "Debug settings"
  785. }
  786. ]
  787. },
  788. {
  789. $type: "div",
  790. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  791. $components: [debug6DoF ]
  792. },
  793. {
  794. $type: "div",
  795. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  796. $components: [_app.widgets.divider]
  797. },
  798. {
  799. $type: "div",
  800. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  801. $components: [debug3DoF]
  802. },
  803. {
  804. $type: "div",
  805. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  806. $components: [
  807. // window._app.widgets.buttonRaised(
  808. // {
  809. // "label": 'Update',
  810. // "onclick": function (e) {
  811. // e.preventDefault();
  812. // let config = JSON.parse(localStorage.getItem('lcs_config'));
  813. // config.reflector = this._refHostField.value;
  814. // config.dbhost = this._dbHostField.value;
  815. // config.luminaryPath = this._lpathField.value;
  816. // config.luminaryGlobalHBPath = this._hbpathField.value;
  817. // localStorage.setItem('lcs_config', JSON.stringify(config));
  818. // window.location.reload(true);
  819. // }
  820. // }),
  821. {
  822. $type: 'span',
  823. $text: " "
  824. },
  825. {
  826. $type: "button",
  827. class: "mdc-button mdc-button--raised",
  828. $text: "Close",
  829. onclick: function (e) {
  830. window.history.back();
  831. //window.location.pathname = '/'
  832. }
  833. }
  834. ]
  835. }
  836. ]
  837. }
  838. ]
  839. }
  840. }
  841. document.querySelector("#appGUI").$cell({
  842. id: "appGUI",
  843. $cell: true,
  844. $type: "div",
  845. $components: [allGUI]
  846. }
  847. );
  848. }
  849. reflectorGUI() {
  850. let self = this;
  851. let webrtcConnection = {
  852. $cell: true,
  853. $components: [
  854. {
  855. $type: "p",
  856. class: "mdc-typography--headline5",
  857. $text: "Use WebRTC for connection"
  858. },
  859. {
  860. $type: 'p'
  861. },
  862. _app.widgets.switch({
  863. 'id': 'forceWebRTC',
  864. 'init': function () {
  865. this._switch = new mdc.switchControl.MDCSwitch(this);
  866. let config = localStorage.getItem('lcs_config');
  867. this._switch.checked = JSON.parse(config).webrtc;
  868. // this._replaceSwitch = this._switch;
  869. },
  870. 'onchange': function (e) {
  871. if (this._switch) {
  872. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  873. if (chkAttr) {
  874. let config = JSON.parse(localStorage.getItem('lcs_config'));
  875. config.webrtc = true;
  876. localStorage.setItem('lcs_config', JSON.stringify(config));
  877. //this._switch.checked = false;
  878. } else {
  879. let config = JSON.parse(localStorage.getItem('lcs_config'));
  880. config.webrtc = false;
  881. localStorage.setItem('lcs_config', JSON.stringify(config));
  882. }
  883. }
  884. }
  885. }
  886. ),
  887. {
  888. $type: 'label',
  889. for: 'input-forceWebRTC',
  890. $text: 'On / Off'
  891. }
  892. ]
  893. }
  894. let streamMsgConfig = {
  895. $cell: true,
  896. _streamMsgConfig: null,
  897. $components: [
  898. {
  899. $type: "p",
  900. class: "mdc-typography--headline5",
  901. $text: "Use Stream of Messages"
  902. },
  903. {
  904. $type: 'p'
  905. },
  906. _app.widgets.switch({
  907. 'id': 'streamMsgConfig',
  908. 'init': function () {
  909. this._switch = new mdc.switchControl.MDCSwitch(this);
  910. let config = localStorage.getItem('lcs_config');
  911. this._switch.checked = JSON.parse(config).streamMsg;
  912. // this._replaceSwitch = this._switch;
  913. },
  914. 'onchange': function (e) {
  915. if (this._switch) {
  916. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  917. if (chkAttr) {
  918. let config = JSON.parse(localStorage.getItem('lcs_config'));
  919. config.streamMsg = true;
  920. localStorage.setItem('lcs_config', JSON.stringify(config));
  921. //this._switch.checked = false;
  922. } else {
  923. let config = JSON.parse(localStorage.getItem('lcs_config'));
  924. config.streamMsg = false;
  925. localStorage.setItem('lcs_config', JSON.stringify(config));
  926. }
  927. }
  928. }
  929. }
  930. ),
  931. {
  932. $type: 'label',
  933. for: 'input-streamMsgConfig',
  934. $text: 'On / Off'
  935. }
  936. ]
  937. }
  938. let multiSocket = {
  939. $cell: true,
  940. $components: [
  941. {
  942. $type: "p",
  943. class: "mdc-typography--headline5",
  944. $text: "Use Rooms & Gun DB MultiSocket (no mem)"
  945. },
  946. {
  947. $type: 'p'
  948. },
  949. _app.widgets.switch({
  950. 'id': 'multisocket',
  951. 'init': function () {
  952. this._switch = new mdc.switchControl.MDCSwitch(this);
  953. let config = localStorage.getItem('lcs_config');
  954. this._switch.checked = JSON.parse(config).multisocket;
  955. // this._replaceSwitch = this._switch;
  956. },
  957. 'onchange': function (e) {
  958. if (this._switch) {
  959. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  960. if (chkAttr) {
  961. let config = JSON.parse(localStorage.getItem('lcs_config'));
  962. config.multisocket = true;
  963. localStorage.setItem('lcs_config', JSON.stringify(config));
  964. //this._switch.checked = false;
  965. } else {
  966. let config = JSON.parse(localStorage.getItem('lcs_config'));
  967. config.multisocket = false;
  968. localStorage.setItem('lcs_config', JSON.stringify(config));
  969. }
  970. }
  971. }
  972. }
  973. ),
  974. {
  975. $type: 'label',
  976. for: 'input-multisocket',
  977. $text: 'On / Off'
  978. }
  979. ]
  980. }
  981. let luminaryGlobalHB = {
  982. $cell: true,
  983. $components: [
  984. {
  985. $type: "p",
  986. class: "mdc-typography--headline5",
  987. $text: "Use Global Heartbeat"
  988. },
  989. {
  990. $type: 'p'
  991. },
  992. _app.widgets.switch({
  993. 'id': 'forceLuminary',
  994. 'init': function () {
  995. this._switch = new mdc.switchControl.MDCSwitch(this);
  996. let config = localStorage.getItem('lcs_config');
  997. this._switch.checked = JSON.parse(config).luminaryGlobalHB;
  998. // this._replaceSwitch = this._switch;
  999. },
  1000. 'onchange': function (e) {
  1001. if (this._switch) {
  1002. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  1003. if (chkAttr) {
  1004. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1005. config.luminaryGlobalHB = true;
  1006. localStorage.setItem('lcs_config', JSON.stringify(config));
  1007. //this._switch.checked = false;
  1008. } else {
  1009. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1010. config.luminaryGlobalHB = false;
  1011. localStorage.setItem('lcs_config', JSON.stringify(config));
  1012. }
  1013. }
  1014. }
  1015. }
  1016. ),
  1017. {
  1018. $type: 'label',
  1019. for: 'input-forceLuminary',
  1020. $text: 'On / Off'
  1021. }
  1022. ]
  1023. }
  1024. let luminaryFeature = {
  1025. $type: 'div',
  1026. $components: [
  1027. {
  1028. $type: "p",
  1029. class: "mdc-typography--headline4",
  1030. $text: "Use Krestianstvo Luminary (experimental)"
  1031. },
  1032. {
  1033. $type: 'p'
  1034. },
  1035. _app.widgets.switch({
  1036. 'id': 'forceLuminary',
  1037. 'init': function () {
  1038. this._switch = new mdc.switchControl.MDCSwitch(this);
  1039. let config = localStorage.getItem('lcs_config');
  1040. this._switch.checked = JSON.parse(config).luminary;
  1041. // this._replaceSwitch = this._switch;
  1042. },
  1043. 'onchange': function (e) {
  1044. if (this._switch) {
  1045. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  1046. if (chkAttr) {
  1047. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1048. config.luminary = true;
  1049. localStorage.setItem('lcs_config', JSON.stringify(config));
  1050. window.location.reload(true);
  1051. //this._switch.checked = false;
  1052. } else {
  1053. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1054. config.luminary = false;
  1055. localStorage.setItem('lcs_config', JSON.stringify(config));
  1056. window.location.reload(true);
  1057. }
  1058. }
  1059. }
  1060. }
  1061. ),
  1062. {
  1063. $type: 'label',
  1064. for: 'input-forceLuminary',
  1065. $text: 'Off / On'
  1066. },
  1067. _app.widgets.p
  1068. ]
  1069. }
  1070. let reflectorGUI =
  1071. {
  1072. $type: "div",
  1073. id: "reflectorGUI",
  1074. //style:"background-color: #efefef",
  1075. class: "mdc-layout-grid mdc-layout-grid--align-left",
  1076. _reflectorHost: null,
  1077. _dbHost: null,
  1078. _refHostField: null,
  1079. _dbHostField: null,
  1080. _lpath: null,
  1081. _lpathField: null,
  1082. _hbpath: null,
  1083. _hbpathField: null,
  1084. //_debug: null,
  1085. _initData: function () {
  1086. this._reflectorHost = '';
  1087. this._dbHost = '';
  1088. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1089. if (config.reflector) {
  1090. this._reflectorHost = config.reflector
  1091. }
  1092. if (config.dbhost) {
  1093. this._dbHost =config.dbhost
  1094. }
  1095. if (config.luminaryPath) {
  1096. this._lpath = config.luminaryPath
  1097. }
  1098. if (config.luminaryGlobalHBPath) {
  1099. this._hbpath = config.luminaryGlobalHBPath
  1100. }
  1101. // if (config.debug) {
  1102. // this._debug = config.debug
  1103. // }
  1104. },
  1105. $init: function () {
  1106. this._initData();
  1107. },
  1108. $update: function () {
  1109. this.$components = [
  1110. {
  1111. $type: "div",
  1112. class: "mdc-layout-grid__inner",
  1113. $components: [
  1114. {
  1115. $type: "div",
  1116. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1117. $components: [
  1118. {
  1119. $type: "h4",
  1120. class: "mdc-typography--headline4",
  1121. $text: "Gun DB settings"
  1122. }
  1123. ]
  1124. },
  1125. {
  1126. $type: "div",
  1127. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1128. $components: [
  1129. {
  1130. $type: "span",
  1131. class: "mdc-typography--headline5",
  1132. $text: "DB Host: "
  1133. },
  1134. window._app.widgets.inputTextFieldOutlined({
  1135. "id": 'dbhostInput',
  1136. "label": "DB Host",
  1137. "value": this._dbHost,
  1138. "type": "text",
  1139. "init": function() {
  1140. this._dbHostField = new mdc.textField.MDCTextField(this);
  1141. },
  1142. "style": 'width: 400px;'
  1143. }),
  1144. ]
  1145. },
  1146. {
  1147. $type: "div",
  1148. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1149. $components: [
  1150. {
  1151. $type: "h4",
  1152. class: "mdc-typography--headline4",
  1153. $text: "Reflector settings"
  1154. }
  1155. ]
  1156. },
  1157. {
  1158. $type: "div",
  1159. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1160. $components: [
  1161. {
  1162. $type: "span",
  1163. class: "mdc-typography--headline5",
  1164. $text: "Reflector: "
  1165. },
  1166. window._app.widgets.inputTextFieldOutlined({
  1167. "id": 'reflectorInput',
  1168. "label": "Reflector",
  1169. "value": this._reflectorHost,
  1170. "type": "text",
  1171. "init": function() {
  1172. this._refHostField = new mdc.textField.MDCTextField(this);
  1173. },
  1174. "style": 'width: 400px;'
  1175. }),
  1176. ]
  1177. },
  1178. {
  1179. $type: "div",
  1180. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1181. $components: [webrtcConnection ]
  1182. },
  1183. {
  1184. $type: "div",
  1185. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1186. $components: [_app.widgets.divider]
  1187. },
  1188. // {
  1189. // $type: "div",
  1190. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1191. // $components: [
  1192. // {
  1193. // $type: "h4",
  1194. // class: "mdc-typography--headline4",
  1195. // $text: "Krestianstvo Luminary settings (experimental)"
  1196. // }
  1197. // ]
  1198. // },
  1199. {
  1200. $type: "div",
  1201. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1202. $components: [
  1203. luminaryFeature
  1204. ]
  1205. },
  1206. {
  1207. $type: "div",
  1208. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1209. $components: [multiSocket]
  1210. },
  1211. {
  1212. $type: "div",
  1213. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1214. $components: [
  1215. {
  1216. $type: "span",
  1217. class: "mdc-typography--headline5",
  1218. $text: "Multisocket Rooms Host: "
  1219. },
  1220. window._app.widgets.inputTextFieldOutlined({
  1221. "id": 'lpathInput',
  1222. "label": "Multisocket Rooms Host",
  1223. "value": this._lpath,
  1224. "type": "text",
  1225. "init": function() {
  1226. this._lpathField = new mdc.textField.MDCTextField(this);
  1227. },
  1228. "style": 'width: 400px;'
  1229. }),
  1230. ]
  1231. },
  1232. {
  1233. $type: "div",
  1234. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1235. $components: [
  1236. {
  1237. $type: "span",
  1238. class: "mdc-typography--headline5",
  1239. $text: "Global Heartbeat Path: "
  1240. },
  1241. window._app.widgets.inputTextFieldOutlined({
  1242. "id": 'hbpathInput',
  1243. "label": "Global Heartbeat Path",
  1244. "value": this._hbpath,
  1245. "type": "text",
  1246. "init": function() {
  1247. this._hbpathField = new mdc.textField.MDCTextField(this);
  1248. },
  1249. "style": 'width: 400px;'
  1250. }),
  1251. ]
  1252. },
  1253. {
  1254. $type: "div",
  1255. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1256. $components: [luminaryGlobalHB ]
  1257. },
  1258. {
  1259. $type: "div",
  1260. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1261. $components: [_app.widgets.divider]
  1262. },
  1263. {
  1264. $type: "div",
  1265. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1266. $components: [streamMsgConfig ]
  1267. },
  1268. // {
  1269. // $type: "div",
  1270. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1271. // $components: [debugGUI]
  1272. // },
  1273. {
  1274. $type: "div",
  1275. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1276. $components: [
  1277. window._app.widgets.buttonRaised(
  1278. {
  1279. "label": 'Update',
  1280. "onclick": function (e) {
  1281. e.preventDefault();
  1282. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1283. config.reflector = this._refHostField.value;
  1284. config.dbhost = this._dbHostField.value;
  1285. config.luminaryPath = this._lpathField.value;
  1286. config.luminaryGlobalHBPath = this._hbpathField.value;
  1287. localStorage.setItem('lcs_config', JSON.stringify(config));
  1288. window.location.reload(true);
  1289. }
  1290. }),
  1291. {
  1292. $type: 'span',
  1293. $text: " "
  1294. },
  1295. {
  1296. $type: "button",
  1297. class: "mdc-button mdc-button--raised",
  1298. $text: "Close",
  1299. onclick: function (e) {
  1300. window.history.back();
  1301. //window.location.pathname = '/'
  1302. }
  1303. }
  1304. ]
  1305. }
  1306. ]
  1307. }
  1308. ]
  1309. }
  1310. }
  1311. document.querySelector("#appGUI").$cell({
  1312. id: "appGUI",
  1313. $cell: true,
  1314. $type: "div",
  1315. $components: [reflectorGUI]
  1316. }
  1317. );
  1318. }
  1319. getLoginGUI(){
  1320. let loginGUI =
  1321. {
  1322. $type: "div",
  1323. id: "loginGUI",
  1324. //style:"background-color: #efefef",
  1325. class: "mdc-layout-grid mdc-layout-grid--align-left",
  1326. _alias: null,
  1327. _pass: null,
  1328. _passField: null,
  1329. _aliasField: null,
  1330. _initData: function () {
  1331. this._alias = '';
  1332. this._pass = '';
  1333. // if (window.sessionStorage.getItem('alias')) {
  1334. // this._alias = window.sessionStorage.getItem('alias')
  1335. // }
  1336. // if (window.sessionStorage.getItem('tmp')) {
  1337. // this._pass = window.sessionStorage.getItem('tmp')
  1338. // }
  1339. },
  1340. $init: function () {
  1341. this._initData();
  1342. },
  1343. $update: function () {
  1344. this.$components = [
  1345. {
  1346. $type: "div",
  1347. class: "mdc-layout-grid__inner",
  1348. $components: [
  1349. {
  1350. $type: "div",
  1351. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1352. $components: [
  1353. {
  1354. $type: "span",
  1355. class: "mdc-typography--headline5",
  1356. $text: _l.t("login") + ": "
  1357. },
  1358. window._app.widgets.inputTextFieldOutlined({
  1359. "id": 'aliasInput',
  1360. "label": _l.t("login"),
  1361. "value": this._alias,
  1362. "type": "text",
  1363. "init": function () {
  1364. this._aliasField = new mdc.textField.MDCTextField(this);
  1365. }
  1366. }),
  1367. ]
  1368. },
  1369. {
  1370. $type: "div",
  1371. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1372. $components: [
  1373. {
  1374. $type: "span",
  1375. class: "mdc-typography--headline5",
  1376. $text: _l.t("password") + ": "
  1377. },
  1378. window._app.widgets.inputTextFieldOutlined({
  1379. "id": 'passwordInput',
  1380. "label": _l.t("password"),
  1381. "value": this._pass,
  1382. "type": "password",
  1383. "init": function () {
  1384. this._passField = new mdc.textField.MDCTextField(this);
  1385. }
  1386. }),
  1387. ]
  1388. },
  1389. {
  1390. $type: "div",
  1391. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1392. $components: [
  1393. window._app.widgets.buttonRaised(
  1394. {
  1395. "label": _l.t("sign up"),
  1396. "onclick": function (e) {
  1397. e.preventDefault();
  1398. let alias = this._aliasField.value;
  1399. let pass = this._passField.value
  1400. if (pass.length < 7) {
  1401. new Noty({
  1402. text: "Your passphrase needs to be longer than 7 letters",
  1403. timeout: 2000,
  1404. theme: 'mint',
  1405. layout: 'bottomRight',
  1406. type: 'error'
  1407. }).show();
  1408. } else {
  1409. //
  1410. _LCSDB.user().create(alias, pass,
  1411. function (ack) {
  1412. if (!ack.wait) { }
  1413. if (ack.err) {
  1414. console.log(ack.err)
  1415. return ack.err
  1416. };
  1417. if (ack.pub) {
  1418. let userObj = {
  1419. 'alias': alias,
  1420. 'pub': ack.pub
  1421. };
  1422. _LCSDB.get('users').get(alias).put(userObj);
  1423. }
  1424. _LCSDB.user().auth(alias, pass);
  1425. });
  1426. }
  1427. }
  1428. }),
  1429. _app.widgets.space,
  1430. window._app.widgets.buttonRaised(
  1431. {
  1432. "label": _l.t("sign in"),
  1433. "onclick": function (e) {
  1434. e.preventDefault();
  1435. let alias = this._aliasField.value;
  1436. let pass = this._passField.value
  1437. _app.helpers.authUser(alias, pass);
  1438. // _LCSDB.user().auth.call(_LCSDB, alias, pass
  1439. // // , function(ack) {
  1440. // // if (ack.err) {
  1441. // // new Noty({
  1442. // // text: ack.err,
  1443. // // timeout: 2000,
  1444. // // theme: 'mint',
  1445. // // layout: 'bottomRight',
  1446. // // type: 'error'
  1447. // // }).show();
  1448. // // }
  1449. // //}
  1450. // );
  1451. }
  1452. })
  1453. ]
  1454. }
  1455. ]
  1456. }
  1457. ]
  1458. }
  1459. }
  1460. return loginGUI
  1461. }
  1462. }
  1463. export { Widgets }