iassign-integration-functions.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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. $('.add_accordion').addClass('accordion');
  338. $('.default_visual_title').toggle();
  339. $('.default_visual_title').append('<span>'+LocalizedStrings.getUI('text_teacher_algorithm')+'</span>');
  340. $('.height_100').removeClass('height_100');
  341. $('.main_title').remove();
  342. $('.ui.accordion').addClass('styled');
  343. $('<div class="content_margin"></div>').insertBefore($('.add_accordion').find('.content').find('.div_to_body'));
  344. $('<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');
  345. var cases_test_div = $('<div class="ui accordion styled"><div class="active title"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('text_teacher_test_case')+'</div><div class="active content"></div></div>');
  346. cases_test_div.insertBefore('.accordion');
  347. var config_div = $('<div class="ui accordion styled"><div class="title"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('text_teacher_config')+'</div><div class="content"></div></div>');
  348. config_div.insertAfter(cases_test_div);
  349. $('.ui.accordion').accordion();
  350. $('.ui.checkbox').checkbox();
  351. prepareTableSettings(config_div.find('.content'));
  352. prepareTableTestCases(cases_test_div.find('.content'));
  353. if (inIframe()) {
  354. $('.ui.styled.accordion').css('width', '96%');
  355. }
  356. }
  357. function prepareTableTestCases (div_el) {
  358. 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>'
  359. + '<tbody class="content_cases"></tbody></table></form>';
  360. div_el.append(table_el);
  361. var table_buttons = '<table class="table_buttons"><tr><td>'
  362. + '<button class="ui teal labeled icon button button_add_case"><i class="plus icon"></i>'+LocalizedStrings.getUI('text_teacher_test_case_add')+'</button>'
  363. + '</td><td class="right_align">'
  364. + '<button class="ui orange labeled icon button button_generate_outputs"><i class="sign-in icon"></i>'+LocalizedStrings.getUI('text_teacher_generate_outputs')+'</button>'
  365. + '</td></tr></table>';
  366. div_el.append(table_buttons);
  367. 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>'));
  368. $('.button_add_case').on('click', function(e) {
  369. addTestCase();
  370. });
  371. $('.button_generate_outputs').on('click', function(e) {
  372. generateOutputs();
  373. });
  374. }
  375. function showAlert (msg) {
  376. $('.ui.basic.modal .content').html('<h3>'+msg+'</h3>');
  377. $('.ui.basic.modal').modal('show');
  378. }
  379. function generateOutputs () {
  380. if (window.program_obj.functions.length == 1 && window.program_obj.functions[0].commands.length == 0) {
  381. showAlert(LocalizedStrings.getUI('text_teacher_generate_outputs_algorithm'));
  382. return;
  383. }
  384. // código:
  385. var code_teacher = window.generator();
  386. // array com as entradas já inseridas:
  387. var test_cases = JSON.parse(prepareTestCases().replace('"testcases" :', ''));
  388. ivprogCore.autoGenerateTestCaseOutput(code_teacher, test_cases).catch(function (error) {
  389. showAlert("Houve um erro durante a execução do seu programa: "+error.message);
  390. });
  391. }
  392. function outputGenerated (test_cases) {
  393. console.log(test_cases);
  394. var fields = $('.text_area_output');
  395. for (var i = 0; i < test_cases.length; i++) {
  396. $(fields[i]).val(test_cases[i].output);
  397. }
  398. }
  399. var hist = false;
  400. function addTestCase (test_case = null) {
  401. var new_row = null;
  402. if (test_case) {
  403. var text_row = '';
  404. text_row += '<tr><td class="counter"></td><td class="expandingArea"><textarea rows="'+test_case.input.length+'" name="input" class="text_area_input">';
  405. for (var i = 0; i < test_case.input.length; i ++) {
  406. text_row += test_case.input[i];
  407. if ((i + 1) < test_case.input.length) {
  408. text_row += '\n';
  409. }
  410. }
  411. text_row += '</textarea></td><td class="expandingArea"><textarea rows="'+test_case.output.length+'" name="output" class="text_area_output">';
  412. for (var i = 0; i < test_case.output.length; i ++) {
  413. text_row += test_case.output[i];
  414. if ((i + 1) < test_case.output.length) {
  415. text_row += '\n';
  416. }
  417. }
  418. text_row += '</textarea></td><td class="btn_actions"><div class="ui button_remove_case"><i class="red icon times large"></i></div></td></tr>';
  419. new_row = $(text_row);
  420. } else {
  421. 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>');
  422. }
  423. $('.content_cases').append(new_row);
  424. new_row.find('.button_remove_case').click(function(e) {
  425. new_row.remove();
  426. updateTestCaseCounter();
  427. });
  428. new_row.find('textarea').on('input', function(e) {
  429. var lines = $(this).val().split('\n').length;
  430. $(this).attr('rows', lines);
  431. });
  432. updateTestCaseCounter();
  433. $('.text_area_output').keydown(function(e) {
  434. var code = e.keyCode || e.which;
  435. if (code == 9 && $(this).closest("tr").is(":last-child")) {
  436. hist = true;
  437. addTestCase();
  438. }
  439. });
  440. if (test_case == null) {
  441. if (!hist) {
  442. $( ".content_cases tr:last" ).find('.text_area_input').focus();
  443. } else {
  444. hist = false;
  445. }
  446. }
  447. }
  448. function updateTestCaseCounter () {
  449. var i = 1;
  450. $( ".content_cases" ).find('tr').each(function() {
  451. $( this ).find('.counter').text(i);
  452. ++i;
  453. });
  454. }
  455. function prepareTableSettings (div_el) {
  456. div_el.append('<h4 class="ui header">'+LocalizedStrings.getUI('text_config_programming')+'</h4>');
  457. div_el.append('<form name="settings_programming_type"><div class="ui stackable five column grid">'
  458. +'<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>'
  459. +'<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>'
  460. +'</div></form>');
  461. div_el.append('<h4 class="ui header">'+LocalizedStrings.getUI('text_teacher_data_types')+'</h4>');
  462. div_el.append('<form name="settings_data_types"><div class="ui stackable five column grid">'
  463. +'<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>'
  464. +'<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>'
  465. +'<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>'
  466. +'<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>'
  467. +'<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>'
  468. +'</div></form>');
  469. div_el.append('<h4 class="ui header">'+LocalizedStrings.getUI('text_teacher_commands')+'</h4>');
  470. div_el.append('<form name="settings_commands"><div class="ui stackable three column grid">'
  471. +'<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>'
  472. +'<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>'
  473. +'<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>'
  474. +'<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>'
  475. +'<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>'
  476. +'<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>'
  477. +'<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>'
  478. +'<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>'
  479. +'<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>'
  480. +'<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>'
  481. +'</div></form>');
  482. div_el.append('<h4 class="ui header">'+LocalizedStrings.getUI('text_teacher_functions')+'</h4>');
  483. div_el.append('<form name="settings_functions"><div class="ui stackable one column grid">'
  484. +'<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>'
  485. +'<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>'
  486. +'</div></form>');
  487. div_el.append('<h4 class="ui header">'+LocalizedStrings.getUI('text_teacher_filter')+'<i class="circular inverted teal question icon"></i></h4>');
  488. div_el.append('<form name="settings_filter"><div class="ui stackable one column grid">'
  489. +'<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>'
  490. +'</div></form>');
  491. $('.circular.inverted.teal.question.icon').popup({
  492. content : LocalizedStrings.getUI("text_teacher_filter_help"),
  493. delay: {
  494. show: 750,
  495. hide: 0
  496. }
  497. });
  498. $('.ui.checkbox').checkbox();
  499. }
  500. function getTrackingLogs () {
  501. return ivprogCore.getLogsAsString();
  502. // var ret = "";
  503. // for (var i = 0; i < trackingMatrix.length; ++i) {
  504. // ret += "\n" + trackingMatrix[i][0] + "," + trackingMatrix[i][1] + "," + trackingMatrix[i][2];
  505. // if (trackingMatrix[i][3] === 1) {
  506. // ret += ',' + trackingMatrix[i][3] + ',"' + trackingMatrix[i][4] + '"';
  507. // }
  508. // }
  509. // return ret;
  510. }
  511. // Tracking mouse movements
  512. // var trackingMatrix = [];
  513. /* function adCoords(e, code){
  514. var x = e.pageX;
  515. var y = e.pageY;
  516. if (code === 1) {
  517. return [new Date().getTime(), x, y, code, e.target.classList['value']];
  518. } else {
  519. return [x, y, code];
  520. }
  521. } */
  522. // $( document ).ready(function() {
  523. // if (inIframe()) {
  524. // orderIcons();
  525. // orderWidth();
  526. // }
  527. // renderAlgorithm();
  528. // });
  529. function orderWidth() {
  530. $('.ui.raised.container.segment.div_to_body').css('width', '100%');
  531. $('.ui.one.column.container.segment.ivprog_visual_panel').css('width', '100%');
  532. }
  533. function orderIcons() {
  534. $('.ui.one.column.doubling.stackable.grid.container').css('display', 'none');
  535. $('.only_in_frame').css('display', 'block');
  536. }
  537. function inIframe () {
  538. try {
  539. return window.self !== window.top;
  540. } catch (e) {
  541. return true;
  542. }
  543. }
  544. function full_screen() {
  545. // check if user allows full screen of elements. This can be enabled or disabled in browser config. By default its enabled.
  546. //its also used to check if browser supports full screen api.
  547. if("fullscreenEnabled" in document || "webkitFullscreenEnabled" in document || "mozFullScreenEnabled" in document || "msFullscreenEnabled" in document) {
  548. if(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled) {
  549. var element = document.getElementById("ui_main_div");
  550. //requestFullscreen is used to display an element in full screen mode.
  551. if("requestFullscreen" in element) {
  552. element.requestFullscreen();
  553. }
  554. else if ("webkitRequestFullscreen" in element) {
  555. element.webkitRequestFullscreen();
  556. }
  557. else if ("mozRequestFullScreen" in element) {
  558. element.mozRequestFullScreen();
  559. }
  560. else if ("msRequestFullscreen" in element) {
  561. element.msRequestFullscreen();
  562. }
  563. }
  564. } else {
  565. $('.expand_button').addClass('disabled');
  566. }
  567. }
  568. function teacherAutoEval (data) {
  569. $.get(iLMparameters.iLM_PARAM_TeacherAutoEval, function (originalData) {
  570. // Ver arquivo js/util/iassignHelpers.js
  571. var content = ivprogCore.prepareActivityToStudentHelper(data);
  572. // Casos de testes agora são delegados ao tratamento apropriado pela função acima
  573. // var testCases = content.testcases;
  574. settingsProgrammingTypes = content.settingsProgrammingType;
  575. settingsDataTypes = content.settingsDataTypes;
  576. settingsCommands = content.settingsCommands;
  577. settingsFunctions = content.settingsFunctions;
  578. settingsFilter = content.settingsFilter;
  579. if (content.algorithmInIlm != null) {
  580. algorithm_in_ilm = content.algorithmInIlm;
  581. parsePreviousAlgorithm();
  582. ivprogCore.autoEval(originalData, parent.getEvaluationCallback);
  583. }
  584. ivprogTextualOrVisual();
  585. if (settingsFilter && settingsFilter[0]) {
  586. blockAllEditingOptions();
  587. }
  588. });
  589. }