123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- // 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;
- }
- // *********************************************************************************
|