Browse Source

Menu flutuante na tela

Igor 5 years ago
parent
commit
ec4f08a1b1

File diff suppressed because it is too large
+ 31 - 0
algoritmo.ivph


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


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


+ 19 - 9
css/ivprog-visual-1.0.css

@@ -647,12 +647,12 @@ 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,
-.ui.inline_add_command .icon.plus.circle, .ui.inline_add_command .icon.circle.back {
+.ui.rail .icon.plus.circle, .ui.rail .icon.circle.back {
 	position: absolute;
 }
 .global_var .circle.add_global_button,
 .ui.add_var_context .icon.plus.circle,
-.inline_add_command .icon.plus.circle {
+.ui.rail .icon.plus.circle {
 	z-index: 10;
 	color: #bf80d4!important;
 	cursor: pointer;
@@ -660,14 +660,14 @@ div.function_name_div_updated:active,
 }
 .global_var i.back,
 .ui.add_var_context .icon.circle.back,
-.inline_add_command .icon.circle.back {
+.ui.rail .icon.circle.back {
 	z-index: 9;
 	color: white !important;
 }
 .ui.add_var_context{
 	margin-left: -4px;
 }
-.inline_add_command {
+.ui.rail {
 	color: #ab0054 !important;
 }
 
@@ -713,11 +713,11 @@ div.function_name_div_updated:active,
 	color: yellow;
 	font-size: 125%;
 }
-.inline_add_command .icon.plus.circle {
+.ui.rail .icon.plus.circle {
 	color: #ec9962 !important;
 }
-.inline_add_command .icon.plus.circle, 
-.inline_add_command .icon.circle.back,
+.ui.rail .icon.plus.circle, 
+.ui.rail .icon.circle.back,
 .ui.add_var_context .icon.plus.circle, 
 .ui.add_var_context .icon.circle.back,
 .global_var .icon.plus.circle, 
@@ -725,8 +725,13 @@ div.function_name_div_updated:active,
 	left: 1.8em !important;
 	margin-top: 1.5em !important;
 }
+
+.ui.rail .icon.plus.circle, 
+.ui.rail .icon.circle.back {
+	left: 1.3em !important;
+}
+
 .ui.icon.button.dropdown.menu_commands {
-    float: left;
     color: white;
     margin-left: -4px;
     padding: 8px;
@@ -774,7 +779,7 @@ div.function_name_div_updated:active,
 }
 
 .command_drag {
-	/*cursor: move;*/
+	cursor: move;
 }
 .command_container.over_command_drag {
 	border: 3px dotted blue !important;
@@ -856,3 +861,8 @@ div.ui.checkbox.transition.visible {
 .div_parent_handler:hover i.handler {
 	opacity: 1;
 }
+
+.ui.block_commands {
+    min-height: 20px !important;
+    padding-top: 5px !important;
+}

+ 3 - 3
js/iassign-integration-functions.js

@@ -425,8 +425,8 @@ function getTrackingLogs () {
     var ret = "";
     for (var i = 0; i < trackingMatrix.length; i++) {
         ret += "\n" + trackingMatrix[i][0] + "," + trackingMatrix[i][1] + "," + trackingMatrix[i][2];
-        if (trackingMatrix[i][2] === 1) {
-            ret += ',"' + trackingMatrix[i][3] + '"';
+        if (trackingMatrix[i][3] === 1) {
+            ret += ',' + trackingMatrix[i][3] + ',"' + trackingMatrix[i][4] + '"';
         }
     }
     return ret;
@@ -439,7 +439,7 @@ function adCoords(e, code){
     var x = e.pageX; 
     var y = e.pageY;
     if (code === 1) {
-        return [x, y, code, e.target.classList['value']];
+        return [new Date().getTime(), x, y, code, e.target.classList['value']];
     } else {
         return [x, y, code];
     }

+ 4 - 0
js/visualUI/algorithm.js

@@ -19,7 +19,11 @@ export function renderAlgorithm () {
 	if (window.block_render) {
 		return;
 	}
+	if (window.draging) {
+		return;
+	}
 	window.block_render = true;
+	console.log('rendering algorithm');
 
  	$('.all_functions').children().off();
 	$('.all_functions').empty();

+ 2 - 11
js/visualUI/commands.js

@@ -237,13 +237,6 @@ export function renderCommand (command, element_reference, before_after_inside,
 			break;
 	}
 
-	createdElement.find('.button_remove_command').mouseover(function() {
-    	createdElement.css({'opacity':'.8'});
-	});
-	createdElement.find('.button_remove_command').mouseout(function() { 
-    	createdElement.css({'opacity':'1'});
-	});
-
 }
 
 export function genericCreateCommand (command_type) {
@@ -461,6 +454,8 @@ function manageCommand (function_obj, function_container, event, command_type) {
 	
 	has_element_created_draged = false;
 	which_element_is_draged = null;
+
+	renderAlgorithm();
 }
 
 function insertCommandInBlockHierar (el, event, function_obj, command_type, hier_dom, hier_obj) {
@@ -504,8 +499,6 @@ function insertCommandInBlockHierar (el, event, function_obj, command_type, hier
 	}
 }
 
-
-
 function findNearbyCommandToAddInBlockScope (el, event, node_list_commands, function_obj, command_type, command_parent) {
 
 	var all_sub = $(node_list_commands).find('div.command_container');
@@ -553,8 +546,6 @@ function findNearbyCommandToAddInBlockScope (el, event, node_list_commands, func
 	}
 }
 
-
-
 function findBeforeOrAfterCommandToAddInsertBlock (el, event, function_obj, command_type) {
 
 	var el_jq = $(el);

+ 1 - 0
js/visualUI/commands/dowhiletrue.js

@@ -22,6 +22,7 @@ export function renderCommand (command, function_obj) {
 
 	var el = $(ret);
 	el.data('command', command);
+	el.find('.block_commands').data('command', command);
 
 	addHandlers(command, function_obj, el);
 

+ 1 - 0
js/visualUI/commands/iftrue.js

@@ -30,6 +30,7 @@ export function renderCommand (command, function_obj) {
 	el.find('.block_commands').data('command', command);
 	el.find('.data_block_if').data('command', command);
 	el.find('.data_block_else').data('command', command);
+	el.find('.commands_if').data('command', command);
 
 	addHandlers(command, function_obj, el);
 

+ 1 - 0
js/visualUI/commands/repeatNtimes.js

@@ -22,6 +22,7 @@ export function renderCommand (command, function_obj) {
 	
 	var el = $(ret);
 	el.data('command', command);
+	el.find('.block_commands').data('command', command);
 
 	addHandlers(command, function_obj, el);
 

+ 1 - 0
js/visualUI/commands/whiletrue.js

@@ -24,6 +24,7 @@ export function renderCommand (command, function_obj) {
 
 	var el = $(ret);
 	el.data('command', command);
+	el.find('.block_commands').data('command', command);
 
 	addHandlers(command, function_obj, el);
 

+ 293 - 14
js/visualUI/functions.js

@@ -276,10 +276,11 @@ function renderFunctionReturn (function_obj, function_element) {
     function_element.find('.function_return').append(ret);
 }
 
+var cont = 0;
 
 export function renderFunction (function_obj) {
   
-  var appender = '<div class="ui secondary segment function_div list-group-item">';
+  var appender = '<div class="ui secondary segment function_div list-group-item function_cont_'+cont+'">';
 
   if (function_obj.function_comment) {
     //appender += renderComment(function_obj.function_comment, sequence, true, -1);
@@ -309,7 +310,13 @@ export function renderFunction (function_obj) {
 
   appender += '<div class="ui top attached segment variables_list_div"></div>';
 
-  appender += '<div class="ui inline_add_command"><i class="icon plus circle purple"></i><i class="icon circle white back"></i><div class="ui icon button dropdown menu_commands orange" style="float: left;" ><i class="icon code"></i> <div class="menu"> ';
+  
+
+  appender += '<div class="ui bottom attached segment commands_list_div commands_cont_'+cont+'">'
+        + '<div class="ui rail" style="width: 35px; margin-left: -36px;"><div class="ui sticky sticky_cont_'+cont+'" style="top: 50px !important;">';
+
+
+  appender += '<i class="icon plus circle purple"></i><i class="icon circle white back"></i><div class="ui icon button dropdown menu_commands orange" ><i class="icon code"></i> <div class="menu"> ';
   appender += '<a class="item" data-command="'+Models.COMMAND_TYPES.reader+'"><i class="download icon"></i> ' +LocalizedStrings.getUI('text_read_var')+ '</a>'
         + '<a class="item" data-command="'+Models.COMMAND_TYPES.writer+'"><i class="upload icon"></i> '+LocalizedStrings.getUI('text_write_var')+'</a>'
         + '<a class="item" data-command="'+Models.COMMAND_TYPES.comment+'"><i class="quote left icon"></i> '+LocalizedStrings.getUI('text_comment')+'</a>'
@@ -321,9 +328,11 @@ export function renderFunction (function_obj) {
         + '<a class="item" data-command="'+Models.COMMAND_TYPES.dowhiletrue+'"><i class="sync icon"></i> '+LocalizedStrings.getUI('text_dowhiletrue')+'</a>'
         + '<a class="item" data-command="'+Models.COMMAND_TYPES.switch+'"><i class="list icon"></i> '+LocalizedStrings.getUI('text_switch')+'</a>'
         + '<a class="item" data-command="'+Models.COMMAND_TYPES.return+'"><i class="reply icon"></i> '+LocalizedStrings.getUI('text_btn_return')+'</a>'
-        + '</div></div></div>';
+        + '</div></div>';
 
-  appender += '<div class="ui bottom attached segment commands_list_div"></div>';
+
+  appender += '</div></div>'
+        +'</div>';
 
   appender += '</div></div>';
 
@@ -359,25 +368,19 @@ export function renderFunction (function_obj) {
     }
   });
 
+  var function_index = program.functions.indexOf(function_obj);
+
   Sortable.create(appender.find(".variables_list_div")[0], {
     handle: '.ellipsis',
     animation: 100,
     ghostClass: 'ghost',
-    group: 'local_vars_drag_' + program.functions.indexOf(function_obj),
+    group: 'local_vars_drag_' + function_index,
     onEnd: function (evt) {
        updateSequenceLocals(evt.oldIndex, evt.newIndex, function_obj);
     }
   });
 
-  /*Sortable.create(appender.find(".commands_list_div")[0], {
-    handle: '.command_drag',
-    animation: 100,
-    ghostClass: 'ghost',
-    group: 'commands_drag_' + program.functions.indexOf(function_obj),
-    onEnd: function (evt) {
-       //updateSequenceLocals(evt.oldIndex, evt.newIndex, function_obj);
-    }
-  });*/
+  addSortableHandler(appender.find(".commands_list_div")[0], function_index);
 
   if (!function_obj.is_main) {
     Sortable.create(appender.find(".container_parameters_list")[0], {
@@ -390,9 +393,285 @@ export function renderFunction (function_obj) {
       }
     });
   }
+
+  var teste  = '.ui.sticky.sticky_cont_'+cont;
+  $(teste).sticky({
+    context: '.ui.bottom.attached.segment.commands_list_div.commands_cont_'+cont,
+    scrollContext: '.ivprog_visual_panel',
+    observeChanges: true,
+    offset: 40,
+    onStick: function (evt) {
+      $(teste).css('top', '20px', 'important');
+    }, 
+    onBottom: function (evt) {
+      $(teste).css('top', '20px', 'important');
+    },
+    onUnstick: function (evt) {
+      $(teste).css('top', '20px', 'important');
+    },
+    onReposition: function (evt) {
+      $(teste).css('top', '20px', 'important');
+    },
+    onScroll: function (evt) {
+      $(teste).css('top', '20px', 'important');
+      if (!isVisible($(teste), $(teste).parent())) {
+        $(teste).removeClass('fixed');
+      }
+    },
+    onTop: function (evt) {
+      $(teste).css('top', '20px', 'important');
+    }
+  });
+  cont ++;
+
   return appender;
 }
 
+function isVisible (element, container) {
+
+  var elementTop = $(element).offset().top,
+      elementHeight = $(element).height(),
+      containerTop = $(container).offset().top,
+      containerHeight = $(container).height() - 30;
+
+  return ((((elementTop - containerTop) + elementHeight) > 0)
+         && ((elementTop - containerTop) < containerHeight));
+}
+
+
+window.evento_drag;
+
+function updateProgramObjDrag () {
+  var nodes = Array.prototype.slice.call( $('.all_functions').children() );
+  var function_index;
+  var start_index;
+  var function_obj;
+  $(evento_drag.item).parentsUntil(".all_functions").each(function (index) {
+    if ($(this).hasClass('function_div')) {
+      function_index = nodes.indexOf(this);
+      start_index = index;
+      function_obj = $(this);
+    }
+  });
+
+  console.log(function_index);
+
+  var path_target = [];
+  $(evento_drag.item).parentsUntil(".all_functions").each(function (index) {
+    if ($(this).hasClass('command_container')) {
+      path_target.push(this);
+    }
+  });
+  if (path_target.length == 0) {
+    //console.log('soltou na raiz, na posição: ' + evento_drag.newIndex + ' mas ainda não sei de onde saiu ');
+  } else {
+    //console.log('soltou dentro de algum bloco, sequência vem logo abaixo (de baixo pra cima): ');
+    //console.log(path_target);
+  }
+
+  var index_each = [];
+  var path_relative = [];
+  for (var i = path_target.length - 1; i >= 0; i --) {
+    console.log('da vez', $(path_target[i + 1]));
+    if (i == (path_target.length - 1)) { // está na raiz
+      var indice_na_raiz = function_obj.find('.command_container').index(path_target[i]);
+      console.log('índice na raiz: ', indice_na_raiz);
+    } else {
+      if ($(path_target[i + 1]).hasClass('iftrue')) {
+        if ($(path_target[i]).parent().hasClass('commands_if')) {
+          path_relative.push('if');
+          index_each.push($(path_target[i]).parent().find('.command_container').index(path_target[i]));
+        } else {
+          path_relative.push('else');
+          index_each.push($(path_target[i]).parent().find('.command_container').index(path_target[i]));
+        }
+      } else if ($(path_target[i + 1]).hasClass('dowhiletrue')) {
+        path_relative.push('dowhiletrue');
+        index_each.push($(path_target[i + 1]).find('.command_container').index(path_target[i]));
+      } else if ($(path_target[i + 1]).hasClass('repeatNtimes')) {
+        path_relative.push('repeatNtimes');
+        index_each.push($(path_target[i + 1]).find('.command_container').index(path_target[i]));
+      } else if ($(path_target[i + 1]).hasClass('whiletrue')) {
+        path_relative.push('whiletrue');
+        index_each.push($(path_target[i + 1]).find('.command_container').index(path_target[i]));
+      } else if ($(path_target[i + 1]).hasClass('switch')) {
+        path_relative.push('switch');
+        //index_each.push($(path_target[i + 1]).find('.command_container').index(path_target[i]));
+      }
+    }
+  }
+  var index_in_block = -1;
+  var is_in_else = $(evento_drag.item).parent().hasClass('commands_else');
+
+  index_in_block = $(evento_drag.item).parent().find('.command_container').index(evento_drag.item);
+
+  var is_in_case_switch = $(evento_drag.item).parent().hasClass('case_commands_block');
+  var index_case_of_switch = -1;
+  if (is_in_case_switch) {
+    index_case_of_switch = $(evento_drag.item).parent().parent().parent().find('.case_div').index($(evento_drag.item).parent().parent());
+  }
+
+  /*console.log('path_relative:');
+  console.log(path_relative);
+  console.log('index_each:');
+  console.log(index_each);
+  console.log('index_in_block:');
+  console.log(index_in_block);
+  console.log('ele está em algum bloco de senão? ');
+  console.log(is_in_else);
+  console.log('ele está dentro de um case de switch?');
+  console.log(is_in_case_switch);
+  console.log('qual é o índice do case: ');
+  console.log(index_case_of_switch);*/
+
+  // encontrar o elemento na árvore:
+  var command_start_point = window.program_obj.functions[function_index].commands[indice_na_raiz];
+  var block_to_insert = command_start_point;
+  for (var i = 0; i < index_each.length; i++) {
+    if (path_relative[i] == "else") {
+      block_to_insert = block_to_insert.commands_else[index_each[i]];
+    } else if (path_relative[i] == "switch") {
+
+    } else {
+      block_to_insert = block_to_insert.commands_block[index_each[i]]
+    }
+  }
+
+  //console.log('command_start_point', command_start_point);
+  //console.log('block_to_insert', block_to_insert);
+
+  // agora tem que alocar o comando na árvore, mas considerar as quatro situações:
+  // (1) se está em um else ou (2) se está em switch ou (3) será um caso padrão ou (4) se será na raiz.
+  
+  if (path_target.length == 0) { // soltou na raiz:
+    window.program_obj.functions[function_index].commands.splice(evento_drag.newIndex, 0, command_in_drag);
+  } else if (is_in_else)  {
+    if (block_to_insert.commands_else) {
+      block_to_insert.commands_else.splice(evento_drag.newIndex, 0, command_in_drag);
+    } else {
+      block_to_insert.commands_else = [];
+      block_to_insert.commands_else.push(command_in_drag);
+    }
+  } else if (is_in_case_switch) {
+
+  } else {
+    // verificar se tem alguma coisa no bloco:
+    if (block_to_insert.commands_block) {
+      block_to_insert.commands_block.splice(evento_drag.newIndex, 0, command_in_drag);
+    } else {
+      block_to_insert.commands_block = [];
+      block_to_insert.commands_block.push(command_in_drag);
+    }
+  }
+
+  window.draging = false;
+  renderAlgorithm();
+  
+
+}
+
+function prepareDragHandler (evt) {
+  window.draging = true;
+
+  var nodes = Array.prototype.slice.call( $('.all_functions').children() );
+  var function_index;
+  var function_obj;
+  $(evt.item).parentsUntil(".all_functions").each(function (index) {
+    if ($(this).hasClass('function_div')) {
+      function_index = nodes.indexOf(this);
+      function_obj = window.program_obj.functions[function_index];
+    }
+  });
+
+  command_in_drag = $(evt.item).data("command");
+
+  //console.log('$(evt.item).parent(): ');
+  //console.log($(evt.item).parent());
+
+  // descobrir qual das quatro situações:
+  if ($(evt.item).parent().hasClass('commands_list_div')) { // está na raiz:
+    if (function_obj.commands.indexOf(command_in_drag) > -1) {
+      function_obj.commands.splice(function_obj.commands.indexOf(command_in_drag), 1);
+    }
+  } else if ($(evt.item).parent().hasClass('commands_else')) { // está no else:
+    if ($(evt.item).parent().data('command').commands_else.indexOf(command_in_drag) > -1) {
+      $(evt.item).parent().data('command').commands_else.splice($(evt.item).parent().data('command').commands_else.indexOf(command_in_drag), 1);
+    }
+  } else if ($(evt.item).parent().hasClass('case_commands_block')) { // está em um switch:
+
+  } else { // caso padrão:
+    if ($(evt.item).parent().data('command').commands_block.indexOf(command_in_drag) > -1) {
+      $(evt.item).parent().data('command').commands_block.splice($(evt.item).parent().data('command').commands_block.indexOf(command_in_drag), 1);
+    }
+  }
+
+}
+
+var command_in_drag;
+
+function addSortableHandler (element, id_function) {
+  var n_group = 'commands_drag_' + id_function;
+  Sortable.create(element, {
+    handle: '.command_drag',
+    ghostClass: 'ghost',
+    animation: 300,
+    group: {name: n_group},
+    onEnd: function (evt) {
+       //updateSequenceLocals(evt.oldIndex, evt.newIndex, function_obj);
+       var itemEl = evt.item;  // dragged HTMLElement
+       evt.to;    // target list
+       evt.from;  // previous list
+       evt.oldIndex;  // element's old index within old parent
+       evt.newIndex;  // element's new index within new parent
+       //console.log('::EVT::');
+       //console.log(evt);
+
+       window.evento_drag = evt;
+
+       try {
+        updateProgramObjDrag();
+       } catch (e) {
+        window.draging = false;
+       }
+    },
+    onStart: function (evt) {
+      //console.log("START::EVT::");
+      //console.log(evt);
+      //console.log("\n\ncommand_in_drag");
+      try {
+        prepareDragHandler(evt);
+      } catch (e) {
+        window.draging = false;
+      }
+    }
+  });
+  element = $(element);
+  element.find(".iftrue").each(function( index ) {
+    addSortableHandler($(this).find(".block_commands")[0], id_function);
+    addSortableHandler($(this).find(".block_commands")[1], id_function);
+  });
+
+  element.find(".repeatNtimes").each(function( index ) {
+    addSortableHandler($(this).find(".block_commands")[0], id_function);
+  });
+
+  element.find(".dowhiletrue").each(function( index ) {
+    addSortableHandler($(this).find(".block_commands")[0], id_function);
+  });
+
+  element.find(".whiletrue").each(function( index ) {
+    addSortableHandler($(this).find(".block_commands")[0], id_function);
+  });
+
+  element.find(".switch").each(function( index ) {
+
+    $(this).find(".case_div").each(function( index ) {
+      addSortableHandler($(this).find(".case_commands_block")[0], id_function);
+    });
+
+  });  
+}
+
 export function initVisualUI () {
   // MUST USE CONST, LET, OR VAR !!!!!!
   const mainDiv = $('#visual-main-div');