Bladeren bron

Alguns bugs corrigidos e mais features

Igor 5 jaren geleden
bovenliggende
commit
89edc08049

File diff suppressed because it is too large
+ 170 - 50
build/ivprog.bundle.js


File diff suppressed because it is too large
+ 1 - 1
build/ivprog.bundle.js.map


+ 18 - 11
css/ivprog-visual-1.0.css

@@ -642,10 +642,8 @@ div.function_name_div_updated:active,
 
 .global_var .circle.add_global_button, .global_var i.back,
 .ui.add_var_context .icon.plus.circle, .ui.add_var_context .icon.circle.back,
-.inline_add_command .icon.plus.circle, .inline_add_command .icon.circle.back {
+.ui.inline_add_command .icon.plus.circle, .ui.inline_add_command .icon.circle.back {
 	position: absolute;
-    margin-top: 22px;
-    margin-left: 22px;
 }
 .global_var .circle.add_global_button,
 .ui.add_var_context .icon.plus.circle,
@@ -710,16 +708,18 @@ div.function_name_div_updated:active,
 	color: yellow;
 	font-size: 125%;
 }
-.inline_add_command .icon.circle.back {
-	margin-top: 20px;
-    margin-left: 20px;
-}
 .inline_add_command .icon.plus.circle {
 	color: #ec9962 !important;
-	margin-top: 20px;
-    margin-left: 20px;
 }
-
+.inline_add_command .icon.plus.circle, 
+.inline_add_command .icon.circle.back,
+.ui.add_var_context .icon.plus.circle, 
+.ui.add_var_context .icon.circle.back,
+.global_var .icon.plus.circle, 
+.global_var .icon.circle.back {
+	left: 1.8em !important;
+	margin-top: 1.5em !important;
+}
 .ui.icon.button.dropdown.menu_commands {
     float: left;
     color: white;
@@ -773,7 +773,14 @@ div.function_name_div_updated:active,
 	border: 2px solid #e76060 !important;
     border-radius: 0.25em !important;
 }
-
 .command_drag {
 	cursor: move;
+}
+.command_container.over_command_drag {
+	border: 3px dotted blue !important;
+	padding: 0.315em !important;
+}
+.commands_list_div.over_command_drag {
+	border: 3px dotted blue !important;
+	padding: 0.2em !important;
 }

+ 11 - 10
grammar/en/langFunctions.js

