operations-schemes.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 operatorTypes = [
  28. {
  29. name: 'Variável',
  30. value: 'VARIABLE'
  31. },
  32. {
  33. name: 'Valor',
  34. value: 'VALUE'
  35. },
  36. {
  37. name: 'Operator',
  38. value: 'OPERATOR'
  39. }
  40. ]
  41. // *********************************************************************************
  42. // Operation types
  43. // *********************************************************************************
  44. export const operationTypes = [
  45. {
  46. name: ';',
  47. value: 'SEMICOLON'
  48. },
  49. {
  50. name: '+',
  51. value: 'PLUS'
  52. },
  53. {
  54. name: '-',
  55. value: 'MINUS'
  56. },
  57. {
  58. name: '*',
  59. value: 'MULTIPLICATION'
  60. },
  61. {
  62. name: '/',
  63. value: 'DIVISION'
  64. },
  65. {
  66. name: '(',
  67. value: 'OPEN_PARENTHESES'
  68. },
  69. {
  70. name: ')',
  71. value: 'CLOSE_PARENTHESES'
  72. },
  73. ]
  74. // *********************************************************************************
  75. // Operator kinds
  76. // *********************************************************************************
  77. export const operatorKinds = [
  78. {
  79. name: 'Variável',
  80. value: 'VARIABLE'
  81. },
  82. {
  83. name: 'Valor',
  84. value: 'VALUE'
  85. }
  86. ]
  87. // *********************************************************************************
  88. // Operation type html schemes
  89. // *********************************************************************************
  90. export function htmlOperationTypeScheme() {
  91. let operationTypesSelect = ``;
  92. for (let i = 0; i < operationTypes.length; i++) {
  93. operationTypesSelect += `<option value="${operationTypes[i].value}">${operationTypes[i].name}</option>`;
  94. }
  95. return `<select id="operation<operationKindId>Select" title="selecione o tipo da operação" >
  96. <option > selecione</option>
  97. ${operationTypesSelect}
  98. </select>`;
  99. }
  100. // *********************************************************************************
  101. // Assign variable operation kind html schemes
  102. // *********************************************************************************
  103. export function htmlOperationKindScheme(operation) {
  104. let operatorKindsSelect = ``;
  105. for (let i = 0; i < operatorKinds.length; i++) {
  106. operatorKindsSelect += `<option value="${operatorKinds[i].value}">${operatorKinds[i].name}</option>`;
  107. }
  108. return `<select id="operation${operation.hash}KindSelect" title="selecione o tipo de atrabuição" operation-id="${operation.hash}">
  109. <option > selecione</option>
  110. ${operatorKindsSelect}
  111. </select>`;
  112. }
  113. // *********************************************************************************
  114. // Assign variable html schemes
  115. // *********************************************************************************
  116. export function htmlAssignVariableScheme() {
  117. let variablesSelect = htmlVariablesSelectScheme();
  118. return `<li id="operation<operationId>Li">
  119. <div class="row">
  120. <form id="operation<operationId>Form">
  121. <select title="selecione a variável" id="operation<operationId>AssignVariableSelect" name="variableSelect" operation-id="<operationId>">
  122. ${variablesSelect}
  123. </select>
  124. <label id="recebe">recebe </label>
  125. <operators id="operation<operationId>OperatorsDiv"></operators>
  126. <button id="operation<operationId>Delete" type="button" class="btn btn-danger" >Excluir</button>
  127. </form>
  128. </div>
  129. </li>`;
  130. }
  131. // *********************************************************************************
  132. // Variable select html schemes
  133. // *********************************************************************************
  134. export function htmlVariablesSelectScheme() {
  135. let variablesSelect = variables.length === 0 ? `<option>N/A</option>` : ``;
  136. for (let i = 0; i < variables.length; i++) {
  137. variablesSelect += `<option value="${variables[i].hash}">${variables[i].name}</option>`
  138. }
  139. return variablesSelect;
  140. }
  141. // *********************************************************************************
  142. // *********************************************************************************
  143. // Operator variable select
  144. // *********************************************************************************
  145. export function htmlOperatorVariablesSelectScheme(operation, operator) {
  146. let variablesSelect = variables.length === 0 ? `<option>N/A</option>` : ``;
  147. for (let i = 0; i < variables.length; i++) {
  148. variablesSelect += `<option value="${variables[i].hash}">${variables[i].name}</option>`
  149. }
  150. return `<select id="operation${operation.hash}Operator${operator.hash}VariableSelect" name="variableSelect" title="selecione a variável" operation-id="${operation.hash}" operator-id="${operator.hash}">
  151. ${variablesSelect}
  152. </select>`;
  153. }
  154. // *********************************************************************************
  155. // Operator value input
  156. // *********************************************************************************
  157. export function htmlOperatorValueInputScheme(operation, operator) {
  158. return `<input type="number" id="operation${operation.hash}Operator${operator.hash}ValueInput" name="" title="valor" operation-id="${operation.hash}" operator-id="${operator.hash}">`;
  159. }
  160. // *********************************************************************************
  161. // Operation type select
  162. // *********************************************************************************
  163. export function htmlOperationTypeSelect(operation, operator) {
  164. let operationTypesSelect = ``;
  165. for (let i = 0; i < operationTypes.length; i++) {
  166. operationTypesSelect += `<option value="${operationTypes[i].value}">${operationTypes[i].name}</option>`;
  167. }
  168. return `<select id="operation${operation.hash}Operator${operator.hash}OperationTypeSelect" title="selecione o tipo da operação" operation-id="${operation.hash}" operator-id="${operator.hash}">
  169. ${operationTypesSelect}
  170. </select>`;
  171. }
  172. // *********************************************************************************
  173. // Util
  174. // *********************************************************************************
  175. export function getOperatorTypeByValue(value) {
  176. for (let i = 0; i < operatorTypes.length; i++) {
  177. if (operatorTypes[i].value === value)
  178. return operatorTypes[i];
  179. }
  180. return null;
  181. }
  182. // *********************************************************************************
  183. export function getOperationTypeByValue(value) {
  184. for (let i = 0; i < operationTypes.length; i++) {
  185. if (operationTypes[i].value === value)
  186. return operationTypes[i];
  187. }
  188. return null;
  189. }
  190. // *********************************************************************************
  191. export function getOperatorByHash(operation, operatorHash) {
  192. for (let i = 0; i < operation.operators.length; i++) {
  193. if (operation.operators[i].hash === operatorHash)
  194. return operation.operators[i];
  195. }
  196. return null;
  197. }
  198. // *********************************************************************************