widgets.js 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  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. return {
  284. $cell: true,
  285. $type: "button",
  286. class: "mdc-button mdc-button--outlined",
  287. $text: obj.label,
  288. onclick: obj.onclick
  289. }
  290. }
  291. buttonRaised(obj){
  292. return {
  293. $cell: true,
  294. $type: "button",
  295. class: "mdc-button mdc-button--raised mdc-ripple-upgraded",
  296. $text: obj.label,
  297. onclick: obj.onclick
  298. }
  299. }
  300. buttonSimple(obj){
  301. return {
  302. $cell: true,
  303. $type: "button",
  304. class: "mdc-button",
  305. $components: [
  306. {
  307. $type: "span",
  308. class: "mdc-button__label",
  309. $text: obj.label
  310. }
  311. ],
  312. onclick: obj.onclick
  313. }
  314. }
  315. sliderDiscrete(obj) {
  316. return {
  317. $cell: true,
  318. $type: "div",
  319. class: "mdc-slider mdc-slider--discrete",
  320. role: "slider",
  321. 'aria-valuemin': obj.min,
  322. 'aria-valuemax': obj.max,
  323. 'aria-label': obj.label,
  324. $init: obj.init,
  325. $components: [
  326. {
  327. $cell: true,
  328. $type: "div",
  329. class: "mdc-slider__track-container",
  330. $components: [
  331. {
  332. $cell: true,
  333. $type: "div",
  334. class: "mdc-slider__track",
  335. }
  336. ]
  337. },
  338. {
  339. $cell: true,
  340. $type: "div",
  341. class: "mdc-slider__thumb-container",
  342. $components: [
  343. {
  344. $cell: true,
  345. $type: "div",
  346. class: "mdc-slider__pin",
  347. $components: [
  348. {
  349. $cell: true,
  350. $type: "span",
  351. class: "mdc-slider__pin-value-marker",
  352. }
  353. ]
  354. },
  355. {
  356. $cell: true,
  357. $type: "svg",
  358. class: "mdc-slider__thumb",
  359. width: 21,
  360. height: 21,
  361. $components: [
  362. {
  363. $cell: true,
  364. $type: "circle",
  365. cx: 10.5,
  366. cy: 10.5,
  367. r: 7.875
  368. }
  369. ]
  370. },
  371. {
  372. $cell: true,
  373. $type: "div",
  374. class: "mdc-slider__focus-ring"
  375. }
  376. ]
  377. }
  378. ]
  379. }
  380. }
  381. sliderContinuous(obj) {
  382. return {
  383. $cell: true,
  384. $type: "div",
  385. class: "mdc-slider",
  386. role: "slider",
  387. tabindex: 0,
  388. 'id': obj.id,
  389. 'aria-valuemin': obj.min,
  390. 'aria-valuemax': obj.max,
  391. 'aria-label': obj.label,
  392. 'aria-valuenow': obj.value,
  393. 'data-step': obj.step,
  394. $init: obj.init,
  395. $components: [
  396. {
  397. $cell: true,
  398. $type: "div",
  399. class: "mdc-slider__track-container",
  400. $components: [
  401. {
  402. $cell: true,
  403. $type: "div",
  404. class: "mdc-slider__track",
  405. }
  406. ]
  407. },
  408. {
  409. $cell: true,
  410. $type: "div",
  411. class: "mdc-slider__thumb-container",
  412. $components: [
  413. {
  414. $cell: true,
  415. $type: "svg",
  416. class: "mdc-slider__thumb",
  417. width: 21,
  418. height: 21,
  419. $components: [
  420. {
  421. $cell: true,
  422. $type: "circle",
  423. cx: 10.5,
  424. cy: 10.5,
  425. r: 7.875
  426. }
  427. ]
  428. },
  429. {
  430. $cell: true,
  431. $type: "div",
  432. class: "mdc-slider__focus-ring"
  433. }
  434. ]
  435. }
  436. ]
  437. }
  438. }
  439. textField(obj) {
  440. return {
  441. class: "mdc-text-field",
  442. style: "width: 100%",
  443. $cell: true,
  444. $type: "div",
  445. $components: [
  446. {
  447. class: "mdc-text-field__input prop-text-field-input",
  448. id: obj.id,
  449. $cell: true,
  450. $type: "input",
  451. type: "text",
  452. value: obj.value,
  453. onchange: obj.funconchange
  454. }
  455. ]
  456. }
  457. }
  458. icontoggle(obj) {
  459. var addClass = "";
  460. if (obj.styleClass){
  461. addClass = obj.styleClass;
  462. }
  463. return {
  464. $type: "button",
  465. class: addClass + " mdc-icon-button",
  466. //$text: obj.label,
  467. id: obj.id,
  468. //'data-toggle-on': obj.on,
  469. // 'data-toggle-off': obj.off,
  470. 'aria-pressed': obj.state,
  471. 'aria-hidden': true,
  472. $init: obj.init,
  473. $components:[
  474. {
  475. $type: "i",
  476. class: "material-icons mdc-icon-button__icon mdc-icon-button__icon--on",
  477. $text: JSON.parse(obj.on).content
  478. },
  479. {
  480. $type: "i",
  481. class: "material-icons mdc-icon-button__icon",
  482. $text: JSON.parse(obj.off).content
  483. },
  484. ]
  485. }
  486. }
  487. floatActionButton(obj) {
  488. var addClass = "";
  489. if (obj.styleClass){
  490. addClass = obj.styleClass;
  491. }
  492. return {
  493. $cell: true,
  494. $type: "button",
  495. class: "mdc-fab material-icons " + addClass,
  496. onclick: obj.onclickfunc,
  497. $components:[
  498. {
  499. $cell: true,
  500. $type: "span",
  501. class: "mdc-fab__icon",
  502. $text: obj.label
  503. }
  504. ]
  505. }
  506. }
  507. iconButton(obj) {
  508. var addClass = "";
  509. if (obj.styleClass){
  510. addClass = obj.styleClass;
  511. }
  512. return {
  513. $cell: true,
  514. $type: "button",
  515. class: "mdc-button " + addClass,
  516. onclick: obj.onclick,
  517. $components:[
  518. {
  519. $cell: true,
  520. $type: "i",
  521. class: "material-icons mdc-button__icon",
  522. $text: obj.label
  523. }
  524. ]
  525. }
  526. }
  527. imageButton(obj){
  528. return {
  529. $cell: true,
  530. $type: "button",
  531. class: "mdc-button mdc-button--compact",
  532. onclick: obj.onclickfunc,
  533. $components:[
  534. {
  535. $cell: true,
  536. class: obj.styleClass,
  537. $type: "img",
  538. src: obj.imgSrc
  539. }
  540. ]
  541. }
  542. }
  543. listTitle(obj){
  544. return {
  545. $type: "div",
  546. class: "mdc-layout-grid__inner",
  547. $components: [
  548. {
  549. $type: "div",
  550. class: "mdc-layout-grid__cell",
  551. $components: [
  552. {
  553. $type: "h3",
  554. class: "",
  555. $text: obj.text
  556. }
  557. ]
  558. }
  559. ]
  560. }
  561. }
  562. gridListItem(obj) {
  563. return {
  564. $type: "div",
  565. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2 tooltip " + obj.styleClass,
  566. $components:[
  567. {
  568. class: "tooltiptext",
  569. $type: "span",
  570. $text: obj.title
  571. },
  572. {
  573. $type: "div",
  574. style: "background-color: transparent;",
  575. $components:[
  576. {
  577. class: "",
  578. $type: "div",
  579. 'aria-label': obj.title,
  580. alt: obj.title,
  581. style: "background-image: url("+ obj.imgSrc + "); background-size: cover; background-repeat: no-repeat; height: "+ obj.imgSize + "; width: " + obj.imgSize + ";",
  582. onclick: obj.onclickfunc,
  583. }
  584. ]
  585. }
  586. ]
  587. }
  588. }
  589. switch(obj) {
  590. return {
  591. $cell: true,
  592. $type: "div",
  593. class: "mdc-switch",
  594. _switch: null,
  595. id: obj.id,
  596. $init: obj.init,
  597. //function(){
  598. // new mdc.switchControl.MDCSwitch(this);
  599. // },
  600. $components: [
  601. {
  602. $type: "div",
  603. class: "mdc-switch__track",
  604. },
  605. {
  606. $type: "div",
  607. class: "mdc-switch__thumb-underlay",
  608. $components:[
  609. {
  610. $type: "div",
  611. class: "mdc-switch__thumb",
  612. $components:[
  613. {
  614. $type: "input",
  615. type: "checkbox",
  616. class: "mdc-switch__native-control",
  617. id: 'input-' + obj.id,
  618. //$init: obj.init,
  619. //id: "basic-switch",
  620. onchange: obj.onchange,
  621. role: "switch"
  622. }
  623. ]
  624. }
  625. ]
  626. }
  627. // {
  628. // $type: "div",
  629. // class: "mdc-switch__background",
  630. // $components: [
  631. // {
  632. // $type: "div",
  633. // class: "mdc-switch__knob"
  634. // }
  635. // ]
  636. // }
  637. ]
  638. }
  639. }
  640. connectionSettingsGUI() {
  641. let connectionSettings = {
  642. id: 'connectionSettings',
  643. $type: 'div',
  644. $components: [
  645. _app.widgets.emptyDiv,
  646. window._app.widgets.buttonRaised(
  647. {
  648. "label": 'Connection settings',
  649. "onclick": function (e) {
  650. e.preventDefault();
  651. window.location.pathname = '/settings';
  652. }
  653. }), _app.widgets.emptyDiv
  654. ]
  655. }
  656. return connectionSettings
  657. }
  658. debugGUI() {
  659. let self = this;
  660. let debug6DoF = {
  661. $cell: true,
  662. $components: [
  663. {
  664. $type: "p",
  665. class: "mdc-typography--headline5",
  666. $text: "Debug 6DoF mode (for using with WebXR emulator)"
  667. },
  668. {
  669. $type: 'p'
  670. },
  671. _app.widgets.switch({
  672. 'id': 'forceDebug6DoF',
  673. 'init': function () {
  674. this._switch = new mdc.switchControl.MDCSwitch(this);
  675. let config = localStorage.getItem('lcs_config');
  676. this._switch.checked = JSON.parse(config).d6DoF;
  677. // this._replaceSwitch = this._switch;
  678. },
  679. 'onchange': function (e) {
  680. if (this._switch) {
  681. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  682. if (chkAttr) {
  683. let config = JSON.parse(localStorage.getItem('lcs_config'));
  684. config.d6DoF = true;
  685. localStorage.setItem('lcs_config', JSON.stringify(config));
  686. //this._switch.checked = false;
  687. } else {
  688. let config = JSON.parse(localStorage.getItem('lcs_config'));
  689. config.d6DoF = false;
  690. localStorage.setItem('lcs_config', JSON.stringify(config));
  691. }
  692. }
  693. }
  694. }
  695. ),
  696. {
  697. $type: 'label',
  698. for: 'input-forceDebug6DoF',
  699. $text: 'On / Off'
  700. }
  701. ]
  702. }
  703. let debug3DoF = {
  704. $cell: true,
  705. $components: [
  706. {
  707. $type: "p",
  708. class: "mdc-typography--headline5",
  709. $text: "Debug 3DoF mode (for using with WebXR emulator)"
  710. },
  711. {
  712. $type: 'p'
  713. },
  714. _app.widgets.switch({
  715. 'id': 'forceDebug3DoF',
  716. 'init': function () {
  717. this._switch = new mdc.switchControl.MDCSwitch(this);
  718. let config = localStorage.getItem('lcs_config');
  719. this._switch.checked = JSON.parse(config).d3DoF;
  720. // this._replaceSwitch = this._switch;
  721. },
  722. 'onchange': function (e) {
  723. if (this._switch) {
  724. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  725. if (chkAttr) {
  726. let config = JSON.parse(localStorage.getItem('lcs_config'));
  727. config.d3DoF = true;
  728. localStorage.setItem('lcs_config', JSON.stringify(config));
  729. //this._switch.checked = false;
  730. } else {
  731. let config = JSON.parse(localStorage.getItem('lcs_config'));
  732. config.d3DoF = false;
  733. localStorage.setItem('lcs_config', JSON.stringify(config));
  734. }
  735. }
  736. }
  737. }
  738. ),
  739. {
  740. $type: 'label',
  741. for: 'input-forceDebug3DoF',
  742. $text: 'On / Off'
  743. }
  744. ]
  745. }
  746. let allGUI =
  747. {
  748. $type: "div",
  749. id: "allGUI",
  750. //style:"background-color: #efefef",
  751. class: "mdc-layout-grid mdc-layout-grid--align-left",
  752. _d3DoF: null,
  753. _d6DoF: null,
  754. _initData: function () {
  755. let config = JSON.parse(localStorage.getItem('lcs_config'));
  756. if (config.d3DoF) {
  757. this._d3DoF = config.d3DoF
  758. }
  759. if (config.d6DoF) {
  760. this._d6DoF =config.d6DoF
  761. }
  762. this._refresh();
  763. },
  764. $init: function () {
  765. this._initData();
  766. },
  767. _refresh: function () {
  768. this.$components = [
  769. {
  770. $type: "div",
  771. class: "mdc-layout-grid__inner",
  772. $components: [
  773. {
  774. $type: "div",
  775. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  776. $components: [
  777. {
  778. $type: "h4",
  779. class: "mdc-typography--headline4",
  780. $text: "Debug settings"
  781. }
  782. ]
  783. },
  784. {
  785. $type: "div",
  786. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  787. $components: [debug6DoF ]
  788. },
  789. {
  790. $type: "div",
  791. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  792. $components: [_app.widgets.divider]
  793. },
  794. {
  795. $type: "div",
  796. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  797. $components: [debug3DoF]
  798. },
  799. {
  800. $type: "div",
  801. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  802. $components: [
  803. // window._app.widgets.buttonRaised(
  804. // {
  805. // "label": 'Update',
  806. // "onclick": function (e) {
  807. // e.preventDefault();
  808. // let config = JSON.parse(localStorage.getItem('lcs_config'));
  809. // config.reflector = this._refHostField.value;
  810. // config.dbhost = this._dbHostField.value;
  811. // config.luminaryPath = this._lpathField.value;
  812. // config.luminaryGlobalHBPath = this._hbpathField.value;
  813. // localStorage.setItem('lcs_config', JSON.stringify(config));
  814. // window.location.reload(true);
  815. // }
  816. // }),
  817. {
  818. $type: 'span',
  819. $text: " "
  820. },
  821. {
  822. $type: "button",
  823. class: "mdc-button mdc-button--raised",
  824. $text: "Close",
  825. onclick: function (e) {
  826. window.history.back();
  827. //window.location.pathname = '/'
  828. }
  829. }
  830. ]
  831. }
  832. ]
  833. }
  834. ]
  835. }
  836. }
  837. document.querySelector("#appGUI").$cell({
  838. id: "appGUI",
  839. $cell: true,
  840. $type: "div",
  841. $components: [allGUI]
  842. }
  843. );
  844. }
  845. reflectorGUI() {
  846. let self = this;
  847. let webrtcConnection = {
  848. $cell: true,
  849. $components: [
  850. {
  851. $type: "p",
  852. class: "mdc-typography--headline5",
  853. $text: "Use WebRTC for connection"
  854. },
  855. {
  856. $type: 'p'
  857. },
  858. _app.widgets.switch({
  859. 'id': 'forceWebRTC',
  860. 'init': function () {
  861. this._switch = new mdc.switchControl.MDCSwitch(this);
  862. let config = localStorage.getItem('lcs_config');
  863. this._switch.checked = JSON.parse(config).webrtc;
  864. // this._replaceSwitch = this._switch;
  865. },
  866. 'onchange': function (e) {
  867. if (this._switch) {
  868. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  869. if (chkAttr) {
  870. let config = JSON.parse(localStorage.getItem('lcs_config'));
  871. config.webrtc = true;
  872. localStorage.setItem('lcs_config', JSON.stringify(config));
  873. //this._switch.checked = false;
  874. } else {
  875. let config = JSON.parse(localStorage.getItem('lcs_config'));
  876. config.webrtc = false;
  877. localStorage.setItem('lcs_config', JSON.stringify(config));
  878. }
  879. }
  880. }
  881. }
  882. ),
  883. {
  884. $type: 'label',
  885. for: 'input-forceWebRTC',
  886. $text: 'On / Off'
  887. }
  888. ]
  889. }
  890. let luminaryGlobalHB = {
  891. $cell: true,
  892. _luminarySwitch: null,
  893. $components: [
  894. {
  895. $type: "p",
  896. class: "mdc-typography--headline5",
  897. $text: "Use Global Heartbeat"
  898. },
  899. {
  900. $type: 'p'
  901. },
  902. _app.widgets.switch({
  903. 'id': 'forceLuminary',
  904. 'init': function () {
  905. this._switch = new mdc.switchControl.MDCSwitch(this);
  906. let config = localStorage.getItem('lcs_config');
  907. this._switch.checked = JSON.parse(config).luminaryGlobalHB;
  908. // this._replaceSwitch = this._switch;
  909. },
  910. 'onchange': function (e) {
  911. if (this._switch) {
  912. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  913. if (chkAttr) {
  914. let config = JSON.parse(localStorage.getItem('lcs_config'));
  915. config.luminaryGlobalHB = true;
  916. localStorage.setItem('lcs_config', JSON.stringify(config));
  917. //this._switch.checked = false;
  918. } else {
  919. let config = JSON.parse(localStorage.getItem('lcs_config'));
  920. config.luminaryGlobalHB = false;
  921. localStorage.setItem('lcs_config', JSON.stringify(config));
  922. }
  923. }
  924. }
  925. }
  926. ),
  927. {
  928. $type: 'label',
  929. for: 'input-forceLuminary',
  930. $text: 'On / Off'
  931. }
  932. ]
  933. }
  934. let luminaryFeature = {
  935. $type: 'div',
  936. _luminarySwitch: null,
  937. $components: [
  938. {
  939. $type: "p",
  940. class: "mdc-typography--headline4",
  941. $text: "Use Krestianstvo Luminary (experimental)"
  942. },
  943. {
  944. $type: 'p'
  945. },
  946. _app.widgets.switch({
  947. 'id': 'forceLuminary',
  948. 'init': function () {
  949. this._switch = new mdc.switchControl.MDCSwitch(this);
  950. let config = localStorage.getItem('lcs_config');
  951. this._switch.checked = JSON.parse(config).luminary;
  952. // this._replaceSwitch = this._switch;
  953. },
  954. 'onchange': function (e) {
  955. if (this._switch) {
  956. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  957. if (chkAttr) {
  958. let config = JSON.parse(localStorage.getItem('lcs_config'));
  959. config.luminary = true;
  960. localStorage.setItem('lcs_config', JSON.stringify(config));
  961. window.location.reload(true);
  962. //this._switch.checked = false;
  963. } else {
  964. let config = JSON.parse(localStorage.getItem('lcs_config'));
  965. config.luminary = false;
  966. localStorage.setItem('lcs_config', JSON.stringify(config));
  967. window.location.reload(true);
  968. }
  969. }
  970. }
  971. }
  972. ),
  973. {
  974. $type: 'label',
  975. for: 'input-forceLuminary',
  976. $text: 'Off / On'
  977. },
  978. _app.widgets.p
  979. ]
  980. }
  981. let reflectorGUI =
  982. {
  983. $type: "div",
  984. id: "reflectorGUI",
  985. //style:"background-color: #efefef",
  986. class: "mdc-layout-grid mdc-layout-grid--align-left",
  987. _reflectorHost: null,
  988. _dbHost: null,
  989. _refHostField: null,
  990. _dbHostField: null,
  991. _lpath: null,
  992. _lpathField: null,
  993. _hbpath: null,
  994. _hbpathField: null,
  995. //_debug: null,
  996. _initData: function () {
  997. this._reflectorHost = '';
  998. this._dbHost = '';
  999. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1000. if (config.reflector) {
  1001. this._reflectorHost = config.reflector
  1002. }
  1003. if (config.dbhost) {
  1004. this._dbHost =config.dbhost
  1005. }
  1006. if (config.luminaryPath) {
  1007. this._lpath = config.luminaryPath
  1008. }
  1009. if (config.luminaryGlobalHBPath) {
  1010. this._hbpath = config.luminaryGlobalHBPath
  1011. }
  1012. // if (config.debug) {
  1013. // this._debug = config.debug
  1014. // }
  1015. },
  1016. $init: function () {
  1017. this._initData();
  1018. },
  1019. $update: function () {
  1020. this.$components = [
  1021. {
  1022. $type: "div",
  1023. class: "mdc-layout-grid__inner",
  1024. $components: [
  1025. {
  1026. $type: "div",
  1027. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1028. $components: [
  1029. {
  1030. $type: "h4",
  1031. class: "mdc-typography--headline4",
  1032. $text: "Gun DB settings"
  1033. }
  1034. ]
  1035. },
  1036. {
  1037. $type: "div",
  1038. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1039. $components: [
  1040. {
  1041. $type: "span",
  1042. class: "mdc-typography--headline5",
  1043. $text: "DB Host: "
  1044. },
  1045. window._app.widgets.inputTextFieldOutlined({
  1046. "id": 'dbhostInput',
  1047. "label": "DB Host",
  1048. "value": this._dbHost,
  1049. "type": "text",
  1050. "init": function() {
  1051. this._dbHostField = new mdc.textField.MDCTextField(this);
  1052. },
  1053. "style": 'width: 400px;'
  1054. }),
  1055. ]
  1056. },
  1057. {
  1058. $type: "div",
  1059. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1060. $components: [
  1061. {
  1062. $type: "h4",
  1063. class: "mdc-typography--headline4",
  1064. $text: "Reflector settings"
  1065. }
  1066. ]
  1067. },
  1068. {
  1069. $type: "div",
  1070. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1071. $components: [
  1072. {
  1073. $type: "span",
  1074. class: "mdc-typography--headline5",
  1075. $text: "Reflector: "
  1076. },
  1077. window._app.widgets.inputTextFieldOutlined({
  1078. "id": 'reflectorInput',
  1079. "label": "Reflector",
  1080. "value": this._reflectorHost,
  1081. "type": "text",
  1082. "init": function() {
  1083. this._refHostField = new mdc.textField.MDCTextField(this);
  1084. },
  1085. "style": 'width: 400px;'
  1086. }),
  1087. ]
  1088. },
  1089. {
  1090. $type: "div",
  1091. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1092. $components: [webrtcConnection ]
  1093. },
  1094. {
  1095. $type: "div",
  1096. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1097. $components: [_app.widgets.divider]
  1098. },
  1099. // {
  1100. // $type: "div",
  1101. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1102. // $components: [
  1103. // {
  1104. // $type: "h4",
  1105. // class: "mdc-typography--headline4",
  1106. // $text: "Krestianstvo Luminary settings (experimental)"
  1107. // }
  1108. // ]
  1109. // },
  1110. {
  1111. $type: "div",
  1112. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1113. $components: [
  1114. luminaryFeature
  1115. ]
  1116. },
  1117. {
  1118. $type: "div",
  1119. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1120. $components: [
  1121. {
  1122. $type: "span",
  1123. class: "mdc-typography--headline5",
  1124. $text: "Luminary Path: "
  1125. },
  1126. window._app.widgets.inputTextFieldOutlined({
  1127. "id": 'lpathInput',
  1128. "label": "Luminary Path",
  1129. "value": this._lpath,
  1130. "type": "text",
  1131. "init": function() {
  1132. this._lpathField = new mdc.textField.MDCTextField(this);
  1133. },
  1134. "style": 'width: 400px;'
  1135. }),
  1136. ]
  1137. },
  1138. {
  1139. $type: "div",
  1140. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1141. $components: [
  1142. {
  1143. $type: "span",
  1144. class: "mdc-typography--headline5",
  1145. $text: "Global Heartbeat Path: "
  1146. },
  1147. window._app.widgets.inputTextFieldOutlined({
  1148. "id": 'hbpathInput',
  1149. "label": "Global Heartbeat Path",
  1150. "value": this._hbpath,
  1151. "type": "text",
  1152. "init": function() {
  1153. this._hbpathField = new mdc.textField.MDCTextField(this);
  1154. },
  1155. "style": 'width: 400px;'
  1156. }),
  1157. ]
  1158. },
  1159. {
  1160. $type: "div",
  1161. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1162. $components: [luminaryGlobalHB ]
  1163. },
  1164. {
  1165. $type: "div",
  1166. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1167. $components: [_app.widgets.divider]
  1168. },
  1169. // {
  1170. // $type: "div",
  1171. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1172. // $components: [debugGUI]
  1173. // },
  1174. {
  1175. $type: "div",
  1176. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1177. $components: [
  1178. window._app.widgets.buttonRaised(
  1179. {
  1180. "label": 'Update',
  1181. "onclick": function (e) {
  1182. e.preventDefault();
  1183. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1184. config.reflector = this._refHostField.value;
  1185. config.dbhost = this._dbHostField.value;
  1186. config.luminaryPath = this._lpathField.value;
  1187. config.luminaryGlobalHBPath = this._hbpathField.value;
  1188. localStorage.setItem('lcs_config', JSON.stringify(config));
  1189. window.location.reload(true);
  1190. }
  1191. }),
  1192. {
  1193. $type: 'span',
  1194. $text: " "
  1195. },
  1196. {
  1197. $type: "button",
  1198. class: "mdc-button mdc-button--raised",
  1199. $text: "Close",
  1200. onclick: function (e) {
  1201. window.history.back();
  1202. //window.location.pathname = '/'
  1203. }
  1204. }
  1205. ]
  1206. }
  1207. ]
  1208. }
  1209. ]
  1210. }
  1211. }
  1212. document.querySelector("#appGUI").$cell({
  1213. id: "appGUI",
  1214. $cell: true,
  1215. $type: "div",
  1216. $components: [reflectorGUI]
  1217. }
  1218. );
  1219. }
  1220. getLoginGUI(){
  1221. let loginGUI =
  1222. {
  1223. $type: "div",
  1224. id: "loginGUI",
  1225. //style:"background-color: #efefef",
  1226. class: "mdc-layout-grid mdc-layout-grid--align-left",
  1227. _alias: null,
  1228. _pass: null,
  1229. _passField: null,
  1230. _aliasField: null,
  1231. _initData: function () {
  1232. this._alias = '';
  1233. this._pass = '';
  1234. // if (window.sessionStorage.getItem('alias')) {
  1235. // this._alias = window.sessionStorage.getItem('alias')
  1236. // }
  1237. // if (window.sessionStorage.getItem('tmp')) {
  1238. // this._pass = window.sessionStorage.getItem('tmp')
  1239. // }
  1240. },
  1241. $init: function () {
  1242. this._initData();
  1243. },
  1244. $update: function () {
  1245. this.$components = [
  1246. {
  1247. $type: "div",
  1248. class: "mdc-layout-grid__inner",
  1249. $components: [
  1250. {
  1251. $type: "div",
  1252. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1253. $components: [
  1254. {
  1255. $type: "span",
  1256. class: "mdc-typography--headline5",
  1257. $text: _l.t("login") + ": "
  1258. },
  1259. window._app.widgets.inputTextFieldOutlined({
  1260. "id": 'aliasInput',
  1261. "label": _l.t("login"),
  1262. "value": this._alias,
  1263. "type": "text",
  1264. "init": function () {
  1265. this._aliasField = new mdc.textField.MDCTextField(this);
  1266. }
  1267. }),
  1268. ]
  1269. },
  1270. {
  1271. $type: "div",
  1272. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1273. $components: [
  1274. {
  1275. $type: "span",
  1276. class: "mdc-typography--headline5",
  1277. $text: _l.t("password") + ": "
  1278. },
  1279. window._app.widgets.inputTextFieldOutlined({
  1280. "id": 'passwordInput',
  1281. "label": _l.t("password"),
  1282. "value": this._pass,
  1283. "type": "password",
  1284. "init": function () {
  1285. this._passField = new mdc.textField.MDCTextField(this);
  1286. }
  1287. }),
  1288. ]
  1289. },
  1290. {
  1291. $type: "div",
  1292. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1293. $components: [
  1294. window._app.widgets.buttonRaised(
  1295. {
  1296. "label": _l.t("sign up"),
  1297. "onclick": function (e) {
  1298. e.preventDefault();
  1299. let alias = this._aliasField.value;
  1300. let pass = this._passField.value
  1301. if (pass.length < 7) {
  1302. new Noty({
  1303. text: "Your passphrase needs to be longer than 7 letters",
  1304. timeout: 2000,
  1305. theme: 'mint',
  1306. layout: 'bottomRight',
  1307. type: 'error'
  1308. }).show();
  1309. } else {
  1310. //
  1311. _LCSDB.user().create(alias, pass,
  1312. function (ack) {
  1313. if (!ack.wait) { }
  1314. if (ack.err) {
  1315. console.log(ack.err)
  1316. return ack.err
  1317. };
  1318. if (ack.pub) {
  1319. let userObj = {
  1320. 'alias': alias,
  1321. 'pub': ack.pub
  1322. };
  1323. _LCSDB.get('users').get(alias).put(userObj);
  1324. }
  1325. _LCSDB.user().auth(alias, pass);
  1326. });
  1327. }
  1328. }
  1329. }),
  1330. _app.widgets.space,
  1331. window._app.widgets.buttonRaised(
  1332. {
  1333. "label": _l.t("sign in"),
  1334. "onclick": function (e) {
  1335. e.preventDefault();
  1336. let alias = this._aliasField.value;
  1337. let pass = this._passField.value
  1338. _app.helpers.authUser(alias, pass);
  1339. // _LCSDB.user().auth.call(_LCSDB, alias, pass
  1340. // // , function(ack) {
  1341. // // if (ack.err) {
  1342. // // new Noty({
  1343. // // text: ack.err,
  1344. // // timeout: 2000,
  1345. // // theme: 'mint',
  1346. // // layout: 'bottomRight',
  1347. // // type: 'error'
  1348. // // }).show();
  1349. // // }
  1350. // //}
  1351. // );
  1352. }
  1353. })
  1354. ]
  1355. }
  1356. ]
  1357. }
  1358. ]
  1359. }
  1360. }
  1361. return loginGUI
  1362. }
  1363. }
  1364. export { Widgets }