operations-schemes.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. type: 'ASSIGN',
  13. operators: [],
  14. editing: true
  15. }
  16. // *********************************************************************************
  17. // Scheme for the operators
  18. // *********************************************************************************
  19. export const operatorScheme = {
  20. hash: 'UUID for the operator',
  21. type: 'Operator type',
  22. value: 'Operator value',
  23. variable: 'Reference to the variable',
  24. operator: 'Reference to operator'
  25. }
  26. // *********************************************************************************
  27. // Operator types
  28. // *********************************************************************************
  29. export const Operators = {
  30. VARIABLE: 'VARIABLE',
  31. VALUE: 'VALUE',
  32. OPERATOR: 'OPERATOR'
  33. }
  34. export const OperatorType = [
  35. {
  36. name: 'Variável',
  37. value: Operators.VARIABLE
  38. },
  39. {
  40. name: 'Valor',
  41. value: Operators.VALUE
  42. },
  43. {
  44. name: 'Operator',
  45. value: Operators.OPERATOR
  46. }
  47. ]
  48. // *********************************************************************************
  49. // Operation types
  50. // *********************************************************************************
  51. export const OperationType = [
  52. {
  53. name: ';',
  54. friendlyName: 'Fim',
  55. value: 'SEMICOLON'
  56. },
  57. {
  58. name: '+',
  59. friendlyName: 'Soma',
  60. value: 'PLUS'
  61. },
  62. {
  63. name: '-',
  64. friendlyName: 'Subtração',
  65. value: 'MINUS'
  66. },
  67. {
  68. name: '*',
  69. friendlyName: 'Multiplicação',
  70. value: 'MULTIPLICATION'
  71. },
  72. {
  73. name: '/',
  74. friendlyName: 'Divisão',
  75. value: 'DIVISION'
  76. },
  77. {
  78. name: '(',
  79. friendlyName: 'Abre parenteses',
  80. value: 'OPEN_PARENTHESES'
  81. },
  82. {
  83. name: ')',
  84. friendlyName: 'Fecha parenteses',
  85. value: 'CLOSE_PARENTHESES'
  86. },
  87. ]
  88. // *********************************************************************************
  89. // Operator kinds
  90. // *********************************************************************************
  91. export const OperatorKind = [
  92. {
  93. name: 'Variável',
  94. value: 'VARIABLE'
  95. },
  96. {
  97. name: 'Valor',
  98. value: 'VALUE'
  99. }
  100. ]
  101. // *********************************************************************************
  102. // Operation type html schemes
  103. // *********************************************************************************
  104. export function htmlOperationTypeScheme () {
  105. let operationTypesSelect = ``;
  106. for (let i = 0; i < OperationType.length; i++) {
  107. operationTypesSelect += `<option value="${OperationType[i].value}">${OperationType[i].name}</option>`;
  108. }
  109. return `<div class="col-2">
  110. <select id="operation<operationKindId>Select" class="form-control" title="selecione o tipo da operação" >
  111. <option > selecione</option>
  112. ${operationTypesSelect}
  113. </select>
  114. <span tabindex="0"></span>
  115. </div>`;
  116. }
  117. // *********************************************************************************
  118. // Assign variable operation kind html schemes
  119. // *********************************************************************************
  120. export function htmlOperationKindScheme (operation) {
  121. let operatorKindsSelect = ``;
  122. for (let i = 0; i < OperatorKind.length; i++) {
  123. operatorKindsSelect += `<option value="${OperatorKind[i].value}">${OperatorKind[i].name}</option>`;
  124. }
  125. return `<div class="col-3">
  126. <select id="operation${operation.hash}KindSelect" class="form-control" title="Selecione o tipo de atribuição" operation-id="${operation.hash}">
  127. <option >Selecione</option>
  128. ${operatorKindsSelect}
  129. </select>
  130. </div>`;
  131. }
  132. // *********************************************************************************
  133. // Assign variable html schemes
  134. // *********************************************************************************
  135. export function htmlAssignVariableScheme () {
  136. const variablesSelect = htmlVariablesSelectScheme();
  137. return `<li id="operation<operationId>Li">
  138. <form id="operation<operationId>Form">
  139. <div class="row p-2 w-100 variable-item" style="background-color: aliceblue;">
  140. <div class="col-2 my-auto">
  141. <select title="Selecione a variável" id="operation<operationId>AssignVariableSelect" class="form-control" name="variableSelect" operation-id="<operationId>">
  142. ${variablesSelect}
  143. </select>
  144. </div>
  145. <div class="col-1 my-auto">
  146. <label for="operation<operationId>AssignVariableSelect" style="margin-bottom: 0px !important" tabindex="0" title="Recebe">recebe</label>
  147. </div>
  148. <div class="col">
  149. <div class="row" id="operation<operationId>OperatorsDiv"></div>
  150. </div>
  151. <div class="col-11 my-auto" style="display: none;" id="operation<operationId>Display" tabindex="0" operation-id="<operationId>" title="Precione 'Enter' para editar">
  152. <code id="operation<operationId>DisplayCode">
  153. </code>
  154. </div>
  155. <div class="col-1 my-auto" style="text-align: end;">
  156. <div class="row justify-content-end">
  157. <div class="col-1" style="margin-right: 4px;">
  158. <a id="operation<operationId>Resume" href="javascript:void(0)" class="text-info" operation-id="<operationId>">
  159. <i class="fas fa-eye"></i>
  160. </a>
  161. </div>
  162. <div class="col-1">
  163. <a id="operation<operationId>Delete" href="javascript:void(0)" class="text-danger" operation-id="<operationId>" title="Excluir">X</a>
  164. </div>
  165. </div>
  166. </div>
  167. </div>
  168. </form>
  169. </li>`;
  170. }
  171. // *********************************************************************************
  172. // Variable select html schemes
  173. // *********************************************************************************
  174. export function htmlVariablesSelectScheme () {
  175. let variablesSelect = variables.length === 0 ? `<option>N/A</option>` : ``;
  176. for (let i = 0; i < variables.length; i++) {
  177. variablesSelect += `<option value="${variables[i].hash}">${variables[i].name}</option>`
  178. }
  179. return variablesSelect;
  180. }
  181. // *********************************************************************************
  182. // *********************************************************************************
  183. // Operator variable select
  184. // *********************************************************************************
  185. export function htmlOperatorVariablesSelectScheme (operation, operator) {
  186. let variablesSelect = variables.length === 0 ? `<option>N/A</option>` : ``;
  187. for (let i = 0; i < variables.length; i++) {
  188. variablesSelect += `<option value="${variables[i].hash}">${variables[i].name}</option>`
  189. }
  190. return `<div class="col-2">
  191. <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}">
  192. ${variablesSelect}
  193. </select>
  194. </div>`;
  195. }
  196. // *********************************************************************************
  197. // Operator value input
  198. // *********************************************************************************
  199. export function htmlOperatorValueInputScheme (operation, operator) {
  200. return `<div class="col-2">
  201. <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}">
  202. </div>`;
  203. }
  204. // *********************************************************************************
  205. // Operation type select
  206. // *********************************************************************************
  207. export function htmlOperationTypeSelect (operation, operator) {
  208. let operationTypesSelect = ``;
  209. for (let i = 0; i < OperationType.length; i++) {
  210. operationTypesSelect += `<option value="${OperationType[i].value}" title="${OperationType[i].friendlyName}">${OperationType[i].name}</option>`;
  211. }
  212. return `<div class="col-2">
  213. <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}">
  214. ${operationTypesSelect}
  215. </select>
  216. </div>`;
  217. }
  218. // *********************************************************************************
  219. // Print operation
  220. // *********************************************************************************
  221. export function printOperationScheme (operation) {
  222. let variablesSelect = variables.length === 0 ? `<option>N/A</option>` : ``;
  223. for (let i = 0; i < variables.length; i++) {
  224. variablesSelect += `<option value="${variables[i].hash}">${variables[i].name}</option>`
  225. }
  226. return `<li id="operation${operation.hash}Li">
  227. <form id="operation${operation.hash}Form">
  228. <div class="row p-2 w-100 variable-item" style="background-color: aliceblue;">
  229. <div class="col-1 my-auto">
  230. <label id="operation${operation.hash}VariableSelectLabel" for="operation${operation.hash}VariableSelect" style="margin-bottom: 0px !important" tabindex="0" title="Escreva">Escreva</label>
  231. </div>
  232. <div class="col-10">
  233. <select id="operation${operation.hash}VariableSelect" class="form-control" name="variableSelect" title="Selecione a variável" operation-id="${operation.hash}">
  234. ${variablesSelect}
  235. </select>
  236. </div>
  237. <div class="col-11 my-auto" style="display: none;" id="operation${operation.hash}Display" tabindex="0" operation-id="${operation.hash}" title="Precione 'Enter' para editar">
  238. <code id="operation${operation.hash}DisplayCode">
  239. </code>
  240. </div>
  241. <div class="col-1 my-auto" style="text-align: end;">
  242. <div class="row justify-content-end">
  243. <div class="col-1" style="margin-right: 4px;">
  244. <a id="operation${operation.hash}Resume" href="javascript:void(0)" class="text-info" operation-id="${operation.hash}">
  245. <i class="fas fa-eye"></i>
  246. </a>
  247. </div>
  248. <div class="col-1">
  249. <a id="operation${operation.hash}Delete" href="javascript:void(0)" class="text-danger" operation-id="${operation.hash}" title="Excluir">X</a>
  250. </div>
  251. </div>
  252. </div>
  253. </div>
  254. </form>
  255. </li>`;
  256. }
  257. // *********************************************************************************
  258. // Util
  259. // *********************************************************************************
  260. export function getOperatorTypeByValue (value) {
  261. for (let i = 0; i < OperatorType.length; i++) {
  262. if (OperatorType[i].value === value)
  263. return OperatorType[i];
  264. }
  265. return null;
  266. }
  267. // *********************************************************************************
  268. export function getOperationTypeByValue (value) {
  269. for (let i = 0; i < OperationType.length; i++) {
  270. if (OperationType[i].value === value)
  271. return OperationType[i];
  272. }
  273. return null;
  274. }
  275. // *********************************************************************************
  276. export function getOperatorByHash (operation, operatorHash) {
  277. for (let i = 0; i < operation.operators.length; i++) {
  278. if (operation.operators[i].hash === operatorHash)
  279. return operation.operators[i];
  280. }
  281. return null;
  282. }
  283. // *********************************************************************************