|
@@ -6,7 +6,7 @@ import {
|
|
|
htmlAssignVariableScheme,
|
|
|
htmlOperationKindScheme, htmlOperationTypeSelect, htmlOperatorValueInputScheme,
|
|
|
htmlOperatorVariablesSelectScheme,
|
|
|
- operationScheme, operatorScheme, operatorTypes
|
|
|
+ operationScheme, Operators, operatorScheme, operatorTypes
|
|
|
} from "./operations-schemes";
|
|
|
import {getVariableByHash, variables} from "../variables/variables";
|
|
|
// Imports
|
|
@@ -34,6 +34,10 @@ export function createOperation () {
|
|
|
updateOperationAssignValue(ev.target.getAttribute('operation-id'), ev.target.value);
|
|
|
});
|
|
|
|
|
|
+ document.getElementById(`operation${operation.hash}Delete`).addEventListener('click', ev => {
|
|
|
+ deleteOperation(ev.target.getAttribute('operation-id'));
|
|
|
+ });
|
|
|
+
|
|
|
addOperatorKind(operation.hash);
|
|
|
}
|
|
|
|
|
@@ -81,8 +85,8 @@ export function insertVariableAfterOperationKind (kindSelect, operation) {
|
|
|
|
|
|
operation.operators.push(operator);
|
|
|
|
|
|
- kindSelect.insertAdjacentHTML('afterend', operatorVariableSelect);
|
|
|
- kindSelect.remove();
|
|
|
+ kindSelect.parentElement.parentElement.insertAdjacentHTML('beforeend', operatorVariableSelect);
|
|
|
+ kindSelect.parentElement.remove();
|
|
|
|
|
|
insertOperationTypeAtEndOfOperation(operation, operator);
|
|
|
|
|
@@ -102,8 +106,8 @@ export function insertValueAfterOperationKind (kindSelect, operation) {
|
|
|
|
|
|
operation.operators.push(operator);
|
|
|
|
|
|
- kindSelect.insertAdjacentHTML('afterend', operatorValueInput);
|
|
|
- kindSelect.remove();
|
|
|
+ kindSelect.parentElement.parentElement.insertAdjacentHTML('beforeend', operatorValueInput);
|
|
|
+ kindSelect.parentElement.remove();
|
|
|
|
|
|
insertOperationTypeAtEndOfOperation(operation, operator);
|
|
|
|
|
@@ -126,9 +130,9 @@ export function insertOperationTypeAtEndOfOperation (operation, afterOperator) {
|
|
|
operation.operators.push(operator);
|
|
|
|
|
|
if (afterOperator.type.value === 'VARIABLE') {
|
|
|
- document.querySelector(`select[operator-id='${afterOperator.hash}']`).insertAdjacentHTML('afterend', operationTypeInput);
|
|
|
+ document.querySelector(`select[operator-id='${afterOperator.hash}']`).parentElement.insertAdjacentHTML('afterend', operationTypeInput);
|
|
|
} else if (afterOperator.type.value === 'VALUE') {
|
|
|
- document.querySelector(`input[operator-id='${afterOperator.hash}']`).insertAdjacentHTML('afterend', operationTypeInput);
|
|
|
+ document.querySelector(`input[operator-id='${afterOperator.hash}']`).parentElement.insertAdjacentHTML('afterend', operationTypeInput);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -162,12 +166,57 @@ export function updateOperationOperator (operationHash, operatorHash, newValue)
|
|
|
break;
|
|
|
case 'OPERATOR':
|
|
|
operator.operator = getOperationTypeByValue(newValue);
|
|
|
- if (operator.operator.name !== ';')
|
|
|
+ if (operator.operator.name !== ';' && (operation.operators.indexOf(operator) === (operation.operators.length - 1)))
|
|
|
addOperatorKind(operation.hash);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// Here we remove all operation that include the variable received as parameter
|
|
|
+export function deleteOperationByVariable (variable) {
|
|
|
+ const operationsToRemove = [];
|
|
|
+
|
|
|
+ for (const i in operations) {
|
|
|
+
|
|
|
+ console.log(operations[i]);
|
|
|
+
|
|
|
+ if (operations[i].assignedVariable.hash === variable.hash) {
|
|
|
+ document.getElementById(`operation${operations[i].hash}Li`).remove();
|
|
|
+ operationsToRemove.push(operations[i]);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (const j in operations[i].operators) {
|
|
|
+ console.log(j);
|
|
|
+ console.log(operations[i].operators[j]);
|
|
|
+ if (operations[i].operators[j].type.value === Operators.VARIABLE) {
|
|
|
+ if (operations[i].operators[j].variable.hash === variable.hash) {
|
|
|
+ document.getElementById(`operation${operations[i].hash}Li`).remove();
|
|
|
+ operationsToRemove.push(operations[i]);
|
|
|
+ // if (operation.operators.length > 2) {
|
|
|
+ //
|
|
|
+ // } else {
|
|
|
+ //
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (const i in operationsToRemove) {
|
|
|
+ operations.splice(operations.indexOf(operationsToRemove[i]), 1);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Here we remove all operation that include the variable received as parameter
|
|
|
+export function deleteOperation (hash) {
|
|
|
+ const operation = getOperationByHash(hash);
|
|
|
+
|
|
|
+ document.getElementById(`operation${hash}Li`).remove();
|
|
|
+
|
|
|
+ operations.splice(operations.indexOf(operation), 1);
|
|
|
+}
|
|
|
+
|
|
|
// ***********************************************************************
|
|
|
// Util
|
|
|
// ***********************************************************************
|