iassign-integration-functions.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  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. function removeCollapseValue (command) {
  21. if (command.collapsed) {
  22. delete command.collapsed;
  23. }
  24. if (command.type == 'iftrue') {
  25. if (command.commands_block)
  26. for (var i = 0; i < command.commands_block.length; i++) {
  27. removeCollapseValue(command.commands_block[i]);
  28. }
  29. if (command.commands_else)
  30. for (var i = 0; i < command.commands_else.length; i++) {
  31. removeCollapseValue(command.commands_else[i]);
  32. }
  33. } else if (command.type == 'repeatNtimes'
  34. || command.type == 'whiletrue'
  35. || command.type == 'dowhiletrue' ) {
  36. if (command.commands_block)
  37. for (var i = 0; i < command.commands_block.length; i++) {
  38. removeCollapseValue(command.commands_block[i]);
  39. }
  40. }
  41. }
  42. // Função chamada pelo iTarefa quando o professor finaliza a criação da atividade
  43. // ou quando o aluno finaliza a resolução do exercício
  44. // O retorno é um JSON com os dados do exercício ou da resolução
  45. // Esse retorno será armazenado no banco de dados do Moodle, pelo iTarefa
  46. function getAnswer () {
  47. // Remover o colapsar usado localmente:
  48. if (window.program_obj) {
  49. for (var i = 0; i < window.program_obj.functions.length; i++) {
  50. for (var j = 0; j < window.program_obj.functions[i].commands.length; j++) {
  51. removeCollapseValue(window.program_obj.functions[i].commands[j]);
  52. }
  53. }
  54. }
  55. // Se o parâmetro "iLM_PARAM_SendAnswer" for false,
  56. // então trata-se de resolução de atividade
  57. if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  58. // Montar o retorno com a resposta do aluno
  59. var contentToSend = previousContent.split("\n::algorithm::")[0];
  60. contentToSend += '\n::algorithm::';
  61. if (settingsProgrammingTypes == "textual") {
  62. contentToSend += ivprogCore.CodeEditor.getCode();
  63. } else {
  64. contentToSend += JSON.stringify(window.program_obj, function(key, value) {
  65. if (key == 'dom_object') {
  66. return;
  67. }
  68. return value;
  69. });
  70. }
  71. contentToSend += '\n::logs::';
  72. contentToSend += getTrackingLogs();
  73. return contentToSend;
  74. } else {
  75. // Montar o retorno com a criação da atividade do professor
  76. var ret = '{ ' + prepareExerciseType()
  77. + prepareTestCases()
  78. + ',\n"settings_programming_type": \n' + JSON.stringify($('form[name="settings_programming_type"]').serializeArray())
  79. + ',\n"settings_data_types": \n' + JSON.stringify($('form[name="settings_data_types"]').serializeArray())
  80. + ',\n"settings_commands": \n' + JSON.stringify($('form[name="settings_commands"]').serializeArray())
  81. + ',\n"settings_functions": \n' + JSON.stringify($('form[name="settings_functions"]').serializeArray())
  82. + ',\n"settings_filter": \n' + JSON.stringify($('form[name="settings_filter"]').serializeArray())
  83. + ' } ';
  84. if ($("input[name='include_algo']").is(':checked')) {
  85. ret += '\n::algorithm::';
  86. ret += JSON.stringify(window.program_obj, function(key, value) {
  87. if (key == 'dom_object') {
  88. return;
  89. }
  90. return value;
  91. });
  92. }
  93. return ret;
  94. }
  95. }
  96. function prepareExerciseType () {
  97. var ret = '\n"exercisetype" : ['
  98. var exercise_type_array = $('form[name="exercise_type"]').serializeArray();
  99. console.log(exercise_type_array);
  100. for (var i = 0; i < exercise_type_array.length; i = i + 1) {
  101. var types = exercise_type_array[i].value.match(/[^\r\n]+/g);
  102. if (types) {
  103. for (var j = 0; j < types.length; j++) {
  104. ret += '"' + types[j] + '"';
  105. if ((j + 1) < types.length) {
  106. ret += ', ';
  107. }
  108. }
  109. }
  110. if ((i + 1) < exercise_type_array.length) {
  111. ret += ',';
  112. }
  113. }
  114. ret += ' ],';
  115. return ret;
  116. }
  117. function prepareTestCases () {
  118. var ret = '\n"testcases" : [ '
  119. var test_cases_array = $('form[name="test_cases"]').serializeArray();
  120. console.log(test_cases_array);
  121. for (var i = 0; i < test_cases_array.length; i = i + 3) {
  122. ret += '\n{ ';
  123. ret += '\n "input": [';
  124. var inps = test_cases_array[i].value.match(/[^\r\n]+/g);
  125. if (inps) {
  126. for (var j = 0; j < inps.length; j++) {
  127. ret += '"' + inps[j] + '"';
  128. if ((j + 1) < inps.length) {
  129. ret += ', ';
  130. }
  131. }
  132. }
  133. ret += '], \n "output": [';
  134. var outs = test_cases_array[i+1].value.match(/[^\r\n]+/g);
  135. console.log(outs);
  136. if (outs) {
  137. for (var j = 0; j < outs.length; j++) {
  138. console.log("output -> ",outs[j]);
  139. ret += '"' + outs[j] + '"';
  140. if ((j + 1) < outs.length) {
  141. ret += ', ';
  142. }
  143. }
  144. }
  145. ret += '], \n "tag": [';
  146. var tags = test_cases_array[i+2].value.match(/[^\r\n]+/g);
  147. console.log(tags);
  148. if (tags) {
  149. for (var j = 0; j < tags.length; j++) {
  150. console.log("tag -> ",tags[j]);
  151. ret += '"' + tags[j] + '"';
  152. if ((j + 1) < tags.length) {
  153. ret += ', ';
  154. }
  155. }
  156. }
  157. ret += ']';
  158. ret += '\n}'
  159. if ((i + 3) < test_cases_array.length) {
  160. ret += ',';
  161. }
  162. }
  163. ret += '\n]';
  164. return ret;
  165. }
  166. // Função chamada pelo iTarefa para receber a nota do aluno na atividade
  167. // O retorno é um valor entre 0.0 e 1.0
  168. function getEvaluation () {
  169. if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  170. // A chamada do método abaixo é obrigatória!
  171. // Observe que a chamada parte do iLM para o iTarefa
  172. //parent.getEvaluationCallback(window.studentGrade);
  173. var canRunAssessment = runCodeAssessment();
  174. if(canRunAssessment === -1) {
  175. parent.getEvaluationCallback(-1);
  176. }
  177. }
  178. }
  179. //var testCases = null
  180. var settingsDataTypes = null;
  181. var settingsCommands = null;
  182. var settingsFunctions = null;
  183. var settingsProgrammingTypes = null;
  184. var settingsFilter = null;
  185. var algorithm_in_ilm = null;
  186. var previousContent = null;
  187. // Função para que o iMA leia os dados da atividade fornecidos pelo iTarefa
  188. function getiLMContent () {
  189. // O parâmetro "iLM_PARAM_Assignment" fornece o URL do endereço que deve ser
  190. // requisitado via AJAX para a captura dos dados da atividade
  191. $.get(iLMparameters.iLM_PARAM_Assignment, function (data) {
  192. //professor invocou a avaliação automática dos exercícios do bloco
  193. if (iLMparameters.iLM_PARAM_TeacherAutoEval != null) {
  194. teacherAutoEval(data);
  195. //não deve exibir nenhuma interface...
  196. return;
  197. } else if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  198. // Aluno está trabalhando em alguma atividade:
  199. previousContent = data;
  200. prepareActivityToStudent(data);
  201. } else { // Professor está editando uma atividade:
  202. previousContent = data;
  203. prepareActivityToEdit(data);
  204. }
  205. window.block_render = false;
  206. renderAlgorithm();
  207. });
  208. }
  209. function prepareActivityToEdit (ilm_cont) {
  210. //var content = JSON.parse(ilm_cont.split('\n::algorithm::')[0]);
  211. // Ver arquivo js/util/iassignHelpers.js
  212. var content = ivprogCore.prepareActivityToStudentHelper(ilm_cont).getOrElse(null);
  213. if(!content) {
  214. showInvalidData();
  215. return;
  216. }
  217. var exerciseType = ivprogCore.getExerciseType();
  218. var testCases = ivprogCore.getTestCases();
  219. settingsProgrammingTypes = content.settingsProgrammingType;
  220. settingsDataTypes = content.settingsDataTypes;
  221. settingsCommands = content.settingsCommands;
  222. settingsFunctions = content.settingsFunctions;
  223. settingsFilter = content.settingsFilter;
  224. for (var i = 0; i < exerciseType.length; i++) {
  225. addType(exerciseType[i]);
  226. }
  227. for (var i = 0; i < testCases.length; i++) {
  228. addTestCase(testCases[i]);
  229. }
  230. if (content.algorithmInIlm != null) {
  231. algorithm_in_ilm = content.algorithmInIlm;
  232. $("input[name='include_algo']").prop('checked', true);
  233. includePreviousAlgorithm();
  234. renderAlgorithm();
  235. }
  236. ivprogTextualOrVisual();
  237. if (settingsFilter && settingsFilter[0]) {
  238. blockAllEditingOptions();
  239. }
  240. }
  241. function parsePreviousAlgorithm () {
  242. window.program_obj.functions = JSON.parse(algorithm_in_ilm).functions;
  243. window.program_obj.globals = JSON.parse(algorithm_in_ilm).globals;
  244. }
  245. function includePreviousAlgorithm () {
  246. if (settingsProgrammingTypes == "textual") {
  247. return;
  248. }
  249. parsePreviousAlgorithm();
  250. window.watchW.watch(window.program_obj.globals, function(){
  251. if (window.insertContext) {
  252. setTimeout(function(){ renderAlgorithm(); }, 300);
  253. window.insertContext = false;
  254. } else {
  255. renderAlgorithm();
  256. }
  257. }, 1);
  258. for (var i = 0; i < window.program_obj.functions.length; i ++) {
  259. window.watchW.watch(window.program_obj.functions[i].parameters_list, function(){
  260. if (window.insertContext) {
  261. setTimeout(function(){ renderAlgorithm(); }, 300);
  262. window.insertContext = false;
  263. } else {
  264. renderAlgorithm();
  265. }
  266. }, 1);
  267. window.watchW.watch(window.program_obj.functions[i].variables_list, function(){
  268. if (window.insertContext) {
  269. setTimeout(function(){ renderAlgorithm(); }, 300);
  270. window.insertContext = false;
  271. } else {
  272. renderAlgorithm();
  273. }
  274. }, 1);
  275. if (window.program_obj.functions[i].is_main) {
  276. window.program_obj.functions[i].name = LocalizedStrings.getUI("start");
  277. }
  278. }
  279. window.watchW.watch(window.program_obj.functions, function(){
  280. if (window.insertContext) {
  281. setTimeout(function(){ renderAlgorithm(); }, 300);
  282. window.insertContext = false;
  283. } else {
  284. renderAlgorithm();
  285. }
  286. }, 1);
  287. }
  288. function prepareActivityToStudent (ilm_cont) {
  289. // Ver arquivo js/util/iassignHelpers.js
  290. var content = ivprogCore.prepareActivityToStudentHelper(ilm_cont).getOrElse(null);
  291. if(!content) {
  292. showInvalidData();
  293. return;
  294. }
  295. // Casos de testes agora são delegados ao tratamento apropriado pela função acima
  296. // var testCases = content.testcases;
  297. settingsProgrammingTypes = content.settingsProgrammingType;
  298. settingsDataTypes = content.settingsDataTypes;
  299. settingsCommands = content.settingsCommands;
  300. settingsFunctions = content.settingsFunctions;
  301. settingsFilter = content.settingsFilter;
  302. if (content.algorithmInIlm != null) {
  303. algorithm_in_ilm = content.algorithmInIlm;
  304. includePreviousAlgorithm();
  305. }
  306. $('.assessment_button').removeClass('disabled');
  307. renderAlgorithm();
  308. ivprogTextualOrVisual();
  309. if (settingsFilter && settingsFilter[0]) {
  310. blockAllEditingOptions();
  311. }
  312. }
  313. // Função para organizar se para criação, visualização ou resolução de atividade
  314. function prepareEnvironment () {
  315. $('.div_to_body').click(function(e) {
  316. // trackingMatrix.push(adCoords(e, 1));
  317. ivprogCore.registerClick(e.pageX, e.pageY, e.target.classList['value']);
  318. });
  319. // Se iLM_PARAM_SendAnswer for false, então trata-se de resolução de atividade,
  320. // portanto, a "DIV" de resolução é liberada
  321. if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  322. //$('.resolucao').css("display","block");
  323. getiLMContent();
  324. // $('.div_to_body').mousemove(function(e) {
  325. // trackingMatrix.push(adCoords(e, 0));
  326. // });
  327. // $('.div_to_body').click(function(e) {
  328. // // trackingMatrix.push(adCoords(e, 1));
  329. // ivprogCore.registerClick(e.pageX, e.pageY, e.target.classList['value']);
  330. // });
  331. } else if (iLMparameters.iLM_PARAM_Assignment) {
  332. // Caso não esteja em modo de resolução de atividade, a visualização no momento
  333. // é para a elaboração de atividade:
  334. //$('.elaboracao').css("display","block");
  335. // Se possuir o parâmetro iLMparameters.iLM_PARAM_Assignment, o professor
  336. // está editando uma atividade:
  337. getiLMContent();
  338. } else {
  339. renderAlgorithm();
  340. }
  341. if ((iLMparameters.iLM_PARAM_AssignmentURL == "true") && (iLMparameters.iLM_PARAM_SendAnswer == "true")) {
  342. prepareActivityCreation();
  343. }
  344. }
  345. function blockAllEditingOptions () {
  346. if ((iLMparameters.iLM_PARAM_AssignmentURL == "true") && (iLMparameters.iLM_PARAM_SendAnswer == "true")) {
  347. return;
  348. }
  349. $('.add_global_button').addClass('disabled');
  350. $('.move_function').addClass('disabled');
  351. $('.add_function_button').addClass('disabled');
  352. $('.add_var_button_function .ui.icon.button.purple').addClass('disabled');
  353. $('.add_var_button_function').addClass('disabled');
  354. $('.menu_commands').addClass('disabled');
  355. $('.global_type').addClass('disabled');
  356. $('.editing_name_var').addClass('disabled');
  357. $('.span_value_variable').addClass('disabled');
  358. $('.remove_global').addClass('disabled');
  359. $('.ui.icon.ellipsis.vertical.inverted').addClass('disabled');
  360. $('.alternate_constant').addClass('disabled');
  361. $('.remove_variable').addClass('disabled');
  362. $('.add_global_matrix_column').addClass('disabled');
  363. $('.remove_global_matrix_column').addClass('disabled');
  364. $('.add_global_matrix_line').addClass('disabled');
  365. $('.remove_global_matrix_line').addClass('disabled');
  366. $('.add_global_vector_column').addClass('disabled');
  367. $('.remove_global_vector_column').addClass('disabled');
  368. $('.add_expression').addClass('disabled');
  369. $('.add_parentheses').addClass('disabled');
  370. $('.remove_function_button').addClass('disabled');
  371. $('.button_remove_command').addClass('disabled');
  372. $('.command_drag').addClass('disabled');
  373. $('.simple_add').addClass('disabled');
  374. $('.add_parameter_button').addClass('disabled');
  375. $('.parameter_div_edit').addClass('disabled');
  376. $('.function_name_div_updated').addClass('disabled');
  377. $('.value_rendered').addClass('disabled');
  378. $('.var_name').addClass('disabled');
  379. $('.variable_rendered').addClass('disabled');
  380. $('.dropdown').addClass('disabled');
  381. $('.remove_parameter').addClass('disabled');
  382. $('.ui.dropdown.global_type.disabled').css('opacity', '1');
  383. $('.ui.dropdown.variable_type.disabled').css('opacity', '1');
  384. $('.ui.dropdown.function_return.disabled').css('opacity', '1');
  385. $('.ui.dropdown.parameter_type.disabled').css('opacity', '1');
  386. ivprogCore.CodeEditor.disable(true);
  387. }
  388. function ivprogTextualOrVisual () {
  389. if (settingsProgrammingTypes) {
  390. if (settingsProgrammingTypes == "textual") {
  391. $('.ivprog_visual_panel').css('display', 'none');
  392. $('.ivprog_textual_panel').css('display', 'block');
  393. $('.ivprog_textual_panel').removeClass('loading');
  394. $('.visual_coding_button').removeClass('active');
  395. $('.textual_coding_button').addClass('active');
  396. $('.visual_coding_button').addClass('disabled');
  397. let textual_code = algorithm_in_ilm;
  398. if(!textual_code) {
  399. textual_code = ivprogCore.LocalizedStrings.getUI("initial_program_code");
  400. textual_code = textual_code.replace(/\\n/g,"\n");
  401. textual_code = textual_code.replace(/\\t/g,"\t");
  402. }
  403. ivprogCore.CodeEditor.setCode(textual_code);
  404. ivprogCore.CodeEditor.disable(false);
  405. }
  406. if (settingsProgrammingTypes == "visual") {
  407. }
  408. }
  409. }
  410. function iassingIntegration () {
  411. // Disable by default...
  412. $('.assessment_button').addClass('disabled');
  413. prepareEnvironment();
  414. if (inIframe()) {
  415. orderIcons();
  416. orderWidth();
  417. }
  418. }
  419. // Função para preparar a interface para o professor criar atividade:
  420. function prepareActivityCreation () {
  421. var menuTab = $('<div class="ui top attached tabular menu">'
  422. + '<a class="item active" data-tab="exercisetype">Exercise Type</a>'
  423. + '<a class="item" data-tab="testcases">' + LocalizedStrings.getUI('text_teacher_test_case') + '</a>'
  424. + '<a class="item" data-tab="algorithm">' + LocalizedStrings.getUI('text_teacher_algorithm') + '</a>'
  425. + '<a class="item" data-tab="settings">' + LocalizedStrings.getUI('text_teacher_config') + '</a>'
  426. + '</div>'
  427. + '<div class="ui bottom attached tab segment active tab_exercise_type" data-tab="exercisetype"></div>'
  428. + '<div class="ui bottom attached tab segment tab_test_cases" data-tab="testcases"></div>'
  429. + '<div class="ui bottom attached tab segment tab_algorithm" data-tab="algorithm"></div>'
  430. + '<div class="ui bottom attached tab segment tab_settings" data-tab="settings"></div>');
  431. menuTab.insertBefore('.add_accordion');
  432. $('.tabular.menu .item').tab();
  433. $('.main_title').remove();
  434. $('.ui.accordion').addClass('styled');
  435. $('<div class="content_margin"></div>').insertBefore($('.add_accordion').find('.content').find('.div_to_body'));
  436. $('<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');
  437. var exercise_type_div = $('<div></div>');
  438. $('.tab_exercise_type').append(exercise_type_div);
  439. var cases_test_div = $('<div></div>');
  440. $('.tab_test_cases').append(cases_test_div);
  441. var config_div = $('<div></div>');
  442. $('.tab_settings').append(config_div);
  443. $('.ui.checkbox').checkbox();
  444. $('.tab_algorithm').append($('.add_accordion'));
  445. prepareTableExerciseType(exercise_type_div);
  446. prepareTableSettings(config_div);
  447. prepareTableTestCases(cases_test_div);
  448. if (inIframe()) {
  449. $('.ui.styled.accordion').css('width', '96%');
  450. }
  451. }
  452. function prepareTableExerciseType (div_el) {
  453. var table_el = '<form name="exercise_type"><table class="ui blue table"><thead><tr><th width="30px">#</th><th>Type</th><th width="80px">Actions</th></tr></thead>'
  454. + '<tbody class="content_types"></tbody></table></form>';
  455. div_el.append(table_el);
  456. var table_buttons = '<table class="table_buttons"><tr><td>'
  457. + '<button class="ui teal labeled icon button button_add_type"><i class="plus icon"></i>Add Type</button>'
  458. + '</td></tr></table>';
  459. div_el.append(table_buttons);
  460. 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>'));
  461. $('.button_add_type').on('click', function(e) {
  462. addType();
  463. });
  464. }
  465. function addType (exercise_type = null) {
  466. var new_row = null;
  467. if (exercise_type) {
  468. var text_row = '';
  469. text_row += '<tr><td class="counter"></td>';
  470. text_row += '<td class="expandingArea"><select id="cboTypes" name="type" class="select_type"><option value=""></option>';
  471. text_row += '<option value="Leitura e Escrita">Leitura e Escrita</option>';
  472. text_row += '<option value="Manipulação de Entrada">Manipulação de Entrada</option>';
  473. text_row += '<option value="Lógica">Lógica</option>';
  474. text_row += '<option value="Matemática">Matemática</option>';
  475. text_row += '<option value="Condição">Condição</option>';
  476. text_row += '<option value="Laço">Laço</option>';
  477. text_row += '<option value="Vetor">Vetor</option>';
  478. text_row += '</select>';
  479. for (var i = 0; i < exercise_type.type.length; i ++) {
  480. text_row += exercise_type.options[exercise_type.selectedIndex].value;
  481. if ((i + 1) < exercise_type.type.length) {
  482. text_row += '\n';
  483. }
  484. }
  485. text_row += '</td><td class="btn_actions"><div class="ui button_remove_type"><i class="red icon times large"></i></div></td></tr>';
  486. new_row = $(text_row);
  487. } else {
  488. new_row = $('<tr><td class="counter"></td><td class="expandingArea"><select id="cboTypes" name="type" class="select_type"><option value=""></option><option value="Leitura e Escrita">Leitura e Escrita</option><option value="Manipulação de Entrada">Manipulação de Entrada</option><option value="Lógica">Lógica</option><option value="Matemática">Matemática</option><option value="Condição">Condição</option><option value="Laço">Laço</option><option value="Vetor">Vetor</option></select></td><td class="btn_actions"><div class="ui button_remove_type"><i class="red icon times large"></i></div></td></tr>');
  489. }
  490. $('.content_types').append(new_row);
  491. new_row.find('.button_remove_type').click(function(e) {
  492. new_row.remove();
  493. updateTypeCounter();
  494. });
  495. new_row.find('textarea').on('type', function(e) {
  496. var lines = $(this).val().split('\n').length;
  497. $(this).attr('rows', lines);
  498. });
  499. updateTypeCounter();
  500. if (exercise_type == null) {
  501. if (!hist) {
  502. $( ".content_types tr:last" ).find('.select_type').focus();
  503. } else {
  504. hist = false;
  505. }
  506. }
  507. }
  508. function updateTypeCounter () {
  509. var i = 1;
  510. $( ".content_types" ).find('tr').each(function() {
  511. $( this ).find('.counter').text(i);
  512. ++i;
  513. });
  514. }
  515. function prepareTableTestCases (div_el) {
  516. 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>Tag</th><th width="80px">'+LocalizedStrings.getUI('text_teacher_test_case_actions')+'</th></tr></thead>'
  517. + '<tbody class="content_cases"></tbody></table></form>';
  518. div_el.append(table_el);
  519. var table_buttons = '<table class="table_buttons"><tr><td>'
  520. + '<button class="ui teal labeled icon button button_add_case"><i class="plus icon"></i>'+LocalizedStrings.getUI('text_teacher_test_case_add')+'</button>'
  521. + '</td><td class="right_align">'
  522. + '<button class="ui orange labeled icon button button_generate_outputs"><i class="sign-in icon"></i>'+LocalizedStrings.getUI('text_teacher_generate_outputs')+'</button>'
  523. + '</td></tr></table>';
  524. div_el.append(table_buttons);
  525. 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>'));
  526. $('.button_add_case').on('click', function(e) {
  527. addTestCase();
  528. });
  529. $('.button_generate_outputs').on('click', function(e) {
  530. generateOutputs();
  531. });
  532. }
  533. function showAlert (msg) {
  534. $('.ui.basic.modal .content').html('<h3>'+msg+'</h3>');
  535. $('.ui.basic.modal').modal('show');
  536. }
  537. function generateOutputs () {
  538. if (window.program_obj.functions.length == 1 && window.program_obj.functions[0].commands.length == 0) {
  539. showAlert(LocalizedStrings.getUI('text_teacher_generate_outputs_algorithm'));
  540. return;
  541. }
  542. // código:
  543. var code_teacher = window.generator();
  544. // array com as entradas já inseridas:
  545. var test_cases = JSON.parse(prepareTestCases().replace('"testcases" :', ''));
  546. ivprogCore.autoGenerateTestCaseOutput(code_teacher, test_cases).catch(function (error) {
  547. showAlert("Houve um erro durante a execução do seu programa: "+error.message);
  548. });
  549. }
  550. function outputGenerated (test_cases) {
  551. var fields = $('.text_area_output');
  552. /*for (var i = 0; i < test_cases.length; i++) {
  553. $(fields[i]).val('');
  554. for (var j = 0; j < test_cases[i].output.length; j++) {
  555. $(fields[i]).val($(fields[i]).val() + test_cases[i].output[j]);
  556. if (j < test_cases[i].output.length - 1) {
  557. $(fields[i]).val($(fields[i]).val() + '\n');
  558. }
  559. }
  560. $(fields[i]).attr('rows', test_cases[i].output.length);
  561. }*/
  562. animateOutput(fields, test_cases, 0);
  563. }
  564. function animateOutput (list, test_cases, index) {
  565. if (list.length == index) return;
  566. $(list[index]).val('');
  567. for (var j = 0; j < test_cases[index].output.length; j++) {
  568. console.log(test_cases[index].output[j].charCodeAt(0));
  569. $(list[index]).val($(list[index]).val() + test_cases[index].output[j]);
  570. if (j < test_cases[index].output.length - 1) {
  571. $(list[index]).val($(list[index]).val() + '\n');
  572. }
  573. }
  574. $(list[index]).attr('rows', test_cases[index].output.length);
  575. $(list[index]).effect('highlight', null, 50, function() {
  576. animateOutput(list, test_cases, index + 1);
  577. });
  578. }
  579. var hist = false;
  580. function addTestCase (test_case = null) {
  581. var new_row = null;
  582. if (test_case) {
  583. var text_row = '';
  584. text_row += '<tr><td class="counter"></td><td class="expandingArea"><textarea rows="'+test_case.input.length+'" name="input" class="text_area_input">';
  585. for (var i = 0; i < test_case.input.length; i ++) {
  586. text_row += test_case.input[i];
  587. if ((i + 1) < test_case.input.length) {
  588. text_row += '\n';
  589. }
  590. }
  591. text_row += '</textarea></td><td class="expandingArea"><textarea rows="'+test_case.output.length+'" name="output" class="text_area_output">';
  592. for (var i = 0; i < test_case.output.length; i ++) {
  593. text_row += test_case.output[i];
  594. if ((i + 1) < test_case.output.length) {
  595. text_row += '\n';
  596. }
  597. }
  598. text_row += '</textarea></td>';
  599. text_row += '<td class="expandingArea"><select id="cboTags" name="tag" class="select_tag"><option value=""></option>';
  600. text_row += '<option value="Caso Geral">Caso Geral</option>';
  601. text_row += '<option value="Caso Limite">Caso Limite</option>';
  602. text_row += '<option value="Caso Nulo">Caso Nulo</option>';
  603. text_row += '<option value="Caso Negativo">Caso Negativo</option>';
  604. text_row += '<option value="Igualdade">Igualdade</option>';
  605. text_row += '<option value="Tipo de Entrada">Tipo de Entrada</option>';
  606. text_row += '</select>';
  607. for (var i = 0; i < test_case.tag.length; i ++) {
  608. text_row += test_case.options[test_case.selectedIndex].value;
  609. if ((i + 1) < test_case.tag.length) {
  610. text_row += '\n';
  611. }
  612. }
  613. text_row += '</td><td class="btn_actions"><div class="ui button_remove_case"><i class="red icon times large"></i></div></td></tr>';
  614. new_row = $(text_row);
  615. } else {
  616. 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="expandingArea"><select id="cboTags" name="tag" class="select_tag"><option value=""></option><option value="Caso Geral">Caso Geral</option><option value="Caso Limite">Caso Limite</option><option value="Caso Nulo">Caso Nulo</option><option value="Caso Negativo">Caso Negativo</option><option value="Igualdade">Igualdade</option><option value="Tipo de Entrada">Tipo de Entrada</option></select></td><td class="btn_actions"><div class="ui button_remove_case"><i class="red icon times large"></i></div></td></tr>');
  617. }
  618. $('.content_cases').append(new_row);
  619. new_row.find('.button_remove_case').click(function(e) {
  620. new_row.remove();
  621. updateTestCaseCounter();
  622. });
  623. new_row.find('textarea').on('input', function(e) {
  624. var lines = $(this).val().split('\n').length;
  625. $(this).attr('rows', lines);
  626. });
  627. updateTestCaseCounter();
  628. $('.text_area_output').keydown(function(e) {
  629. var code = e.keyCode || e.which;
  630. if (code == 9 && $(this).closest("tr").is(":last-child")) {
  631. hist = true;
  632. addTestCase();
  633. }
  634. });
  635. if (test_case == null) {
  636. if (!hist) {
  637. $( ".content_cases tr:last" ).find('.text_area_input').focus();
  638. } else {
  639. hist = false;
  640. }
  641. }
  642. }
  643. function updateTestCaseCounter () {
  644. var i = 1;
  645. $( ".content_cases" ).find('tr').each(function() {
  646. $( this ).find('.counter').text(i);
  647. ++i;
  648. });
  649. }
  650. function prepareTableSettings (div_el) {
  651. 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>'
  652. +'<div class="content content_segment_settings"><form name="settings_programming_type"><div class="ui stackable five column grid">'
  653. +'<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>'
  654. +'<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>'
  655. +'</div></form></div></div>');
  656. 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>'
  657. +'<div class="content content_segment_settings"><form name="settings_data_types"><div class="ui stackable five column grid">'
  658. +'<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>'
  659. +'<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>'
  660. +'<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>'
  661. +'<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>'
  662. +'<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>'
  663. +'</div></form></div></div>');
  664. 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>'
  665. +'<div class="content content_segment_settings"><form name="settings_commands"><div class="ui stackable three column grid">'
  666. +'<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>'
  667. +'<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>'
  668. +'<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>'
  669. +'<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>'
  670. +'<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>'
  671. +'<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>'
  672. +'<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>'
  673. +'<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>'
  674. +'<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>'
  675. +'<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>'
  676. +'</div></form></div></div>');
  677. 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>'
  678. +'<div class="content content_segment_settings"><form name="settings_functions"><div class="ui stackable one column grid">'
  679. +'<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>'
  680. +'<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>'
  681. +'</div></form></div></div>');
  682. 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>'
  683. +'<div class="content content_segment_settings"><form name="settings_filter"><div class="ui stackable one column grid">'
  684. +'<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>'
  685. +'</div></form></div></div>');
  686. $('.circular.inverted.teal.question.icon').popup({
  687. content : LocalizedStrings.getUI("text_teacher_filter_help"),
  688. delay: {
  689. show: 750,
  690. hide: 0
  691. }
  692. });
  693. $('.ui.checkbox').checkbox();
  694. }
  695. function getTrackingLogs () {
  696. return ivprogCore.getLogsAsString();
  697. // var ret = "";
  698. // for (var i = 0; i < trackingMatrix.length; ++i) {
  699. // ret += "\n" + trackingMatrix[i][0] + "," + trackingMatrix[i][1] + "," + trackingMatrix[i][2];
  700. // if (trackingMatrix[i][3] === 1) {
  701. // ret += ',' + trackingMatrix[i][3] + ',"' + trackingMatrix[i][4] + '"';
  702. // }
  703. // }
  704. // return ret;
  705. }
  706. // Tracking mouse movements
  707. // var trackingMatrix = [];
  708. /* function adCoords(e, code){
  709. var x = e.pageX;
  710. var y = e.pageY;
  711. if (code === 1) {
  712. return [new Date().getTime(), x, y, code, e.target.classList['value']];
  713. } else {
  714. return [x, y, code];
  715. }
  716. } */
  717. // $( document ).ready(function() {
  718. // if (inIframe()) {
  719. // orderIcons();
  720. // orderWidth();
  721. // }
  722. // renderAlgorithm();
  723. // });
  724. function orderWidth() {
  725. $('.ui.raised.container.segment.div_to_body').css('width', '100%');
  726. $('.ui.one.column.container.segment.ivprog_visual_panel').css('width', '100%');
  727. }
  728. function orderIcons() {
  729. $('.ui.one.column.doubling.stackable.grid.container').css('display', 'none');
  730. $('.only_in_frame').css('display', 'block');
  731. }
  732. function inIframe () {
  733. try {
  734. return window.self !== window.top;
  735. } catch (e) {
  736. return true;
  737. }
  738. }
  739. function full_screen() {
  740. // check if user allows full screen of elements. This can be enabled or disabled in browser config. By default its enabled.
  741. //its also used to check if browser supports full screen api.
  742. if("fullscreenEnabled" in document || "webkitFullscreenEnabled" in document || "mozFullScreenEnabled" in document || "msFullscreenEnabled" in document) {
  743. if(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled) {
  744. var element = document.getElementById("ui_main_div");
  745. //requestFullscreen is used to display an element in full screen mode.
  746. if("requestFullscreen" in element) {
  747. element.requestFullscreen();
  748. }
  749. else if ("webkitRequestFullscreen" in element) {
  750. element.webkitRequestFullscreen();
  751. }
  752. else if ("mozRequestFullScreen" in element) {
  753. element.mozRequestFullScreen();
  754. }
  755. else if ("msRequestFullscreen" in element) {
  756. element.msRequestFullscreen();
  757. }
  758. }
  759. } else {
  760. $('.expand_button').addClass('disabled');
  761. }
  762. }
  763. function getAutoEvalOriginalData () {
  764. return parent.getAutoEvalOriginalData();
  765. }
  766. function teacherAutoEval (data) {
  767. previousContent = data;
  768. // Ver arquivo js/util/iassignHelpers.js
  769. var content = ivprogCore.prepareActivityToStudentHelper(data).getOrElse(null);
  770. if(!content) {
  771. showInvalidData();
  772. return;
  773. }
  774. // Casos de testes agora são delegados ao tratamento apropriado pela função acima
  775. // var testCases = content.testcases;
  776. settingsProgrammingTypes = content.settingsProgrammingType;
  777. settingsDataTypes = content.settingsDataTypes;
  778. settingsCommands = content.settingsCommands;
  779. settingsFunctions = content.settingsFunctions;
  780. settingsFilter = content.settingsFilter;
  781. if (content.algorithmInIlm != null) {
  782. algorithm_in_ilm = content.algorithmInIlm;
  783. parsePreviousAlgorithm();
  784. var originalData = getAutoEvalOriginalData();
  785. ivprogCore.autoEval(originalData, parent.postResultAutoEval);
  786. }
  787. ivprogTextualOrVisual();
  788. if (settingsFilter && settingsFilter[0]) {
  789. blockAllEditingOptions();
  790. }
  791. }
  792. function displayGrade(grade) {
  793. alert(grade);
  794. }
  795. function showInvalidData () {
  796. $('.ui.height_100.add_accordion').dimmer({
  797. closable: false
  798. });
  799. $('.dimmer_content_message h3').html(LocalizedStrings.getUI('text_message_error_activity_file'));
  800. $('.dimmer_content_message button').text(LocalizedStrings.getUI('text_message_error_activity_reload'));
  801. $('.dimmer_content_message').css('display', 'block');
  802. $('.ui.height_100.add_accordion').dimmer('add content', '.dimmer_content_message');
  803. $('.ui.height_100.add_accordion').dimmer('show');
  804. }