@@ -4,21 +4,21 @@ export default {
   main_function: "start",
   $read: "read",
   $write: "write",
-  $numElements: "numero_elementos",
-  $matrixLines: "matriz_linhas",
-  $matrixColumns: "matriz_colunas",
+  $numElements: "total_of_elements",
+  $matrixLines: "total_of_lines",
+  $matrixColumns: "total_of_columns",
   $substring: "subcadeia",
   $length: "comprimento",
   $uppercase: "caixa_alta",
   $lowercase: "caixa_baixa",
   $charAt: "char_at",
-  $isReal: "e_real",
-  $isInt: "e_inteiro",
-  $isBool: "e_logico",
-  $castReal: "como_real",
-  $castInt: "como_inteiro",
-  $castBool: "como_logico",
-  $castString: "como_cadeia",
+  $isReal: "is_real",
+  $isInt: "is_integer",
+  $isBool: "is_logic",
+  $castReal: "to_real",
+  $castInt: "to_integer",
+  $castBool: "to_logic",
+  $castString: "to_string",
   $sin: "sin",
   $cos: "cos",
   $tan: "tan",
@@ -30,4 +30,5 @@ export default {
   $invert: "invert",
   $max: "maximum",
   $min: "minimum"
+
 }

+ 1 - 1
grammar/en/langLibs.js

@@ -6,5 +6,5 @@ export default {
   $ioLib: "ES",
   $strLib: "Texto",
   $arrayLib: "Arranjo",
-  $langLib: "IV"
+  $langLib: "Conversion"
 }

+ 10 - 10
grammar/es/langFunctions.js

@@ -4,21 +4,21 @@ export default {
   main_function: "inicio",
   $read: "leia",
   $write: "escreva",
-  $numElements: "numero_elementos",
-  $matrixLines: "matriz_linhas",
-  $matrixColumns: "matriz_colunas",
+  $numElements: "total_of_elements",
+  $matrixLines: "total_of_lines",
+  $matrixColumns: "total_of_columns",
   $substring: "subcadeia",
   $length: "comprimento",
   $uppercase: "caixa_alta",
   $lowercase: "caixa_baixa",
   $charAt: "char_at",
-  $isReal: "e_real",
-  $isInt: "e_inteiro",
-  $isBool: "e_logico",
-  $castReal: "como_real",
-  $castInt: "como_inteiro",
-  $castBool: "como_logico",
-  $castString: "como_cadeia",
+  $isReal: "is_real",
+  $isInt: "is_integer",
+  $isBool: "is_logic",
+  $castReal: "to_real",
+  $castInt: "to_integer",
+  $castBool: "to_logic",
+  $castString: "to_string",
   $sin: "sin",
   $cos: "cos",
   $tan: "tan",

+ 1 - 1
grammar/es/langLibs.js

@@ -6,5 +6,5 @@ export default {
   $ioLib: "ES",
   $strLib: "Texto",
   $arrayLib: "Arranjo",
-  $langLib: "IV"
+  $langLib: "Conversion"
 }

+ 3 - 3
grammar/pt/langFunctions.js

@@ -4,9 +4,9 @@ export default {
   main_function: "inicio",
   $read: "leia",
   $write: "escreva",
-  $numElements: "numero_elementos",
-  $matrixLines: "matriz_linhas",
-  $matrixColumns: "matriz_colunas",
+  $numElements: "total_de_elementos",
+  $matrixLines: "total_de_linhas",
+  $matrixColumns: "total_de_colunas",
   $substring: "subcadeia",
   $length: "comprimento",
   $uppercase: "caixa_alta",

+ 1 - 1
grammar/pt/langLibs.js

@@ -6,5 +6,5 @@ export default {
   $ioLib: "ES",
   $strLib: "Texto",
   $arrayLib: "Arranjo",
-  $langLib: "IV"
+  $langLib: "Conversao"
 }

+ 13 - 1
i18n/en/ui.json

@@ -76,6 +76,8 @@
   "text_menu_functions_text":"Text",
   "text_menu_functions_arrangement":"Arrangement",
   "text_menu_functions_conversion":"Conversion",
+  "text_none_variable":"There is no declared variable",
+  "text_none_variable_instruction":"Create a new variable to use it",
   "tooltip_visual": "Visual programming",
   "tooltip_textual": "Textual programming",
   "tooltip_upload": "Upload code file",
@@ -111,5 +113,15 @@
   "$length": "length",
   "$uppercase": "uppercase",
   "$lowercase": "lowercase",
-  "$charAt": "char_at"
+  "$charAt": "char_at",
+  "$numElements": "total_of_elements",
+  "$matrixLines": "total_of_lines",
+  "$matrixColumns": "total_of_columns",
+  "$isReal": "is_real",
+  "$isInt": "is_integer",
+  "$isBool": "is_logic",
+  "$castReal": "to_real",
+  "$castInt": "to_integer",
+  "$castBool": "to_logic",
+  "$castString": "to_string"
 }

+ 13 - 1
i18n/es/ui.json

@@ -76,6 +76,8 @@
   "text_menu_functions_text":"Text",
   "text_menu_functions_arrangement":"Arrangement",
   "text_menu_functions_conversion":"Conversion",
+  "text_none_variable":"There is no declared variable",
+  "text_none_variable_instruction":"Create a new variable to use it",
   "tooltip_visual": "Visual programming",
   "tooltip_textual": "Textual programming",
   "tooltip_upload": "Upload code file",
@@ -116,5 +118,15 @@
   "$length": "length",
   "$uppercase": "uppercase",
   "$lowercase": "lowercase",
-  "$charAt": "char_at"
+  "$charAt": "char_at",
+  "$numElements": "total_of_elements",
+  "$matrixLines": "total_of_lines",
+  "$matrixColumns": "total_of_columns",
+  "$isReal": "is_real",
+  "$isInt": "is_integer",
+  "$isBool": "is_logic",
+  "$castReal": "to_real",
+  "$castInt": "to_integer",
+  "$castBool": "to_logic",
+  "$castString": "to_string"
 }

+ 13 - 1
i18n/pt/ui.json

@@ -82,6 +82,8 @@
   "text_menu_functions_text":"Texto",
   "text_menu_functions_arrangement":"Arranjo",
   "text_menu_functions_conversion":"Conversão",
+  "text_none_variable":"Nenhuma variável declarada",
+  "text_none_variable_instruction":"Antes de utilizar uma variável, é necessário criá-la",
   "tooltip_visual": "Programação visual",
   "tooltip_textual": "Programação textual",
   "tooltip_upload": "Upload de código fonte",
@@ -118,5 +120,15 @@
   "$length": "comprimento",
   "$uppercase": "caixa_alta",
   "$lowercase": "caixa_baixa",
-  "$charAt": "texto_na_posicao"
+  "$charAt": "texto_na_posicao",
+  "$numElements": "total_de_elementos",
+  "$matrixLines": "total_de_linhas",
+  "$matrixColumns": "total_de_colunas",
+  "$isReal": "e_real",
+  "$isInt": "e_inteiro",
+  "$isBool": "e_logico",
+  "$castReal": "como_real",
+  "$castInt": "como_inteiro",
+  "$castBool": "como_logico",
+  "$castString": "como_cadeia"
 }

