1
0

iassign-integration-functions.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  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 (settingsProgrammingTypes == "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].trim() + '"';
  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. if (outs) {
  84. for (var j = 0; j < outs.length; j++) {
  85. ret += '"' + outs[j].trim() + '"';
  86. if ((j + 1) < outs.length) {
  87. ret += ', ';
  88. }
  89. }
  90. }
  91. ret += ']';
  92. ret += '\n}'
  93. if ((i + 2) < test_cases_array.length) {
  94. ret += ',';
  95. }
  96. }
  97. ret += '\n] ';
  98. return ret;
  99. }
  100. // Função chamada pelo iTarefa para receber a nota do aluno na atividade
  101. // O retorno é um valor entre 0.0 e 1.0
  102. function getEvaluation () {
  103. if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  104. // A chamada do método abaixo é obrigatória!
  105. // Observe que a chamada parte do iLM para o iTarefa
  106. //parent.getEvaluationCallback(window.studentGrade);
  107. var canRunAssessment = runCodeAssessment();
  108. if(canRunAssessment === -1) {
  109. parent.getEvaluationCallback(-1);
  110. }
  111. }
  112. }
  113. //var testCases = null
  114. var settingsDataTypes = null;
  115. var settingsCommands = null;
  116. var settingsFunctions = null;
  117. var settingsProgrammingTypes = null;
  118. var settingsFilter = null;
  119. var algorithm_in_ilm = null;
  120. var previousContent = null;
  121. // Função para que o iMA leia os dados da atividade fornecidos pelo iTarefa
  122. function getiLMContent () {
  123. // O parâmetro "iLM_PARAM_Assignment" fornece o URL do endereço que deve ser
  124. // requisitado via AJAX para a captura dos dados da atividade
  125. $.get(iLMparameters.iLM_PARAM_Assignment, function (data) {
  126. //professor invocou a avaliação automática dos exercícios do bloco
  127. if (iLMparameters.iLM_PARAM_TeacherAutoEval != null) {
  128. teacherAutoEval(data);
  129. //não deve exibir nenhuma interface...
  130. return;
  131. } else if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  132. // Aluno está trabalhando em alguma atividade:
  133. previousContent = data;
  134. prepareActivityToStudent(data);
  135. } else { // Professor está editando uma atividade:
  136. previousContent = data;
  137. prepareActivityToEdit(data);
  138. }
  139. window.block_render = false;
  140. renderAlgorithm();
  141. });
  142. }
  143. function prepareActivityToEdit (ilm_cont) {
  144. //var content = JSON.parse(ilm_cont.split('\n::algorithm::')[0]);
  145. // Ver arquivo js/util/iassignHelpers.js
  146. var content = ivprogCore.prepareActivityToStudentHelper(ilm_cont);
  147. var testCases = ivprogCore.getTestCases();
  148. settingsProgrammingTypes = content.settingsProgrammingType;
  149. settingsDataTypes = content.settingsDataTypes;
  150. settingsCommands = content.settingsCommands;
  151. settingsFunctions = content.settingsFunctions;
  152. settingsFilter = content.settingsFilter;
  153. for (var i = 0; i < testCases.length; i++) {
  154. addTestCase(testCases[i]);
  155. }
  156. if (content.algorithmInIlm != null) {
  157. algorithm_in_ilm = content.algorithmInIlm;
  158. $("input[name='include_algo']").prop('checked', true);
  159. includePreviousAlgorithm();
  160. renderAlgorithm();
  161. }
  162. ivprogTextualOrVisual();
  163. if (settingsFilter && settingsFilter[0]) {
  164. blockAllEditingOptions();
  165. }
  166. }
  167. function parsePreviousAlgorithm () {
  168. window.program_obj.functions = JSON.parse(algorithm_in_ilm).functions;
  169. window.program_obj.globals = JSON.parse(algorithm_in_ilm).globals;
  170. }
  171. function includePreviousAlgorithm () {
  172. if (settingsProgrammingTypes == "textual") {
  173. return;
  174. }
  175. parsePreviousAlgorithm();
  176. window.watchW.watch(window.program_obj.globals, function(){
  177. if (window.insertContext) {
  178. setTimeout(function(){ renderAlgorithm(); }, 300);
  179. window.insertContext = false;
  180. } else {
  181. renderAlgorithm();
  182. }
  183. }, 1);
  184. for (var i = 0; i < window.program_obj.functions.length; i ++) {
  185. window.watchW.watch(window.program_obj.functions[i].parameters_list, function(){
  186. if (window.insertContext) {
  187. setTimeout(function(){ renderAlgorithm(); }, 300);
  188. window.insertContext = false;
  189. } else {
  190. renderAlgorithm();
  191. }
  192. }, 1);
  193. window.watchW.watch(window.program_obj.functions[i].variables_list, function(){
  194. if (window.insertContext) {
  195. setTimeout(function(){ renderAlgorithm(); }, 300);
  196. window.insertContext = false;
  197. } else {
  198. renderAlgorithm();
  199. }
  200. }, 1);
  201. if (window.program_obj.functions[i].is_main) {
  202. window.program_obj.functions[i].name = LocalizedStrings.getUI("start");
  203. }
  204. }
  205. window.watchW.watch(window.program_obj.functions, function(){
  206. if (window.insertContext) {
  207. setTimeout(function(){ renderAlgorithm(); }, 300);
  208. window.insertContext = false;
  209. } else {
  210. renderAlgorithm();
  211. }
  212. }, 1);
  213. }
  214. function prepareActivityToStudent (ilm_cont) {
  215. // Ver arquivo js/util/iassignHelpers.js
  216. var content = ivprogCore.prepareActivityToStudentHelper(ilm_cont);
  217. // Casos de testes agora são delegados ao tratamento apropriado pela função acima
  218. // var testCases = content.testcases;
  219. settingsProgrammingTypes = content.settingsProgrammingType;
  220. settingsDataTypes = content.settingsDataTypes;
  221. settingsCommands = content.settingsCommands;
  222. settingsFunctions = content.settingsFunctions;
  223. settingsFilter = content.settingsFilter;
  224. if (content.algorithmInIlm != null) {
  225. algorithm_in_ilm = content.algorithmInIlm;
  226. includePreviousAlgorithm();
  227. }
  228. $('.assessment_button').removeClass('disabled');
  229. renderAlgorithm();
  230. ivprogTextualOrVisual();
  231. if (settingsFilter && settingsFilter[0]) {
  232. blockAllEditingOptions();
  233. }
  234. }
  235. // Função para organizar se para criação, visualização ou resolução de atividade
  236. function prepareEnvironment () {
  237. $('.div_to_body').click(function(e) {
  238. // trackingMatrix.push(adCoords(e, 1));
  239. ivprogCore.registerClick(e.pageX, e.pageY, e.target.classList['value']);
  240. });
  241. // Se iLM_PARAM_SendAnswer for false, então trata-se de resolução de atividade,
  242. // portanto, a "DIV" de resolução é liberada
  243. if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  244. //$('.resolucao').css("display","block");
  245. getiLMContent();
  246. // $('.div_to_body').mousemove(function(e) {
  247. // trackingMatrix.push(adCoords(e, 0));
  248. // });
  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. } else if (iLMparameters.iLM_PARAM_Assignment) {
  254. // Caso não esteja em modo de resolução de atividade, a visualização no momento
  255. // é para a elaboração de atividade:
  256. //$('.elaboracao').css("display","block");
  257. // Se possuir o parâmetro iLMparameters.iLM_PARAM_Assignment, o professor
  258. // está editando uma atividade:
  259. getiLMContent();
  260. } else {
  261. renderAlgorithm();
  262. }
  263. if ((iLMparameters.iLM_PARAM_AssignmentURL == "true") && (iLMparameters.iLM_PARAM_SendAnswer == "true")) {
  264. prepareActivityCreation();
  265. }
  266. }
  267. function blockAllEditingOptions () {
  268. if ((iLMparameters.iLM_PARAM_AssignmentURL == "true") && (iLMparameters.iLM_PARAM_SendAnswer == "true")) {
  269. return;
  270. }
  271. $('.add_global_button').addClass('disabled');
  272. $('.move_function').addClass('disabled');
  273. $('.add_function_button').addClass('disabled');
  274. $('.add_var_button_function .ui.icon.button.purple').addClass('disabled');
  275. $('.add_var_button_function').addClass('disabled');
  276. $('.menu_commands').addClass('disabled');
  277. $('.global_type').addClass('disabled');
  278. $('.editing_name_var').addClass('disabled');
  279. $('.span_value_variable').addClass('disabled');
  280. $('.remove_global').addClass('disabled');
  281. $('.ui.icon.ellipsis.vertical.inverted').addClass('disabled');
  282. $('.alternate_constant').addClass('disabled');
  283. $('.remove_variable').addClass('disabled');
  284. $('.add_global_matrix_column').addClass('disabled');
  285. $('.remove_global_matrix_column').addClass('disabled');
  286. $('.add_global_matrix_line').addClass('disabled');
  287. $('.remove_global_matrix_line').addClass('disabled');
  288. $('.add_global_vector_column').addClass('disabled');
  289. $('.remove_global_vector_column').addClass('disabled');
  290. $('.add_expression').addClass('disabled');
  291. $('.add_parentheses').addClass('disabled');
  292. $('.remove_function_button').addClass('disabled');
  293. $('.button_remove_command').addClass('disabled');
  294. $('.command_drag').addClass('disabled');
  295. $('.simple_add').addClass('disabled');
  296. $('.add_parameter_button').addClass('disabled');
  297. $('.parameter_div_edit').addClass('disabled');
  298. $('.function_name_div_updated').addClass('disabled');
  299. $('.value_rendered').addClass('disabled');
  300. $('.var_name').addClass('disabled');
  301. $('.variable_rendered').addClass('disabled');
  302. $('.dropdown').addClass('disabled');
  303. $('.remove_parameter').addClass('disabled');
  304. $('.ui.dropdown.global_type.disabled').css('opacity', '1');
  305. $('.ui.dropdown.variable_type.disabled').css('opacity', '1');
  306. $('.ui.dropdown.function_return.disabled').css('opacity', '1');
  307. $('.ui.dropdown.parameter_type.disabled').css('opacity', '1');
  308. ivprogCore.CodeEditor.disable(true);
  309. }
  310. function ivprogTextualOrVisual () {
  311. if (settingsProgrammingTypes) {
  312. if (settingsProgrammingTypes == "textual") {
  313. $('.ivprog_visual_panel').css('display', 'none');
  314. $('.ivprog_textual_panel').css('display', 'block');
  315. $('.ivprog_textual_panel').removeClass('loading');
  316. $('.visual_coding_button').removeClass('active');
  317. $('.textual_coding_button').addClass('active');
  318. $('.visual_coding_button').addClass('disabled');
  319. ivprogCore.CodeEditor.setCode(algorithm_in_ilm);
  320. ivprogCore.CodeEditor.disable(false);
  321. }
  322. if (settingsProgrammingTypes == "visual") {
  323. }
  324. }
  325. }
  326. function iassingIntegration () {
  327. // Disable by default...
  328. $('.assessment_button').addClass('disabled');
  329. prepareEnvironment();
  330. if (inIframe()) {
  331. orderIcons();
  332. orderWidth();
  333. }
  334. }
  335. // Função para preparar a interface para o professor criar atividade:
  336. function prepareActivityCreation () {
  337. var menuTab = $('<div class="ui top attached tabular menu">'
  338. + '<a class="item active" data-tab="testcases">' + LocalizedStrings.getUI('text_teacher_test_case') + '</a>'
  339. + '<a class="item" data-tab="algorithm">' + LocalizedStrings.getUI('text_teacher_algorithm') + '</a>'
  340. + '<a class="item" data-tab="settings">' + LocalizedStrings.getUI('text_teacher_config') + '</a>'
  341. + '</div>'
  342. + '<div class="ui bottom attached tab segment active tab_test_cases" data-tab="testcases"></div>'
  343. + '<div class="ui bottom attached tab segment tab_algorithm" data-tab="algorithm"></div>'
  344. + '<div class="ui bottom attached tab segment tab_settings" data-tab="settings"></div>');
  345. menuTab.insertBefore('.add_accordion');
  346. $('.tabular.menu .item').tab();
  347. $('.main_title').remove();
  348. $('.ui.accordion').addClass('styled');
  349. $('<div class="content_margin"></div>').insertBefore($('.add_accordion').find('.content').find('.div_to_body'));
  350. $('<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');
  351. var cases_test_div = $('<div></div>');
  352. $('.tab_test_cases').append(cases_test_div);
  353. var config_div = $('<div></div>');
  354. $('.tab_settings').append(config_div);
  355. $('.ui.checkbox').checkbox();
  356. $('.tab_algorithm').append($('.add_accordion'));
  357. prepareTableSettings(config_div);
  358. prepareTableTestCases(cases_test_div);
  359. if (inIframe()) {
  360. $('.ui.styled.accordion').css('width', '96%');
  361. }
  362. }
  363. function prepareTableTestCases (div_el) {
  364. 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>'
  365. + '<tbody class="content_cases"></tbody></table></form>';
  366. div_el.append(table_el);
  367. var table_buttons = '<table class="table_buttons"><tr><td>'
  368. + '<button class="ui teal labeled icon button button_add_case"><i class="plus icon"></i>'+LocalizedStrings.getUI('text_teacher_test_case_add')+'</button>'
  369. + '</td><td class="right_align">'
  370. + '<button class="ui orange labeled icon button button_generate_outputs"><i class="sign-in icon"></i>'+LocalizedStrings.getUI('text_teacher_generate_outputs')+'</button>'
  371. + '</td></tr></table>';
  372. div_el.append(table_buttons);
  373. 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>'));
  374. $('.button_add_case').on('click', function(e) {
  375. addTestCase();
  376. });
  377. $('.button_generate_outputs').on('click', function(e) {
  378. generateOutputs();
  379. });
  380. }
  381. function showAlert (msg) {
  382. $('.ui.basic.modal .content').html('<h3>'+msg+'</h3>');
  383. $('.ui.basic.modal').modal('show');
  384. }
  385. function generateOutputs () {
  386. if (window.program_obj.functions.length == 1 && window.program_obj.functions[0].commands.length == 0) {
  387. showAlert(LocalizedStrings.getUI('text_teacher_generate_outputs_algorithm'));
  388. return;
  389. }
  390. // código:
  391. var code_teacher = window.generator();
  392. // array com as entradas já inseridas:
  393. var test_cases = JSON.parse(prepareTestCases().replace('"testcases" :', ''));
  394. ivprogCore.autoGenerateTestCaseOutput(code_teacher, test_cases).catch(function (error) {
  395. showAlert("Houve um erro durante a execução do seu programa: "+error.message);
  396. });
  397. }
  398. function outputGenerated (test_cases) {
  399. var fields = $('.text_area_output');
  400. /*for (var i = 0; i < test_cases.length; i++) {
  401. $(fields[i]).val('');
  402. for (var j = 0; j < test_cases[i].output.length; j++) {
  403. $(fields[i]).val($(fields[i]).val() + test_cases[i].output[j]);
  404. if (j < test_cases[i].output.length - 1) {
  405. $(fields[i]).val($(fields[i]).val() + '\n');
  406. }
  407. }
  408. $(fields[i]).attr('rows', test_cases[i].output.length);
  409. }*/
  410. animateOutput(fields, test_cases, 0);
  411. }
  412. function animateOutput (list, test_cases, index) {
  413. if (list.length == index) return;
  414. $(list[index]).val('');
  415. for (var j = 0; j < test_cases[index].output.length; j++) {
  416. $(list[index]).val($(list[index]).val() + test_cases[index].output[j]);
  417. if (j < test_cases[index].output.length - 1) {
  418. $(list[index]).val($(list[index]).val() + '\n');
  419. }
  420. }
  421. $(list[index]).attr('rows', test_cases[index].output.length);
  422. $(list[index]).effect('highlight', null, 50, function() {
  423. animateOutput(list, test_cases, index + 1);
  424. });
  425. }
  426. var hist = false;
  427. function addTestCase (test_case = null) {
  428. var new_row = null;
  429. if (test_case) {
  430. var text_row = '';
  431. text_row += '<tr><td class="counter"></td><td class="expandingArea"><textarea rows="'+test_case.input.length+'" name="input" class="text_area_input">';
  432. for (var i = 0; i < test_case.input.length; i ++) {
  433. text_row += test_case.input[i];
  434. if ((i + 1) < test_case.input.length) {
  435. text_row += '\n';
  436. }
  437. }
  438. text_row += '</textarea></td><td class="expandingArea"><textarea rows="'+test_case.output.length+'" name="output" class="text_area_output">';
  439. for (var i = 0; i < test_case.output.length; i ++) {
  440. text_row += test_case.output[i];
  441. if ((i + 1) < test_case.output.length) {
  442. text_row += '\n';
  443. }
  444. }
  445. text_row += '</textarea></td><td class="btn_actions"><div class="ui button_remove_case"><i class="red icon times large"></i></div></td></tr>';
  446. new_row = $(text_row);
  447. } else {
  448. 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>');
  449. }
  450. $('.content_cases').append(new_row);
  451. new_row.find('.button_remove_case').click(function(e) {
  452. new_row.remove();
  453. updateTestCaseCounter();
  454. });
  455. new_row.find('textarea').on('input', function(e) {
  456. var lines = $(this).val().split('\n').length;
  457. $(this).attr('rows', lines);
  458. });
  459. updateTestCaseCounter();
  460. $('.text_area_output').keydown(function(e) {
  461. var code = e.keyCode || e.which;
  462. if (code == 9 && $(this).closest("tr").is(":last-child")) {
  463. hist = true;
  464. addTestCase();
  465. }
  466. });
  467. if (test_case == null) {
  468. if (!hist) {
  469. $( ".content_cases tr:last" ).find('.text_area_input').focus();
  470. } else {
  471. hist = false;
  472. }
  473. }
  474. }
  475. function updateTestCaseCounter () {
  476. var i = 1;
  477. $( ".content_cases" ).find('tr').each(function() {
  478. $( this ).find('.counter').text(i);
  479. ++i;
  480. });
  481. }
  482. function prepareTableSettings (div_el) {
  483. 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>'
  484. +'<div class="content content_segment_settings"><form name="settings_programming_type"><div class="ui stackable five column grid">'
  485. +'<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>'
  486. +'<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>'
  487. +'</div></form></div></div>');
  488. 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>'
  489. +'<div class="content content_segment_settings"><form name="settings_data_types"><div class="ui stackable five column grid">'
  490. +'<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>'
  491. +'<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>'
  492. +'<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>'
  493. +'<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>'
  494. +'<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>'
  495. +'</div></form></div></div>');
  496. 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>'
  497. +'<div class="content content_segment_settings"><form name="settings_commands"><div class="ui stackable three column grid">'
  498. +'<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>'
  499. +'<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>'
  500. +'<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>'
  501. +'<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>'
  502. +'<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>'
  503. +'<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>'
  504. +'<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>'
  505. +'<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>'
  506. +'<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>'
  507. +'<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>'
  508. +'</div></form></div></div>');
  509. 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>'
  510. +'<div class="content content_segment_settings"><form name="settings_functions"><div class="ui stackable one column grid">'
  511. +'<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>'
  512. +'<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>'
  513. +'</div></form></div></div>');
  514. 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>'
  515. +'<div class="content content_segment_settings"><form name="settings_filter"><div class="ui stackable one column grid">'
  516. +'<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>'
  517. +'</div></form></div></div>');
  518. $('.circular.inverted.teal.question.icon').popup({
  519. content : LocalizedStrings.getUI("text_teacher_filter_help"),
  520. delay: {
  521. show: 750,
  522. hide: 0
  523. }
  524. });
  525. $('.ui.checkbox').checkbox();
  526. }
  527. function getTrackingLogs () {
  528. return ivprogCore.getLogsAsString();
  529. // var ret = "";
  530. // for (var i = 0; i < trackingMatrix.length; ++i) {
  531. // ret += "\n" + trackingMatrix[i][0] + "," + trackingMatrix[i][1] + "," + trackingMatrix[i][2];
  532. // if (trackingMatrix[i][3] === 1) {
  533. // ret += ',' + trackingMatrix[i][3] + ',"' + trackingMatrix[i][4] + '"';
  534. // }
  535. // }
  536. // return ret;
  537. }
  538. // Tracking mouse movements
  539. // var trackingMatrix = [];
  540. /* function adCoords(e, code){
  541. var x = e.pageX;
  542. var y = e.pageY;
  543. if (code === 1) {
  544. return [new Date().getTime(), x, y, code, e.target.classList['value']];
  545. } else {
  546. return [x, y, code];
  547. }
  548. } */
  549. // $( document ).ready(function() {
  550. // if (inIframe()) {
  551. // orderIcons();
  552. // orderWidth();
  553. // }
  554. // renderAlgorithm();
  555. // });
  556. function orderWidth() {
  557. $('.ui.raised.container.segment.div_to_body').css('width', '100%');
  558. $('.ui.one.column.container.segment.ivprog_visual_panel').css('width', '100%');
  559. }
  560. function orderIcons() {
  561. $('.ui.one.column.doubling.stackable.grid.container').css('display', 'none');
  562. $('.only_in_frame').css('display', 'block');
  563. }
  564. function inIframe () {
  565. try {
  566. return window.self !== window.top;
  567. } catch (e) {
  568. return true;
  569. }
  570. }
  571. function full_screen() {
  572. // check if user allows full screen of elements. This can be enabled or disabled in browser config. By default its enabled.
  573. //its also used to check if browser supports full screen api.
  574. if("fullscreenEnabled" in document || "webkitFullscreenEnabled" in document || "mozFullScreenEnabled" in document || "msFullscreenEnabled" in document) {
  575. if(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled) {
  576. var element = document.getElementById("ui_main_div");
  577. //requestFullscreen is used to display an element in full screen mode.
  578. if("requestFullscreen" in element) {
  579. element.requestFullscreen();
  580. }
  581. else if ("webkitRequestFullscreen" in element) {
  582. element.webkitRequestFullscreen();
  583. }
  584. else if ("mozRequestFullScreen" in element) {
  585. element.mozRequestFullScreen();
  586. }
  587. else if ("msRequestFullscreen" in element) {
  588. element.msRequestFullscreen();
  589. }
  590. }
  591. } else {
  592. $('.expand_button').addClass('disabled');
  593. }
  594. }
  595. function teacherAutoEval (data) {
  596. $.get(iLMparameters.iLM_PARAM_TeacherAutoEval, function (originalData) {
  597. // Ver arquivo js/util/iassignHelpers.js
  598. var content = ivprogCore.prepareActivityToStudentHelper(data);
  599. // Casos de testes agora são delegados ao tratamento apropriado pela função acima
  600. // var testCases = content.testcases;
  601. settingsProgrammingTypes = content.settingsProgrammingType;
  602. settingsDataTypes = content.settingsDataTypes;
  603. settingsCommands = content.settingsCommands;
  604. settingsFunctions = content.settingsFunctions;
  605. settingsFilter = content.settingsFilter;
  606. if (content.algorithmInIlm != null) {
  607. algorithm_in_ilm = content.algorithmInIlm;
  608. parsePreviousAlgorithm();
  609. ivprogCore.autoEval(originalData, parent.getEvaluationCallback);
  610. }
  611. ivprogTextualOrVisual();
  612. if (settingsFilter && settingsFilter[0]) {
  613. blockAllEditingOptions();
  614. }
  615. });
  616. }