Browse Source

Implement config with additional settings based on the settings form

Lucas de Souza 5 years ago
parent
commit
63f78d1586
6 changed files with 37 additions and 22 deletions
  1. 11 11
      js/ast/ivprogParser.js
  2. 4 2
      js/main.js
  3. 2 2
      js/typeSystem/parsers.js
  4. 13 1
      js/util/config.js
  5. 6 5
      js/visualUI/algorithm.js
  6. 1 1
      js/visualUI/functions.js

+ 11 - 11
js/ast/ivprogParser.js

@@ -246,7 +246,7 @@ export class IVProgParser {
     const eosToken = this.getToken();
     if (eosToken.type === this.lexerClass.EOS && eosToken.text.match(';')) {
       this.pos++;
-      return;  
+      return;
     }
     throw SyntaxErrorFactory.token_missing_one(';', eosToken);
   }
@@ -294,7 +294,7 @@ export class IVProgParser {
     // Check for array or vector
     // ID[int/IDi?][int/IDj?]
     if (this.checkOpenBrace(true)) {
-      this.pos += 1;    
+      this.pos += 1;
       this.consumeNewLines();
       dim1 = this.parseArrayDimension();
       this.consumeNewLines();
@@ -389,7 +389,7 @@ export class IVProgParser {
       if(dim2 == null) {
         n_columns = new Expressions.IntLiteral(toInt(initial.columns));
         n_columns.sourceInfo = sourceInfo;
-      } 
+      }
     }
     const declaration = new Commands.ArrayDeclaration(idString,
       new ArrayType(typeString, dimensions), n_lines, n_columns, initial, isConst);
@@ -512,7 +512,7 @@ export class IVProgParser {
     return exp;
   }
 
-  /** 
+  /**
    * Returns a list of ArrayLiterals. Helper function for parsing matrices
   */
   parseVectorList (typeString) {
@@ -547,7 +547,7 @@ export class IVProgParser {
       const commaToken = this.getToken();
       if(commaToken.type !== this.lexerClass.COMMA) {
         break;
-      } 
+      }
       this.pos += 1;
       this.consumeNewLines();
     }
@@ -603,7 +603,7 @@ export class IVProgParser {
     this.pos++;
     this.consumeNewLines();
     if (!this.checkCloseParenthesis(true)) {
-      formalParams = this.parseFormalParameters(); // formal parameters 
+      formalParams = this.parseFormalParameters(); // formal parameters
       this.consumeNewLines();
       this.checkCloseParenthesis();
       this.pos++;
@@ -694,7 +694,7 @@ export class IVProgParser {
     const token = this.getToken();
     if(token.type !== this.lexerClass.ID && token.type !== this.lexerClass.LIB_ID) {
       throw SyntaxErrorFactory.id_missing(token);
-    } 
+    }
     this.pos++;
     return token.text;
   }
@@ -721,7 +721,7 @@ export class IVProgParser {
           break;
       }
     }
-    
+
     throw SyntaxErrorFactory.invalid_type(this.getTypeArray(), token);
   }
 
