operations-schemes.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. // Imports
  2. import {variables} from "../variables/variables";
  3. import {eltP} from "codemirror/src/util/dom";
  4. import {operations} from "./operations";
  5. // Imports
  6. // *********************************************************************************
  7. // Scheme for the operations list
  8. // *********************************************************************************
  9. export const operationScheme = {
  10. hash: 'UUID for the operation',
  11. assignedVariable: 'Reference to the assigned variable',
  12. operators: []
  13. }
  14. // *********************************************************************************
  15. // Scheme for the operators
  16. // *********************************************************************************
  17. export const operatorScheme = {
  18. hash: 'UUID for the operator',
  19. type: 'Operator type',
  20. value: 'Operator value',
  21. variable: 'Reference to the variable',
  22. operator: 'Reference to operator'
  23. }
  24. // *********************************************************************************
  25. // Operator types
  26. // *********************************************************************************
  27. export const Operators = {
  28. VARIABLE: 'VARIABLE',
  29. VALUE: 'VALUE',
  30. OPERATOR: 'OPERATOR'
  31. }
  32. export const operatorTypes = [
  33. {
  34. name: 'Variável',
  35. value: Operators.VARIABLE
  36. },
  37. {
  38. name: 'Valor',
  39. value: Operators.VALUE
  40. },
  41. {
  42. name: 'Operator',
  43. value: Operators.OPERATOR
  44. }
  45. ]
  46. // *********************************************************************************
  47. // Operation types
  48. // *********************************************************************************
  49. export const operationTypes = [
  50. {
  51. name: ';',
  52. friendlyName: 'Fim',
  53. value: 'SEMICOLON'
  54. },
  55. {
  56. name: '+',
  57. friendlyName: 'Soma',
  58. value: 'PLUS'
  59. },
  60. {
  61. name: '-',
  62. friendlyName: 'Subtração',
  63. value: 'MINUS'
  64. },
  65. {
  66. name: '*',
  67. friendlyName: 'Multiplicação',
  68. value: 'MULTIPLICATION'
  69. },
  70. {
  71. name: '/',
  72. friendlyName: 'Divisão',
  73. value: 'DIVISION'
  74. },
  75. {
  76. name: '(',
  77. friendlyName: 'Abre parenteses',
  78. value: 'OPEN_PARENTHESES'
  79. },
  80. {
  81. name: ')',
  82. friendlyName: 'Fecha parenteses',
  83. value: 'CLOSE_PARENTHESES'
  84. },
  85. ]
  86. // *********************************************************************************
  87. // Operator kinds
  88. // *********************************************************************************
  89. export const operatorKinds = [
  90. {
  91. name: 'Variável',
  92. value: 'VARIABLE'
  93. },
  94. {
  95. name: 'Valor',
  96. value: 'VALUE'
  97. }
  98. ]
  99. // *********************************************************************************
  100. // Operation type html schemes
  101. // *********************************************************************************
  102. export function htmlOperationTypeScheme () {
  103. let operationTypesSelect = ``;
  104. for (let i = 0; i < operationTypes.length; i++) {
  105. operationTypesSelect += `<option value="${operationTypes[i].value}">${operationTypes[i].name}</option>`;
  106. }
  107. return `<div class="col-2">
  108. <select id="operation<operationKindId>Select" class="form-control" title="selecione o tipo da operação" >
  109. <option > selecione</option>
  110. ${operationTypesSelect}
  111. </select>
  112. </div>`;
  113. }
  114. // *********************************************************************************
  115. // Assign variable operation kind html schemes
  116. // *********************************************************************************
  117. export function htmlOperationKindScheme (operation) {
  118. let operatorKindsSelect = ``;
  119. for (let i = 0; i < operatorKinds.length; i++) {
  120. operatorKindsSelect += `<option value="${operatorKinds[i].value}">${operatorKinds[i].name}</option>`;
  121. }
  122. return `<div class="col-3">
  123. <select id="operation${operation.hash}KindSelect" class="form-control" title="Selecione o tipo de atrabuição" operation-id="${operation.hash}">
  124. <option >Selecione</option>
  125. ${operatorKindsSelect}
  126. </select>
  127. </div>`;
  128. }
  129. // *********************************************************************************
  130. // Assign variable html schemes
  131. // *********************************************************************************
  132. export function htmlAssignVariableScheme () {
  133. const variablesSelect = htmlVariablesSelectScheme();
  134. return `<li id="operation<operationId>Li">
  135. <form id="operation<operationId>Form">
  136. <div class="row p-2 w-100 variable-item" style="background-color: aliceblue;">
  137. <div class="col-2 my-auto">
  138. <select title="Selecione a variável" id="operation<operationId>AssignVariableSelect" class="form-control" name="variableSelect" operation-id="<operationId>">
  139. ${variablesSelect}
  140. </select>
  141. </div>
  142. <div class="col-1 my-auto">
  143. <label for="operation<operationId>AssignVariableSelect" style="margin-bottom: 0px !important" tabindex="0" title="Recebe">recebe</label>
  144. </div>
  145. <div class="col">
  146. <div class="row" id="operation<operationId>OperatorsDiv"></div>
  147. </div>
  148. <div class="col-1 my-auto" style="text-align: end;">
  149. <a id="operation<operationId>Delete" href="javascript:void(0)" class="text-danger" operation-id="<operationId>" title="Excluir">X</a>
  150. </div>
  151. </div>
  152. </form>
  153. </li>`;
  154. }
  155. // *********************************************************************************
  156. // Variable select html schemes
  157. // *********************************************************************************
  158. export function htmlVariablesSelectScheme () {
  159. let variablesSelect = variables.length === 0 ? `<option>N/A</option>` : ``;
  160. for (let i = 0; i < variables.length; i++) {
  161. variablesSelect += `<option value="${variables[i].hash}">${variables[i].name}</option>`
  162. }
  163. return variablesSelect;
  164. }
  165. // *********************************************************************************
  166. // *********************************************************************************
  167. // Operator variable select
  168. // *********************************************************************************
  169. export function htmlOperatorVariablesSelectScheme (operation, operator) {
  170. let variablesSelect = variables.length === 0 ? `<option>N/A</option>` : ``;
  171. for (let i = 0; i < variables.length; i++) {
  172. variablesSelect += `<option value="${variables[i].hash}">${variables[i].name}</option>`
  173. }
  174. return `<div class="col-2">
  175. <select id="operation${operation.hash}Operator${operator.hash}VariableSelect" class="form-control" name="variableSelect" title="Selecione a variável" operation-id="${operation.hash}" operator-id="${operator.hash}">
  176. ${variablesSelect}
  177. </select>
  178. </div>`;
  179. }
  180. // *********************************************************************************
  181. // Operator value input
  182. // *********************************************************************************
  183. export function htmlOperatorValueInputScheme (operation, operator) {
  184. return `<div class="col-2">
  185. <input type="number" id="operation${operation.hash}Operator${operator.hash}ValueInput" class="form-control" name="" title="Insira um valor" operation-id="${operation.hash}" operator-id="${operator.hash}">
  186. </div>`;
  187. }
  188. // *********************************************************************************
  189. // Operation type select
  190. // *********************************************************************************
  191. export function htmlOperationTypeSelect (operation, operator) {
  192. let operationTypesSelect = ``;
  193. for (let i = 0; i < operationTypes.length; i++) {
  194. operationTypesSelect += `<option value="${operationTypes[i].value}" title="${operationTypes[i].friendlyName}">${operationTypes[i].name}</option>`;
  195. }
  196. return `<div class="col-2">
  197. <select id="operation${operation.hash}Operator${operator.hash}OperationTypeSelect" class="form-control" title="selecione o tipo da operação" operation-id="${operation.hash}" operator-id="${operator.hash}">
  198. ${operationTypesSelect}
  199. </select>
  200. </div>`;
  201. }
  202. // *********************************************************************************
  203. // Util
  204. // *********************************************************************************
  205. export function getOperatorTypeByValue (value) {
  206. for (let i = 0; i < operatorTypes.length; i++) {
  207. if (operatorTypes[i].value === value)
  208. return operatorTypes[i];
  209. }
  210. return null;
  211. }
  212. // *********************************************************************************
  213. export function getOperationTypeByValue (value) {
  214. for (let i = 0; i < operationTypes.length; i++) {
  215. if (operationTypes[i].value === value)
  216. return operationTypes[i];
  217. }
  218. return null;
  219. }
  220. // *********************************************************************************
  221. export function getOperatorByHash (operation, operatorHash) {
  222. for (let i = 0; i < operation.operators.length; i++) {
  223. if (operation.operators[i].hash === operatorHash)
  224. return operation.operators[i];
  225. }
  226. return null;
  227. }
  228. // *********************************************************************************