Browse Source

work in progress

Igor 2 years ago
parent
commit
85e8db5c74
3 changed files with 88 additions and 6 deletions
  1. 45 6
      js/iassign-integration-functions.js
  2. 2 0
      js/main.js
  3. 41 0
      js/util/iassignHelpers.js

+ 45 - 6
js/iassign-integration-functions.js

@@ -43,6 +43,26 @@ function removeCollapseValue (command) {
   }
 }
 
+function configAuxiliar (form_element) {
+  var _array = form_element.serializeArray();
+  var temp = _array.reduce(function(map, obj) {
+    map[obj.name] = obj.value == "on";
+    return map;
+  }, {});
+
+  return temp;
+}
+
+function configAuxiliarProgrammingType (form_element) {
+  var _array = form_element.serializeArray();
+  var temp = _array.reduce(function(map, obj) {
+    map[obj.name] = obj.value;
+    return map;
+  }, {});
+
+  return temp;
+}
+
 // Função chamada pelo iTarefa quando o professor finaliza a criação da atividade
 // ou quando o aluno finaliza a resolução do exercício
 // O retorno é um JSON com os dados do exercício ou da resolução
@@ -57,8 +77,8 @@ function getAnswer () {
   if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
     // Montar o retorno com a resposta do aluno
 
-    objAnswer.test_cases = ivprogCore.getTestCases();
     objAnswer.code = generator();
+    objAnswer.test_cases = ivprogCore.getTestCases();
     objAnswer.logs = ivprogCore.getLogs();
     objAnswer.settings = {
       "programming": ivprogCore.Config.activity_programming_type,
@@ -75,11 +95,11 @@ function getAnswer () {
     objAnswer.test_cases = prepareTestCases();
 
     objAnswer.settings = {
-      "programming": $('form[name="settings_programming_type"]').serializeArray(),
-      "functions": $('form[name="settings_functions"]').serializeArray(),
-      "datatypes": $('form[name="settings_data_types"]').serializeArray(),
-      "commands": $('form[name="settings_commands"]').serializeArray(),
-      "filter": $('form[name="settings_filter"]').serializeArray()
+      "programming": configAuxiliarProgrammingType($('form[name="settings_programming_type"]')),
+      "functions": configAuxiliar($('form[name="settings_functions"]')),
+      "datatypes": configAuxiliar($('form[name="settings_data_types"]')),
+      "commands": configAuxiliar($('form[name="settings_commands"]')),
+      "filter": configAuxiliar($('form[name="settings_filter"]'))
     };
 
     if ($("input[name='include_algo']").is(':checked')) {
@@ -261,12 +281,31 @@ function includePreviousAlgorithm () {
 }
 
 function prepareActivityToStudent (ilm_cont) {
+
+    // File version (1.0):
+    try {
+      var jsonObj = JSON.parse(ilm_cont);
+      ivprogCore.prepareActivityToStudentHelperJSON(jsonObj);
+
+      if (ivprogCore.getTestCases())
+        $('.assessment_button').removeClass('disabled');
+
+      renderAlgorithm();
+      return;
+    }
+    catch (e) {
+      console.log('Previous file format!');
+      console.log(e);
+    }
+
+    // Previous file format:
     // Ver arquivo js/util/iassignHelpers.js
     var content = ivprogCore.prepareActivityToStudentHelper(ilm_cont).getOrElse(null);
     if(!content) {
       showInvalidData();
       return;
     }
+    
     // Casos de testes agora são delegados ao tratamento apropriado pela função acima
     // var testCases = content.testcases;
     settingsProgrammingTypes = content.settingsProgrammingType;

+ 2 - 0
js/main.js

@@ -19,6 +19,7 @@ import {
 } from "./services/userLog";
 import {
   prepareActivityToStudentHelper,
+  prepareActivityToStudentHelperJSON,
   autoEval,
 } from "./util/iassignHelpers";
 import { openAssessmentDetail, levenshteinDistance } from "./util/utils";
@@ -58,6 +59,7 @@ export {
   getTestCases,
   autoEval,
   prepareActivityToStudentHelper,
+  prepareActivityToStudentHelperJSON,
   LocalizedStrings,
   i18n,
   getLogs,

+ 41 - 0
js/util/iassignHelpers.js

@@ -26,6 +26,47 @@ function parseActivityData (data) {
   return Maybe.some(content);
 }
 
+function configAuxiliar (obj_config) {
+
+  return new Map(
+    Object
+        .keys(obj_config)
+        .map(
+            key => [key, obj_config[key]]
+        )
+  )
+
+}
+    
+function setActivityConfig (config_json) {
+
+  ivprogCore.Config.activity_commands = configAuxiliar(config_json.commands);
+  ivprogCore.Config.activity_functions = configAuxiliar(config_json.functions);
+  ivprogCore.Config.activity_datatypes = configAuxiliar(config_json.datatypes);
+  ivprogCore.Config.activity_filter = configAuxiliar(config_json.filter);
+  ivprogCore.Config.activity_programming_type = configAuxiliar(config_json.programming);
+
+}
+
+function setPreviousAlgorithm (code) {
+  console.log('conteúdo: ')
+  console.log(code)
+}
+
+export function prepareActivityToStudentHelperJSON (ilm_cont) {
+  
+  setTestCases(ilm_cont.test_cases)
+
+  setActivityConfig(ilm_cont.settings)
+
+  if (ilm_cont.code)
+    setPreviousAlgorithm(ilm_cont.code)
+  else 
+    if (ilm_cont.algorithm)
+      setPreviousAlgorithm(ilm_cont.algorithm)
+
+}
+
 export function prepareActivityToStudentHelper (ilm_cont) {
   const maybe_content = parseActivityData(ilm_cont);
   return maybe_content.map((content) => {