operations-schemes.js 12 KB

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