widgets.js 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  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. reflectorGUI() {
  659. let webrtcConnection = {
  660. $cell: true,
  661. $components: [
  662. {
  663. $type: "p",
  664. class: "mdc-typography--headline5",
  665. $text: "Use WebRTC for connection"
  666. },
  667. {
  668. $type: 'p'
  669. },
  670. _app.widgets.switch({
  671. 'id': 'forceWebRTC',
  672. 'init': function () {
  673. this._switch = new mdc.switchControl.MDCSwitch(this);
  674. let config = localStorage.getItem('lcs_config');
  675. this._switch.checked = JSON.parse(config).webrtc;
  676. // this._replaceSwitch = this._switch;
  677. },
  678. 'onchange': function (e) {
  679. if (this._switch) {
  680. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  681. if (chkAttr) {
  682. let config = JSON.parse(localStorage.getItem('lcs_config'));
  683. config.webrtc = true;
  684. localStorage.setItem('lcs_config', JSON.stringify(config));
  685. //this._switch.checked = false;
  686. } else {
  687. let config = JSON.parse(localStorage.getItem('lcs_config'));
  688. config.webrtc = false;
  689. localStorage.setItem('lcs_config', JSON.stringify(config));
  690. }
  691. }
  692. }
  693. }
  694. ),
  695. {
  696. $type: 'label',
  697. for: 'input-forceWebRTC',
  698. $text: 'On / Off'
  699. }
  700. ]
  701. }
  702. let luminaryGlobalHB = {
  703. $cell: true,
  704. _luminarySwitch: null,
  705. $components: [
  706. {
  707. $type: "p",
  708. class: "mdc-typography--headline5",
  709. $text: "Use Global Heartbeat"
  710. },
  711. {
  712. $type: 'p'
  713. },
  714. _app.widgets.switch({
  715. 'id': 'forceLuminary',
  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).luminaryGlobalHB;
  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.luminaryGlobalHB = 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.luminaryGlobalHB = false;
  733. localStorage.setItem('lcs_config', JSON.stringify(config));
  734. }
  735. }
  736. }
  737. }
  738. ),
  739. {
  740. $type: 'label',
  741. for: 'input-forceLuminary',
  742. $text: 'On / Off'
  743. }
  744. ]
  745. }
  746. let luminaryFeature = {
  747. $type: 'div',
  748. _luminarySwitch: null,
  749. $components: [
  750. {
  751. $type: "p",
  752. class: "mdc-typography--headline4",
  753. $text: "Use Krestianstvo Luminary (experimental)"
  754. },
  755. {
  756. $type: 'p'
  757. },
  758. _app.widgets.switch({
  759. 'id': 'forceLuminary',
  760. 'init': function () {
  761. this._switch = new mdc.switchControl.MDCSwitch(this);
  762. let config = localStorage.getItem('lcs_config');
  763. this._switch.checked = JSON.parse(config).luminary;
  764. // this._replaceSwitch = this._switch;
  765. },
  766. 'onchange': function (e) {
  767. if (this._switch) {
  768. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  769. if (chkAttr) {
  770. let config = JSON.parse(localStorage.getItem('lcs_config'));
  771. config.luminary = true;
  772. localStorage.setItem('lcs_config', JSON.stringify(config));
  773. window.location.reload(true);
  774. //this._switch.checked = false;
  775. } else {
  776. let config = JSON.parse(localStorage.getItem('lcs_config'));
  777. config.luminary = false;
  778. localStorage.setItem('lcs_config', JSON.stringify(config));
  779. window.location.reload(true);
  780. }
  781. }
  782. }
  783. }
  784. ),
  785. {
  786. $type: 'label',
  787. for: 'input-forceLuminary',
  788. $text: 'Off / On'
  789. },
  790. _app.widgets.p
  791. ]
  792. }
  793. let reflectorGUI =
  794. {
  795. $type: "div",
  796. id: "reflectorGUI",
  797. //style:"background-color: #efefef",
  798. class: "mdc-layout-grid mdc-layout-grid--align-left",
  799. _reflectorHost: null,
  800. _dbHost: null,
  801. _refHostField: null,
  802. _dbHostField: null,
  803. _lpath: null,
  804. _lpathField: null,
  805. _hbpath: null,
  806. _hbpathField: null,
  807. _initData: function () {
  808. this._reflectorHost = '';
  809. this._dbHost = '';
  810. let config = JSON.parse(localStorage.getItem('lcs_config'));
  811. if (config.reflector) {
  812. this._reflectorHost = config.reflector
  813. }
  814. if (config.dbhost) {
  815. this._dbHost =config.dbhost
  816. }
  817. if (config.luminaryPath) {
  818. this._lpath = config.luminaryPath
  819. }
  820. if (config.luminaryGlobalHBPath) {
  821. this._hbpath = config.luminaryGlobalHBPath
  822. }
  823. },
  824. $init: function () {
  825. this._initData();
  826. },
  827. $update: function () {
  828. this.$components = [
  829. {
  830. $type: "div",
  831. class: "mdc-layout-grid__inner",
  832. $components: [
  833. {
  834. $type: "div",
  835. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  836. $components: [
  837. {
  838. $type: "h4",
  839. class: "mdc-typography--headline4",
  840. $text: "Gun DB settings"
  841. }
  842. ]
  843. },
  844. {
  845. $type: "div",
  846. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  847. $components: [
  848. {
  849. $type: "span",
  850. class: "mdc-typography--headline5",
  851. $text: "DB Host: "
  852. },
  853. window._app.widgets.inputTextFieldOutlined({
  854. "id": 'dbhostInput',
  855. "label": "DB Host",
  856. "value": this._dbHost,
  857. "type": "text",
  858. "init": function() {
  859. this._dbHostField = new mdc.textField.MDCTextField(this);
  860. },
  861. "style": 'width: 400px;'
  862. }),
  863. ]
  864. },
  865. {
  866. $type: "div",
  867. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  868. $components: [
  869. {
  870. $type: "h4",
  871. class: "mdc-typography--headline4",
  872. $text: "Reflector settings"
  873. }
  874. ]
  875. },
  876. {
  877. $type: "div",
  878. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  879. $components: [
  880. {
  881. $type: "span",
  882. class: "mdc-typography--headline5",
  883. $text: "Reflector: "
  884. },
  885. window._app.widgets.inputTextFieldOutlined({
  886. "id": 'reflectorInput',
  887. "label": "Reflector",
  888. "value": this._reflectorHost,
  889. "type": "text",
  890. "init": function() {
  891. this._refHostField = new mdc.textField.MDCTextField(this);
  892. },
  893. "style": 'width: 400px;'
  894. }),
  895. ]
  896. },
  897. {
  898. $type: "div",
  899. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  900. $components: [webrtcConnection ]
  901. },
  902. {
  903. $type: "div",
  904. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  905. $components: [_app.widgets.divider]
  906. },
  907. // {
  908. // $type: "div",
  909. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  910. // $components: [
  911. // {
  912. // $type: "h4",
  913. // class: "mdc-typography--headline4",
  914. // $text: "Krestianstvo Luminary settings (experimental)"
  915. // }
  916. // ]
  917. // },
  918. {
  919. $type: "div",
  920. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  921. $components: [
  922. luminaryFeature
  923. ]
  924. },
  925. {
  926. $type: "div",
  927. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  928. $components: [
  929. {
  930. $type: "span",
  931. class: "mdc-typography--headline5",
  932. $text: "Luminary Path: "
  933. },
  934. window._app.widgets.inputTextFieldOutlined({
  935. "id": 'lpathInput',
  936. "label": "Luminary Path",
  937. "value": this._lpath,
  938. "type": "text",
  939. "init": function() {
  940. this._lpathField = new mdc.textField.MDCTextField(this);
  941. },
  942. "style": 'width: 400px;'
  943. }),
  944. ]
  945. },
  946. {
  947. $type: "div",
  948. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  949. $components: [
  950. {
  951. $type: "span",
  952. class: "mdc-typography--headline5",
  953. $text: "Global Heartbeat Path: "
  954. },
  955. window._app.widgets.inputTextFieldOutlined({
  956. "id": 'hbpathInput',
  957. "label": "Global Heartbeat Path",
  958. "value": this._hbpath,
  959. "type": "text",
  960. "init": function() {
  961. this._hbpathField = new mdc.textField.MDCTextField(this);
  962. },
  963. "style": 'width: 400px;'
  964. }),
  965. ]
  966. },
  967. {
  968. $type: "div",
  969. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  970. $components: [luminaryGlobalHB ]
  971. },
  972. {
  973. $type: "div",
  974. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  975. $components: [
  976. window._app.widgets.buttonRaised(
  977. {
  978. "label": 'Update',
  979. "onclick": function (e) {
  980. e.preventDefault();
  981. let config = JSON.parse(localStorage.getItem('lcs_config'));
  982. config.reflector = this._refHostField.value;
  983. config.dbhost = this._dbHostField.value;
  984. config.luminaryPath = this._lpathField.value;
  985. config.luminaryGlobalHBPath = this._hbpathField.value;
  986. localStorage.setItem('lcs_config', JSON.stringify(config));
  987. window.location.reload(true);
  988. }
  989. }),
  990. {
  991. $type: 'span',
  992. $text: " "
  993. },
  994. {
  995. $type: "button",
  996. class: "mdc-button mdc-button--raised",
  997. $text: "Close",
  998. onclick: function (e) {
  999. window.location.pathname = '/'
  1000. }
  1001. }
  1002. ]
  1003. }
  1004. ]
  1005. }
  1006. ]
  1007. }
  1008. }
  1009. document.querySelector("#appGUI").$cell({
  1010. id: "appGUI",
  1011. $cell: true,
  1012. $type: "div",
  1013. $components: [reflectorGUI]
  1014. }
  1015. );
  1016. }
  1017. getLoginGUI(){
  1018. let loginGUI =
  1019. {
  1020. $type: "div",
  1021. id: "loginGUI",
  1022. //style:"background-color: #efefef",
  1023. class: "mdc-layout-grid mdc-layout-grid--align-left",
  1024. _alias: null,
  1025. _pass: null,
  1026. _passField: null,
  1027. _aliasField: null,
  1028. _initData: function () {
  1029. this._alias = '';
  1030. this._pass = '';
  1031. // if (window.sessionStorage.getItem('alias')) {
  1032. // this._alias = window.sessionStorage.getItem('alias')
  1033. // }
  1034. // if (window.sessionStorage.getItem('tmp')) {
  1035. // this._pass = window.sessionStorage.getItem('tmp')
  1036. // }
  1037. },
  1038. $init: function () {
  1039. this._initData();
  1040. },
  1041. $update: function () {
  1042. this.$components = [
  1043. {
  1044. $type: "div",
  1045. class: "mdc-layout-grid__inner",
  1046. $components: [
  1047. {
  1048. $type: "div",
  1049. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1050. $components: [
  1051. {
  1052. $type: "span",
  1053. class: "mdc-typography--headline5",
  1054. $text: _l.t("login") + ": "
  1055. },
  1056. window._app.widgets.inputTextFieldOutlined({
  1057. "id": 'aliasInput',
  1058. "label": _l.t("login"),
  1059. "value": this._alias,
  1060. "type": "text",
  1061. "init": function () {
  1062. this._aliasField = new mdc.textField.MDCTextField(this);
  1063. }
  1064. }),
  1065. ]
  1066. },
  1067. {
  1068. $type: "div",
  1069. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1070. $components: [
  1071. {
  1072. $type: "span",
  1073. class: "mdc-typography--headline5",
  1074. $text: _l.t("password") + ": "
  1075. },
  1076. window._app.widgets.inputTextFieldOutlined({
  1077. "id": 'passwordInput',
  1078. "label": _l.t("password"),
  1079. "value": this._pass,
  1080. "type": "password",
  1081. "init": function () {
  1082. this._passField = new mdc.textField.MDCTextField(this);
  1083. }
  1084. }),
  1085. ]
  1086. },
  1087. {
  1088. $type: "div",
  1089. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1090. $components: [
  1091. window._app.widgets.buttonRaised(
  1092. {
  1093. "label": _l.t("sign up"),
  1094. "onclick": function (e) {
  1095. e.preventDefault();
  1096. let alias = this._aliasField.value;
  1097. let pass = this._passField.value
  1098. if (pass.length < 7) {
  1099. new Noty({
  1100. text: "Your passphrase needs to be longer than 7 letters",
  1101. timeout: 2000,
  1102. theme: 'mint',
  1103. layout: 'bottomRight',
  1104. type: 'error'
  1105. }).show();
  1106. } else {
  1107. //
  1108. _LCSDB.user().create(alias, pass,
  1109. function (ack) {
  1110. if (!ack.wait) { }
  1111. if (ack.err) {
  1112. console.log(ack.err)
  1113. return ack.err
  1114. };
  1115. if (ack.pub) {
  1116. let userObj = {
  1117. 'alias': alias,
  1118. 'pub': ack.pub
  1119. };
  1120. _LCSDB.get('users').get(alias).put(userObj);
  1121. }
  1122. _LCSDB.user().auth(alias, pass);
  1123. });
  1124. }
  1125. }
  1126. }),
  1127. _app.widgets.space,
  1128. window._app.widgets.buttonRaised(
  1129. {
  1130. "label": _l.t("sign in"),
  1131. "onclick": function (e) {
  1132. e.preventDefault();
  1133. let alias = this._aliasField.value;
  1134. let pass = this._passField.value
  1135. _app.helpers.authUser(alias, pass);
  1136. // _LCSDB.user().auth.call(_LCSDB, alias, pass
  1137. // // , function(ack) {
  1138. // // if (ack.err) {
  1139. // // new Noty({
  1140. // // text: ack.err,
  1141. // // timeout: 2000,
  1142. // // theme: 'mint',
  1143. // // layout: 'bottomRight',
  1144. // // type: 'error'
  1145. // // }).show();
  1146. // // }
  1147. // //}
  1148. // );
  1149. }
  1150. })
  1151. ]
  1152. }
  1153. ]
  1154. }
  1155. ]
  1156. }
  1157. }
  1158. return loginGUI
  1159. }
  1160. }
  1161. export { Widgets }