widgets.js 66 KB

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