From ef39443eb054977115681f11f4ca35898dcf7061 Mon Sep 17 00:00:00 2001 From: Robert Best Date: Sun, 5 Oct 2014 01:03:54 -0400 Subject: [PATCH] Relocated keyboard shortcut code to Metamaps.Listeners.... Then added CTRL+ R , +H, and +D shortcuts for remove, hide and delete --- .../javascripts/src/Metamaps.GlobalUI.js | 24 +- app/assets/javascripts/src/Metamaps.JIT.js | 42 +-- app/assets/javascripts/src/Metamaps.js | 47 +++ db/schema.rb | 268 +++++++++--------- 4 files changed, 187 insertions(+), 194 deletions(-) diff --git a/app/assets/javascripts/src/Metamaps.GlobalUI.js b/app/assets/javascripts/src/Metamaps.GlobalUI.js index db1af137..c37f8da1 100644 --- a/app/assets/javascripts/src/Metamaps.GlobalUI.js +++ b/app/assets/javascripts/src/Metamaps.GlobalUI.js @@ -373,29 +373,7 @@ Metamaps.GlobalUI.Search = { self.close(0, true); } break; - case 65: - case 97: - - if (e.ctrlKey){ - Metamaps.Control.deselectAllNodes(); - Metamaps.Control.deselectAllEdges(); - - e.preventDefault(); - Metamaps.Visualize.mGraph.graph.eachNode(function (n) { - Metamaps.Control.selectNode(n,e); - }); - - Metamaps.Visualize.mGraph.plot(); - } - - break; - case 69: - case 101: - if (e.ctrlKey){ - e.preventDefault(); - Metamaps.JIT.zoomExtents(); - } - break; + default: break; //console.log(e.which); } diff --git a/app/assets/javascripts/src/Metamaps.JIT.js b/app/assets/javascripts/src/Metamaps.JIT.js index bc81bff8..73ffa823 100644 --- a/app/assets/javascripts/src/Metamaps.JIT.js +++ b/app/assets/javascripts/src/Metamaps.JIT.js @@ -1654,6 +1654,11 @@ Metamaps.JIT = { var ratioX = spanX / width; var ratioY = spanY / height; + var cogX = (maxX + minX)/2; + var cogY = (maxY + minY)/2; + + canvas.translate(-1* cogX, -1* cogY); + var newRatio = Math.max(ratioX,ratioY); var scaleMultiplier = 1/newRatio*0.9; @@ -1669,43 +1674,6 @@ Metamaps.JIT = { canvas.scale(scaleMultiplier,scaleMultiplier); } - counter = 0; - - nodes.forEach(function (n) { - var x = n.pos.x, - y = n.pos.y; - - if (counter == 0){ - maxX = x; - minX = x; - maxY = y; - minY = y; - } - - var arrayOfLabelLines = Metamaps.Util.splitLine(n.name, 30).split('\n'), - dim = n.getData('dim'), - ctx = canvas.getCtx(); - - var height = 25 * arrayOfLabelLines.length; - - var index, lineWidths = []; - for (index = 0; index < arrayOfLabelLines.length; ++index) { - lineWidths.push(ctx.measureText(arrayOfLabelLines[index]).width) - } - var width = Math.max.apply(null, lineWidths) + 8; - - maxX = Math.max(x + width /2,maxX); - maxY = Math.max(y + n.getData("height") + 5 + height,maxY); - minX = Math.min(x - width /2,minX); - minY = Math.min(y - dim,minY); - - counter++; - }); - - var cogX = (maxX + minX)/2; - var cogY = (maxY + minY)/2; - - canvas.translate(-1* cogX, -1* cogY); $(document).trigger(Metamaps.JIT.events.zoom, [event]); } else if(nodes.length == 1){ diff --git a/app/assets/javascripts/src/Metamaps.js b/app/assets/javascripts/src/Metamaps.js index 3cd98fb5..d3e7043f 100644 --- a/app/assets/javascripts/src/Metamaps.js +++ b/app/assets/javascripts/src/Metamaps.js @@ -2743,6 +2743,53 @@ Metamaps.Listeners = { case 27: if (Metamaps.Active.Map) Metamaps.JIT.escKeyHandler(); break; + case 65: //if a or A is pressed + case 97: + + if (e.ctrlKey){ + Metamaps.Control.deselectAllNodes(); + Metamaps.Control.deselectAllEdges(); + + e.preventDefault(); + Metamaps.Visualize.mGraph.graph.eachNode(function (n) { + Metamaps.Control.selectNode(n,e); + }); + + Metamaps.Visualize.mGraph.plot(); + } + + break; + case 69: //if e or E is pressed + case 101: + if (e.ctrlKey){ + e.preventDefault(); + Metamaps.JIT.zoomExtents(); + } + break; + case 82: //if r or R is pressed + case 114: + if (e.ctrlKey){ + e.preventDefault(); + Metamaps.Control.removeSelectedNodes(); + console.log('Once function works, selected nodes will be removed'); + } + break; + case 68: //if d or D is pressed + case 100: + if (e.ctrlKey){ + e.preventDefault(); + Metamaps.Control.deleteSelectedNodes(); + console.log('Once function works, selected nodes will be deleted'); + } + break; + case 72: //if h or H is pressed + case 104: + if (e.ctrlKey){ + e.preventDefault(); + Metamaps.Control.hideSelectedNodes(); + console.log('Once function works, selected nodes will be hidden'); + } + break; default: break; //alert(e.which); } diff --git a/db/schema.rb b/db/schema.rb index 113dba8a..606735d7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,134 +1,134 @@ -# encoding: UTF-8 -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). -# -# It's strongly recommended to check this file into your version control system. - -ActiveRecord::Schema.define(:version => 20140930013020) do - - create_table "in_metacode_sets", :force => true do |t| - t.integer "metacode_id" - t.integer "metacode_set_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - add_index "in_metacode_sets", ["metacode_id"], :name => "index_in_metacode_sets_on_metacode_id" - add_index "in_metacode_sets", ["metacode_set_id"], :name => "index_in_metacode_sets_on_metacode_set_id" - - create_table "mappings", :force => true do |t| - t.text "category" - t.integer "xloc" - t.integer "yloc" - t.integer "topic_id" - t.integer "synapse_id" - t.integer "map_id" - t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "maps", :force => true do |t| - t.text "name" - t.boolean "arranged" - t.text "desc" - t.text "permission" - t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.boolean "featured" - t.string "screenshot_file_name" - t.string "screenshot_content_type" - t.integer "screenshot_file_size" - t.datetime "screenshot_updated_at" - end - - create_table "metacode_sets", :force => true do |t| - t.string "name" - t.text "desc" - t.integer "user_id" - t.boolean "mapperContributed" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - add_index "metacode_sets", ["user_id"], :name => "index_metacode_sets_on_user_id" - - create_table "metacodes", :force => true do |t| - t.text "name" - t.string "icon" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.string "color" - end - - create_table "synapses", :force => true do |t| - t.text "desc" - t.text "category" - t.text "weight" - t.text "permission" - t.integer "node1_id" - t.integer "node2_id" - t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "topics", :force => true do |t| - t.text "name" - t.text "desc" - t.text "link" - t.text "permission" - t.integer "user_id" - t.integer "metacode_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.string "image_file_name" - t.string "image_content_type" - t.integer "image_file_size" - t.datetime "image_updated_at" - t.string "audio_file_name" - t.string "audio_content_type" - t.integer "audio_file_size" - t.datetime "audio_updated_at" - end - - create_table "users", :force => true do |t| - t.string "name" - t.string "email" - t.text "settings" - t.string "code", :limit => 8 - t.string "joinedwithcode", :limit => 8 - t.string "crypted_password" - t.string "password_salt" - t.string "persistence_token" - t.string "perishable_token" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.string "encrypted_password", :limit => 128, :default => "" - t.string "remember_token" - t.datetime "remember_created_at" - t.string "reset_password_token" - t.datetime "last_sign_in_at" - t.string "last_sign_in_ip" - t.integer "sign_in_count", :default => 0 - t.datetime "current_sign_in_at" - t.string "current_sign_in_ip" - t.datetime "reset_password_sent_at" - t.boolean "admin" - t.string "image_file_name" - t.string "image_content_type" - t.integer "image_file_size" - t.datetime "image_updated_at" - end - - add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true - -end +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended to check this file into your version control system. + +ActiveRecord::Schema.define(:version => 20140930013020) do + + create_table "in_metacode_sets", :force => true do |t| + t.integer "metacode_id" + t.integer "metacode_set_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "in_metacode_sets", ["metacode_id"], :name => "index_in_metacode_sets_on_metacode_id" + add_index "in_metacode_sets", ["metacode_set_id"], :name => "index_in_metacode_sets_on_metacode_set_id" + + create_table "mappings", :force => true do |t| + t.text "category" + t.integer "xloc" + t.integer "yloc" + t.integer "topic_id" + t.integer "synapse_id" + t.integer "map_id" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "maps", :force => true do |t| + t.text "name" + t.boolean "arranged" + t.text "desc" + t.text "permission" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.boolean "featured" + t.string "screenshot_file_name" + t.string "screenshot_content_type" + t.integer "screenshot_file_size" + t.datetime "screenshot_updated_at" + end + + create_table "metacode_sets", :force => true do |t| + t.string "name" + t.text "desc" + t.integer "user_id" + t.boolean "mapperContributed" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "metacode_sets", ["user_id"], :name => "index_metacode_sets_on_user_id" + + create_table "metacodes", :force => true do |t| + t.text "name" + t.string "icon" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "color" + end + + create_table "synapses", :force => true do |t| + t.text "desc" + t.text "category" + t.text "weight" + t.text "permission" + t.integer "node1_id" + t.integer "node2_id" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "topics", :force => true do |t| + t.text "name" + t.text "desc" + t.text "link" + t.text "permission" + t.integer "user_id" + t.integer "metacode_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "image_file_name" + t.string "image_content_type" + t.integer "image_file_size" + t.datetime "image_updated_at" + t.string "audio_file_name" + t.string "audio_content_type" + t.integer "audio_file_size" + t.datetime "audio_updated_at" + end + + create_table "users", :force => true do |t| + t.string "name" + t.string "email" + t.text "settings" + t.string "code", :limit => 8 + t.string "joinedwithcode", :limit => 8 + t.string "crypted_password" + t.string "password_salt" + t.string "persistence_token" + t.string "perishable_token" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "encrypted_password", :limit => 128, :default => "" + t.string "remember_token" + t.datetime "remember_created_at" + t.string "reset_password_token" + t.datetime "last_sign_in_at" + t.string "last_sign_in_ip" + t.integer "sign_in_count", :default => 0 + t.datetime "current_sign_in_at" + t.string "current_sign_in_ip" + t.datetime "reset_password_sent_at" + t.boolean "admin" + t.string "image_file_name" + t.string "image_content_type" + t.integer "image_file_size" + t.datetime "image_updated_at" + end + + add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true + +end