widgets.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. /*
  2. * Cell widgets
  3. */
  4. class Widgets {
  5. constructor() {
  6. console.log("widget constructor")
  7. }
  8. get divider(){
  9. return {
  10. $cell: true,
  11. $type: "hr",
  12. class: "mdc-list-divider",
  13. }
  14. }
  15. inputTextFieldOutlined(obj){
  16. function initFunc() {
  17. new mdc.textField.MDCTextField.attachTo(this);
  18. }
  19. let inputType = obj.type ? obj.type: 'text';
  20. let init = obj.init ? obj.init: initFunc;
  21. let style = obj.style ? obj.style: "";
  22. return {
  23. $cell: true,
  24. $type: "div",
  25. class: "mdc-text-field mdc-text-field--outlined mdc-text-field--dense",
  26. style: style,
  27. $init: init,
  28. $components:[
  29. {
  30. $type: "input",
  31. type: inputType,
  32. id: obj.id,
  33. class: "mdc-text-field__input",
  34. value: obj.value,
  35. onchange: obj.change
  36. },
  37. {
  38. $type: "label",
  39. class: "mdc-floating-label",
  40. for: obj.id,
  41. $text: obj.label
  42. },
  43. {
  44. $type: "div",
  45. class: "mdc-notched-outline",
  46. $components:[
  47. {
  48. $type: "svg",
  49. $components:[
  50. {
  51. $type: "path",
  52. class: "mdc-notched-outline__path"
  53. }
  54. ]
  55. }
  56. ]
  57. },
  58. {
  59. $type: "div",
  60. class: "mdc-notched-outline__idle"
  61. }
  62. ]
  63. //onclick: obj.onclick
  64. }
  65. }
  66. inputTextFieldStandart(obj){
  67. return {
  68. $cell: true,
  69. $type: "div",
  70. class: "mdc-text-field text-field mdc-ripple-upgraded",
  71. $init: function(){
  72. //new mdc.mdc.notchedOutline.MDCNotchedOutline(document.querySelector('.mdc-notched-outline'));
  73. new mdc.textField.MDCTextField.attachTo(this);
  74. },
  75. $components:[
  76. {
  77. $type: "input",
  78. type: "text",
  79. id: obj.id,
  80. class: "mdc-text-field__input",
  81. value: obj.value,
  82. onchange: obj.change
  83. },
  84. {
  85. $type: "label",
  86. class: "mdc-floating-label",
  87. for: obj.id,
  88. $text: obj.label
  89. },
  90. {
  91. $type: "div",
  92. class: "mdc-line-ripple"
  93. }
  94. ]
  95. //onclick: obj.onclick
  96. }
  97. }
  98. headerH3(headertype, label, cssclass) {
  99. return {
  100. $cell: true,
  101. $type: headertype,
  102. class: cssclass,
  103. $text: label
  104. }
  105. }
  106. simpleCard(obj){
  107. let style = 'background-image: url(' + obj.imgSrc + '); background-size: cover; background-repeat: no-repeat; height:' + obj.imgHeight + ';';
  108. var addonClass = obj.addonClass;
  109. if (!addonClass){
  110. addonClass = ''
  111. }
  112. return {
  113. $cell: true,
  114. $type: "div",
  115. $components:[
  116. {
  117. $cell: true,
  118. $type: "div",
  119. class: "mdc-card" +' '+ addonClass,
  120. onclick: obj.onclickfunc,
  121. $components:[
  122. {
  123. $cell: true,
  124. $type: "section",
  125. class: "mdc-card__media",
  126. style: style
  127. },
  128. {
  129. $cell: true,
  130. $type: "section",
  131. class: "mdc-card__supporting-text",
  132. $text: obj.text
  133. }
  134. ]
  135. }
  136. ]
  137. }
  138. }
  139. listDivider() {
  140. return {
  141. $cell: true,
  142. $type: "hr",
  143. class: "mdc-list-divider mdc-list-divider--inset"
  144. }
  145. }
  146. createListItem(obj) {
  147. return {
  148. $cell: true,
  149. $type: "li",
  150. class: "mdc-list-item",
  151. $components: [
  152. {
  153. $cell: true,
  154. $type: "span",
  155. class: "mdc-list-item__graphic",
  156. $components: [
  157. {
  158. $cell: true,
  159. class: "createItems",
  160. $type: "img",
  161. src: obj.imgSrc,
  162. onclick: obj.onclickfunc
  163. }
  164. ]
  165. },
  166. {
  167. $cell: true,
  168. $type: "span",
  169. class: "mdc-list-item__text",
  170. $text: obj.title
  171. // $components: [
  172. // {
  173. // $text: obj.title
  174. // },
  175. // {
  176. // $cell: true,
  177. // $type: "span",
  178. // class: "mdc-list-item__secondary-text",
  179. // $text: obj.subTitle
  180. // }
  181. // ]
  182. }
  183. ]
  184. }
  185. }
  186. createCard(obj){
  187. return {
  188. $cell: true,
  189. $type: "div",
  190. $components:[
  191. {
  192. $cell: true,
  193. $type: "div",
  194. class: "mdc-card",
  195. $components:[
  196. {
  197. $cell: true,
  198. $type: "div",
  199. class: "mdc-card__horizontal-block",
  200. $components:[
  201. {
  202. $cell: true,
  203. $type: "section",
  204. class: "mdc-card__primary",
  205. $components:[
  206. {
  207. $cell: true,
  208. $type: "h1",
  209. class: "mdc-card__title mdc-card__title--large",
  210. $text: obj.title
  211. },
  212. {
  213. $cell: true,
  214. $type: "h2",
  215. class: "mdc-card__subtitle",
  216. $text: obj.subTitle
  217. }
  218. ]
  219. },
  220. {
  221. $cell: true,
  222. $type: "img",
  223. class: "",
  224. src: obj.imgSrc
  225. }
  226. ]
  227. },
  228. {
  229. $cell: true,
  230. $type: "section",
  231. class: "mdc-card__actions",
  232. $components:[
  233. {
  234. $cell: true,
  235. $type: "button",
  236. class: "mdc-button mdc-button--compact mdc-card__action",
  237. $text: obj.actionLabel
  238. }
  239. ]
  240. }
  241. ]
  242. }
  243. ]
  244. }
  245. }
  246. buttonStroked(obj){
  247. return {
  248. $cell: true,
  249. $type: "button",
  250. class: "mdc-button mdc-button--outlined",
  251. $text: obj.label,
  252. onclick: obj.onclick
  253. }
  254. }
  255. buttonRaised(obj){
  256. return {
  257. $cell: true,
  258. $type: "button",
  259. class: "mdc-button mdc-button--raised mdc-ripple-upgraded",
  260. $text: obj.label,
  261. onclick: obj.onclick
  262. }
  263. }
  264. buttonSimple(obj){
  265. return {
  266. $cell: true,
  267. $type: "button",
  268. class: "mdc-button",
  269. $text: obj.label,
  270. onclick: obj.onclick
  271. }
  272. }
  273. sliderDiscrete(obj) {
  274. return {
  275. $cell: true,
  276. $type: "div",
  277. class: "mdc-slider mdc-slider--discrete",
  278. role: "slider",
  279. 'aria-valuemin': obj.min,
  280. 'aria-valuemax': obj.max,
  281. 'aria-label': obj.label,
  282. $init: obj.init,
  283. $components: [
  284. {
  285. $cell: true,
  286. $type: "div",
  287. class: "mdc-slider__track-container",
  288. $components: [
  289. {
  290. $cell: true,
  291. $type: "div",
  292. class: "mdc-slider__track",
  293. }
  294. ]
  295. },
  296. {
  297. $cell: true,
  298. $type: "div",
  299. class: "mdc-slider__thumb-container",
  300. $components: [
  301. {
  302. $cell: true,
  303. $type: "div",
  304. class: "mdc-slider__pin",
  305. $components: [
  306. {
  307. $cell: true,
  308. $type: "span",
  309. class: "mdc-slider__pin-value-marker",
  310. }
  311. ]
  312. },
  313. {
  314. $cell: true,
  315. $type: "svg",
  316. class: "mdc-slider__thumb",
  317. width: 21,
  318. height: 21,
  319. $components: [
  320. {
  321. $cell: true,
  322. $type: "circle",
  323. cx: 10.5,
  324. cy: 10.5,
  325. r: 7.875
  326. }
  327. ]
  328. },
  329. {
  330. $cell: true,
  331. $type: "div",
  332. class: "mdc-slider__focus-ring"
  333. }
  334. ]
  335. }
  336. ]
  337. }
  338. }
  339. sliderContinuous(obj) {
  340. return {
  341. $cell: true,
  342. $type: "div",
  343. class: "mdc-slider",
  344. role: "slider",
  345. tabindex: 0,
  346. 'id': obj.id,
  347. 'aria-valuemin': obj.min,
  348. 'aria-valuemax': obj.max,
  349. 'aria-label': obj.label,
  350. 'aria-valuenow': obj.value,
  351. 'data-step': obj.step,
  352. $init: obj.init,
  353. $components: [
  354. {
  355. $cell: true,
  356. $type: "div",
  357. class: "mdc-slider__track-container",
  358. $components: [
  359. {
  360. $cell: true,
  361. $type: "div",
  362. class: "mdc-slider__track",
  363. }
  364. ]
  365. },
  366. {
  367. $cell: true,
  368. $type: "div",
  369. class: "mdc-slider__thumb-container",
  370. $components: [
  371. {
  372. $cell: true,
  373. $type: "svg",
  374. class: "mdc-slider__thumb",
  375. width: 21,
  376. height: 21,
  377. $components: [
  378. {
  379. $cell: true,
  380. $type: "circle",
  381. cx: 10.5,
  382. cy: 10.5,
  383. r: 7.875
  384. }
  385. ]
  386. },
  387. {
  388. $cell: true,
  389. $type: "div",
  390. class: "mdc-slider__focus-ring"
  391. }
  392. ]
  393. }
  394. ]
  395. }
  396. }
  397. textField(obj) {
  398. return {
  399. class: "mdc-text-field",
  400. style: "width: 100%",
  401. $cell: true,
  402. $type: "div",
  403. $components: [
  404. {
  405. class: "mdc-text-field__input prop-text-field-input",
  406. id: obj.id,
  407. $cell: true,
  408. $type: "input",
  409. type: "text",
  410. value: obj.value,
  411. onchange: obj.funconchange
  412. }
  413. ]
  414. }
  415. }
  416. icontoggle(obj) {
  417. var addClass = "";
  418. if (obj.styleClass){
  419. addClass = obj.styleClass;
  420. }
  421. return {
  422. $type: "i",
  423. class: addClass + " mdc-icon-toggle material-icons",
  424. role: "button",
  425. $text: obj.label,
  426. id: obj.id,
  427. 'data-toggle-on': obj.on,
  428. 'data-toggle-off': obj.off,
  429. 'aria-pressed': obj.state,
  430. 'aria-hidden': true,
  431. $init: obj.init
  432. }
  433. }
  434. floatActionButton(obj) {
  435. var addClass = "";
  436. if (obj.styleClass){
  437. addClass = obj.styleClass;
  438. }
  439. return {
  440. $cell: true,
  441. $type: "button",
  442. class: "mdc-fab material-icons " + addClass,
  443. onclick: obj.onclickfunc,
  444. $components:[
  445. {
  446. $cell: true,
  447. $type: "span",
  448. class: "mdc-fab__icon",
  449. $text: obj.label
  450. }
  451. ]
  452. }
  453. }
  454. iconButton(obj) {
  455. var addClass = "";
  456. if (obj.styleClass){
  457. addClass = obj.styleClass;
  458. }
  459. return {
  460. $cell: true,
  461. $type: "button",
  462. class: "mdc-button" + addClass,
  463. onclick: obj.onclickfunc,
  464. $components:[
  465. {
  466. $cell: true,
  467. $type: "i",
  468. class: "material-icons mdc-button__icon",
  469. $text: obj.label
  470. }
  471. ]
  472. }
  473. }
  474. imageButton(obj){
  475. return {
  476. $cell: true,
  477. $type: "button",
  478. class: "mdc-button mdc-button--compact",
  479. onclick: obj.onclickfunc,
  480. $components:[
  481. {
  482. $cell: true,
  483. class: obj.styleClass,
  484. $type: "img",
  485. src: obj.imgSrc
  486. }
  487. ]
  488. }
  489. }
  490. gridListItem(obj) {
  491. return {
  492. $cell: true,
  493. $type: "li",
  494. class: "mdc-grid-tile " + obj.styleClass,
  495. $components:[
  496. {
  497. $cell: true,
  498. class: "mdc-grid-tile__primary",
  499. $type: "div",
  500. style: "background-color: transparent;",
  501. $components:[
  502. {
  503. $cell: true,
  504. class: "mdc-grid-tile__primary-content tooltip",
  505. $type: "div",
  506. 'aria-label': obj.title,
  507. alt: obj.title,
  508. style: "background-image: url("+ obj.imgSrc + ");",
  509. onclick: obj.onclickfunc,
  510. $components:[
  511. {
  512. $cell: true,
  513. class: "tooltiptext",
  514. $type: "span",
  515. $text: obj.title
  516. }
  517. ]
  518. }
  519. ]
  520. }
  521. ]
  522. }
  523. }
  524. switch(obj) {
  525. return {
  526. $cell: true,
  527. $type: "div",
  528. class: "mdc-switch",
  529. _switch: null,
  530. id: obj.id,
  531. $init: obj.init,
  532. //function(){
  533. // new mdc.switchControl.MDCSwitch(this);
  534. // },
  535. $components: [
  536. {
  537. $type: "div",
  538. class: "mdc-switch__track",
  539. },
  540. {
  541. $type: "div",
  542. class: "mdc-switch__thumb-underlay",
  543. $components:[
  544. {
  545. $type: "div",
  546. class: "mdc-switch__thumb",
  547. $components:[
  548. {
  549. $type: "input",
  550. type: "checkbox",
  551. class: "mdc-switch__native-control",
  552. id: 'input-' + obj.id,
  553. //$init: obj.init,
  554. //id: "basic-switch",
  555. onchange: obj.onchange,
  556. role: "switch"
  557. }
  558. ]
  559. }
  560. ]
  561. }
  562. // {
  563. // $type: "div",
  564. // class: "mdc-switch__background",
  565. // $components: [
  566. // {
  567. // $type: "div",
  568. // class: "mdc-switch__knob"
  569. // }
  570. // ]
  571. // }
  572. ]
  573. }
  574. }
  575. reflectorGUI() {
  576. let reflectorGUI =
  577. {
  578. $type: "div",
  579. id: "reflectorGUI",
  580. //style:"background-color: #efefef",
  581. class: "mdc-layout-grid mdc-layout-grid--align-left",
  582. _reflectorHost: null,
  583. _dbHost: null,
  584. _refHostField: null,
  585. _dbHostField: null,
  586. _initData: function () {
  587. this._reflectorHost = '';
  588. this._dbHost = '';
  589. let config = JSON.parse(localStorage.getItem('lcs_config'));
  590. if (config.reflector) {
  591. this._reflectorHost = config.reflector
  592. }
  593. if (config.dbhost) {
  594. this._dbHost =config.dbhost
  595. }
  596. },
  597. $init: function () {
  598. this._initData();
  599. },
  600. $update: function () {
  601. this.$components = [
  602. {
  603. $type: "div",
  604. class: "mdc-layout-grid__inner",
  605. $components: [
  606. {
  607. $type: "div",
  608. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  609. $components: [
  610. {
  611. $type: "h4",
  612. class: "mdc-typography--headline4",
  613. $text: "Connection settings"
  614. }
  615. ]
  616. },
  617. {
  618. $type: "div",
  619. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  620. $components: [
  621. {
  622. $type: "span",
  623. class: "mdc-typography--headline5",
  624. $text: "Reflector: "
  625. },
  626. window._app.widgets.inputTextFieldOutlined({
  627. "id": 'reflectorInput',
  628. "label": "Reflector",
  629. "value": this._reflectorHost,
  630. "type": "text",
  631. "init": function() {
  632. this._refHostField = new mdc.textField.MDCTextField(this);
  633. },
  634. "style": 'width: 400px;'
  635. }),
  636. ]
  637. },
  638. {
  639. $type: "div",
  640. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  641. $components: [
  642. {
  643. $type: "span",
  644. class: "mdc-typography--headline5",
  645. $text: "DB Host: "
  646. },
  647. window._app.widgets.inputTextFieldOutlined({
  648. "id": 'dbhostInput',
  649. "label": "DB Host",
  650. "value": this._dbHost,
  651. "type": "text",
  652. "init": function() {
  653. this._dbHostField = new mdc.textField.MDCTextField(this);
  654. },
  655. "style": 'width: 400px;'
  656. }),
  657. ]
  658. },
  659. {
  660. $type: "div",
  661. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  662. $components: [
  663. window._app.widgets.buttonRaised(
  664. {
  665. "label": 'Update',
  666. "onclick": function (e) {
  667. e.preventDefault();
  668. let config = JSON.parse(localStorage.getItem('lcs_config'));
  669. config.reflector = this._refHostField.value;
  670. config.dbhost = this._dbHostField.value;
  671. localStorage.setItem('lcs_config', JSON.stringify(config));
  672. window.location.reload(true);
  673. }
  674. }),
  675. {
  676. $type: 'span',
  677. $text: " "
  678. },
  679. {
  680. $type: "button",
  681. class: "mdc-button mdc-button--raised",
  682. $text: "Close",
  683. onclick: function (e) {
  684. window.location.pathname = '/'
  685. }
  686. }
  687. ]
  688. }
  689. ]
  690. }
  691. ]
  692. }
  693. }
  694. document.querySelector("#appGUI").$cell({
  695. id: "appGUI",
  696. $cell: true,
  697. $type: "div",
  698. $components: [reflectorGUI]
  699. }
  700. );
  701. }
  702. }
  703. export { Widgets }