iassign-integration-functions.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. // Função para ler parâmetros informados pelo iTarefa via URL
  2. // Apesar de não ser obrigatório, será muito útil para capturar os parâmetros
  3. function getParameterByName (name, defaultReturn = null) {
  4. var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
  5. return match ? decodeURIComponent(match[1].replace(/\+/g, ' ')) : defaultReturn;
  6. }
  7. // Criando um object com os parâmetros informados pelo iTarefa
  8. // Observe que para cada parâmetro, é realizada a chamada do método getParameterByName, implementado acima
  9. var iLMparameters = {
  10. iLM_PARAM_ServerToGetAnswerURL: getParameterByName("iLM_PARAM_ServerToGetAnswerURL"),
  11. iLM_PARAM_SendAnswer: getParameterByName("iLM_PARAM_SendAnswer"),
  12. iLM_PARAM_AssignmentURL: getParameterByName("iLM_PARAM_AssignmentURL"),
  13. iLM_PARAM_Assignment: getParameterByName("iLM_PARAM_Assignment"),
  14. iLM_PARAM_TeacherAutoEval: getParameterByName("iLM_PARAM_TeacherAutoEval"),
  15. lang: getParameterByName("lang", "pt")
  16. };
  17. // Set the lang parameter to the localStorage for easy access
  18. // and no dependency to the global scope, avoind future 'strict mode' problems
  19. //localStorage.setItem('ivprog.lang', iLMparameters.lang);
  20. // Função chamada pelo iTarefa quando o professor finaliza a criação da atividade
  21. // ou quando o aluno finaliza a resolução do exercício
  22. // O retorno é um JSON com os dados do exercício ou da resolução
  23. // Esse retorno será armazenado no banco de dados do Moodle, pelo iTarefa
  24. function getAnswer () {
  25. // Se o parâmetro "iLM_PARAM_SendAnswer" for false,
  26. // então trata-se de resolução de atividade
  27. if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  28. // Montar o retorno com a resposta do aluno
  29. var contentToSend = previousContent.split("\n::algorithm::")[0];
  30. contentToSend += '\n::algorithm::';
  31. if (ivprogCore.Config.programming_type == "textual") {
  32. contentToSend += ivprogCore.CodeEditor.getCode();
  33. } else {
  34. contentToSend += JSON.stringify(window.program_obj, function(key, value) {
  35. if (key == 'dom_object') {
  36. return;
  37. }
  38. return value;
  39. });
  40. }
  41. contentToSend += '\n::logs::';
  42. contentToSend += getTrackingLogs();
  43. return contentToSend;
  44. } else {
  45. // Montar o retorno com a criação da atividade do professor
  46. var ret = ' { ' + prepareTestCases()
  47. + ',\n"settings_programming_type": \n' + JSON.stringify($('form[name="settings_programming_type"]').serializeArray())
  48. + ',\n"settings_data_types": \n' + JSON.stringify($('form[name="settings_data_types"]').serializeArray())
  49. + ',\n"settings_commands": \n' + JSON.stringify($('form[name="settings_commands"]').serializeArray())
  50. + ',\n"settings_functions": \n' + JSON.stringify($('form[name="settings_functions"]').serializeArray())
  51. + ',\n"settings_filter": \n' + JSON.stringify($('form[name="settings_filter"]').serializeArray())
  52. + ' } ';
  53. if ($("input[name='include_algo']").is(':checked')) {
  54. ret += '\n::algorithm::';
  55. ret += JSON.stringify(window.program_obj, function(key, value) {
  56. if (key == 'dom_object') {
  57. return;
  58. }
  59. return value;
  60. });
  61. }
  62. return ret;
  63. }
  64. }
  65. function prepareTestCases () {
  66. var ret = ' \n "testcases" : [ '
  67. var test_cases_array = $('form[name="test_cases"]').serializeArray();
  68. console.log(test_cases_array);
  69. for (var i = 0; i < test_cases_array.length; i = i + 2) {
  70. ret += '\n{ ';
  71. ret += '\n "input": [';
  72. var inps = test_cases_array[i].value.match(/[^\r\n]+/g);
  73. if (inps) {
  74. for (var j = 0; j < inps.length; j++) {
  75. ret += '"' + inps[j] + '"';
  76. if ((j + 1) < inps.length) {
  77. ret += ', ';
  78. }
  79. }
  80. }
  81. ret += '], \n "output": [';
  82. var outs = test_cases_array[i+1].value.match(/[^\r\n]+/g);
  83. console.log(outs);
  84. if (outs) {
  85. for (var j = 0; j < outs.length; j++) {
  86. console.log("output -> ",outs[j]);
  87. ret += '"' + outs[j] + '"';
  88. if ((j + 1) < outs.length) {
  89. ret += ', ';
  90. }
  91. }
  92. }
  93. ret += ']';
  94. ret += '\n}'
  95. if ((i + 2) < test_cases_array.length) {
  96. ret += ',';
  97. }
  98. }
  99. ret += '\n] ';
  100. return ret;
  101. }
  102. // Função chamada pelo iTarefa para receber a nota do aluno na atividade
  103. // O retorno é um valor entre 0.0 e 1.0
  104. function getEvaluation () {
  105. if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  106. // A chamada do método abaixo é obrigatória!
  107. // Observe que a chamada parte do iLM para o iTarefa
  108. //parent.getEvaluationCallback(window.studentGrade);
  109. var canRunAssessment = runCodeAssessment();
  110. if(canRunAssessment === -1) {
  111. parent.getEvaluationCallback(-1);
  112. }
  113. }
  114. }
  115. //var testCases = null
  116. /*var settingsDataTypes = null;
  117. var settingsCommands = null;
  118. var settingsFunctions = null;
  119. var ivprogCore.Config.programming_type = null;
  120. var settingsFilter = null;*/
  121. var algorithm_in_ilm = null;
  122. var previousContent = null;
  123. // Função para que o iMA leia os dados da atividade fornecidos pelo iTarefa
  124. function getiLMContent () {
  125. // O parâmetro "iLM_PARAM_Assignment" fornece o URL do endereço que deve ser
  126. // requisitado via AJAX para a captura dos dados da atividade
  127. $.get(iLMparameters.iLM_PARAM_Assignment, function (data) {
  128. //professor invocou a avaliação automática dos exercícios do bloco
  129. if (iLMparameters.iLM_PARAM_TeacherAutoEval != null) {
  130. teacherAutoEval(data);
  131. //não deve exibir nenhuma interface...
  132. return;
  133. } else if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  134. // Aluno está trabalhando em alguma atividade:
  135. previousContent = data;
  136. prepareActivityToStudent(data);
  137. } else { // Professor está editando uma atividade:
  138. previousContent = data;
  139. prepareActivityToEdit(data);
  140. }
  141. window.block_render = false;
  142. renderAlgorithm();
  143. });
  144. }
  145. function prepareActivityToEdit (ilm_cont) {
  146. //var content = JSON.parse(ilm_cont.split('\n::algorithm::')[0]);
  147. // Ver arquivo js/util/iassignHelpers.js
  148. var content = ivprogCore.prepareActivityToStudentHelper(ilm_cont).getOrElse(null);
  149. if(!content) {
  150. showInvalidData();
  151. return;
  152. }
  153. var testCases = ivprogCore.getTestCases();
  154. const settings = parseFormSettingsData(content.settingsDataTypes, content.settingsCommands, content.settingsFunctions, content.settingsFilter);
  155. const programming_type = content.settingsProgrammingType;
  156. ivprogCore.Config.setConfig({
  157. ui_settings: settings,
  158. programming_type: programming_type
  159. });
  160. for (var i = 0; i < testCases.length; i++) {
  161. addTestCase(testCases[i]);
  162. }
  163. if (content.algorithmInIlm != null) {
  164. algorithm_in_ilm = content.algorithmInIlm;
  165. $("input[name='include_algo']").prop('checked', true);
  166. includePreviousAlgorithm();
  167. renderAlgorithm();
  168. }
  169. ivprogTextualOrVisual();
  170. if (ivprogCore.Config.isSettingEnabled("filter_active")) {
  171. blockAllEditingOptions();
  172. }
  173. }
  174. function parsePreviousAlgorithm () {
  175. window.program_obj.functions = JSON.parse(algorithm_in_ilm).functions;
  176. window.program_obj.globals = JSON.parse(algorithm_in_ilm).globals;
  177. }
  178. function includePreviousAlgorithm () {
  179. if (ivprogCore.Config.programming_type == "textual") {
  180. return;
  181. }
  182. parsePreviousAlgorithm();
  183. window.watchW.watch(window.program_obj.globals, function(){
  184. if (window.insertContext) {
  185. setTimeout(function(){ renderAlgorithm(); }, 300);
  186. window.insertContext = false;
  187. } else {
  188. renderAlgorithm();
  189. }
  190. }, 1);
  191. for (var i = 0; i < window.program_obj.functions.length; i ++) {
  192. window.watchW.watch(window.program_obj.functions[i].parameters_list, function(){
  193. if (window.insertContext) {
  194. setTimeout(function(){ renderAlgorithm(); }, 300);
  195. window.insertContext = false;
  196. } else {
  197. renderAlgorithm();
  198. }
  199. }, 1);
  200. window.watchW.watch(window.program_obj.functions[i].variables_list, function(){
  201. if (window.insertContext) {
  202. setTimeout(function(){ renderAlgorithm(); }, 300);
  203. window.insertContext = false;
  204. } else {
  205. renderAlgorithm();
  206. }
  207. }, 1);
  208. if (window.program_obj.functions[i].is_main) {
  209. window.program_obj.functions[i].name = LocalizedStrings.getUI("start");
  210. }
  211. }
  212. window.watchW.watch(window.program_obj.functions, function(){
  213. if (window.insertContext) {
  214. setTimeout(function(){ renderAlgorithm(); }, 300);
  215. window.insertContext = false;
  216. } else {
  217. renderAlgorithm();
  218. }
  219. }, 1);
  220. }
  221. function prepareActivityToStudent (ilm_cont) {
  222. // Ver arquivo js/util/iassignHelpers.js
  223. var content = ivprogCore.prepareActivityToStudentHelper(ilm_cont).getOrElse(null);
  224. if(!content) {
  225. showInvalidData();
  226. return;
  227. }
  228. // Casos de testes agora são delegados ao tratamento apropriado pela função acima
  229. // var testcases = content.testcases;
  230. const settings = parseFormSettingsData(content.settingsDataTypes, content.settingsCommands, content.settingsFunctions, content.settingsFilter);
  231. const programming_type = content.settingsProgrammingType;
  232. ivprogCore.Config.setConfig({
  233. ui_settings: settings,
  234. programming_type: programming_type
  235. });
  236. if (content.algorithmInIlm != null) {
  237. algorithm_in_ilm = content.algorithmInIlm;
  238. includePreviousAlgorithm();
  239. }
  240. $('.assessment_button').removeClass('disabled');
  241. renderAlgorithm();
  242. ivprogTextualOrVisual();
  243. if (ivprogCore.isSettingEnabled("filter_active")) {
  244. blockAllEditingOptions();
  245. }
  246. }
  247. // Função para organizar se para criação, visualização ou resolução de atividade
  248. function prepareEnvironment () {
  249. $('.div_to_body').click(function(e) {
  250. // trackingMatrix.push(adCoords(e, 1));
  251. ivprogCore.registerClick(e.pageX, e.pageY, e.target.classList['value']);
  252. });
  253. // Se iLM_PARAM_SendAnswer for false, então trata-se de resolução de atividade,
  254. // portanto, a "DIV" de resolução é liberada
  255. if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  256. //$('.resolucao').css("display","block");
  257. getiLMContent();
  258. // $('.div_to_body').mousemove(function(e) {
  259. // trackingMatrix.push(adCoords(e, 0));
  260. // });
  261. // $('.div_to_body').click(function(e) {
  262. // // trackingMatrix.push(adCoords(e, 1));
  263. // ivprogCore.registerClick(e.pageX, e.pageY, e.target.classList['value']);
  264. // });
  265. } else if (iLMparameters.iLM_PARAM_Assignment) {
  266. // Caso não esteja em modo de resolução de atividade, a visualização no momento
  267. // é para a elaboração de atividade:
  268. //$('.elaboracao').css("display","block");
  269. // Se possuir o parâmetro iLMparameters.iLM_PARAM_Assignment, o professor
  270. // está editando uma atividade:
  271. getiLMContent();
  272. } else {
  273. renderAlgorithm();
  274. }
  275. if ((iLMparameters.iLM_PARAM_AssignmentURL == "true") && (iLMparameters.iLM_PARAM_SendAnswer == "true")) {
  276. prepareActivityCreation();
  277. }
  278. }
  279. function blockAllEditingOptions () {
  280. if ((iLMparameters.iLM_PARAM_AssignmentURL == "true") && (iLMparameters.iLM_PARAM_SendAnswer == "true")) {
  281. return;
  282. }
  283. $('.add_global_button').addClass('disabled');
  284. $('.move_function').addClass('disabled');
  285. $('.add_function_button').addClass('disabled');
  286. $('.add_var_button_function .ui.icon.button.purple').addClass('disabled');
  287. $('.add_var_button_function').addClass('disabled');
  288. $('.menu_commands').addClass('disabled');
  289. $('.global_type').addClass('disabled');
  290. $('.editing_name_var').addClass('disabled');
  291. $('.span_value_variable').addClass('disabled');
  292. $('.remove_global').addClass('disabled');
  293. $('.ui.icon.ellipsis.vertical.inverted').addClass('disabled');
  294. $('.alternate_constant').addClass('disabled');
  295. $('.remove_variable').addClass('disabled');
  296. $('.add_global_matrix_column').addClass('disabled');
  297. $('.remove_global_matrix_column').addClass('disabled');
  298. $('.add_global_matrix_line').addClass('disabled');
  299. $('.remove_global_matrix_line').addClass('disabled');
  300. $('.add_global_vector_column').addClass('disabled');
  301. $('.remove_global_vector_column').addClass('disabled');
  302. $('.add_expression').addClass('disabled');
  303. $('.add_parentheses').addClass('disabled');
  304. $('.remove_function_button').addClass('disabled');
  305. $('.button_remove_command').addClass('disabled');
  306. $('.command_drag').addClass('disabled');
  307. $('.simple_add').addClass('disabled');
  308. $('.add_parameter_button').addClass('disabled');
  309. $('.parameter_div_edit').addClass('disabled');
  310. $('.function_name_div_updated').addClass('disabled');
  311. $('.value_rendered').addClass('disabled');
  312. $('.var_name').addClass('disabled');
  313. $('.variable_rendered').addClass('disabled');
  314. $('.dropdown').addClass('disabled');
  315. $('.remove_parameter').addClass('disabled');
  316. $('.ui.dropdown.global_type.disabled').css('opacity', '1');
  317. $('.ui.dropdown.variable_type.disabled').css('opacity', '1');
  318. $('.ui.dropdown.function_return.disabled').css('opacity', '1');
  319. $('.ui.dropdown.parameter_type.disabled').css('opacity', '1');
  320. ivprogCore.CodeEditor.disable(true);
  321. }
  322. function ivprogTextualOrVisual () {
  323. if (ivprogCore.Config.programming_type) {
  324. if (ivprogCore.Config.programming_type == "textual") {
  325. $('.ivprog_visual_panel').css('display', 'none');
  326. $('.ivprog_textual_panel').css('display', 'block');
  327. $('.ivprog_textual_panel').removeClass('loading');
  328. $('.visual_coding_button').removeClass('active');
  329. $('.textual_coding_button').addClass('active');
  330. $('.visual_coding_button').addClass('disabled');
  331. let textual_code = algorithm_in_ilm;
  332. if(!textual_code) {
  333. textual_code = ivprogCore.LocalizedStrings.getUI("initial_program_code");
  334. textual_code = textual_code.replace(/\\n/g,"\n");
  335. textual_code = textual_code.replace(/\\t/g,"\t");
  336. }
  337. ivprogCore.CodeEditor.setCode(textual_code);
  338. ivprogCore.CodeEditor.disable(false);
  339. }
  340. if (ivprogCore.Config.programming_type == "visual") {
  341. }
  342. }
  343. }
  344. function iassingIntegration () {
  345. // Disable by default...
  346. $('.assessment_button').addClass('disabled');
  347. prepareEnvironment();
  348. if (inIframe()) {
  349. orderIcons();
  350. orderWidth();
  351. }
  352. }
  353. // Função para preparar a interface para o professor criar atividade:
  354. function prepareActivityCreation () {
  355. var menuTab = $('<div class="ui top attached tabular menu">'
  356. + '<a class="item active" data-tab="testcases">' + LocalizedStrings.getUI('text_teacher_test_case') + '</a>'
  357. + '<a class="item" data-tab="algorithm">' + LocalizedStrings.getUI('text_teacher_algorithm') + '</a>'
  358. + '<a class="item" data-tab="settings">' + LocalizedStrings.getUI('text_teacher_config') + '</a>'
  359. + '</div>'
  360. + '<div class="ui bottom attached tab segment active tab_test_cases" data-tab="testcases"></div>'
  361. + '<div class="ui bottom attached tab segment tab_algorithm" data-tab="algorithm"></div>'
  362. + '<div class="ui bottom attached tab segment tab_settings" data-tab="settings"></div>');
  363. menuTab.insertBefore('.add_accordion');
  364. $('.tabular.menu .item').tab();
  365. $('.main_title').remove();
  366. $('.ui.accordion').addClass('styled');
  367. $('<div class="content_margin"></div>').insertBefore($('.add_accordion').find('.content').find('.div_to_body'));
  368. $('<div class="ui checkbox"><input type="checkbox" name="include_algo" class="include_algo" tabindex="0" class="hidden"><label>'+LocalizedStrings.getUI('text_teacher_algorithm_include')+'</label></div>').insertAfter('.content_margin');
  369. var cases_test_div = $('<div></div>');
  370. $('.tab_test_cases').append(cases_test_div);
  371. var config_div = $('<div></div>');
  372. $('.tab_settings').append(config_div);
  373. $('.ui.checkbox').checkbox();
  374. $('.tab_algorithm').append($('.add_accordion'));
  375. prepareTableSettings(config_div);
  376. prepareTableTestCases(cases_test_div);
  377. if (inIframe()) {
  378. $('.ui.styled.accordion').css('width', '96%');
  379. }
  380. }
  381. function prepareTableTestCases (div_el) {
  382. var table_el = '<form name="test_cases"><table class="ui blue table"><thead><tr><th width="30px">#</th><th>'+LocalizedStrings.getUI('text_teacher_test_case_input')+'</th><th>'+LocalizedStrings.getUI('text_teacher_test_case_output')+'</th><th width="80px">'+LocalizedStrings.getUI('text_teacher_test_case_actions')+'</th></tr></thead>'
  383. + '<tbody class="content_cases"></tbody></table></form>';
  384. div_el.append(table_el);
  385. var table_buttons = '<table class="table_buttons"><tr><td>'
  386. + '<button class="ui teal labeled icon button button_add_case"><i class="plus icon"></i>'+LocalizedStrings.getUI('text_teacher_test_case_add')+'</button>'
  387. + '</td><td class="right_align">'
  388. + '<button class="ui orange labeled icon button button_generate_outputs"><i class="sign-in icon"></i>'+LocalizedStrings.getUI('text_teacher_generate_outputs')+'</button>'
  389. + '</td></tr></table>';
  390. div_el.append(table_buttons);
  391. div_el.append($('<div class="ui basic modal"><div class="content"><p>Olá</p></div><div class="actions"><div class="ui green ok inverted button">Fechar</div></div></div>'));
  392. $('.button_add_case').on('click', function(e) {
  393. addTestCase();
  394. });
  395. $('.button_generate_outputs').on('click', function(e) {
  396. generateOutputs();
  397. });
  398. }
  399. function showAlert (msg) {
  400. $('.ui.basic.modal .content').html('<h3>'+msg+'</h3>');
  401. $('.ui.basic.modal').modal('show');
  402. }
  403. function generateOutputs () {
  404. if (window.program_obj.functions.length == 1 && window.program_obj.functions[0].commands.length == 0) {
  405. showAlert(LocalizedStrings.getUI('text_teacher_generate_outputs_algorithm'));
  406. return;
  407. }
  408. // código:
  409. var code_teacher = window.generator();
  410. // array com as entradas já inseridas:
  411. var test_cases = JSON.parse(prepareTestCases().replace('"testcases" :', ''));
  412. ivprogCore.autoGenerateTestCaseOutput(code_teacher, test_cases).catch(function (error) {
  413. showAlert("Houve um erro durante a execução do seu programa: "+error.message);
  414. });
  415. }
  416. function outputGenerated (test_cases) {
  417. var fields = $('.text_area_output');
  418. /*for (var i = 0; i < test_cases.length; i++) {
  419. $(fields[i]).val('');
  420. for (var j = 0; j < test_cases[i].output.length; j++) {
  421. $(fields[i]).val($(fields[i]).val() + test_cases[i].output[j]);
  422. if (j < test_cases[i].output.length - 1) {
  423. $(fields[i]).val($(fields[i]).val() + '\n');
  424. }
  425. }
  426. $(fields[i]).attr('rows', test_cases[i].output.length);
  427. }*/
  428. animateOutput(fields, test_cases, 0);
  429. }
  430. function animateOutput (list, test_cases, index) {
  431. if (list.length == index) return;
  432. $(list[index]).val('');
  433. for (var j = 0; j < test_cases[index].output.length; j++) {
  434. console.log(test_cases[index].output[j].charCodeAt(0));
  435. $(list[index]).val($(list[index]).val() + test_cases[index].output[j]);
  436. if (j < test_cases[index].output.length - 1) {
  437. $(list[index]).val($(list[index]).val() + '\n');
  438. }
  439. }
  440. $(list[index]).attr('rows', test_cases[index].output.length);
  441. $(list[index]).effect('highlight', null, 50, function() {
  442. animateOutput(list, test_cases, index + 1);
  443. });
  444. }
  445. var hist = false;
  446. function addTestCase (test_case = null) {
  447. var new_row = null;
  448. if (test_case) {
  449. var text_row = '';
  450. text_row += '<tr><td class="counter"></td><td class="expandingArea"><textarea rows="'+test_case.input.length+'" name="input" class="text_area_input">';
  451. for (var i = 0; i < test_case.input.length; i ++) {
  452. text_row += test_case.input[i];
  453. if ((i + 1) < test_case.input.length) {
  454. text_row += '\n';
  455. }
  456. }
  457. text_row += '</textarea></td><td class="expandingArea"><textarea rows="'+test_case.output.length+'" name="output" class="text_area_output">';
  458. for (var i = 0; i < test_case.output.length; i ++) {
  459. text_row += test_case.output[i];
  460. if ((i + 1) < test_case.output.length) {
  461. text_row += '\n';
  462. }
  463. }
  464. text_row += '</textarea></td><td class="btn_actions"><div class="ui button_remove_case"><i class="red icon times large"></i></div></td></tr>';
  465. new_row = $(text_row);
  466. } else {
  467. new_row = $('<tr><td class="counter"></td><td class="expandingArea"><textarea rows="1" name="input" class="text_area_input"></textarea></td><td class="expandingArea"><textarea rows="1" name="output" class="text_area_output"></textarea></td><td class="btn_actions"><div class="ui button_remove_case"><i class="red icon times large"></i></div></td></tr>');
  468. }
  469. $('.content_cases').append(new_row);
  470. new_row.find('.button_remove_case').click(function(e) {
  471. new_row.remove();
  472. updateTestCaseCounter();
  473. });
  474. new_row.find('textarea').on('input', function(e) {
  475. var lines = $(this).val().split('\n').length;
  476. $(this).attr('rows', lines);
  477. });
  478. updateTestCaseCounter();
  479. $('.text_area_output').keydown(function(e) {
  480. var code = e.keyCode || e.which;
  481. if (code == 9 && $(this).closest("tr").is(":last-child")) {
  482. hist = true;
  483. addTestCase();
  484. }
  485. });
  486. if (test_case == null) {
  487. if (!hist) {
  488. $( ".content_cases tr:last" ).find('.text_area_input').focus();
  489. } else {
  490. hist = false;
  491. }
  492. }
  493. }
  494. function updateTestCaseCounter () {
  495. var i = 1;
  496. $( ".content_cases" ).find('tr').each(function() {
  497. $( this ).find('.counter').text(i);
  498. ++i;
  499. });
  500. }
  501. function prepareTableSettings (div_el) {
  502. div_el.append('<div class="ui segment settings_topic"><h3 class="ui header"><i class="window maximize outline icon"></i><div class="content">'+LocalizedStrings.getUI('text_config_programming')+'</div></h3>'
  503. +'<div class="content content_segment_settings"><form name="settings_programming_type"><div class="ui stackable five column grid">'
  504. +'<div class="column"><div class="ui radio"><input type="radio" name="programming_type" id="programming_textual" value="textual" tabindex="0" class="hidden small"><label for="programming_textual">'+LocalizedStrings.getUI('text_config_programming_textual')+'</label></div></div>'
  505. +'<div class="column"><div class="ui radio"><input type="radio" name="programming_type" id="programming_visual" value="visual" checked tabindex="0" class="hidden small"><label for="programming_visual">'+LocalizedStrings.getUI('text_config_programming_visual')+'</label></div></div>'
  506. +'</div></form></div></div>');
  507. div_el.append('<div class="ui segment settings_topic"><h3 class="ui header"><i class="qrcode icon"></i><div class="content">'+LocalizedStrings.getUI('text_teacher_data_types')+'</div></h3>'
  508. +'<div class="content content_segment_settings"><form name="settings_data_types"><div class="ui stackable five column grid">'
  509. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="integer_data_type" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('type_integer')+'</label></div></div>'
  510. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="real_data_type" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('type_real')+'</label></div></div>'
  511. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="text_data_type" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('type_text')+'</label></div></div>'
  512. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="boolean_data_type" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('type_boolean')+'</label></div></div>'
  513. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="void_data_type" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('type_void')+'</label></div></div>'
  514. +'</div></form></div></div>');
  515. div_el.append('<div class="ui segment settings_topic"><h3 class="ui header"><i class="code icon"></i><div class="content">'+LocalizedStrings.getUI('text_teacher_commands')+'</div></h3>'
  516. +'<div class="content content_segment_settings"><form name="settings_commands"><div class="ui stackable three column grid">'
  517. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_read" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_read_var')+'</label></div></div>'
  518. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_write" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_write_var')+'</label></div></div>'
  519. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_comment" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_comment')+'</label></div></div>'
  520. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_attribution" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_attribution')+'</label></div></div>'
  521. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_functioncall" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_functioncall')+'</label></div></div>'
  522. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_iftrue" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_iftrue')+'</label></div></div>'
  523. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_repeatNtimes" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_repeatNtimes')+'</label></div></div>'
  524. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_while" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_whiletrue')+'</label></div></div>'
  525. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_dowhile" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_dowhiletrue')+'</label></div></div>'
  526. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_switch" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_switch')+'</label></div></div>'
  527. +'</div></form></div></div>');
  528. div_el.append('<div class="ui segment settings_topic"><h3 class="ui header"><i class="terminal icon"></i><div class="content">'+LocalizedStrings.getUI('text_teacher_functions')+'</div></h3>'
  529. +'<div class="content content_segment_settings"><form name="settings_functions"><div class="ui stackable one column grid">'
  530. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="functions_creation" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_teacher_create_functions')+'</label></div></div>'
  531. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="functions_move" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_teacher_create_movement_functions')+'</label></div></div>'
  532. +'</div></form></div></div>');
  533. div_el.append('<div class="ui segment settings_topic"><h3 class="ui header"><i class="filter icon"></i><div class="content">'+LocalizedStrings.getUI('text_teacher_filter')+'</div><i class="circular inverted teal question icon"></i></h3>'
  534. +'<div class="content content_segment_settings"><form name="settings_filter"><div class="ui stackable one column grid">'
  535. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="filter_active" tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_teacher_filter_active')+'</label></div></div>'
  536. +'</div></form></div></div>');
  537. $('.circular.inverted.teal.question.icon').popup({
  538. content : LocalizedStrings.getUI("text_teacher_filter_help"),
  539. delay: {
  540. show: 750,
  541. hide: 0
  542. }
  543. });
  544. $('.ui.checkbox').checkbox();
  545. }
  546. function getTrackingLogs () {
  547. return ivprogCore.getLogsAsString();
  548. // var ret = "";
  549. // for (var i = 0; i < trackingMatrix.length; ++i) {
  550. // ret += "\n" + trackingMatrix[i][0] + "," + trackingMatrix[i][1] + "," + trackingMatrix[i][2];
  551. // if (trackingMatrix[i][3] === 1) {
  552. // ret += ',' + trackingMatrix[i][3] + ',"' + trackingMatrix[i][4] + '"';
  553. // }
  554. // }
  555. // return ret;
  556. }
  557. // Tracking mouse movements
  558. // var trackingMatrix = [];
  559. /* function adCoords(e, code){
  560. var x = e.pageX;
  561. var y = e.pageY;
  562. if (code === 1) {
  563. return [new Date().getTime(), x, y, code, e.target.classList['value']];
  564. } else {
  565. return [x, y, code];
  566. }
  567. } */
  568. // $( document ).ready(function() {
  569. // if (inIframe()) {
  570. // orderIcons();
  571. // orderWidth();
  572. // }
  573. // renderAlgorithm();
  574. // });
  575. function orderWidth() {
  576. $('.ui.raised.container.segment.div_to_body').css('width', '100%');
  577. $('.ui.one.column.container.segment.ivprog_visual_panel').css('width', '100%');
  578. }
  579. function orderIcons() {
  580. $('.ui.one.column.doubling.stackable.grid.container').css('display', 'none');
  581. $('.only_in_frame').css('display', 'block');
  582. }
  583. function inIframe () {
  584. try {
  585. return window.self !== window.top;
  586. } catch (e) {
  587. return true;
  588. }
  589. }
  590. function full_screen() {
  591. // check if user allows full screen of elements. This can be enabled or disabled in browser config. By default its enabled.
  592. //its also used to check if browser supports full screen api.
  593. if("fullscreenEnabled" in document || "webkitFullscreenEnabled" in document || "mozFullScreenEnabled" in document || "msFullscreenEnabled" in document) {
  594. if(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled) {
  595. var element = document.getElementById("ui_main_div");
  596. //requestFullscreen is used to display an element in full screen mode.
  597. if("requestFullscreen" in element) {
  598. element.requestFullscreen();
  599. }
  600. else if ("webkitRequestFullscreen" in element) {
  601. element.webkitRequestFullscreen();
  602. }
  603. else if ("mozRequestFullScreen" in element) {
  604. element.mozRequestFullScreen();
  605. }
  606. else if ("msRequestFullscreen" in element) {
  607. element.msRequestFullscreen();
  608. }
  609. }
  610. } else {
  611. $('.expand_button').addClass('disabled');
  612. }
  613. }
  614. function teacherAutoEval (data) {
  615. previousContent = data;
  616. $.get(iLMparameters.iLM_PARAM_TeacherAutoEval, function (originalData) {
  617. // Ver arquivo js/util/iassignHelpers.js
  618. var content = ivprogCore.prepareActivityToStudentHelper(data).getOrElse(null);
  619. if(!content) {
  620. showInvalidData();
  621. return;
  622. }
  623. // Casos de testes agora são delegados ao tratamento apropriado pela função acima
  624. // var testCases = content.testcases;
  625. const settings = parseFormSettingsData(content.settingsDataTypes, content.settingsCommands, content.settingsFunctions, content.settingsFilter);
  626. const programming_type = content.settingsProgrammingType;
  627. ivprogCore.Config.setConfig({
  628. ui_settings: settings,
  629. programming_type: programming_type
  630. });
  631. //ivprogCore.Config.programming_type = content.settingsProgrammingType;
  632. //settingsDataTypes = content.settingsDataTypes;
  633. //settingsCommands = content.settingsCommands;
  634. //settingsFunctions = content.settingsFunctions;
  635. //settingsFilter = content.settingsFilter;
  636. if (content.algorithmInIlm != null) {
  637. algorithm_in_ilm = content.algorithmInIlm;
  638. parsePreviousAlgorithm();
  639. ivprogCore.autoEval(originalData, displayGrade);
  640. }
  641. ivprogTextualOrVisual();
  642. if (ivprogCore.Config.isSettingEnabled("filter_active")) {
  643. blockAllEditingOptions();
  644. }
  645. });
  646. }
  647. function displayGrade(grade) {
  648. alert(grade);
  649. }
  650. function showInvalidData () {
  651. $('.ui.height_100.add_accordion').dimmer({
  652. closable: false
  653. });
  654. $('.dimmer_content_message h3').html(LocalizedStrings.getUI('text_message_error_activity_file'));
  655. $('.dimmer_content_message button').text(LocalizedStrings.getUI('text_message_error_activity_reload'));
  656. $('.dimmer_content_message').css('display', 'block');
  657. $('.ui.height_100.add_accordion').dimmer('add content', '.dimmer_content_message');
  658. $('.ui.height_100.add_accordion').dimmer('show');
  659. }
  660. function parseFormSettingsData (...array_data) {
  661. const list = []
  662. array_data.forEach(array => list = list.concat(array));
  663. return list;
  664. }