Procházet zdrojové kódy

Implement settings storage from the assignment creation interface

Lucas de Souza před 5 roky
rodič
revize
c739799caf
3 změnil soubory, kde provedl 104 přidání a 62 odebrání
  1. 43 29
      js/iassign-integration-functions.js
  2. 28 1
      js/util/config.js
  3. 33 32
      js/visualUI/functions.js

+ 43 - 29
js/iassign-integration-functions.js

@@ -32,7 +32,7 @@ function getAnswer () {
     var contentToSend = previousContent.split("\n::algorithm::")[0];
     contentToSend += '\n::algorithm::';
 
-    if (settingsProgrammingTypes == "textual") {
+    if (ivprogCore.Config.programming_type == "textual") {
       contentToSend +=  ivprogCore.CodeEditor.getCode();
     } else {
       contentToSend += JSON.stringify(window.program_obj, function(key, value) {
@@ -127,11 +127,11 @@ function getEvaluation () {
 }
 
 //var testCases = null
-var settingsDataTypes = null;
+/*var settingsDataTypes = null;
 var settingsCommands = null;
 var settingsFunctions = null;
-var settingsProgrammingTypes = null;
-var settingsFilter = null;
+var ivprogCore.Config.programming_type = null;
+var settingsFilter = null;*/
 var algorithm_in_ilm = null;
 var previousContent = null;
 
@@ -170,11 +170,12 @@ function prepareActivityToEdit (ilm_cont) {
   }
   var testCases = ivprogCore.getTestCases();
 
-  settingsProgrammingTypes = content.settingsProgrammingType;
-  settingsDataTypes = content.settingsDataTypes;
-  settingsCommands = content.settingsCommands;
-  settingsFunctions = content.settingsFunctions;
-  settingsFilter = content.settingsFilter;
+  const settings = parseFormSettingsData(content.settingsDataTypes, content.settingsCommands, content.settingsFunctions, content.settingsFilter);
+  const programming_type = content.settingsProgrammingType;
+  ivprogCore.Config.setConfig({
+    ui_settings: settings,
+    programming_type: programming_type
+  });
 
   for (var i = 0; i < testCases.length; i++) {
     addTestCase(testCases[i]);
@@ -188,7 +189,7 @@ function prepareActivityToEdit (ilm_cont) {
   }
 
   ivprogTextualOrVisual();
-  if (settingsFilter && settingsFilter[0]) {
+  if (ivprogCore.Config.isSettingEnabled("filter_active")) {
     blockAllEditingOptions();
   }
 }
@@ -199,7 +200,7 @@ function parsePreviousAlgorithm () {
 }
 
 function includePreviousAlgorithm () {
-  if (settingsProgrammingTypes == "textual") {
+  if (ivprogCore.Config.programming_type == "textual") {
     return;
   }
 
@@ -256,12 +257,14 @@ function prepareActivityToStudent (ilm_cont) {
       return;
     }
     // Casos de testes agora são delegados ao tratamento apropriado pela função acima
-    // var testCases = content.testcases;
-    settingsProgrammingTypes = content.settingsProgrammingType;
-    settingsDataTypes = content.settingsDataTypes;
-    settingsCommands = content.settingsCommands;
-    settingsFunctions = content.settingsFunctions;
-    settingsFilter = content.settingsFilter;
+    // var testcases = content.testcases;
+    const settings = parseFormSettingsData(content.settingsDataTypes, content.settingsCommands, content.settingsFunctions, content.settingsFilter);
+    const programming_type = content.settingsProgrammingType;
+    ivprogCore.Config.setConfig({
+      ui_settings: settings,
+      programming_type: programming_type
+    });
+
 
     if (content.algorithmInIlm != null) {
         algorithm_in_ilm = content.algorithmInIlm;
@@ -271,7 +274,7 @@ function prepareActivityToStudent (ilm_cont) {
     renderAlgorithm();
 
     ivprogTextualOrVisual();
-    if (settingsFilter && settingsFilter[0]) {
+    if (ivprogCore.isSettingEnabled("filter_active")) {
       blockAllEditingOptions();
     }
 }
@@ -377,8 +380,8 @@ function blockAllEditingOptions () {
 
 function ivprogTextualOrVisual () {
 
-  if (settingsProgrammingTypes) {
-    if (settingsProgrammingTypes == "textual") {
+  if (ivprogCore.Config.programming_type) {
+    if (ivprogCore.Config.programming_type == "textual") {
       $('.ivprog_visual_panel').css('display', 'none');
       $('.ivprog_textual_panel').css('display', 'block');
       $('.ivprog_textual_panel').removeClass('loading');
@@ -393,11 +396,11 @@ function ivprogTextualOrVisual () {
         textual_code = textual_code.replace(/\\n/g,"\n");
         textual_code = textual_code.replace(/\\t/g,"\t");
       }
-      
+
       ivprogCore.CodeEditor.setCode(textual_code);
       ivprogCore.CodeEditor.disable(false);
     }
-    if (settingsProgrammingTypes == "visual") {
+    if (ivprogCore.Config.programming_type == "visual") {
 
     }
   }
@@ -751,11 +754,17 @@ function teacherAutoEval (data) {
     }
     // Casos de testes agora são delegados ao tratamento apropriado pela função acima
     // var testCases = content.testcases;
-    settingsProgrammingTypes = content.settingsProgrammingType;
-    settingsDataTypes = content.settingsDataTypes;
-    settingsCommands = content.settingsCommands;
-    settingsFunctions = content.settingsFunctions;
-    settingsFilter = content.settingsFilter;
+    const settings = parseFormSettingsData(content.settingsDataTypes, content.settingsCommands, content.settingsFunctions, content.settingsFilter);
+    const programming_type = content.settingsProgrammingType;
+    ivprogCore.Config.setConfig({
+      ui_settings: settings,
+      programming_type: programming_type
+    });
+    //ivprogCore.Config.programming_type = content.settingsProgrammingType;
+    //settingsDataTypes = content.settingsDataTypes;
+    //settingsCommands = content.settingsCommands;
+    //settingsFunctions = content.settingsFunctions;
+    //settingsFilter = content.settingsFilter;
 
     if (content.algorithmInIlm != null) {
       algorithm_in_ilm = content.algorithmInIlm;
@@ -764,8 +773,7 @@ function teacherAutoEval (data) {
     }
 
     ivprogTextualOrVisual();
-    if (settingsFilter && settingsFilter[0]) {
-
+    if (ivprogCore.Config.isSettingEnabled("filter_active")) {
       blockAllEditingOptions();
     }
   });
@@ -785,3 +793,9 @@ function showInvalidData () {
   $('.ui.height_100.add_accordion').dimmer('add content', '.dimmer_content_message');
   $('.ui.height_100.add_accordion').dimmer('show');
 }
+
+function parseFormSettingsData (...array_data) {
+  const list = []
+  array_data.forEach(array => list = list.concat(array));
+  return list;
+}

+ 28 - 1
js/util/config.js

@@ -9,6 +9,33 @@ class ConfigObject {
     this.suspend_threshold = 100;
     // this.max_instruction_count = 350250; - automated evaluation limit
     this.max_instruction_count = Number.MAX_SAFE_INTEGER;
+    this.programming_type = "visual";
+    this.ui_settings = [{"name":"integer_data_type","value":"on"},
+      {"name":"real_data_type","value":"on"},{"name":"text_data_type","value":"on"},
+      {"name":"boolean_data_type","value":"on"},{"name":"void_data_type","value":"on"},
+      {"name":"commands_read","value":"on"},{"name":"commands_write","value":"on"},
+      {"name":"commands_comment","value":"on"},{"name":"commands_attribution","value":"on"},
+      {"name":"commands_functioncall","value":"on"},{"name":"commands_iftrue","value":"on"},
+      {"name":"commands_repeatNtimes","value":"on"},{"name":"commands_while","value":"on"},
+      {"name":"commands_dowhile","value":"on"},{"name":"commands_switch","value":"on"},
+      {name:"functions_creation", value: "on"},{name:"filter_active", value:"off"}];
+  }
+
+  isSettingEnabled (setting_name) {
+    for(const setting_obj in this.ui_settings) {
+      if(setting_obj.name == setting_name) {
+        return setting_obj.value == "on";
+      }
+    }
+    return false;
+  }
+
+  setSetting (setting_name, value) {
+    for(const setting_obj in this.ui_settings) {
+      if(setting_obj.name == setting_name) {
+         setting_obj.value = value;
+      }
+    }
   }
 
   setConfig (opts) {
@@ -20,4 +47,4 @@ class ConfigObject {
   }
 }
 const config = new ConfigObject();
-export const Config = config;
+export const Config = config;

+ 33 - 32
js/visualUI/functions.js

@@ -18,6 +18,7 @@ import VersionInfo from './../../.ima_version.json';
 import * as TextEditor from "./text_editor";
 import { isValidIdentifier } from "./../util/utils";
 import { Modes } from '../processor/modes';
+import { Config } from '../util/config';
 
 var counter_new_functions = 0;
 var counter_new_parameters = 0;
@@ -246,7 +247,7 @@ function addHandlers (function_obj, function_container) {
         function_container.find(".inline_add_command").toggle();
       });
     }
-    
+
   });
 }
 
@@ -254,7 +255,7 @@ function addHandlers (function_obj, function_container) {
 function renderFunctionReturn (function_obj, function_element) {
 
   var ret = '<div class="ui dropdown function_return">';
-    
+
     if (function_obj.return_dimensions == 1) {
       ret += '<div class="text">'+ LocalizedStrings.getUI("vector") +': '+ LocalizedStrings.getUI(`type_${function_obj.return_type.toLowerCase()}`);
       ret += ' [ ] </div>';
@@ -301,20 +302,20 @@ function renderFunctionReturn (function_obj, function_element) {
     ret += '</div></div>';
 
     ret = $(ret);
-    
+
     function_element.find('.function_return').append(ret);
 }
 
 var cont = 0;
 
 export function renderFunction (function_obj) {
-  
+
   var appender = '<div class="ui secondary segment function_div list-group-item function_cont_'+cont+'">';
 
   if (function_obj.function_comment) {
     //appender += renderComment(function_obj.function_comment, sequence, true, -1);
   }
-    
+
   appender += '<span class="glyphicon glyphicon-move move_function" aria-hidden="true"><i class="icon sort alternate vertical"></i></span>';
 
   appender += (function_obj.is_main ? '<div class="div_start_minimize_v"> </div>' : '<button class="ui icon button large remove_function_button"><i class="red icon times"></i></button>')
@@ -328,10 +329,10 @@ export function renderFunction (function_obj) {
   } else {
       appender += '<div class="ui function_return"></div>';
 
-      appender += '<div class="function_name_div function_name_div_updated"><span class="span_name_function name_function_updated">'+function_obj.name+'</span> </div> ' 
+      appender += '<div class="function_name_div function_name_div_updated"><span class="span_name_function name_function_updated">'+function_obj.name+'</span> </div> '
         + ' <span class="parethesis_function"> ( </span> <i class="ui icon plus square outline add_parameter_button"></i> <div class="ui large labels parameters_list container_parameters_list">';
   }
-    
+
   appender += '</div> <span class="parethesis_function"> ) </span> </div>'
     + (function_obj.is_hidden ? ' <div class="function_area" style="display: none;"> ' : ' <div class="function_area"> ');
 
@@ -380,7 +381,7 @@ export function renderFunction (function_obj) {
 
   addHandlers(function_obj, appender);
 
-  // Rendering parameters: 
+  // Rendering parameters:
   for (var j = 0; j < function_obj.parameters_list.length; j++) {
     renderParameter(function_obj, function_obj.parameters_list[j], appender);
   }
@@ -436,7 +437,7 @@ export function renderFunction (function_obj) {
       offset: 40,
       onStick: function (evt) {
         $(teste).css('top', '20px', 'important');
-      }, 
+      },
       onBottom: function (evt) {
         $(teste).css('top', '20px', 'important');
       },
@@ -457,7 +458,7 @@ export function renderFunction (function_obj) {
       }
     });
   }
-  
+
   cont ++;
 
   return appender;
@@ -578,7 +579,7 @@ function updateProgramObjDrag () {
 
   // agora tem que alocar o comando na árvore, mas considerar as quatro situações:
   // (1) se está em um else ou (2) se está em switch ou (3) será um caso padrão ou (4) se será na raiz.
-  
+
   if (path_target.length == 0) { // soltou na raiz:
     window.program_obj.functions[function_index].commands.splice(evento_drag.newIndex - 1, 0, command_in_drag);
   } else if (is_in_else)  {
@@ -603,7 +604,7 @@ function updateProgramObjDrag () {
 
   window.draging = false;
   renderAlgorithm();
-  
+
 
 }
 
@@ -647,7 +648,7 @@ function prepareDragHandler (evt) {
 var command_in_drag;
 
 function addSortableHandler (element, id_function) {
-  
+
   var n_group = 'commands_drag_' + id_function;
   Sortable.create(element, {
     handle: '.command_drag',
@@ -720,7 +721,7 @@ function addSortableHandler (element, id_function) {
       addSortableHandler($(this).find(".case_commands_block")[0], id_function);
     });
 
-  });  
+  });
 }
 
 export function initVisualUI () {
@@ -881,7 +882,7 @@ export function setTestCases (testCases) {
 
 export function getTestCases () {
   // Deep clone of test cases to avoid unauthorized modification
-  // TODO: It may be not possible to use this once custom test are fully implemented 
+  // TODO: It may be not possible to use this once custom test are fully implemented
   return JSON.parse(JSON.stringify(_testCases));
 }
 
@@ -908,12 +909,12 @@ function runCodeAssessment () {
     // cannot run assessment or it's already running
     return -1;
   }
-  
+
   let strCode = null;
 
   window.studentGrade = null;
 
-  if (settingsProgrammingTypes == "textual") {
+  if (Config.programming_type == "textual") {
     strCode = TextEditor.getCode();
   } else {
     strCode = CodeManagement.generate();
@@ -960,7 +961,7 @@ function runCode () {
   }
   let strCode = null;
 
-  if (settingsProgrammingTypes == "textual") {
+  if (Config.programming_type == "textual") {
     strCode = TextEditor.getCode();
   } else {
     strCode = CodeManagement.generate();
@@ -969,7 +970,7 @@ function runCode () {
   if (strCode == null) {
     return;
   }
-  
+
   toggleConsole(true);
 
   // if(domConsole == null)
@@ -986,7 +987,7 @@ function runCode () {
       scheduleCall(() => {
         if(domConsole.pending_writes.length == 0) {
           if(proc.mode === Modes.ABORT) {
-            domConsole.info(LocalizedStrings.getMessage("aborted_execution"));  
+            domConsole.info(LocalizedStrings.getMessage("aborted_execution"));
           } else {
             domConsole.info(LocalizedStrings.getMessage("success_execution"));
           }
@@ -1014,7 +1015,7 @@ function runCode () {
         }
         return false;
       },100);
-    }) 
+    })
   } catch (error) {
     scheduleCall(() => {
       if(domConsole.pending_writes.length == 0) {
@@ -1028,7 +1029,7 @@ function runCode () {
       return false;
     },100);
   }
-  
+
 }
 
 function toggleConsole (is_running) {
@@ -1073,7 +1074,7 @@ function toggleConsole (is_running) {
 
 function toggleTextualCoding () {
   let code = null;
-  if (settingsProgrammingTypes != "textual") {
+  if (Config.programming_type == "textual") {
     code = CodeManagement.generate();
     if (code == null) {
       return;
@@ -1145,7 +1146,7 @@ function renderParameter (function_obj, parameter_obj, function_container) {
 
   ret += '<div class="menu">';
 
-  
+
   for (const tm in Types) {
       if (tm == Types.VOID.toUpperCase()) {
         continue;
@@ -1188,13 +1189,13 @@ function renderParameter (function_obj, parameter_obj, function_container) {
   ret += ' <i class="yellow inverted icon times remove_parameter"></i></div>';
 
   ret = $(ret);
-  
+
   function_container.find('.container_parameters_list').append(ret);
 
   ret.find('.remove_parameter').on('click', function(e){
     removeParameter(function_obj, parameter_obj, ret);
   });
-  
+
   ret.find('.ui.dropdown.parameter_type').dropdown({
     onChange: function(_, __, $selectedItem) {
       if ($selectedItem.data('dimensions')) {
@@ -1215,7 +1216,7 @@ function renderParameter (function_obj, parameter_obj, function_container) {
 }
 
 function updateParameterName (parameter_var, new_name, parameter_obj_dom, function_obj) {
-  
+
   if (parameter_var.name == new_name) {
     return;
   }
@@ -1254,11 +1255,11 @@ function variableNameAlreadyExists (name_var, function_obj) {
 }
 
 function updateFunctionName (function_var, new_name, function_obj_dom) {
-  
+
   if (function_var.name == new_name) {
     return;
   }
-  
+
   if (isValidIdentifier(new_name)) {
     if (functionNameAlreadyExists(new_name)) {
       Utils.renderErrorMessage(function_obj_dom.find('.function_name_div'), LocalizedStrings.getError('inform_valid_function_duplicated', [new_name]));
@@ -1368,7 +1369,7 @@ function enableNameFunctionUpdate (function_obj, parent_node) {
   }
   parent_node.find('.span_name_function').css('padding-left', '0');
   parent_node.find('.span_name_function').css('padding-right', '0');
-  
+
   input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"+function_obj.name+"' />" );
   input_field.insertBefore(parent_node.find('.span_name_function'));
 
@@ -1432,7 +1433,7 @@ function enableNameFunctionUpdate (function_obj, parent_node) {
     }
   });
   input_field.select();
-  
+
 }
 
 export function addFunctionChangeListener (callback) {
@@ -1481,4 +1482,4 @@ function stopExecution () {
     return;
   }
   proc.mode = Modes.ABORT;
-}
+}