Browse Source

Work in progress

Igor 2 years ago
parent
commit
34de25a6c1

+ 19 - 1
i18n/ui.csv

@@ -9,6 +9,9 @@ btn_arithmetic_division,Divisão,Division,División
 btn_arithmetic_module,Módulo,Remainder,Resto
 btn_break,Pare,break,break
 btn_case,Caso,Case,Caso
+btn_add_var,Adicionar variável,Add a variable,Add a variable
+btn_drag_and_drop_function,Mover função,Move function,Mover función 
+btn_delete_function,Excluir função,Delete function,Borrar función 
 expression_invalid,Expressão inválida. Verifique a sintáxe antes de continuar.,Invalid expression. Check the syntax before proceeding.,Expresión no válida. Verifique la sintaxis antes de continuar.
 expression_undelcared_variable,Variáveis não declaradas:,Undeclared variables:,Variables no declaradas:
 expression_undeclared_function,Funções não definidas:,Undefined functions:,Funcíon no declaradas:
@@ -72,8 +75,10 @@ text_config_programming_textual,Textual,Textual,Textual
 text_config_programming_visual,Visual,Visual,Visual
 text_logic_expression,Lógicos,Logic,Lógicos
 text_arithmetic_expression,Aritméticos,Arithmetics,Aritmética
-text_iftrue,Se verdadeiro então,If true then,Si verdad entonces
+text_iftrue,Se condição senão,If condition else,Si condicion sino
 text_message_error_activity_file,Aconteceu um erro ao processar a atividade. <br> Recarregue a página para tentar novamente.,There was an error processing the activity.<br> Reload the page to try again.,Se produjo un error al procesar la actividad.<br> Recargar la página para volver a intentarlo.
+text_message_error_upload_file,Não foi possível carregar o arquivo.<br>Verifique o conteúdo do arquivo e tente novamente.,It was not possible upload the file.<br>Verify the file's content and try again.,text_message_error_upload_file
+text_message_error_upload_close,Fechar,Close,Close
 text_message_error_activity_reload,Recarregar,Reload,Recargar
 text_repeatNtimes,Repita N vezes,Repeat N times,Repetir N veces
 text_receives,recebe,receives,receives
@@ -126,6 +131,19 @@ inform_valid_expression,Construa uma expressão lógica!,Construct a logic expre
 tooltip_terminal_clear,Limpa o terminal removendo todos os textos já escritos e os pendentes.,Clears the terminal by removing all wrriten and pending text.,Borra el terminal eliminando todo el texto escrito y pendiente.
 tooltip_terminal_show,Exibe o terminal caso esteja escondido,Shows the terminal if it is hidden,Muestra el terminal si está oculto.
 tooltip_terminal_hide,Esconde o terminal caso não esteja escondido,Hides the terminal if it is not on display,Oculta el terminal si no está en exhibición
+tooltip_menu_read,Comando para receber dados pelo teclado,Command to input data from keyboard,Command to input data from keyboard
+tooltip_menu_write,Comando para apresentar conteúdo ao usuário,Command to present content to user,Command to present content to user
+tooltip_menu_comments,Bloco para comentários internos do programador,Block to comments from developer,Block to comments from developer
+tooltip_menu_attribution,Comando para atribuir uma expressão a uma variável,Command to assign an expression to a variable,Command to assign an expression to a variable
+tooltip_menu_call_function,Comando para realizar a chamada de uma função,Command to execute a function call,Command to execute a function call
+tooltip_menu_if_else,Estrutura para que os comandos só sejam executados de acordo com as condições estabelecidas,Structure in which command only run when the conditions are satisfied,Structure in which command only run when the conditions are satisfied
+tooltip_menu_repeat_n_times,Estrutura para executar um bloco de comandos repetidamente,Structure to execute a block of commands repeatedly,Structure to execute a block of commands repeatedly
+tooltip_menu_repeat_whiletrue,Estrutura para repetir um bloco de comandos enquanto a condição for verdadeira,Structure to execute a block repeatdly while condition is true,Structure to execute a block repeatdly while condition is true
+tooltip_menu_repeat_dowhiletrue,Estrutura que executa um bloco e o repete enquanto a condição for verdadeira,Structure that executes a block and repeat while the condition is true,Structure that executes a block and repeat while the condition is true
+tooltip_menu_repeat_switch,Estrutura de escolha do bloco a ser executado,Structure that choices the block to be executed,Structure that choices the block to be executed
+tooltip_menu_repeat_return,Comando para devolver o resultado e finalizar a função,Command to return the result and finish the function,Command to return the result and finish the function
+tooltip_move_var,Mover variável,Move variable,Move variable
+tooltip_remove_var,Excluir variável,Delete variable,Delete variable
 text_ivprog_version,Versão,Version,Version
 text_teacher_filter,Filtro,Filter,Filter
 text_teacher_filter_active,Ativado,Activated,Activated

File diff suppressed because it is too large
+ 3 - 0
js/filesaver.min.js


+ 18 - 0
js/iassign-integration-functions.js

