From 24280e82fa0e558f2baa74e87a958ff25f044378 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Wed, 25 Jun 2014 10:24:24 -0400 Subject: [PATCH 1/4] removed alert('failure') using alerts (especially with no information beyond just 'it failed') is terrible user experience --- app/assets/javascripts/application.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index f07ea1d8..05f0f857 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -128,7 +128,7 @@ function fetchRelatives(node) { } }, error: function () { - alert('failure'); + console.log('failed to recenter'); } }); } @@ -392,4 +392,4 @@ function cancelMapCreate(id) { form.find('.mapCommonsIcon').addClass('selected'); return false; -} \ No newline at end of file +} From 3018186c3f16df38990d81b264c3b57f59d93b9d Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Wed, 25 Jun 2014 10:26:35 -0400 Subject: [PATCH 2/4] removed other alerts --- app/assets/javascripts/application.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 05f0f857..93cc4596 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -160,7 +160,7 @@ function updateMetacode(node, metacode) { }, 500); }, error: function () { - alert('failed to update metacode'); + console.log('failed to update metacode'); } }); } @@ -182,7 +182,7 @@ function updateTopicPermission(node, permission) { node.setData("permission", permission); }, error: function () { - alert('failed to update permission'); + console.log('failed to update permission'); } }); } @@ -204,7 +204,7 @@ function updateSynapsePermission(edge, permission) { edge.setData("permission", permission); }, error: function () { - alert('failed to update permission'); + console.log('failed to update permission'); } }); } @@ -225,7 +225,7 @@ function updateMapPermission(mapid, permission) { $('.mapPermission .permissionSelect').remove(); }, error: function () { - alert('failed to update permission'); + console.log('failed to update permission'); } }); } From f75c2c1f8a90287cf93e4bbc4903e86ed31c2bfa Mon Sep 17 00:00:00 2001 From: Robert Best Date: Wed, 6 Aug 2014 04:22:06 -0400 Subject: [PATCH 3/4] Added Recenter map, zoom in, zoom out, Zoom to extents and buttons for each. Also, renamed selection function to just SelectWithBox() --- .../javascripts/metamaps/Metamaps.JIT.js | 100 ++++++- app/assets/javascripts/metamaps/Metamaps.js | 2 +- app/assets/stylesheets/application.css | 41 +++ app/views/maps/show.html.erb | 5 + db/schema.rb | 258 +++++++++--------- 5 files changed, 271 insertions(+), 135 deletions(-) diff --git a/app/assets/javascripts/metamaps/Metamaps.JIT.js b/app/assets/javascripts/metamaps/Metamaps.JIT.js index 8c6cb11e..41ff23ba 100644 --- a/app/assets/javascripts/metamaps/Metamaps.JIT.js +++ b/app/assets/javascripts/metamaps/Metamaps.JIT.js @@ -8,6 +8,10 @@ Metamaps.JIT = { var self = Metamaps.JIT; self.prepareVizData(); + $(".zoomIn").click(self.zoomIn); + $(".zoomOut").click(self.zoomOut); + $(".centerMap").click(self.centerMap); + $(".zoomExtents").click(self.zoomExtents); }, /** * convert our topic JSON into something JIT can use @@ -307,7 +311,7 @@ Metamaps.JIT = { if (Metamaps.Mouse.boxStartCoordinates) { Metamaps.Visualize.mGraph.busy = false; Metamaps.Mouse.boxEndCoordinates = eventInfo.getPos(); - Metamaps.JIT.selectNodesWithBox(e); + Metamaps.JIT.selectWithBox(e); return; } @@ -331,7 +335,7 @@ Metamaps.JIT = { if (Metamaps.Mouse.boxStartCoordinates) { Metamaps.Visualize.mGraph.busy = false; Metamaps.Mouse.boxEndCoordinates = eventInfo.getPos(); - Metamaps.JIT.selectNodesWithBox(e); + Metamaps.JIT.selectWithBox(e); return; } @@ -897,7 +901,7 @@ Metamaps.JIT = { } return 'nothing'; //case 4? }, // handleSelectionBeforeDragging - selectNodesWithBox: function (e) { + selectWithBox: function (e) { var sX = Metamaps.Mouse.boxStartCoordinates.x, sY = Metamaps.Mouse.boxStartCoordinates.y, @@ -1025,7 +1029,7 @@ Metamaps.JIT = { Metamaps.Mouse.boxStartCoordinates = false; Metamaps.Mouse.boxEndCoordinates = false; Metamaps.Visualize.mGraph.plot(); - }, // selectNodesWithBox + }, // selectWithBox drawSelectBox: function (eventInfo, e) { var ctx = Metamaps.Visualize.mGraph.canvas.getCtx(); @@ -1425,5 +1429,91 @@ Metamaps.JIT = { y: posChild.y }, 13, inv, canvas, 0.3); } - } //renderEdgeArrows + }, //renderEdgeArrows + zoomIn: function () { + Metamaps.Visualize.mGraph.canvas.scale(1.25,1.25); + }, + zoomOut: function () { + Metamaps.Visualize.mGraph.canvas.scale(0.8,0.8); + }, + centerMap: function () { + var canvas = Metamaps.Visualize.mGraph.canvas; + var offsetScale = canvas.scaleOffsetX; + + canvas.scale(1/offsetScale,1/offsetScale); + + var offsetX = canvas.translateOffsetX; + var offsetY = canvas.translateOffsetY; + + canvas.translate(-1*offsetX,-1*offsetY); + }, + zoomExtents: function () { + Metamaps.JIT.centerMap(); + var height = $(document).height(), + width = $(document).width(), + maxX, minX, maxY, minY, counter = 0; + + var nodes = Metamaps.Visualize.mGraph.graph; + + + if(Object.keys(nodes).length >1){ + + + nodes.eachNode(function (n) { + var x = n.pos.x, + y = n.pos.y; + + if (counter == 0){ + maxX = x; + minX = x; + maxY = y; + minY = y; + } + + maxX = Math.max(x,maxX); + maxY = Math.max(y,maxY); + minX = Math.min(x,minX); + minY = Math.min(y,minY); + + counter++; + }); + + var spanX = maxX - minX; + var spanY = maxY - minY; + var ratioX = spanX / width; + var ratioY = spanY / height; + + var newRatio = Math.max(ratioX,ratioY); + + var canvas = Metamaps.Visualize.mGraph.canvas; + + canvas.scale(1/newRatio*0.9,1/newRatio*0.9); + + counter = 0; + + nodes.eachNode(function (n) { + var x = n.pos.x, + y = n.pos.y; + + if (counter == 0){ + maxX = x; + minX = x; + maxY = y; + minY = y; + } + + maxX = Math.max(x,maxX); + maxY = Math.max(y,maxY); + minX = Math.min(x,minX); + minY = Math.min(y,minY); + + counter++; + }); + + var cogX = (maxX + minX)/2; + var cogY = (maxY + minY)/2; + + canvas.translate(-1* cogX, -1* cogY); + } + } }; \ No newline at end of file diff --git a/app/assets/javascripts/metamaps/Metamaps.js b/app/assets/javascripts/metamaps/Metamaps.js index 61dd77f5..820c6395 100644 --- a/app/assets/javascripts/metamaps/Metamaps.js +++ b/app/assets/javascripts/metamaps/Metamaps.js @@ -2060,7 +2060,7 @@ Metamaps.Filter = { var addedSynapses = []; Metamaps.Synapses.each(function(synapse) { - if (newSynapsesList.indexOf(synapse.get('desc')) === -1) { + if (synapse.get('desc') && newSynapsesList.indexOf(synapse.get('desc')) === -1) { newSynapsesList.push(synapse.get('desc').toString()); } }); diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 9d17ce88..d7b824bb 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -791,6 +791,47 @@ li.accountInvite span { width: 35px; height: 35px; } + +.zoomIn { + position: absolute; + bottom: 100px; + right: 20px; + z-index: 200; + width: 35px; + height: 35px; + background: blue; +} + +.zoomOut { + position: absolute; + bottom: 60px; + right: 20px; + z-index: 200; + width: 35px; + height: 35px; + background: blue; +} + +.centerMap { + position: absolute; + bottom: 140px; + right: 20px; + z-index: 200; + width: 35px; + height: 35px; + background: blue; +} + +.zoomExtents { + position: absolute; + bottom: 180px; + right: 20px; + z-index: 200; + width: 35px; + height: 35px; + background: blue; +} + .sidebarFilter.loggedout { right: 35px; } diff --git a/app/views/maps/show.html.erb b/app/views/maps/show.html.erb index 19924710..77cb06f9 100644 --- a/app/views/maps/show.html.erb +++ b/app/views/maps/show.html.erb @@ -42,6 +42,11 @@ +
+
+
-
+
C
+
E
+
diff --git a/db/schema.rb b/db/schema.rb index ec86b421..c3fce2b2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,129 +1,129 @@ -# 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 => 20140707161810) 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" - 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 - 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 => 20140707161810) 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" + 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 + 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 From e7a445423dd6dec34f398be4017389422e4976de Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Wed, 6 Aug 2014 10:09:01 -0400 Subject: [PATCH 4/4] work in progress on explore maps pages --- .../javascripts/metamaps/Metamaps.GlobalUI.js | 8 +++-- .../javascripts/metamaps/Metamaps.Router.js | 25 +++++++++---- .../javascripts/metamaps/Metamaps.Views.js | 26 ++++++++++++++ app/assets/javascripts/metamaps/metamaps.js | 6 ++-- app/controllers/maps_controller.rb | 8 ++--- app/views/layouts/_templates.html.erb | 35 ++++++++++++++++++- app/views/layouts/application.html.erb | 2 +- app/views/main/home.html.erb | 2 +- app/views/maps/index.html.erb | 8 ++--- config/routes.rb | 6 ++-- 10 files changed, 100 insertions(+), 26 deletions(-) create mode 100644 app/assets/javascripts/metamaps/Metamaps.Views.js diff --git a/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js b/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js index 3e517193..33a1d5e0 100644 --- a/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js +++ b/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js @@ -82,9 +82,13 @@ Metamaps.GlobalUI = { $('.alert.metamaps').delay(10000).fadeOut('fast'); // initialize global backbone models and collections - Metamaps.Active.Mapper = new Metamaps.Backbone.Mapper(Metamaps.Active.Mapper); + if (Metamaps.Active.Mapper) Metamaps.Active.Mapper = new Metamaps.Backbone.Mapper(Metamaps.Active.Mapper); Metamaps.Mappers = new Metamaps.Backbone.MapperCollection([Metamaps.Active.Mapper]); - Metamaps.Maps = new Metamaps.Backbone.MapsCollection(); + Metamaps.Maps = {}; + Metamps.Maps.Mine = new Metamaps.Backbone.MapsCollection(); + Metamps.Maps.Featured = new Metamaps.Backbone.MapsCollection(); + Metamps.Maps.Active = new Metamaps.Backbone.MapsCollection(); + Metamps.Maps.New = new Metamaps.Backbone.MapsCollection(); }, openLightbox: function (which) { var self = Metamaps.GlobalUI; diff --git a/app/assets/javascripts/metamaps/Metamaps.Router.js b/app/assets/javascripts/metamaps/Metamaps.Router.js index 7ecb49b3..f1dfe1ec 100644 --- a/app/assets/javascripts/metamaps/Metamaps.Router.js +++ b/app/assets/javascripts/metamaps/Metamaps.Router.js @@ -5,18 +5,29 @@ "explore/:section": "explore", // #explore/active "maps/:id": "maps" // #maps/7 }, + home: function () { + + document.title = 'My Maps | Metamaps'; + $('#cards').show(); + }, explore: function (section) { - console.log(section); + + var capitalize = section.charAt(0).toUpperCase() + section.slice(1); + + document.title = 'Explore ' + capitalize + ' Maps | Metamaps'; + //$('#cards').hide(); }, maps: function (id) { - console.log(id); + + document.title = 'Map ' + id + ' | Metamaps'; + $('#cards').hide(); } }); Metamaps.Router = new Router(); Metamaps.Router.init = function () { - /*Backbone.history.start({ + Backbone.history.start({ pushState: true, - root: '' + root: '/' }); console.log('router started'); $(document).on("click", "a:not([data-bypass])", function (evt) { @@ -25,11 +36,13 @@ attr: $(this).attr("href") }; var root = location.protocol + "//" + location.host + Backbone.history.options.root; - + + if (href.prop && href.prop === root) href.attr = "" + if (href.prop && href.prop.slice(0, root.length) === root) { evt.preventDefault(); Backbone.history.navigate(href.attr, true); } - });*/ + }); } })(); \ No newline at end of file diff --git a/app/assets/javascripts/metamaps/Metamaps.Views.js b/app/assets/javascripts/metamaps/Metamaps.Views.js new file mode 100644 index 00000000..396f6beb --- /dev/null +++ b/app/assets/javascripts/metamaps/Metamaps.Views.js @@ -0,0 +1,26 @@ +(function () { + Metamaps.Views = {}; + + Metamaps.Views.MapCard = Backbone.View.extend({ + + tagName: "div", + + className: "map", + + events: { + "click .icon": "open", + "click .button.edit": "openEditDialog", + "click .button.delete": "destroy" + }, + + initialize: function () { + this.listenTo(this.model, "change", this.render); + }, + + render: function () { + + } + + }); + +})(); \ No newline at end of file diff --git a/app/assets/javascripts/metamaps/metamaps.js b/app/assets/javascripts/metamaps/metamaps.js index ea0addf8..08b594d5 100644 --- a/app/assets/javascripts/metamaps/metamaps.js +++ b/app/assets/javascripts/metamaps/metamaps.js @@ -1632,9 +1632,8 @@ Metamaps.Control = { }, deleteNode: function (nodeid) { // refers to deleting topics permanently var node = Metamaps.Visualize.mGraph.graph.getNode(nodeid); - var id = node.getData('id'); Metamaps.Control.deselectNode(node); - Metamaps.Topics.get(id).destroy(); + Metamaps.Topics.get(nodeid).destroy(); Metamaps.Control.hideNode(nodeid); }, removeSelectedNodes: function () { // refers to removing topics permanently from a map @@ -1653,11 +1652,10 @@ Metamaps.Control = { removeNode: function (nodeid) { // refers to removing topics permanently from a map var mapperm = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper); var node = Metamaps.Visualize.mGraph.graph.getNode(nodeid); - var mappingid = node.getData("mapping").id; if (mapperm) { Metamaps.Control.deselectNode(node); - Metamaps.Mappings.get(mappingid).destroy(); + node.getData('mapping').destroy(); Metamaps.Control.hideNode(nodeid); } }, diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index a3a1da03..35dea28e 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -12,22 +12,22 @@ class MapsController < ApplicationController # GET /maps/mappers/:id def index - if request.path == "/maps" + if request.path == "/explore" redirect_to activemaps_url and return end @current = current_user @user = nil - if request.path =="/maps/active" + if request.path =="/explore/active" @maps = Map.order("updated_at DESC").limit(20) @request = "active" - elsif request.path =="/maps/featured" + elsif request.path =="/explore/featured" @maps = Map.order("name ASC").find_all_by_featured(true) @request = "featured" - elsif request.path == "/maps/new" + elsif request.path == "/explore/new" @maps = Map.order("created_at DESC").limit(20) @request = "new" diff --git a/app/views/layouts/_templates.html.erb b/app/views/layouts/_templates.html.erb index fc6b241f..85392e8c 100644 --- a/app/views/layouts/_templates.html.erb +++ b/app/views/layouts/_templates.html.erb @@ -4,7 +4,40 @@ #%>
- + + + +