+ 4 - 1
index.html

@@ -24,7 +24,7 @@
   </head>
   <body>
 
-    <div class="ui height_100 add_accordion">
+    <div class="ui height_100 add_accordion" id="ui_main_div">
 
       <div class="title default_visual_title">
         <i class="dropdown icon"></i>
@@ -65,6 +65,9 @@
         <a class="item assessment assessment_button">
           <i class="check icon"></i>
         </a>
+        <!--<a class="item expand_button">
+          <i class="expand arrows alternate icon"></i>
+        </a>-->
         <a class="item help_button">
           <i class="help icon"></i>
         </a>

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

@@ -134,6 +134,43 @@ function prepareActivityToStudent (ilm_cont) {
         algorithm_in_ilm = ilm_cont.split('\n::algorithm::')[1].split('\n::logs::')[0];
         window.program_obj.functions = JSON.parse(algorithm_in_ilm).functions;
         window.program_obj.globals = JSON.parse(algorithm_in_ilm).globals;
+
+        window.watchW.watch(window.program_obj.globals, function(){
+          if (window.insertContext) {
+            setTimeout(function(){ renderAlgorithm(); }, 300);
+            window.insertContext = false;
+          } else {
+            renderAlgorithm();
+          }
+        }, 1);
+
+        for (var i = 0; i < window.program_obj.functions.length; i ++) {
+            window.watchW.watch(window.program_obj.functions[i].parameters_list, function(){
+              if (window.insertContext) {
+                setTimeout(function(){ renderAlgorithm(); }, 300);
+                window.insertContext = false;
+              } else {
+                renderAlgorithm();
+              }
+            }, 1);
+
+            window.watchW.watch(window.program_obj.functions[i].variables_list, function(){
+              if (window.insertContext) {
+                setTimeout(function(){ renderAlgorithm(); }, 300);
+                window.insertContext = false;
+              } else {
+                renderAlgorithm();
+              }
+            }, 1);
+        }
+        window.watchW.watch(window.program_obj.functions, function(){
+          if (window.insertContext) {
+            setTimeout(function(){ renderAlgorithm(); }, 300);
+            window.insertContext = false;
+          } else {
+            renderAlgorithm();
+          }
+        }, 1);
     }
     $('.assessment_button').removeClass('disabled');
     renderAlgorithm();
@@ -344,4 +381,30 @@ function inIframe () {
     } catch (e) {
         return true;
     }
