Browse Source

feat: added logic to generate resume and update them when needed

Marcelo Vilas Boas Correa Filho 3 years ago
parent
commit
758c64c4b6

+ 41 - 2
js/accessibleUI/modules/operations/operations.js

@@ -39,6 +39,7 @@ export function createOperation () {
     });
 
     addOperatorKind(operation.hash);
+    updateResume(operation.hash);
 
     // Changing focus to the variable type after creation for screen readers
     document.getElementById(`operation${operation.hash}AssignVariableSelect`).focus();
@@ -97,6 +98,8 @@ export function insertVariableAfterOperationKind (kindSelect, operation) {
         updateOperationOperator(ev.target.getAttribute('operation-id'), ev.target.getAttribute('operator-id'), ev.target.value)
     });
 
+    updateResume(operation.hash);
+
     // Changing focus to the variable select after select for screen readers
     document.getElementById(`operation${operation.hash}Operator${operator.hash}VariableSelect`).focus();
 }
@@ -121,11 +124,13 @@ export function insertValueAfterOperationKind (kindSelect, operation) {
         updateOperationOperator(ev.target.getAttribute('operation-id'), ev.target.getAttribute('operator-id'), ev.target.value)
     });
 
+    updateResume(operation.hash);
+
     // Changing focus to the input value after select for screen readers
     document.getElementById(`operation${operation.hash}Operator${operator.hash}ValueInput`).focus();
 }
 
-// Add final operation typt end of the operation
+// Add final operation type end of the operation
 export function insertOperationTypeAtEndOfOperation (operation, afterOperator) {
     let operator = Object.assign({}, operatorScheme);
 
@@ -144,7 +149,6 @@ export function insertOperationTypeAtEndOfOperation (operation, afterOperator) {
         document.querySelector(`input[operator-id='${afterOperator.hash}']`).parentElement.insertAdjacentHTML('afterend', operationTypeInput);
     }
 
-
     document.getElementById(`operation${operation.hash}Operator${operator.hash}OperationTypeSelect`).addEventListener('change', ev => {
         updateOperationOperator(ev.target.getAttribute('operation-id'), ev.target.getAttribute('operator-id'), ev.target.value)
     });
@@ -159,6 +163,8 @@ export function updateOperationAssignValue (operationHash, newVariable) {
     let variable = getVariableByHash(newVariable);
 
     operation.assignedVariable = variable;
+
+    updateResume(operation.hash);
 }
 
 export function updateOperationOperator (operationHash, operatorHash, newValue) {
@@ -203,6 +209,8 @@ export function updateOperationOperator (operationHash, operatorHash, newValue)
                 }
             break;
     }
+
+    updateResume(operation.hash);
 }
 
 // Here we remove all operation that include the variable received as parameter
@@ -259,6 +267,37 @@ export function deleteAllOperation () {
     operations.length = 0;
 }
 
+// ***********************************************************************
+// Updating variable resume
+// ***********************************************************************
+
+function updateResume (hash) {
+    document.getElementById(`operation${hash}Resume`).setAttribute('title', generateResume(hash));
+}
+
+function generateResume (hash) {
+    const operation = getOperationByHash(hash);
+
+    let resume = `${operation.assignedVariable.name} recebe `;
+
+    for (const i in operation.operators) {
+        console.log(operation.operators[i]);
+        switch (operation.operators[i].type.value) {
+            case Operators.OPERATOR:
+                resume += `${operation.operators[i].operator.friendlyName} `;
+                break;
+            case Operators.VALUE:
+                resume += `${operation.operators[i].value} `;
+                break;
+            case Operators.VARIABLE:
+                resume += `${operation.operators[i].variable.name} `;
+                break;
+        }
+    }
+
+    return resume;
+}
+
 // ***********************************************************************
 // Util
 // ***********************************************************************

+ 18 - 0
js/accessibleUI/modules/variables/variables.js

@@ -51,6 +51,8 @@ export function createVariable () {
         deleteVariable(variableHash);
     });
 
+    updateResume(variable.hash);
+
     // Changing focus to the variable type after creation for screen readers
     document.getElementById(`variable${variable.hash}Type`).focus();
 }
@@ -83,6 +85,8 @@ function updateVariable (hash) {
     if (variable.value !== variableValue) {
         variable.value = variableValue;
     }
+
+    updateResume(hash);
 }
 
 // *********************************************************************************
@@ -106,6 +110,20 @@ export function deleteAllVariable () {
     variables.length = 0
 }
 
+// ***********************************************************************
+// Updating variable resume
+// ***********************************************************************
+
+function updateResume (hash) {
+    document.getElementById(`variable${hash}Resume`).setAttribute('title', generateResume(hash));
+}
+
+function generateResume (hash) {
+    const variable = getVariableByHash(hash);
+
+    return `${variable.type.name} ${variable.name} recebe ${variable.value}`;
+}
+
 // *********************************************************************************
 // Util
 // *********************************************************************************