// Imports import {variables} from "../variables/variables"; import {eltP} from "codemirror/src/util/dom"; import {operations} from "./operations"; // Imports // ********************************************************************************* // Scheme for the operations list // ********************************************************************************* export const operationScheme = { hash: 'UUID for the operation', assignedVariable: 'Reference to the assigned variable', operators: [] } // ********************************************************************************* // Scheme for the operators // ********************************************************************************* export const operatorScheme = { hash: 'UUID for the operator', type: 'Operator type', value: 'Operator value', variable: 'Reference to the variable', operator: 'Reference to operator' } // ********************************************************************************* // Operator types // ********************************************************************************* export const operatorTypes = [ { name: 'Variável', value: 'VARIABLE' }, { name: 'Valor', value: 'VALUE' }, { name: 'Operator', value: 'OPERATOR' } ] // ********************************************************************************* // Operation types // ********************************************************************************* export const operationTypes = [ { name: ';', value: 'SEMICOLON' }, { name: '+', value: 'PLUS' }, { name: '-', value: 'MINUS' }, { name: '*', value: 'MULTIPLICATION' }, { name: '/', value: 'DIVISION' }, { name: '(', value: 'OPEN_PARENTHESES' }, { name: ')', value: 'CLOSE_PARENTHESES' }, ] // ********************************************************************************* // Operator kinds // ********************************************************************************* export const operatorKinds = [ { name: 'Variável', value: 'VARIABLE' }, { name: 'Valor', value: 'VALUE' } ] // ********************************************************************************* // Operation type html schemes // ********************************************************************************* export function htmlOperationTypeScheme () { let operationTypesSelect = ``; for (let i = 0; i < operationTypes.length; i++) { operationTypesSelect += `<option value="${operationTypes[i].value}">${operationTypes[i].name}</option>`; } return `<select id="operation<operationKindId>Select" title="selecione o tipo da operação" > <option > selecione</option> ${operationTypesSelect} </select>`; } // ********************************************************************************* // Assign variable operation kind html schemes // ********************************************************************************* export function htmlOperationKindScheme (operation) { let operatorKindsSelect = ``; for (let i = 0; i < operatorKinds.length; i++) { operatorKindsSelect += `<option value="${operatorKinds[i].value}">${operatorKinds[i].name}</option>`; } return `<select id="operation${operation.hash}KindSelect" title="selecione o tipo de atrabuição" operation-id="${operation.hash}"> <option > selecione</option> ${operatorKindsSelect} </select>`; } // ********************************************************************************* // Assign variable html schemes // ********************************************************************************* export function htmlAssignVariableScheme () { let variablesSelect = htmlVariablesSelectScheme(); return `<li id="operation<operationId>Li"> <div class="row"> <form id="operation<operationId>Form"> <select title="selecione a variável" id="operation<operationId>AssignVariableSelect" name="variableSelect" operation-id="<operationId>"> ${variablesSelect} </select> <label id="recebe">recebe </label> <operators id="operation<operationId>OperatorsDiv"></operators> <button id="operation<operationId>Delete" type="button" class="btn btn-danger" >Excluir</button> </form> </div> </li>`; } // ********************************************************************************* // Variable select html schemes // ********************************************************************************* export function htmlVariablesSelectScheme () { let variablesSelect = variables.length === 0 ? `<option>N/A</option>` : ``; for (let i = 0; i < variables.length; i++) { variablesSelect += `<option value="${variables[i].hash}">${variables[i].name}</option>` } return variablesSelect; } // ********************************************************************************* // ********************************************************************************* // Operator variable select // ********************************************************************************* export function htmlOperatorVariablesSelectScheme (operation, operator) { let variablesSelect = variables.length === 0 ? `<option>N/A</option>` : ``; for (let i = 0; i < variables.length; i++) { variablesSelect += `<option value="${variables[i].hash}">${variables[i].name}</option>` } 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}"> ${variablesSelect} </select>`; } // ********************************************************************************* // Operator value input // ********************************************************************************* export function htmlOperatorValueInputScheme (operation, operator) { return `<input type="number" id="operation${operation.hash}Operator${operator.hash}ValueInput" name="" title="valor" operation-id="${operation.hash}" operator-id="${operator.hash}">`; } // ********************************************************************************* // Operation type select // ********************************************************************************* export function htmlOperationTypeSelect (operation, operator) { let operationTypesSelect = ``; for (let i = 0; i < operationTypes.length; i++) { operationTypesSelect += `<option value="${operationTypes[i].value}">${operationTypes[i].name}</option>`; } 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}"> ${operationTypesSelect} </select>`; } // ********************************************************************************* // Util // ********************************************************************************* export function getOperatorTypeByValue (value) { for (let i = 0; i < operatorTypes.length; i++) { if (operatorTypes[i].value === value) return operatorTypes[i]; } return null; } // ********************************************************************************* export function getOperationTypeByValue (value) { for (let i = 0; i < operationTypes.length; i++) { if (operationTypes[i].value === value) return operationTypes[i]; } return null; } // ********************************************************************************* export function getOperatorByHash (operation, operatorHash) { for (let i = 0; i < operation.operators.length; i++) { if (operation.operators[i].hash === operatorHash) return operation.operators[i]; } return null; } // *********************************************************************************