+}
+
+
+function full_screen() {
+     // check if user allows full screen of elements. This can be enabled or disabled in browser config. By default its enabled.
+    //its also used to check if browser supports full screen api.
+    if("fullscreenEnabled" in document || "webkitFullscreenEnabled" in document || "mozFullScreenEnabled" in document || "msFullscreenEnabled" in document) {
+        if(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled) {
+            var element = document.getElementById("ui_main_div");
+            //requestFullscreen is used to display an element in full screen mode.
+            if("requestFullscreen" in element) {
+                element.requestFullscreen();
+            } 
+            else if ("webkitRequestFullscreen" in element) {
+                element.webkitRequestFullscreen();
+            } 
+            else if ("mozRequestFullScreen" in element) {
+                element.mozRequestFullScreen();
+            } 
+            else if ("msRequestFullscreen" in element) {
+                element.msRequestFullscreen();
+            }
+        }
+    } else {
+        $('.expand_button').addClass('disabled');
+    }
 }

+ 2 - 0
js/visualUI/algorithm.js

@@ -16,6 +16,8 @@ import { LanguageService } from '../services/languageService';
 var block_render = false;
 
 export function renderAlgorithm () {
+	console.log('rendering algorithm...');
+
 	if (block_render) {
 		return;
 	}

+ 43 - 1
js/visualUI/commands.js

@@ -109,7 +109,16 @@ export function createFloatingCommand (function_obj, function_container, command
 			break;
 	}
 
-	floatingObject.draggable().appendTo("body");
+	floatingObject.draggable({
+		drag: function(evt) {
+	        borderMouseDragCommand(function_obj, function_container, evt);
+	    },
+	    stop: function(evt) {
+	    	function_container.find('.over_command_drag').each(function( index ) {
+				$(this).removeClass('over_command_drag');
+			});
+	    }
+	}).appendTo("body");
 
 	floatingObject.mouseup(function(evt) {
 	  manageCommand(function_obj, function_container, evt, command_type);
@@ -123,6 +132,39 @@ export function createFloatingCommand (function_obj, function_container, command
 	floatingObject.trigger(mouse_event);
 }
 
+function borderMouseDragCommand (function_obj, function_container, evt) {
+
+	function_container.find('.over_command_drag').each(function( index ) {
+		$(this).removeClass('over_command_drag');
+	});
+
+	var prev = null;
+
+	function_container.find('.commands_list_div').each(function( index ) { 
+		prev = $(this);
+		var objLeft = prev.offset().left;
+        var objTop = prev.offset().top;
+        var objRight = objLeft + prev.width();
+        var objBottom = objTop + prev.height();
+        if (evt.pageX > objLeft && evt.pageX < objRight && evt.pageY > objTop && evt.pageY < objBottom) {
+        	prev.addClass("over_command_drag"); 
+        }
+	});
+
+	function_container.find('.command_container').each(function( index ) { 
+		var obj = $(this);
+		var objLeft = obj.offset().left;
+        var objTop = obj.offset().top;
+        var objRight = objLeft + obj.width();
+        var objBottom = objTop + obj.height();
+        if (evt.pageX > objLeft && evt.pageX < objRight && evt.pageY > objTop && evt.pageY < objBottom) {
+        	prev.removeClass('over_command_drag');
+        	obj.addClass("over_command_drag"); 
+        	return;
+        }
+	});
+}
+
 // before_after_inside: 1 -> before, 2 -> after, 3 -> inside
 export function renderCommand (command, element_reference, before_after_inside, function_obj) {
 	var createdElement;

+ 68 - 13
js/visualUI/commands/variable_value_menu.js

@@ -93,7 +93,9 @@ export function renderMenu (command, ref_object, dom_object, function_obj, size_
     if (ref_object.content || ref_object.function_called) {
     	if (ref_object.content) {
     		// Verificar se a variável ainda existe:
-    		if (isVarInProgram(ref_object.content, function_obj)) {
+    		var variable_fun = isVarInProgram(ref_object.content, function_obj);
+    		if (variable_fun) {
+    			ref_object.content = variable_fun;
     			renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
 	    	} else {
 	    		if (ref_object.content && ref_object.content.type) {
@@ -105,7 +107,9 @@ export function renderMenu (command, ref_object, dom_object, function_obj, size_
 	    	}
     	} else if (ref_object.function_called) {
     		// Verificar se a função ainda existe:
-    		if (isFunctionInProgram(ref_object.function_called)) {
+    		var ret_function = isFunctionInProgram(ref_object.function_called);
+    		if (ret_function) {
+    			ref_object.function_called = ret_function;
     			renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
     		} else {
     			ref_object.content = null;
@@ -141,14 +145,28 @@ function appendSelectText (ref_object, menu_var_or_value) {
 }
 
 function isFunctionInProgram (function_called_obj) {
-	if (window.program_obj.functions) {
-		for (var i = 0; i < window.program_obj.functions.length; i++) {
-			if (window.program_obj.functions[i] == function_called_obj) {
-				return true;
+	if (function_called_obj.name) {
+		if (window.program_obj.functions) {
+			for (var i = 0; i < window.program_obj.functions.length; i++) {
+				if (window.program_obj.functions[i] == function_called_obj) {
+					return window.program_obj.functions[i];
+				}
+			}
+			for (var i = 0; i < window.program_obj.functions.length; i++) {
+				if (window.program_obj.functions[i].name == function_called_obj.name) {
+					return window.program_obj.functions[i];
+				}
+			}
+		}
+	} else if (function_called_obj.identifier) {
+		for (var i = 0; i < window.system_functions.length; i++) {
+			if (window.system_functions[i].identifier == function_called_obj.identifier) {
+				return window.system_functions[i];
 			}
 		}
 	}
-	return false;
+	
+	return null;
 }
 
 function isVarInProgram (var_obj, function_obj) {
@@ -156,7 +174,7 @@ function isVarInProgram (var_obj, function_obj) {
 	if (function_obj.variables_list) {
 		for (var i = 0; i < function_obj.variables_list.length; i++) {
 			if (function_obj.variables_list[i] == var_obj) {
-				return true;
+				return function_obj.variables_list[i];
 			}
 		}
 	}
@@ -164,7 +182,7 @@ function isVarInProgram (var_obj, function_obj) {
 	if (function_obj.parameters_list) {
 		for (var i = 0; i < function_obj.parameters_list.length; i++) {
 			if (function_obj.parameters_list[i] == var_obj) {
-				return true;
+				return function_obj.parameters_list[i];
 			}
 		}
 	}
@@ -172,11 +190,37 @@ function isVarInProgram (var_obj, function_obj) {
 	if (window.program_obj.globals) {
 		for (var i = 0; i < window.program_obj.globals.length; i++) {
 			if (window.program_obj.globals[i] == var_obj) {
-				return true;
+				return window.program_obj.globals[i];
 			}
 		}
 	}
-	return false;
+
+	// If not found, verify if the reference was lost
+	if (var_obj) {
+		if (function_obj.variables_list) {
+			for (var i = 0; i < function_obj.variables_list.length; i++) {
+				if (function_obj.variables_list[i].name == var_obj.name) {
+					return function_obj.variables_list[i];
+				}
+			}
+		}
+		if (function_obj.parameters_list) {
+			for (var i = 0; i < function_obj.parameters_list.length; i++) {
+				if (function_obj.parameters_list[i].name == var_obj.name) {
+					return function_obj.parameters_list[i];
+				}
+			}
+		}
+		if (window.program_obj.globals) {
+			for (var i = 0; i < window.program_obj.globals.length; i++) {
+				if (window.program_obj.globals[i].name == var_obj.name) {
+					return window.program_obj.globals[i];
+				}
+			}
+		}
+	}
+
+	return null;
 }
 
 export function refreshMenu (menu_var_or_value_dom) {
@@ -213,8 +257,10 @@ function variableValueMenuCode (command, variable_obj, dom_object, function_obj,
 	
 	if (variable_obj.content || variable_obj.function_called) {
     	// Verificar se a variável ainda existe:
-    	if (isVarInProgram(variable_obj.content, function_obj)) {
-    		
+    	var var_fun = isVarInProgram(variable_obj.content, function_obj);
+
+    	if (var_fun) {
+	    	variable_obj.content = var_fun;
     	} else {
     		if (variable_obj.content && variable_obj.content.type) {
     			variable_obj.content = null;
@@ -661,6 +707,7 @@ function addVariablesToMenu (function_obj, menu_var_or_value, ref_object, expres
 
 	var sub_menu = menu_var_or_value.find('.menu_only_vars');
 	sub_menu.text('');
+	var is_there = false;
 
 	if (window.program_obj.globals) {
 
@@ -669,6 +716,7 @@ function addVariablesToMenu (function_obj, menu_var_or_value, ref_object, expres
 				var temp = $('<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_variable+'">' + window.program_obj.globals[i].name + ' </div>');
 				temp.data('variable_reference', window.program_obj.globals[i]);
 				sub_menu.append(temp);
+				is_there = true;
 			}
 		} else {
 			for (var i = 0; i < window.program_obj.globals.length; i++) {
@@ -676,6 +724,7 @@ function addVariablesToMenu (function_obj, menu_var_or_value, ref_object, expres
 					var temp = $('<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_variable+'">' + window.program_obj.globals[i].name + ' </div>');
 					temp.data('variable_reference', window.program_obj.globals[i]);
 					sub_menu.append(temp);
+					is_there = true;
 				}
 			}
 		}
@@ -686,6 +735,7 @@ function addVariablesToMenu (function_obj, menu_var_or_value, ref_object, expres
 			var temp = $('<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_variable+'">' + function_obj.parameters_list[i].name + ' </div>');
 			temp.data('variable_reference', function_obj.parameters_list[i]);
 			sub_menu.append(temp);
+			is_there = true;
 		}
 	}
 
@@ -694,8 +744,13 @@ function addVariablesToMenu (function_obj, menu_var_or_value, ref_object, expres
 			var temp = $('<div class="item" data-option="'+VAR_OR_VALUE_TYPES.only_variable+'">' + function_obj.variables_list[i].name + ' </div>');
 			temp.data('variable_reference', function_obj.variables_list[i]);
 			sub_menu.append(temp);
+			is_there = true;
 		}
 	}
+	if (!is_there) {
+		sub_menu.append($('<div class="header">'+LocalizedStrings.getUI('text_none_variable')+'</div>'));
+		sub_menu.append($('<div class="item disabled">'+LocalizedStrings.getUI('text_none_variable_instruction')+'</div>'));
+	}
 
 }
 

+ 16 - 1
js/visualUI/functions.js

@@ -105,8 +105,18 @@ window.generator = CodeManagement.generate;
 window.runCodeAssessment = runCodeAssessment;
 window.renderAlgorithm = AlgorithmManagement.renderAlgorithm;
 window.insertContext = false;
+window.watchW = WatchJS;
 
-WatchJS.watch(program.globals, function(){
+WatchJS.watch(window.program_obj.globals, function(){
+  if (window.insertContext) {
+    setTimeout(function(){ AlgorithmManagement.renderAlgorithm(); }, 300);
+    window.insertContext = false;
+  } else {
+    AlgorithmManagement.renderAlgorithm();
+  }
+}, 1);
+
+WatchJS.watch(window.program_obj.functions, function(){
   if (window.insertContext) {
     setTimeout(function(){ AlgorithmManagement.renderAlgorithm(); }, 300);
     window.insertContext = false;
@@ -122,6 +132,8 @@ function addFunctionHandler () {
 
 	counter_new_functions ++;
 
+  window.insertContext = true;
+
   var newe = renderFunction(new_function);
 
   newe.css('display', 'none');
@@ -419,6 +431,9 @@ export function initVisualUI () {
   $('.div_toggle_console').on('click', () => {
     toggleConsole();
   });
+  $('.expand_button').on('click', () => {
+    full_screen();
+  });
 }
 
 var is_iassign = false;