operations-schemes.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. <div class="row justify-content-end">
  150. <div class="col-1" style="margin-right: 4px;">
  151. <a id="operation<operationId>Resume" href="javascript:void(0)" class="text-info" operation-id="<operationId>">
  152. <i class="fas fa-eye"></i>
  153. </a>
  154. </div>
  155. <div class="col-1">
  156. <a id="operation<operationId>Delete" href="javascript:void(0)" class="text-danger" operation-id="<operationId>" title="Excluir">X</a>
  157. </div>
  158. </div>
  159. </div>
  160. </div>
  161. </form>
  162. </li>`;
  163. }
  164. // *********************************************************************************
  165. // Variable select html schemes
  166. // *********************************************************************************
  167. export function htmlVariablesSelectScheme () {
  168. let variablesSelect = variables.length === 0 ? `<option>N/A</option>` : ``;
  169. for (let i = 0; i < variables.length; i++) {
  170. variablesSelect += `<option value="${variables[i].hash}">${variables[i].name}</option>`
  171. }
  172. return variablesSelect;
  173. }
  174. // *********************************************************************************
  175. // *********************************************************************************
  176. // Operator variable select
  177. // *********************************************************************************
  178. export function htmlOperatorVariablesSelectScheme (operation, operator) {
  179. let variablesSelect = variables.length === 0 ? `<option>N/A</option>` : ``;
  180. for (let i = 0; i < variables.length; i++) {
  181. variablesSelect += `<option value="${variables[i].hash}">${variables[i].name}</option>`
  182. }
  183. return `<div class="col-2">
  184. <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}">
  185. ${variablesSelect}
  186. </select>
  187. </div>`;
  188. }
  189. // *********************************************************************************
  190. // Operator value input
  191. // *********************************************************************************
  192. export function htmlOperatorValueInputScheme (operation, operator) {
  193. return `<div class="col-2">
  194. <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}">
  195. </div>`;
  196. }
  197. // *********************************************************************************
  198. // Operation type select
  199. // *********************************************************************************
  200. export function htmlOperationTypeSelect (operation, operator) {
  201. let operationTypesSelect = ``;
  202. for (let i = 0; i < operationTypes.length; i++) {
  203. operationTypesSelect += `<option value="${operationTypes[i].value}" title="${operationTypes[i].friendlyName}">${operationTypes[i].name}</option>`;
  204. }
  205. return `<div class="col-2">
  206. <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}">
  207. ${operationTypesSelect}
  208. </select>
  209. </div>`;
  210. }
  211. // *********************************************************************************
  212. // Util
  213. // *********************************************************************************
  214. export function getOperatorTypeByValue (value) {
  215. for (let i = 0; i < operatorTypes.length; i++) {
  216. if (operatorTypes[i].value === value)
  217. return operatorTypes[i];
  218. }
  219. return null;
  220. }
  221. // *********************************************************************************
  222. export function getOperationTypeByValue (value) {
  223. for (let i = 0; i < operationTypes.length; i++) {
  224. if (operationTypes[i].value === value)
  225. return operationTypes[i];
  226. }
  227. return null;
  228. }
  229. // *********************************************************************************
  230. export function getOperatorByHash (operation, operatorHash) {
  231. for (let i = 0; i < operation.operators.length; i++) {
  232. if (operation.operators[i].hash === operatorHash)
  233. return operation.operators[i];
  234. }
  235. return null;
  236. }
  237. // *********************************************************************************