@@ -1041,7 +1041,7 @@ export class IVProgParser {
     }
     if (for_from == null) {
       // TODO better error message
-      const keyword = this.lexer.literalNames[keyword_code];      
+      const keyword = this.lexer.literalNames[keyword_code];
       throw new Error("Error de sintaxe no comando repeita_para: "+ int_or_id.text + " não é compativel com o esperado para o paramentro "+ keyword + ". O valor deve ser um inteiro ou variável.");
     }
     if (is_unary_op) {
@@ -1146,7 +1146,7 @@ export class IVProgParser {
       const finalExp = new Expressions.UnaryApp(not, exp1);
       finalExp.sourceInfo = SourceInfo.createSourceInfo(opToken);
       return finalExp;
-      
+
     } else {
       return this.parseExpressionRel();
     }
@@ -1253,7 +1253,7 @@ export class IVProgParser {
         tokenB = this.getToken();
         this.pos++;
       }
-      const sourceInfo = SourceInfo.createSourceInfoFromList(tokenA, tokenB); 
+      const sourceInfo = SourceInfo.createSourceInfoFromList(tokenA, tokenB);
       const exp = new Expressions.ArrayAccess(id, firstIndex, secondIndex);
       exp.sourceInfo = sourceInfo;
       return exp;

+ 4 - 2
js/main.js

@@ -9,6 +9,7 @@ import { prepareActivityToStudentHelper, autoEval } from "./util/iassignHelpers"
 import { openAssessmentDetail } from "./util/utils";
 import * as CodeEditorAll from "./visualUI/text_editor";
 import {autoGenerateTestCaseOutput} from './util/auto_gen_output';
+import { Config } from "./util/config";
 
 const CodeEditor = {
   initTextEditor: CodeEditorAll.initTextEditor,
@@ -41,5 +42,6 @@ export {
   ActionTypes,
   CodeEditor,
   openAssessmentDetail,
-  autoGenerateTestCaseOutput
-}
+  autoGenerateTestCaseOutput,
+  Config
+}

+ 2 - 2
js/typeSystem/parsers.js

@@ -56,7 +56,7 @@ export function convertToString(value, type) {
       return value.toString();
     case Types.REAL.ord: {
       if (value.dp() <= 0) {
-        return value.toFixed(1);  
+        return value.toFixed(1);
       } else {
         return value.toFixed(Config.decimalPlaces);
       }
@@ -66,4 +66,4 @@ export function convertToString(value, type) {
     default:
       return value;
   }
-}
+}

+ 13 - 1
js/util/config.js

@@ -30,12 +30,23 @@ class ConfigObject {
     return false;
   }
 
+  getSetting (setting_name) {
+    for (const setting_obj in this.ui_settings) {
+      if (setting_obj.name == setting_name) {
+        return setting_obj.value;
+      }
+    }
+    return undefined;
+  }
+
   setSetting (setting_name, value) {
     for(const setting_obj in this.ui_settings) {
       if(setting_obj.name == setting_name) {
-         setting_obj.value = value;
+        setting_obj.value = value;
+        return;
       }
     }
+    this.ui_settings.push({name: setting_name, value: value});
   }
 
   setConfig (opts) {
@@ -48,3 +59,4 @@ class ConfigObject {
 }
 const config = new ConfigObject();
 export const Config = config;
+

+ 6 - 5
js/visualUI/algorithm.js

@@ -1,5 +1,6 @@
 import * as GlobalsManagement from './globals';
 import * as FunctionsManagement from './functions';
+import { Config } from './../util/config';
 
 window.block_render = false;
 
@@ -17,7 +18,7 @@ export function renderAlgorithm () {
 	$('.all_functions').empty();
 
 	$('.list_globals').children().off();
-	$('.list_globals').empty();	
+	$('.list_globals').empty();
 
 	for (var i = 0; i < window.program_obj.functions.length; i++) {
 		FunctionsManagement.renderFunction(window.program_obj.functions[i]);
@@ -25,12 +26,12 @@ export function renderAlgorithm () {
 
 	for (var i = 0; i < window.program_obj.globals.length; i++) {
 		GlobalsManagement.renderGlobal(window.program_obj.globals[i]);
-	}	
+	}
 
 	setTimeout(function(){ window.block_render = false; }, 100);
 	console.log('fim do render');
 
-	if (settingsFilter && settingsFilter[0]) {
+	if (Config.isSettingEnabled("filter_active")) {
       blockAllEditingOptions();
-    } 
-}
+    }
+}

+ 1 - 1
js/visualUI/functions.js

@@ -1074,7 +1074,7 @@ function toggleConsole (is_running) {
 
 function toggleTextualCoding () {
   let code = null;
-  if (Config.programming_type == "textual") {
+  if (Config.programming_type == "visual") {
     code = CodeManagement.generate();
     if (code == null) {
       return;