@@ -818,4 +818,22 @@ function showInvalidData () {
   $('.dimmer_content_message').css('display', 'block');
   $('.ui.height_100.add_accordion').dimmer('add content', '.dimmer_content_message');
   $('.ui.height_100.add_accordion').dimmer('show');
+  $('.dimmer_content_message button').on('click', function(e) {
+    window.parent.location.reload()
+  })
 }
+
+
+function showInvalidFile () {
+  $('.ui.height_100.add_accordion').dimmer({
+    closable: true
+  });
+  $('.dimmer_content_message h3').html(LocalizedStrings.getUI('text_message_error_upload_file'));
+  $('.dimmer_content_message button').text(LocalizedStrings.getUI('text_message_error_upload_close'));
+  $('.dimmer_content_message').css('display', 'block');
+  $('.ui.height_100.add_accordion').dimmer('add content', '.dimmer_content_message');
+  $('.ui.height_100.add_accordion').dimmer('show');
+  $('.dimmer_content_message button').on('click', function(e) {
+    $('.ui.height_100.add_accordion').dimmer('hide');
+  })
+}

+ 2 - 1
js/visualUI/code_generator.js

@@ -597,6 +597,7 @@ export function elementExpressionCode (expression_obj) {
     if (expression_obj[i].type) {
       ret += variableValueMenuCode(expression_obj[i]);
     } else if (expression_obj[i].type_op) {
+      console.log('veja', expression_obj[i].item)
       switch (expression_obj[i].item) {
         case Models.ARITHMETIC_TYPES.plus:
           ret += " + ";
@@ -650,7 +651,7 @@ export function elementExpressionCode (expression_obj) {
           ret += " <= ";
           break;
         case Models.EXPRESSION_TYPES.write_sep:
-          ret += ", ";
+          ret += ', " ", ';
           break;
       }
     } else {

+ 172 - 2
js/visualUI/functions.js

@@ -395,7 +395,8 @@ export function renderFunction (function_obj) {
   for (var j = 0; j < function_obj.commands.length; j++) {
     CommandsManagement.renderCommand(function_obj.commands[j], $(appender.find('.commands_list_div')[0]), 3, function_obj);
   }
-  $('.minimize_function_button').popup({
+
+  appender.find('.minimize_function_button').popup({
     content : LocalizedStrings.getUI("tooltip_hide_function"),
     delay: {
       show: 750,
@@ -403,6 +404,129 @@ export function renderFunction (function_obj) {
     }
   });
 
+  appender.find('.move_function').popup({
+    content : LocalizedStrings.getUI("btn_drag_and_drop_function"),
+    delay: {
+      show: 1000,
+      hide: 0
+    }
+  });
+
+  appender.find('.remove_function_button').popup({
+    content : LocalizedStrings.getUI("btn_delete_function"),
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+  
+  appender.find('.add_var_button_function').popup({
+    content : LocalizedStrings.getUI("btn_add_var"),
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
+  appender.find('a[data-command="attribution"]').popup({
+    content : LocalizedStrings.getUI("tooltip_menu_attribution"),
+    position: 'right center',
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
+  appender.find('a[data-command="functioncall"]').popup({
+    content : LocalizedStrings.getUI("tooltip_menu_call_function"),
+    position: 'right center',
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
+  appender.find('a[data-command="iftrue"]').popup({
+    content : LocalizedStrings.getUI("tooltip_menu_if_else"),
+    position: 'right center',
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
+  appender.find('a[data-command="comment"]').popup({
+    content : LocalizedStrings.getUI("tooltip_menu_comments"),
+    position: 'right center',
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
+  appender.find('a[data-command="reader"]').popup({
+    content : LocalizedStrings.getUI("tooltip_menu_read"),
+    position: 'right center',
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
+  appender.find('a[data-command="writer"]').popup({
+    content : LocalizedStrings.getUI("tooltip_menu_write"),
+    position: 'right center',
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
+  appender.find('a[data-command="repeatNtimes"]').popup({
+    content : LocalizedStrings.getUI("tooltip_menu_repeat_n_times"),
+    position: 'right center',
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
+  appender.find('a[data-command="whiletrue"]').popup({
+    content : LocalizedStrings.getUI("tooltip_menu_repeat_whiletrue"),
+    position: 'right center',
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
+  appender.find('a[data-command="dowhiletrue"]').popup({
+    content : LocalizedStrings.getUI("tooltip_menu_repeat_dowhiletrue"),
+    position: 'right center',
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
+  appender.find('a[data-command="switch"]').popup({
+    content : LocalizedStrings.getUI("tooltip_menu_repeat_switch"),
+    position: 'right center',
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
+  appender.find('a[data-command="return"]').popup({
+    content : LocalizedStrings.getUI("tooltip_menu_repeat_return"),
+    position: 'right center',
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
   var function_index = program.functions.indexOf(function_obj);
 
   Sortable.create(appender.find(".variables_list_div")[0], {
@@ -740,6 +864,14 @@ export function initVisualUI () {
     runCode();
   });
 
+  $('#download_file_button').on('click', function () {
+    downloadFile();
+  });
+
+  $('#upload_file_button').on('click', function () {
+    $('#ivph_file').click().off('change').change(uploadFile);
+  });
+
   $('#stop_button').on('click', function () {
     showRunButton();
     stopExecution();
@@ -1479,4 +1611,42 @@ function stopExecution () {
     return;
   }
   proc.mode = Modes.ABORT;
-}
+}
+
+function downloadFile() {
+  
+  var contentToSend = '';
+
+  if (settingsProgrammingTypes == "textual") {
+    contentToSend +=  ivprogCore.CodeEditor.getCode();
+  } else {
+    contentToSend += JSON.stringify(window.program_obj, function(key, value) {
+      if (key == 'dom_object') {
+          return;
+      }
+      return value;
+    });
+  }
+
+  var date = new Date(); 
+  var temp = date.toISOString().split('T')[0] + "_" + date.toTimeString().split(' ')[0].replaceAll(':', '-');
+  var blob = new Blob([contentToSend],
+                { type: "text/plain;charset=utf-8" });
+  
+  saveAs(blob, "ivprog-exported_" + temp + ".ivph");
+}
+
+function uploadFile (evt) {
+    var oFReader = new FileReader();
+    oFReader.readAsText(document.getElementById("ivph_file").files[0]);
+    oFReader.onload = function (oFREvent) {
+      var txt = oFREvent.target.result;
+      try {
+        window.program_obj = JSON.parse(txt);
+        window.renderAlgorithm();
+      }
+      catch (e) {
+        showInvalidFile();
+      }
+    };
+  }

+ 16 - 0
js/visualUI/globals.js

@@ -490,6 +490,22 @@ function addHandlers (global_container) {
 		removeGlobal(global_var, global_container);
 	});
 
+	global_container.find( ".ellipsis" ).popup({
+    content : LocalizedStrings.getUI("tooltip_move_var"),
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
+	global_container.find( ".remove_global" ).popup({
+    content : LocalizedStrings.getUI("tooltip_remove_var"),
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
 }
 
 function updateColumnsAndRowsText (global_container, global_var) {

+ 17 - 1
js/visualUI/variables.js

@@ -5,7 +5,7 @@ import * as Utils from './utils';
 import { registerUserEvent, registerSystemEvent, ActionTypes } from "./../services/userLog";
 import { isValidIdentifier } from "./../util/utils";
 
-var counter_new_variables = 0;
+var counter_new_variables = 0;	
 
 export function addVariable (function_obj, function_container, is_in_click = false) {
 	var new_var = new Models.Variable(Types.INTEGER, LocalizedStrings.getUI('new_variable') + '_' + counter_new_variables, 0);
@@ -120,6 +120,22 @@ function addHandlers (variable_obj, variable_container, function_obj) {
 		removeVariable(variable_obj, variable_container, function_obj.name);
 	});
 
+	variable_container.find( ".ellipsis" ).popup({
+    content : LocalizedStrings.getUI("tooltip_move_var"),
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
+	variable_container.find( ".remove_variable" ).popup({
+    content : LocalizedStrings.getUI("tooltip_remove_var"),
+    delay: {
+      show: 750,
+      hide: 0
+    }
+  });
+
 }
 
 export function renderVariable (function_container, new_var, function_obj) {

+ 7 - 3
templates/index.html

@@ -15,10 +15,14 @@
     <script src="js/jquery-ui.min.js"></script>
     <script src="js/semantic.min.js"></script>
     <script src="js/Sortable.js"></script>
+    <script src="js/filesaver.min.js"></script>
     <script src="js/iassign-integration-functions.js"></script>
+
   </head>
   <body>
 
+    <input type="file" name="ivph_file" id="ivph_file" style="position:absolute;margin-top: -500px !important;">
+
     <div class="ui height_100 add_accordion" id="ui_main_div">
 
       <div class="title default_visual_title">
@@ -40,10 +44,10 @@
           <a class="item textual_coding_button">
             <i class="code icon"></i>
           </a>
-          <a class="item upload_file_button disabled">
+          <a class="item upload_file_button" id="upload_file_button">
             <i class="upload icon"></i>
           </a>
-          <a class="item download_file_button disabled">
+          <a class="item download_file_button" id="download_file_button">
             <i class="download icon"></i>
           </a>
           <a class="item undo_button disabled">
@@ -111,7 +115,7 @@
     </div>
     <div class="dimmer_content_message">
       <h3>Aconteceu um erro ao processar a atividade. <br> Recarregue a página para tentar novamente.</h3>
-      <button class="positive ui button" onclick="window.parent.location.reload()">Recarregar</button>
+      <button class="positive ui button">Recarregar</button>
     </div>
     <script src="js/iassign-integration-functions.js"></script>
   </div>

+ 1 - 0
webpack.config.js

@@ -96,6 +96,7 @@ module.exports = {
       { from: "js/jquery.min.js", to: path.resolve(__dirname, "build/js") },
       { from: "js/jquery-ui.min.js", to: path.resolve(__dirname, "build/js") },
       { from: "js/semantic.min.js", to: path.resolve(__dirname, "build/js") },
+      { from: "js/filesaver.min.js", to: path.resolve(__dirname, "build/js") },
       {
         from: "css/semantic.min.css",
         to: path.resolve(__dirname, "build/css"),