widgets.js 67 KB

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