appui.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //-----App ui-----
  2. function createApp() {
  3. let self = this
  4. if(!window._rubik){
  5. window._rubik = {
  6. command: 'Ff'
  7. };
  8. }
  9. function makeRobotButtons() {
  10. let nodeNames = ['Left', 'Right', 'Back', 'Front' ];
  11. return nodeNames.map(el => {
  12. return self.widgets.gridListItem({
  13. imgSrc: "/drivers/model/rubik/assets/" + el.toLowerCase() + ".png",
  14. imgSize: "30px",
  15. styleClass:"", //"createListItem",
  16. title: el,
  17. onclickfunc: function () {
  18. window._LegoView.changeDeviceID(el.toLowerCase());
  19. var status = document.querySelector('#currentRobotID');
  20. status._val = _LegoView.device.id
  21. // status.$components = [
  22. // {
  23. // $type: "h3",
  24. // $text: _LegoView.device.id
  25. // }
  26. // ]
  27. //let sceneID = vwf.find("", "/")[0];
  28. //let boostID = _LegoView.device.id; //_LegoView.isConnected() ? _LegoView.device.id : 'none';
  29. //vwf_view.kernel.callMethod(sceneID, "createLegoBoost", [boostID]);
  30. }
  31. })
  32. })
  33. }
  34. function doFun() {
  35. let sceneID = vwf.find("", "/")[0];
  36. vwf_view.kernel.callMethod(sceneID, "doOnRubik", [window._rubik.command]);
  37. }
  38. return {
  39. $cell: true,
  40. $type: "div",
  41. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  42. $components: [
  43. {
  44. $cell: true,
  45. $type: "div",
  46. class: "mdc-layout-grid__inner",
  47. $components: [
  48. {
  49. $cell: true,
  50. $type: "div",
  51. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  52. $components: [
  53. {
  54. $cell: true,
  55. $type: "button",
  56. class: "mdc-button mdc-button--raised",
  57. $text: "Create Rubik",
  58. onclick: function (e) {
  59. let sceneID = vwf.find("", "/")[0];
  60. let rubikID = "rubik-" + _app.helpers.randId();
  61. vwf_view.kernel.callMethod(sceneID, "createRubik", [rubikID, false]);
  62. }
  63. }
  64. ]
  65. },
  66. {
  67. $type: "div",
  68. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  69. $components: [
  70. {
  71. $type: "h2",
  72. $text: "Rubik Robot"
  73. }
  74. ]
  75. },
  76. {
  77. $cell: true,
  78. $type: "div",
  79. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  80. $components: [
  81. {
  82. $cell: true,
  83. $type: "button",
  84. class: "mdc-button mdc-button--raised",
  85. $text: "Create Rubik & Robot",
  86. onclick: function (e) {
  87. let sceneID = vwf.find("", "/")[0];
  88. let rubikID = "rubik-" + _app.helpers.randId();
  89. vwf_view.kernel.callMethod(sceneID, "createRubik", [rubikID, true]);
  90. }
  91. }
  92. ]
  93. },
  94. {
  95. $type: "div",
  96. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  97. $components: [
  98. {
  99. $type: "div",
  100. class: "mdc-layout-grid__inner",
  101. $components: makeRobotButtons()
  102. }
  103. ]
  104. },
  105. {
  106. $cell: true,
  107. $type: "div",
  108. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  109. id: "currentRobotID",
  110. _val: "none",
  111. $components: [
  112. {
  113. $type: "h3",
  114. $text: _LegoView.device.id
  115. }
  116. ],
  117. $update: function(){
  118. this.$components = [
  119. {
  120. $type: "h3",
  121. $text: this._val
  122. }
  123. ]
  124. }
  125. },
  126. {
  127. $cell: true,
  128. $type: "div",
  129. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  130. $components: [
  131. self.widgets.buttonRaised(
  132. {
  133. "label": _LegoView.isConnected() ? "Disconnect" : "Connect",
  134. "onclick": function (e) {
  135. if (!_LegoView.isConnected()) {
  136. this.$text = 'Disconnect';
  137. _LegoView.connect();
  138. } else {
  139. this.$text = 'Connect';
  140. _LegoView.disconnect();
  141. }
  142. }
  143. }
  144. )
  145. ]
  146. },
  147. {
  148. $cell: true,
  149. $type: "div",
  150. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  151. $components: [
  152. self.widgets.inputTextFieldOutlined({
  153. "id": 'commandt',
  154. "label": "Command: ",
  155. "value": window._rubik.command,
  156. "change": function (e) {
  157. window._rubik.command = this.value;
  158. }
  159. })
  160. ]
  161. },
  162. {
  163. $cell: true,
  164. $type: "div",
  165. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  166. $components: [
  167. self.widgets.buttonRaised(
  168. {
  169. "label": "DO",
  170. "onclick": doFun
  171. })
  172. ]
  173. },
  174. _app.widgets.divider
  175. ]
  176. }
  177. ]
  178. }
  179. }