operations-schemes.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. value: 'SEMICOLON'
  53. },
  54. {
  55. name: '+',
  56. value: 'PLUS'
  57. },
  58. {
  59. name: '-',
  60. value: 'MINUS'
  61. },
  62. {
  63. name: '*',
  64. value: 'MULTIPLICATION'
  65. },
  66. {
  67. name: '/',
  68. value: 'DIVISION'
  69. },
  70. {
  71. name: '(',
  72. value: 'OPEN_PARENTHESES'
  73. },
  74. {
  75. name: ')',
  76. value: 'CLOSE_PARENTHESES'
  77. },
  78. ]
  79. // *********************************************************************************
  80. // Operator kinds
  81. // *********************************************************************************
  82. export const operatorKinds = [
  83. {
  84. name: 'Variável',
  85. value: 'VARIABLE'
  86. },
  87. {
  88. name: 'Valor',
  89. value: 'VALUE'
  90. }
  91. ]
  92. // *********************************************************************************
  93. // Operation type html schemes
  94. // *********************************************************************************
  95. export function htmlOperationTypeScheme () {
  96. let operationTypesSelect = ``;
  97. for (let i = 0; i < operationTypes.length; i++) {
  98. operationTypesSelect += `<option value="${operationTypes[i].value}">${operationTypes[i].name}</option>`;
  99. }
  100. return `<div class="col-2">
  101. <select id="operation<operationKindId>Select" class="form-control" title="selecione o tipo da operação" >
  102. <option > selecione</option>
  103. ${operationTypesSelect}
  104. </select>
  105. </div>`;
  106. }
  107. // *********************************************************************************
  108. // Assign variable operation kind html schemes
  109. // *********************************************************************************
  110. export function htmlOperationKindScheme (operation) {
  111. let operatorKindsSelect = ``;
  112. for (let i = 0; i < operatorKinds.length; i++) {
  113. operatorKindsSelect += `<option value="${operatorKinds[i].value}">${operatorKinds[i].name}</option>`;
  114. }
  115. return `<div class="col-3">
  116. <select id="operation${operation.hash}KindSelect" class="form-control" title="Selecione o tipo de atrabuição" operation-id="${operation.hash}">
  117. <option >Selecione</option>
  118. ${operatorKindsSelect}
  119. </select>
  120. </div>`;
  121. }
  122. // *********************************************************************************
  123. // Assign variable html schemes
  124. // *********************************************************************************
  125. export function htmlAssignVariableScheme () {
  126. const variablesSelect = htmlVariablesSelectScheme();
  127. return `<li id="operation<operationId>Li">
  128. <form id="operation<operationId>Form">
  129. <div class="row p-2 w-100 variable-item" style="background-color: aliceblue;">
  130. <div class="col-2 my-auto">
  131. <select title="selecione a variável" id="operation<operationId>AssignVariableSelect" class="form-control" name="variableSelect" operation-id="<operationId>">
  132. ${variablesSelect}
  133. </select>
  134. </div>
  135. <div class="col-1 my-auto">
  136. <label id="recebe" style="margin-bottom: 0px !important">recebe</label>
  137. </div>
  138. <div class="col">
  139. <div class="row" id="operation<operationId>OperatorsDiv"></div>
  140. </div>
  141. <div class="col-1 my-auto" style="text-align: end;">
  142. <a id="operation<operationId>Delete" href="javascript:void(0)" class="text-danger" operation-id="<operationId>">X</a>
  143. </div>
  144. </div>
  145. </form>
  146. </li>`;
  147. }
  148. // *********************************************************************************
  149. // Variable select html schemes
  150. // *********************************************************************************
  151. export function htmlVariablesSelectScheme () {
  152. let variablesSelect = variables.length === 0 ? `<option>N/A</option>` : ``;
  153. for (let i = 0; i < variables.length; i++) {
  154. variablesSelect += `<option value="${variables[i].hash}">${variables[i].name}</option>`
  155. }
  156. return variablesSelect;
  157. }
  158. // *********************************************************************************
  159. // *********************************************************************************
  160. // Operator variable select
  161. // *********************************************************************************
  162. export function htmlOperatorVariablesSelectScheme (operation, operator) {
  163. let variablesSelect = variables.length === 0 ? `<option>N/A</option>` : ``;
  164. for (let i = 0; i < variables.length; i++) {
  165. variablesSelect += `<option value="${variables[i].hash}">${variables[i].name}</option>`
  166. }
  167. return `<div class="col-2">
  168. <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}">
  169. ${variablesSelect}
  170. </select>
  171. </div>`;
  172. }
  173. // *********************************************************************************
  174. // Operator value input
  175. // *********************************************************************************
  176. export function htmlOperatorValueInputScheme (operation, operator) {
  177. return `<div class="col-2">
  178. <input type="number" id="operation${operation.hash}Operator${operator.hash}ValueInput" class="form-control" name="" title="valor" operation-id="${operation.hash}" operator-id="${operator.hash}">
  179. </div>`;
  180. }
  181. // *********************************************************************************
  182. // Operation type select
  183. // *********************************************************************************
  184. export function htmlOperationTypeSelect (operation, operator) {
  185. let operationTypesSelect = ``;
  186. for (let i = 0; i < operationTypes.length; i++) {
  187. operationTypesSelect += `<option value="${operationTypes[i].value}">${operationTypes[i].name}</option>`;
  188. }
  189. return `<div class="col-2">
  190. <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}">
  191. ${operationTypesSelect}
  192. </select>
  193. </div>`;
  194. }
  195. // *********************************************************************************
  196. // Util
  197. // *********************************************************************************
  198. export function getOperatorTypeByValue (value) {
  199. for (let i = 0; i < operatorTypes.length; i++) {
  200. if (operatorTypes[i].value === value)
  201. return operatorTypes[i];
  202. }
  203. return null;
  204. }
  205. // *********************************************************************************
  206. export function getOperationTypeByValue (value) {
  207. for (let i = 0; i < operationTypes.length; i++) {
  208. if (operationTypes[i].value === value)
  209. return operationTypes[i];
  210. }
  211. return null;
  212. }
  213. // *********************************************************************************
  214. export function getOperatorByHash (operation, operatorHash) {
  215. for (let i = 0; i < operation.operators.length; i++) {
  216. if (operation.operators[i].hash === operatorHash)
  217. return operation.operators[i];
  218. }
  219. return null;
  220. }
  221. // *********************************************************************************