From 6ac05fa2c66f856e5ac8d4161d7c314107334a02 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 21 Mar 2013 21:29:09 -0400 Subject: [PATCH 1/9] allow Enter to keep all selected nodes in commons --- .../Jit/graphsettings-event-handlers.js | 14 ++++++++++++++ app/assets/javascripts/application.js | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/app/assets/javascripts/Jit/graphsettings-event-handlers.js b/app/assets/javascripts/Jit/graphsettings-event-handlers.js index 52f12e20..759b187c 100644 --- a/app/assets/javascripts/Jit/graphsettings-event-handlers.js +++ b/app/assets/javascripts/Jit/graphsettings-event-handlers.js @@ -29,6 +29,20 @@ function selectEdgeOnClickHandler(adj, e) { }//selectEdgeOnClickHandler function nodeDoubleClickHandler(node, e) { + keepFromCommons(node); +} + +function enterKeyHandler() { + var selectedNodesCopy = MetamapsModel.selectedNodes.slice(0); + var len = selectedNodesCopy.length; + for (var i = 0; i < len; i += 1) { + n = selectedNodesCopy[i]; + keepFromCommons(n); + }//for + Mconsole.plot(); +}//enterKeyHandler + +function keepFromCommons(node) { if (userid == null) { return; } diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 012cbcc2..1f5ab3e2 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -286,3 +286,9 @@ function MconsoleReset() { Mconsole.canvas.scale((1/mX),(1/mY)); } + +$('*').keypress(function(e) { + if (e.which == 13) { + enterKeyHandler(); + } +}); From e5095093ec9acc677c954d88367897f88103696a Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 21 Mar 2013 21:33:42 -0400 Subject: [PATCH 2/9] added Keep Selected button to console, map view, topic view --- app/views/main/console.html.erb | 1 + app/views/maps/show.html.erb | 1 + app/views/topics/show.html.erb | 1 + 3 files changed, 3 insertions(+) diff --git a/app/views/main/console.html.erb b/app/views/main/console.html.erb index b992b2fd..0e744d83 100644 --- a/app/views/main/console.html.erb +++ b/app/views/main/console.html.erb @@ -7,6 +7,7 @@ #%>
+ <% if authenticated? %> diff --git a/app/views/maps/show.html.erb b/app/views/maps/show.html.erb index e199d5eb..00645ef4 100644 --- a/app/views/maps/show.html.erb +++ b/app/views/maps/show.html.erb @@ -9,6 +9,7 @@ <% end %> + <% if authenticated? %> <% if (@map.permission == "commons" && authenticated?) || @map.user == user %> diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb index c48bcc46..93806d8d 100644 --- a/app/views/topics/show.html.erb +++ b/app/views/topics/show.html.erb @@ -15,6 +15,7 @@ #%>
+ <% if authenticated? %> <% end %> From 0628c88f80543b02b82786f1d62b0eb8c4a2e4cd Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 21 Mar 2013 21:33:59 -0400 Subject: [PATCH 3/9] README updates --- README.rdoc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.rdoc b/README.rdoc index 9ed21fa0..9f2c9edd 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,4 +1,4 @@ -How to code in Metamaps +==How to code in Metamaps Here are the important folders/files: @@ -17,7 +17,7 @@ app/assets/views/*.js.erb: Javascript that is called in response to, e.g., editi Setting up the database: 1) Copy database.yml.default to database.yml - - Then you'll need to figure out how to configure it to work with Postgresql (which you need to install - try Herokuapp's exe or app) + - Then you'll need to figure out how to configure it to work with Postgresql (which you need to install - try Herokuapp's exe or app) 2) In a terminal: $ rake db:create $ rake db:migrate @@ -25,8 +25,9 @@ Setting up the database: Running the server: -$rails s #runs the server -$rails c #gives you an interactive console + $rails s #runs the server + $ + $rails c #gives you an interactive console ==Installing on Ubuntu From 45f856fc054eec4c0629a444da3fce143f9fcf73 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 21 Mar 2013 21:58:32 -0400 Subject: [PATCH 4/9] fix #170 --- app/assets/javascripts/Jit/graphsettings-event-handlers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/Jit/graphsettings-event-handlers.js b/app/assets/javascripts/Jit/graphsettings-event-handlers.js index 30622f35..b5031b42 100644 --- a/app/assets/javascripts/Jit/graphsettings-event-handlers.js +++ b/app/assets/javascripts/Jit/graphsettings-event-handlers.js @@ -193,8 +193,8 @@ function onDragMoveTopicHandler(node, eventInfo, e) { var yOffset = new Array(); for (var i = 0; i < len; i += 1) { n = MetamapsModel.selectedNodes[i]; - xOffset[i] = n.getData('xloc') - node.getData('xloc'); - yOffset[i] = n.getData('yloc') - node.getData('yloc'); + xOffset[i] = n.pos.x - node.pos.x; + yOffset[i] = n.pos.y - node.pos.y; }//for for (var i = 0; i < len; i += 1) { From 600e5814f082680401230655587c44a8f79f7875 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 21 Mar 2013 22:18:20 -0400 Subject: [PATCH 5/9] fix #172, unless the problem applies to topics as well which I haven't investigated further --- .../Jit/select-edit-delete-nodes-and-edges.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js b/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js index fa5ee66c..987f5c77 100644 --- a/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js +++ b/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js @@ -75,6 +75,16 @@ function add_perms_form(edge) { $('#edit_synapse .click-to-edit').attr('title', 'Click to Edit'); $('#edit_synapse .click-to-edit').append(best_in_place_perms(edge)); $('#edit_synapse .editSettings').append('
'); + + $('#edit_synapse').find('.best_in_place_permission').bind("ajax:success", function() { + var permission = $(this).html(); + switch(permission) { + case 'commons': $('#edit_synapse .mapPerm').html('co'); break; + case 'public': $('#edit_synapse .mapPerm').html('pu'); break; + case 'private': $('#edit_synapse .mapPerm').html('pr'); break; + }//switch + }); + $('#edit_synapse .permActivator').bind('mouseover', function() { clearTimeout(MetamapsModel.edgePermTimer2); that = this; From 24269a10b921e94a828bd21ce63557ea397c70a1 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Fri, 22 Mar 2013 02:37:56 -0400 Subject: [PATCH 6/9] developed an initial attempt at a box to select feature. SO NICE. you just hold down shift and mouse over the ones you want. fixed an important bug that was causing deselecting to go wacky --- Gemfile | 2 +- Gemfile.lock | 2 + Gemfile~ | 4 +- .../javascripts/Jit/graphsettings-model.js | 4 ++ app/assets/javascripts/Jit/graphsettings.js | 61 ++++++++++++++++++- .../Jit/select-edit-delete-nodes-and-edges.js | 50 +++++++++------ app/views/maps/show.html.erb | 2 +- 7 files changed, 101 insertions(+), 24 deletions(-) diff --git a/Gemfile b/Gemfile index cb1ac1c2..6b2f6e48 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ gem 'formtastic' gem 'json' gem 'rails3-jquery-autocomplete' gem 'best_in_place' -gem 'therubyracer' #optional +#gem 'therubyracer' #optional gem 'rb-readline' # Gems used only for assets and not required diff --git a/Gemfile.lock b/Gemfile.lock index cc33f0b6..a85dcd9a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -94,6 +94,7 @@ GEM rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) rake (10.0.3) + rb-readline (0.4.1) rdoc (3.12) json (~> 1.4) sass (3.2.1) @@ -133,5 +134,6 @@ DEPENDENCIES pg rails (= 3.2.11) rails3-jquery-autocomplete + rb-readline sass-rails (~> 3.2.3) uglifier (>= 1.0.3) diff --git a/Gemfile~ b/Gemfile~ index 1f7c3bd8..cb1ac1c2 100644 --- a/Gemfile~ +++ b/Gemfile~ @@ -13,8 +13,8 @@ gem 'formtastic' gem 'json' gem 'rails3-jquery-autocomplete' gem 'best_in_place' -#gem 'therubyracer' #optional -#gem 'rb-readline' +gem 'therubyracer' #optional +gem 'rb-readline' # Gems used only for assets and not required # in production environments by default. diff --git a/app/assets/javascripts/Jit/graphsettings-model.js b/app/assets/javascripts/Jit/graphsettings-model.js index dbfecf4f..e5372c9e 100644 --- a/app/assets/javascripts/Jit/graphsettings-model.js +++ b/app/assets/javascripts/Jit/graphsettings-model.js @@ -20,6 +20,10 @@ MetamapsModel.widthOfLabel = null; //is the mouse hovering over an edge? which one? MetamapsModel.edgeHoveringOver = false; +//coordinates of shift click for using box select +MetamapsModel.boxStartCoordinates = false; +MetamapsModel.boxEndCoordinates = false; + //double clicking of nodes or canvas MetamapsModel.lastNodeClick = 0; MetamapsModel.lastCanvasClick = 0; diff --git a/app/assets/javascripts/Jit/graphsettings.js b/app/assets/javascripts/Jit/graphsettings.js index b9002d79..d7a4b2d1 100644 --- a/app/assets/javascripts/Jit/graphsettings.js +++ b/app/assets/javascripts/Jit/graphsettings.js @@ -105,7 +105,11 @@ function graphSettings(type, embed) { if (e.target.id != "infovis-canvas") return false; //topic and synapse editing cards - if (!Mconsole.events.moved) hideCards(); + if (!Mconsole.events.moved && !node) { + hideCards(); + deselectAllNodes(); + deselectAllEdges(); + } //clicking on a node, or clicking on blank part of canvas? if (node.nodeFrom) { @@ -427,10 +431,65 @@ var nodeSettings = { } } +function drawSelectBox(eventInfo, e) { + var ctx=Mconsole.canvas.getCtx(); + + var startX = MetamapsModel.boxStartCoordinates.x, + startY = MetamapsModel.boxStartCoordinates.y, + currX = eventInfo.getPos().x, + currY = eventInfo.getPos().y; + + Mconsole.plot(); + ctx.moveTo(startX,startY); + ctx.lineTo(startX,currY); + ctx.stroke(); + ctx.lineTo(currX,currY); + ctx.stroke(); + ctx.lineTo(currX,startY); + ctx.stroke(); + ctx.lineTo(startX,startY); + ctx.stroke(); +} + +function selectNodesWithBox() { + + var sX = MetamapsModel.boxStartCoordinates.x, + sY = MetamapsModel.boxStartCoordinates.y, + eX = MetamapsModel.boxEndCoordinates.x, + eY = MetamapsModel.boxEndCoordinates.y; + + + Mconsole.graph.eachNode(function (n) { + var x = n.pos.x, y = n.pos.y; + + if ((sX < x && x < eX && sY < y && y < eY) || (sX > x && x > eX && sY > y && y > eY) || (sX > x && x > eX && sY < y && y < eY) || (sX < x && x < eX && sY > y && y > eY)) { + selectNode(n); + } + }); + + MetamapsModel.boxStartCoordinates = false; + MetamapsModel.boxEndCoordinates = false; + Mconsole.plot(); +} function onMouseMoveHandler(node, eventInfo, e) { if (Mconsole.busy) return; + + if (!MetamapsModel.boxStartCoordinates && e.shiftKey) { + MetamapsModel.boxStartCoordinates = eventInfo.getPos(); + return; + } + if (MetamapsModel.boxStartCoordinates && e.shiftKey) { + drawSelectBox(eventInfo,e); + return; + } + if (MetamapsModel.boxStartCoordinates && !e.shiftKey) { + MetamapsModel.boxEndCoordinates = eventInfo.getPos(); + Mconsole.plot(); + selectNodesWithBox(); + return; + } var node = eventInfo.getNode(); var edge = eventInfo.getEdge(); diff --git a/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js b/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js index 987f5c77..c328839d 100644 --- a/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js +++ b/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js @@ -230,12 +230,21 @@ function best_in_place_perms(edge) { }//best_in_place_perms function deselectAllEdges() { - for (var i = 0; i < MetamapsModel.selectedEdges.length; i += 1) { + var l = MetamapsModel.selectedEdges.length; + for (var i = l-1; i >= 0; i -= 1) { var edge = MetamapsModel.selectedEdges[i]; deselectEdge(edge); } } +function deselectAllNodes() { + var l = MetamapsModel.selectedNodes.length; + for (var i = l-1; i >= 0; i -= 1) { + var node = MetamapsModel.selectedNodes[i]; + deselectNode(node); + } +} + // this is for hiding one topic from your canvas function removeEdge(edge) { var id = edge.getData("id"); @@ -261,7 +270,8 @@ function hideEdge(edge) { } function hideSelectedEdges() { - for (var i = 0; i < MetamapsModel.selectedEdges.length; i += 1) { + var l = MetamapsModel.selectedEdges.length; + for (var i = l-1; i >= 0; i -= 1) { var edge = MetamapsModel.selectedEdges[i]; hideEdge(edge); } @@ -269,7 +279,8 @@ function hideSelectedEdges() { } function removeSelectedEdges() { - for (var i = 0; i < MetamapsModel.selectedEdges.length; i += 1) { + var l = MetamapsModel.selectedEdges.length; + for (var i = l-1; i >= 0; i -= 1) { if (mapid != null) { var edge = MetamapsModel.selectedEdges[i]; var id = edge.getData("id"); @@ -285,7 +296,8 @@ function removeSelectedEdges() { } function deleteSelectedEdges() { - for (var i = 0; i < MetamapsModel.selectedEdges.length; i += 1) { + var l = MetamapsModel.selectedEdges.length; + for (var i = l-1; i >= 0; i -= 1) { var edge = MetamapsModel.selectedEdges[i]; var id = edge.getData("id"); $.ajax({ @@ -400,11 +412,11 @@ function hideNode(nodeid) { } function hideSelectedNodes() { - Mconsole.graph.eachNode( function (n) { - if (n.getData('whiteCircle') == true) { - hideNode(n.id); - } - }); + var l = MetamapsModel.selectedNodes.length; + for (var i = l-1; i >= 0; i -= 1) { + var node = MetamapsModel.selectedNodes[i]; + hideNode(node.id); + } } function removeNode(nodeid) { @@ -419,11 +431,11 @@ function removeNode(nodeid) { } function removeSelectedNodes() { if (mapperm) { - Mconsole.graph.eachNode( function (n) { - if (n.getData('whiteCircle') == true) { - removeNode(n.id); - } - }); + var l = MetamapsModel.selectedNodes.length; + for (var i = l-1; i >= 0; i -= 1) { + var node = MetamapsModel.selectedNodes[i]; + removeNode(node.id); + } } } @@ -438,9 +450,9 @@ function deleteNode(nodeid) { }); } function deleteSelectedNodes() { - Mconsole.graph.eachNode( function (n) { - if (n.getData('whiteCircle') == true) { - deleteNode(n.id); - } - }); + var l = MetamapsModel.selectedNodes.length; + for (var i = l-1; i >= 0; i -= 1) { + var node = MetamapsModel.selectedNodes[i]; + deleteNode(node.id); + } } diff --git a/app/views/maps/show.html.erb b/app/views/maps/show.html.erb index c83538b4..1f40a4ff 100644 --- a/app/views/maps/show.html.erb +++ b/app/views/maps/show.html.erb @@ -9,7 +9,7 @@ <% end %> - + <% if authenticated? %> <% if (@map.permission == "commons" && authenticated?) || @map.user == user %> From 3f0e94297b2b3e2f923c72c046618e2d6c40bc3a Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Fri, 22 Mar 2013 02:44:22 -0400 Subject: [PATCH 7/9] reset therubyracer for the wonderful Devin --- Gemfile | 2 +- Gemfile~ | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 6b2f6e48..cb1ac1c2 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ gem 'formtastic' gem 'json' gem 'rails3-jquery-autocomplete' gem 'best_in_place' -#gem 'therubyracer' #optional +gem 'therubyracer' #optional gem 'rb-readline' # Gems used only for assets and not required diff --git a/Gemfile~ b/Gemfile~ index cb1ac1c2..6b2f6e48 100644 --- a/Gemfile~ +++ b/Gemfile~ @@ -13,7 +13,7 @@ gem 'formtastic' gem 'json' gem 'rails3-jquery-autocomplete' gem 'best_in_place' -gem 'therubyracer' #optional +#gem 'therubyracer' #optional gem 'rb-readline' # Gems used only for assets and not required From 1f096cf5a5caab4b4b1c86c1b5eb986956aefaea Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 28 Mar 2013 18:56:34 -0400 Subject: [PATCH 8/9] esc deselects all nodes/synapses --- app/assets/javascripts/Jit/graphsettings-event-handlers.js | 5 +++++ app/assets/javascripts/application.js | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/Jit/graphsettings-event-handlers.js b/app/assets/javascripts/Jit/graphsettings-event-handlers.js index b5031b42..60e57a16 100644 --- a/app/assets/javascripts/Jit/graphsettings-event-handlers.js +++ b/app/assets/javascripts/Jit/graphsettings-event-handlers.js @@ -42,6 +42,11 @@ function enterKeyHandler() { Mconsole.plot(); }//enterKeyHandler +function escKeyHandler() { + deselectAllEdges(); + deselectAllNodes(); +}//escKeyHandler + function keepFromCommons(node) { if (userid == null) { return; diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 70607ce1..47bba8d2 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -302,7 +302,9 @@ function MconsoleReset() { } $('*').keypress(function(e) { - if (e.which == 13) { - enterKeyHandler(); + switch(e.which) { + case 13: enterKeyHandler(); break; + case 27: escKeyHandler(); break; + default: //alert(e.which); break; } }); From 5f86d879ac370900a7abca562ba80ce4aa83c830 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 28 Mar 2013 21:09:07 -0400 Subject: [PATCH 9/9] allow dragging on topic view --- .../Jit/graphsettings-event-handlers.js | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/Jit/graphsettings-event-handlers.js b/app/assets/javascripts/Jit/graphsettings-event-handlers.js index b5031b42..4dfcb33f 100644 --- a/app/assets/javascripts/Jit/graphsettings-event-handlers.js +++ b/app/assets/javascripts/Jit/graphsettings-event-handlers.js @@ -1,5 +1,4 @@ function selectEdgeOnClickHandler(adj, e) { - if (Mconsole.busy) return; //editing overrides everything else @@ -42,6 +41,10 @@ function enterKeyHandler() { Mconsole.plot(); }//enterKeyHandler +/* + * Make a node "in the commons" (with a green circle) lose its + * green circle so it stays on the console/map/... + */ function keepFromCommons(node) { if (userid == null) { return; @@ -72,7 +75,6 @@ function keepFromCommons(node) { node.setData('mappingid', data.id); }); } - }//doubleClickNodeHandler /* @@ -181,7 +183,11 @@ function onDragMoveTopicHandler(node, eventInfo, e) { if ( e.touches || (e.button == 0 && !e.altKey && (e.buttons == 0 || e.buttons == 1 || e.buttons == undefined))) { //if the node dragged isn't already selected, select it var whatToDo = handleSelectionBeforeDragging(node, e); - if (whatToDo == 'only-drag-this-one') { + if (node.pos.rho || node.pos.rho === 0) { + var rho = Math.sqrt(pos.x * pos.x + pos.y * pos.y); + var theta = Math.atan2(pos.y, pos.x); + node.pos.setp(theta, rho); + } else if (whatToDo == 'only-drag-this-one') { node.pos.setc(pos.x, pos.y); node.setData('xloc', pos.x); node.setData('yloc', pos.y); @@ -192,16 +198,18 @@ function onDragMoveTopicHandler(node, eventInfo, e) { var xOffset = new Array(); var yOffset = new Array(); for (var i = 0; i < len; i += 1) { - n = MetamapsModel.selectedNodes[i]; - xOffset[i] = n.pos.x - node.pos.x; - yOffset[i] = n.pos.y - node.pos.y; + var n = MetamapsModel.selectedNodes[i]; + xOffset[i] = n.pos.x - node.pos.x; + yOffset[i] = n.pos.y - node.pos.y; }//for for (var i = 0; i < len; i += 1) { - n = MetamapsModel.selectedNodes[i]; - n.pos.setc(pos.x + xOffset[i], pos.y + yOffset[i]); - n.setData('xloc', pos.x + xOffset[i]); - n.setData('yloc', pos.y + yOffset[i]); + var n = MetamapsModel.selectedNodes[i]; + var x = pos.x + xOffset[i]; + var y = pos.y + yOffset[i]; + n.pos.setc(x, y); + n.setData('xloc', x); + n.setData('yloc', y); }//for }//if