From 194a4dc975780a77b7a4edfb76d13f3e1fa765c4 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 4 Aug 2016 16:53:09 +0800 Subject: [PATCH 01/12] add production schema file --- db/schema.rb | 75 +++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index d3dc9634..e5bd754e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -38,15 +38,12 @@ ActiveRecord::Schema.define(version: 20160401133937) do t.string "eventable_type" t.integer "user_id" t.integer "map_id" - t.integer "sequence_id" t.datetime "created_at" t.datetime "updated_at" end add_index "events", ["eventable_type", "eventable_id"], name: "index_events_on_eventable_type_and_eventable_id", using: :btree - add_index "events", ["map_id", "sequence_id"], name: "index_events_on_map_id_and_sequence_id", unique: true, using: :btree add_index "events", ["map_id"], name: "index_events_on_map_id", using: :btree - add_index "events", ["sequence_id"], name: "index_events_on_sequence_id", using: :btree add_index "events", ["user_id"], name: "index_events_on_user_id", using: :btree create_table "in_metacode_sets", force: :cascade do |t| @@ -80,16 +77,16 @@ ActiveRecord::Schema.define(version: 20160401133937) do add_index "mappings", ["user_id"], name: "index_mappings_on_user_id", using: :btree create_table "maps", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false 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 "arranged" t.boolean "featured" - t.string "screenshot_file_name" - t.string "screenshot_content_type" + t.string "screenshot_file_name", limit: 255 + t.string "screenshot_content_type", limit: 255 t.integer "screenshot_file_size" t.datetime "screenshot_updated_at" end @@ -110,22 +107,22 @@ ActiveRecord::Schema.define(version: 20160401133937) do add_index "messages", ["user_id"], name: "index_messages_on_user_id", using: :btree create_table "metacode_sets", force: :cascade do |t| - t.string "name" + t.string "name", limit: 255 t.text "desc" t.integer "user_id" t.boolean "mapperContributed" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + 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", using: :btree create_table "metacodes", force: :cascade do |t| t.text "name" - t.string "manual_icon" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "color" + t.string "manual_icon", limit: 255 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "color", limit: 255 t.string "aws_icon_file_name" t.string "aws_icon_content_type" t.integer "aws_icon_file_size" @@ -175,13 +172,13 @@ ActiveRecord::Schema.define(version: 20160401133937) do create_table "synapses", force: :cascade 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 + t.text "permission" + t.text "weight" t.integer "defer_to_map_id" end @@ -205,17 +202,17 @@ ActiveRecord::Schema.define(version: 20160401133937) do 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.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "permission" + t.string "image_file_name", limit: 255 + t.string "image_content_type", limit: 255 t.integer "image_file_size" t.datetime "image_updated_at" - t.string "audio_file_name" - t.string "audio_content_type" + t.string "audio_file_name", limit: 255 + t.string "audio_content_type", limit: 255 t.integer "audio_file_size" t.datetime "audio_updated_at" t.integer "defer_to_map_id" @@ -235,30 +232,30 @@ ActiveRecord::Schema.define(version: 20160401133937) do add_index "user_maps", ["user_id"], name: "index_user_maps_on_user_id", using: :btree create_table "users", force: :cascade 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.string "name", limit: 255 + t.string "email", limit: 255 + t.string "crypted_password", limit: 255 + t.string "password_salt", limit: 255 + t.string "persistence_token", limit: 255 + t.string "perishable_token", limit: 255 t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "code", limit: 8 + t.string "joinedwithcode", limit: 8 + t.text "settings" t.string "encrypted_password", limit: 128, default: "" - t.string "remember_token" + t.string "remember_token", limit: 255 t.datetime "remember_created_at" - t.string "reset_password_token" + t.string "reset_password_token", limit: 255 t.datetime "last_sign_in_at" - t.string "last_sign_in_ip" + t.string "last_sign_in_ip", limit: 255 t.integer "sign_in_count", default: 0 t.datetime "current_sign_in_at" - t.string "current_sign_in_ip" + t.string "current_sign_in_ip", limit: 255 t.datetime "reset_password_sent_at" t.boolean "admin" - t.string "image_file_name" - t.string "image_content_type" + t.string "image_file_name", limit: 255 + t.string "image_content_type", limit: 255 t.integer "image_file_size" t.datetime "image_updated_at" t.integer "generation" From 69bdb0bf01074a51e76ab845b00b00617043f95b Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 4 Aug 2016 17:04:01 +0800 Subject: [PATCH 02/12] hotfix master with mappable_policy.try --- app/policies/mapping_policy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/policies/mapping_policy.rb b/app/policies/mapping_policy.rb index 5826ccd4..ce8522df 100644 --- a/app/policies/mapping_policy.rb +++ b/app/policies/mapping_policy.rb @@ -16,7 +16,7 @@ class MappingPolicy < ApplicationPolicy end def show? - map_policy.show? && mappable_policy.show? + map_policy.show? && mappable_policy.try(:show?) end def create? From a6951920eb4fed44b439f8d24fa667da1170788e Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 4 Aug 2016 17:08:10 +0800 Subject: [PATCH 03/12] fix module.exports javascript bug --- app/assets/javascripts/src/Metamaps.Import.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/assets/javascripts/src/Metamaps.Import.js b/app/assets/javascripts/src/Metamaps.Import.js index 159298b8..e82a05c5 100644 --- a/app/assets/javascripts/src/Metamaps.Import.js +++ b/app/assets/javascripts/src/Metamaps.Import.js @@ -320,5 +320,3 @@ Metamaps.Import = { Metamaps.Synapse.renderSynapse(mapping, synapse, node1, node2, true) } } - -module.exports = Metamaps.Import From d778016571dbda18074b5e1e7ecc8251073e5e16 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 7 Aug 2016 13:17:25 +0800 Subject: [PATCH 04/12] fix selection box on radial view - fix #463 --- app/assets/javascripts/src/Metamaps.JIT.js | 35 +++++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/src/Metamaps.JIT.js b/app/assets/javascripts/src/Metamaps.JIT.js index 01b321f7..4fc1506e 100644 --- a/app/assets/javascripts/src/Metamaps.JIT.js +++ b/app/assets/javascripts/src/Metamaps.JIT.js @@ -1082,7 +1082,18 @@ Metamaps.JIT = { } return 'nothing'; // case 4? }, // handleSelectionBeforeDragging + getNodeXY: function(node) { + if (typeof node.pos.x === "number" && typeof node.pos.y === "number") { + return node.pos + } else if (typeof node.pos.theta === "number" && typeof node.pos.rho === "number") { + return new $jit.Polar(node.pos.theta, node.pos.rho).getc(true) + } else { + console.error('getNodeXY: unrecognized node pos format') + return {} + } + }, selectWithBox: function (e) { + var self = this var sX = Metamaps.Mouse.boxStartCoordinates.x, sY = Metamaps.Mouse.boxStartCoordinates.y, eX = Metamaps.Mouse.boxEndCoordinates.x, @@ -1094,11 +1105,17 @@ Metamaps.JIT = { } // select all nodes that are within the box - Metamaps.Visualize.mGraph.graph.eachNode(function (n) { - var x = n.pos.x, - y = n.pos.y + Metamaps.Visualize.mGraph.graph.eachNode(function(n) { + var pos = self.getNodeXY(n) + var x = pos.x, + y = 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)) { + // depending on which way the person dragged the box, check that + // x and y are between the start and end values of the box + 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)) { if (e.shiftKey) { if (n.selected) { Metamaps.Control.deselectNode(n) @@ -1123,10 +1140,12 @@ Metamaps.JIT = { } }) edgesToToggle.forEach(function (edge) { - var fromNodeX = edge.nodeFrom.pos.x - var fromNodeY = -1 * edge.nodeFrom.pos.y - var toNodeX = edge.nodeTo.pos.x - var toNodeY = -1 * edge.nodeTo.pos.y + var fromNodePos = self.getNodeXY(edge.nodeFrom) + var fromNodeX = fromNodePos.x + var fromNodeY = -1 * fromNodePos.y + var toNodePos = self.getNodeXY(edge.nodeTo) + var toNodeX = toNodePos.x + var toNodeY = -1 * toNodePos.y var maxX = fromNodeX var maxY = fromNodeY From 23543ac7adc7960a596c615fcf20936587d12964 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 7 Aug 2016 17:18:54 +0800 Subject: [PATCH 05/12] fix: synapse import fails if synapses are missing desc --- app/assets/javascripts/src/Metamaps.Import.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/src/Metamaps.Import.js b/app/assets/javascripts/src/Metamaps.Import.js index e82a05c5..c04a0f5b 100644 --- a/app/assets/javascripts/src/Metamaps.Import.js +++ b/app/assets/javascripts/src/Metamaps.Import.js @@ -272,7 +272,7 @@ Metamaps.Import = { name: name, metacode_id: metacode.id, permission: permission || Metamaps.Active.Map.get('permission'), - desc: desc, + desc: desc || "", link: link }) Metamaps.Topics.add(topic) @@ -292,7 +292,7 @@ Metamaps.Import = { Metamaps.Famous.viz.hideInstructions() }, - createSynapseWithParameters: function (description, category, permission, + createSynapseWithParameters: function (desc, category, permission, topic1, topic2) { var node1 = topic1.get('node') var node2 = topic2.get('node') @@ -303,7 +303,7 @@ Metamaps.Import = { } // if var synapse = new Metamaps.Backbone.Synapse({ - desc: description, + desc: desc || "", category: category, permission: permission, node1_id: topic1.id, From b66b75615a8d8232ce02cc43e3f8f354cb1924da Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 7 Aug 2016 19:40:26 +0800 Subject: [PATCH 06/12] remove frontend folder reference from travis --- .travis.yml | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5e192554..28559996 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,6 @@ before_script: - . $HOME/.nvm/nvm.sh - nvm install stable - nvm use stable - - (cd frontend && npm install) + - npm install script: - - bundle exec rspec && (cd frontend && npm test) && bundle exec brakeman -q -z + - bundle exec rspec && npm test && bundle exec brakeman -q -z diff --git a/package.json b/package.json index acf69b97..9fe29143 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "build": "webpack", "build:watch": "webpack --watch", - "test": "mocha test || echo 'Run `npm install` to setup testing'" + "test": "mocha frontend/test || echo 'Run `npm install` to setup testing'" }, "repository": { "type": "git", From 713063e578db5a56ef860792c2f96f637ad968f2 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 7 Aug 2016 19:51:17 +0800 Subject: [PATCH 07/12] fix npm testing script - it will actually break travis now --- frontend/test/Metamaps.Import.spec.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/test/Metamaps.Import.spec.js b/frontend/test/Metamaps.Import.spec.js index 59ab45e6..8dcf8e97 100644 --- a/frontend/test/Metamaps.Import.spec.js +++ b/frontend/test/Metamaps.Import.spec.js @@ -2,7 +2,7 @@ const chai = require('chai') const expect = chai.expect -const Metamaps = {} +Metamaps = {} require('../../app/assets/javascripts/src/Metamaps.Import') describe('Metamaps.Import.js', function () { diff --git a/package.json b/package.json index 9fe29143..0ad44676 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "build": "webpack", "build:watch": "webpack --watch", - "test": "mocha frontend/test || echo 'Run `npm install` to setup testing'" + "test": "mocha frontend/test || (echo 'Run `npm install` to setup testing' && false)" }, "repository": { "type": "git", From 3b65ad923bb2bc6de812069025506b0451f0fb8c Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 7 Aug 2016 21:26:53 +0800 Subject: [PATCH 08/12] only show travis build status badge for develop branch --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 20d8db27..26de4e6c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Metamaps ======= [![Join the chat at https://gitter.im/metamaps/metamaps](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/metamaps/metamaps?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![Build Status](https://travis-ci.org/metamaps/metamaps.svg)](https://travis-ci.org/metamaps/metamaps) +[![Build Status](https://travis-ci.org/metamaps/metamaps.svg?branch=develop)](https://travis-ci.org/metamaps/metamaps) Welcome to the Metamaps GitHub repo. From 5510cb2e99f71b2e4f34c01f05200a7fb4b29ef8 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 7 Aug 2016 15:34:30 +0800 Subject: [PATCH 09/12] enable removal of topics from topic view - fixes #467 --- .../javascripts/src/Metamaps.Control.js | 13 +++++++++++-- app/assets/javascripts/src/Metamaps.JIT.js | 19 +++++++------------ app/assets/javascripts/src/Metamaps.Map.js | 2 ++ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/src/Metamaps.Control.js b/app/assets/javascripts/src/Metamaps.Control.js index 4db7f82b..a6058ac2 100644 --- a/app/assets/javascripts/src/Metamaps.Control.js +++ b/app/assets/javascripts/src/Metamaps.Control.js @@ -111,6 +111,14 @@ Metamaps.Control = { } }, removeSelectedNodes: function () { // refers to removing topics permanently from a map + if (Metamaps.Active.Topic) { + // hideNode will handle synapses as well + _.each(Metamaps.Selected.Nodes, function(node) { + Metamaps.Control.hideNode(node.id) + Metamaps.Topics.remove(node.id) + }) + return + } if (!Metamaps.Active.Map) return var l = Metamaps.Selected.Nodes.length, @@ -285,12 +293,13 @@ Metamaps.Control = { } }, removeSelectedEdges: function () { + // Topic view is handled by removeSelectedNodes + if (!Metamaps.Active.Map) return + var l = Metamaps.Selected.Edges.length, i, edge - if (!Metamaps.Active.Map) return - var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper) if (!authorized) { diff --git a/app/assets/javascripts/src/Metamaps.JIT.js b/app/assets/javascripts/src/Metamaps.JIT.js index 01b321f7..3aaf0ceb 100644 --- a/app/assets/javascripts/src/Metamaps.JIT.js +++ b/app/assets/javascripts/src/Metamaps.JIT.js @@ -1313,6 +1313,7 @@ Metamaps.JIT = { if (Metamaps.Active.Map) menustring += '
  • Hide until refresh
    Ctrl+H
  • ' if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '
  • Remove from map
    Ctrl+M
  • ' + if (Metamaps.Active.Topic) menustring += '
  • Remove from view
    Ctrl+M
  • ' if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '
  • Delete
    Ctrl+D
  • ' if (Metamaps.Active.Topic) { @@ -1397,7 +1398,7 @@ Metamaps.JIT = { } // remove the selected things from the map - if (authorized) { + if (Metamaps.Active.Topic || authorized) { $('.rc-remove').click(function () { $('.rightclickmenu').remove() Metamaps.Control.removeSelectedEdges() @@ -1440,11 +1441,11 @@ Metamaps.JIT = { }) // fetch relatives - var fetched = false + var fetch_sent = false $('.rc-siblings').hover(function () { - if (!fetched) { + if (!fetch_sent) { Metamaps.JIT.populateRightClickSiblings(node) - fetched = true + fetch_sent = true } }) $('.rc-siblings .fetchAll').click(function () { @@ -1457,13 +1458,6 @@ Metamaps.JIT = { var self = Metamaps.JIT // depending on how many topics are selected, do different things - /*if (Metamaps.Selected.Nodes.length > 1) { - // we don't bother filling the submenu with - // specific numbers, because there are too many topics - // selected to find those numbers - $('#loadingSiblings').remove() - return - }*/ var topic = node.getData('topic') @@ -1494,7 +1488,7 @@ Metamaps.JIT = { } $.ajax({ - type: 'Get', + type: 'GET', url: '/topics/' + topic.id + '/relative_numbers.json?network=' + topics_string, success: successCallback, error: function () {} @@ -1567,6 +1561,7 @@ Metamaps.JIT = { if (Metamaps.Active.Map) menustring += '
  • Hide until refresh
    Ctrl+H
  • ' if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '
  • Remove from map
    Ctrl+M
  • ' + if (Metamaps.Active.Topic) menustring += '
  • Remove from view
    Ctrl+M
  • ' if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '
  • Delete
    Ctrl+D
  • ' if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '
  • ' diff --git a/app/assets/javascripts/src/Metamaps.Map.js b/app/assets/javascripts/src/Metamaps.Map.js index 34374614..ec3b946f 100644 --- a/app/assets/javascripts/src/Metamaps.Map.js +++ b/app/assets/javascripts/src/Metamaps.Map.js @@ -673,6 +673,8 @@ Metamaps.Map.InfoBox = { return string }, updateNumbers: function () { + if (!Metamaps.Active.Map) return + var self = Metamaps.Map.InfoBox var mapper = Metamaps.Active.Mapper var relevantPeople = Metamaps.Active.Map.get('permission') === 'commons' ? Metamaps.Mappers : Metamaps.Collaborators From 9cedf69432bf6e4d87dd9a599b16b224c6f0d574 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 8 Aug 2016 21:46:05 +0800 Subject: [PATCH 10/12] fetch siblings & center topic keyboard shortcuts - fixes #466 (#588) * fetch siblings & center topic keyboard shortcuts - fixes #466 * add keyboard shortcut labels * update keyboard shortcuts to Ctrl+E, Ctrl+R, and Ctrl+T, and update docs * zoom extents back to Ctrl+E and use e.preventDefault --- app/assets/javascripts/src/Metamaps.JIT.js | 6 +- .../javascripts/src/Metamaps.Listeners.js | 67 ++++++++++++++----- app/assets/javascripts/src/Metamaps.Map.js | 2 + app/assets/stylesheets/application.css.erb | 3 +- app/views/shared/_cheatsheet.html.erb | 5 +- 5 files changed, 61 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/src/Metamaps.JIT.js b/app/assets/javascripts/src/Metamaps.JIT.js index 4fc1506e..63c89b67 100644 --- a/app/assets/javascripts/src/Metamaps.JIT.js +++ b/app/assets/javascripts/src/Metamaps.JIT.js @@ -1335,7 +1335,7 @@ Metamaps.JIT = { if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '
  • Delete
    Ctrl+D
  • ' if (Metamaps.Active.Topic) { - menustring += '
  • Center this topic
  • ' + menustring += '
  • Center this topic
    Ctrl+E
  • ' } menustring += '
  • Open in new tab
  • ' if (Metamaps.Active.Mapper) { @@ -1360,10 +1360,10 @@ Metamaps.JIT = { // set up the get sibling menu as a "lazy load" // only fill in the submenu when they hover over the get siblings list item var siblingMenu = '
      \ -
    • All
    • \ +
    • All
      Ctrl+R
    • \
    • \
    ' - menustring += '
  • Get siblings' + siblingMenu + '
  • ' + menustring += '
  • Reveal siblings' + siblingMenu + '
  • ' } menustring += '' diff --git a/app/assets/javascripts/src/Metamaps.Listeners.js b/app/assets/javascripts/src/Metamaps.Listeners.js index 83204eee..32f4c418 100644 --- a/app/assets/javascripts/src/Metamaps.Listeners.js +++ b/app/assets/javascripts/src/Metamaps.Listeners.js @@ -11,6 +11,7 @@ */ Metamaps.Listeners = { init: function () { + var self = this $(document).on('keydown', function (e) { if (!(Metamaps.Active.Map || Metamaps.Active.Topic)) return @@ -35,21 +36,6 @@ Metamaps.Listeners = { Metamaps.Visualize.mGraph.plot() } - break - case 69: // if e or E is pressed - if (e.ctrlKey) { - e.preventDefault() - if (Metamaps.Active.Map) { - Metamaps.JIT.zoomExtents(null, Metamaps.Visualize.mGraph.canvas) - } - } - break - case 77: // if m or M is pressed - if (e.ctrlKey) { - e.preventDefault() - Metamaps.Control.removeSelectedNodes() - Metamaps.Control.removeSelectedEdges() - } break case 68: // if d or D is pressed if (e.ctrlKey) { @@ -57,6 +43,19 @@ Metamaps.Listeners = { Metamaps.Control.deleteSelected() } break + case 69: // if e or E is pressed + if (e.ctrlKey) { + e.preventDefault() + if (Metamaps.Active.Topic) { + self.centerAndReveal(Metamaps.Selected.Nodes, { + center: true, + reveal: false + }) + } else if (Metamaps.Active.Map) { + Metamaps.JIT.zoomExtents(null, Metamaps.Visualize.mGraph.canvas) + } + } + break case 72: // if h or H is pressed if (e.ctrlKey) { e.preventDefault() @@ -64,8 +63,34 @@ Metamaps.Listeners = { Metamaps.Control.hideSelectedEdges() } break + case 77: // if m or M is pressed + if (e.ctrlKey) { + e.preventDefault() + Metamaps.Control.removeSelectedNodes() + Metamaps.Control.removeSelectedEdges() + } + break + case 82: // if r or R is pressed + if (e.ctrlKey && Metamaps.Active.Topic) { + e.preventDefault() + self.centerAndReveal(Metamaps.Selected.Nodes, { + center: false, + reveal: true + }) + } + break + case 84: // if t or T is pressed + if (e.ctrlKey && Metamaps.Active.Topic) { + e.preventDefault() + self.centerAndReveal(Metamaps.Selected.Nodes, { + center: true, + reveal: true + }) + } + break default: - break; // alert(e.which) + // console.log(e.which) + break } }) @@ -74,5 +99,15 @@ Metamaps.Listeners = { if ((Metamaps.Active.Map || Metamaps.Active.Topic) && Metamaps.Famous && Metamaps.Famous.maps.surf) Metamaps.Famous.maps.reposition() if (Metamaps.Active.Map && Metamaps.Realtime.inConversation) Metamaps.Realtime.positionVideos() }) + }, + centerAndReveal: function(nodes, opts) { + if (nodes.length < 1) return + var node = nodes[nodes.length - 1] + if (opts.center) { + Metamaps.Topic.centerOn(node.id) + } + if (opts.reveal) { + Metamaps.Topic.fetchRelatives(node) + } } }; // end Metamaps.Listeners diff --git a/app/assets/javascripts/src/Metamaps.Map.js b/app/assets/javascripts/src/Metamaps.Map.js index 34374614..ec3b946f 100644 --- a/app/assets/javascripts/src/Metamaps.Map.js +++ b/app/assets/javascripts/src/Metamaps.Map.js @@ -673,6 +673,8 @@ Metamaps.Map.InfoBox = { return string }, updateNumbers: function () { + if (!Metamaps.Active.Map) return + var self = Metamaps.Map.InfoBox var mapper = Metamaps.Active.Mapper var relevantPeople = Metamaps.Active.Map.get('permission') === 'commons' ? Metamaps.Mappers : Metamaps.Collaborators diff --git a/app/assets/stylesheets/application.css.erb b/app/assets/stylesheets/application.css.erb index 6c76dd9e..d1f866bc 100644 --- a/app/assets/stylesheets/application.css.erb +++ b/app/assets/stylesheets/application.css.erb @@ -1249,8 +1249,9 @@ h3.filterBox { .rightclickmenu .rc-metacode > ul > li, .rightclickmenu .rc-siblings > ul > li { padding: 6px 24px 6px 8px; - width: auto; white-space: nowrap; + width: auto; + min-width: 5em; } .rightclickmenu .rc-metacode ul ul, .rightclickmenu .rc-siblings ul ul { diff --git a/app/views/shared/_cheatsheet.html.erb b/app/views/shared/_cheatsheet.html.erb index c02246ac..6468ccb6 100644 --- a/app/views/shared/_cheatsheet.html.erb +++ b/app/views/shared/_cheatsheet.html.erb @@ -26,8 +26,9 @@
    -
    Recenter Topics around chosen Topic: Alt + click on the topic OR Right-click + 'center this topic'
    - +
    Recenter Topics around chosen Topic: Alt + click on the topic OR Ctrl + E
    +
    Reveal the siblings for a Topic: Right-click and choose 'Reveal siblings' OR Ctrl + R
    +
    Center topic and reveal siblings: Ctrl + T
    From b9247d269222a7f4b76fc94258606542f19953fd Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 8 Aug 2016 21:58:23 +0800 Subject: [PATCH 11/12] multi-buildpack setup for heroku: $ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-multi.git will set it up --- .buildpacks | 1 + lib/tasks/extensions.rake | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 lib/tasks/extensions.rake diff --git a/.buildpacks b/.buildpacks index ff2497d3..9fb12425 100644 --- a/.buildpacks +++ b/.buildpacks @@ -1 +1,2 @@ +https://github.com/heroku/heroku-buildpack-nodejs.git https://github.com/heroku/heroku-buildpack-ruby.git diff --git a/lib/tasks/extensions.rake b/lib/tasks/extensions.rake new file mode 100644 index 00000000..bf07cec2 --- /dev/null +++ b/lib/tasks/extensions.rake @@ -0,0 +1,8 @@ +namespace :assets do + task :js_compile do + system "npm install" + system "npm run build" + end +end + +Rake::Task[:'assets:precompile'].enhance([:'assets:js_compile']) From beb52bc4718ac641c0f9f90f2bac8e2edc8bc423 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 9 Aug 2016 23:53:50 +0800 Subject: [PATCH 12/12] fix topic view keyboard shortcuts (#597) * fix topic view selection crash on centerAndReveal * topic view shortcuts switch to Alt * change delete behaviour to be smarter * fetchRelatives recursively handles arrays * update topic url and Metamaps.Active.Topic when you center * make heroku work 4 realz --- .../javascripts/src/Metamaps.Control.js | 11 ++++++-- app/assets/javascripts/src/Metamaps.JIT.js | 4 +-- .../javascripts/src/Metamaps.Listeners.js | 26 +++++++++++------ app/assets/javascripts/src/Metamaps.Topic.js | 28 +++++++++++++++---- app/views/shared/_cheatsheet.html.erb | 6 ++-- package.json | 14 ++++------ 6 files changed, 59 insertions(+), 30 deletions(-) diff --git a/app/assets/javascripts/src/Metamaps.Control.js b/app/assets/javascripts/src/Metamaps.Control.js index a6058ac2..da6854c2 100644 --- a/app/assets/javascripts/src/Metamaps.Control.js +++ b/app/assets/javascripts/src/Metamaps.Control.js @@ -113,9 +113,14 @@ Metamaps.Control = { removeSelectedNodes: function () { // refers to removing topics permanently from a map if (Metamaps.Active.Topic) { // hideNode will handle synapses as well - _.each(Metamaps.Selected.Nodes, function(node) { - Metamaps.Control.hideNode(node.id) - Metamaps.Topics.remove(node.id) + var nodeids = _.map(Metamaps.Selected.Nodes, function(node) { + return node.id + }) + _.each(nodeids, function(nodeid) { + if (Metamaps.Active.Topic.id !== nodeid) { + Metamaps.Topics.remove(nodeid) + Metamaps.Control.hideNode(nodeid) + } }) return } diff --git a/app/assets/javascripts/src/Metamaps.JIT.js b/app/assets/javascripts/src/Metamaps.JIT.js index 26c33b4c..4d8d8e30 100644 --- a/app/assets/javascripts/src/Metamaps.JIT.js +++ b/app/assets/javascripts/src/Metamaps.JIT.js @@ -1336,7 +1336,7 @@ Metamaps.JIT = { if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '
  • Delete
    Ctrl+D
  • ' if (Metamaps.Active.Topic) { - menustring += '
  • Center this topic
    Ctrl+E
  • ' + menustring += '
  • Center this topic
    Alt+E
  • ' } menustring += '
  • Open in new tab
  • ' if (Metamaps.Active.Mapper) { @@ -1361,7 +1361,7 @@ Metamaps.JIT = { // set up the get sibling menu as a "lazy load" // only fill in the submenu when they hover over the get siblings list item var siblingMenu = '
      \ -
    • All
      Ctrl+R
    • \ +
    • All
      Alt+R
    • \
    • \
    ' menustring += '
  • Reveal siblings' + siblingMenu + '
  • ' diff --git a/app/assets/javascripts/src/Metamaps.Listeners.js b/app/assets/javascripts/src/Metamaps.Listeners.js index 32f4c418..822cf657 100644 --- a/app/assets/javascripts/src/Metamaps.Listeners.js +++ b/app/assets/javascripts/src/Metamaps.Listeners.js @@ -44,16 +44,21 @@ Metamaps.Listeners = { } break case 69: // if e or E is pressed - if (e.ctrlKey) { + if (e.ctrlKey && Metamaps.Active.Map) { e.preventDefault() + Metamaps.JIT.zoomExtents(null, Metamaps.Visualize.mGraph.canvas) + break + } + if (e.altKey && Metamaps.Active.Topic) { + e.preventDefault() + if (Metamaps.Active.Topic) { self.centerAndReveal(Metamaps.Selected.Nodes, { center: true, reveal: false }) - } else if (Metamaps.Active.Map) { - Metamaps.JIT.zoomExtents(null, Metamaps.Visualize.mGraph.canvas) } + break } break case 72: // if h or H is pressed @@ -71,7 +76,7 @@ Metamaps.Listeners = { } break case 82: // if r or R is pressed - if (e.ctrlKey && Metamaps.Active.Topic) { + if (e.altKey && Metamaps.Active.Topic) { e.preventDefault() self.centerAndReveal(Metamaps.Selected.Nodes, { center: false, @@ -80,7 +85,7 @@ Metamaps.Listeners = { } break case 84: // if t or T is pressed - if (e.ctrlKey && Metamaps.Active.Topic) { + if (e.altKey && Metamaps.Active.Topic) { e.preventDefault() self.centerAndReveal(Metamaps.Selected.Nodes, { center: true, @@ -103,11 +108,14 @@ Metamaps.Listeners = { centerAndReveal: function(nodes, opts) { if (nodes.length < 1) return var node = nodes[nodes.length - 1] - if (opts.center) { + if (opts.center && opts.reveal) { + Metamaps.Topic.centerOn(node.id, function() { + Metamaps.Topic.fetchRelatives(nodes) + }) + } else if (opts.center) { Metamaps.Topic.centerOn(node.id) - } - if (opts.reveal) { - Metamaps.Topic.fetchRelatives(node) + } else if (opts.reveal) { + Metamaps.Topic.fetchRelatives(nodes) } } }; // end Metamaps.Listeners diff --git a/app/assets/javascripts/src/Metamaps.Topic.js b/app/assets/javascripts/src/Metamaps.Topic.js index da1bfc8c..3d8919e2 100644 --- a/app/assets/javascripts/src/Metamaps.Topic.js +++ b/app/assets/javascripts/src/Metamaps.Topic.js @@ -99,16 +99,25 @@ Metamaps.Topic = { Metamaps.Filter.close() } }, - centerOn: function (nodeid) { + centerOn: function (nodeid, callback) { + // don't clash with fetchRelatives if (!Metamaps.Visualize.mGraph.busy) { Metamaps.Visualize.mGraph.onClick(nodeid, { hideLabels: false, duration: 1000, - onComplete: function () {} + onComplete: function () { + if (callback) callback() + } }) + Metamaps.Router.navigate('/topics/' + nodeid) + Metamaps.Active.Topic = Metamaps.Topics.get(nodeid) } }, - fetchRelatives: function (node, metacode_id) { + fetchRelatives: function (nodes, metacode_id) { + var self = this + + var node = $.isArray(nodes) ? nodes[0] : nodes + var topics = Metamaps.Topics.map(function (t) { return t.id }) var topics_string = topics.join() @@ -117,7 +126,13 @@ Metamaps.Topic = { var topic = node.getData('topic') - var successCallback = function (data) { + var successCallback; + successCallback = function (data) { + if (Metamaps.Visualize.mGraph.busy) { + // don't clash with centerOn + window.setTimeout(function() { successCallback(data) }, 100) + return + } if (data.creators.length > 0) Metamaps.Creators.add(data.creators) if (data.topics.length > 0) Metamaps.Topics.add(data.topics) if (data.synapses.length > 0) Metamaps.Synapses.add(data.synapses) @@ -153,13 +168,16 @@ Metamaps.Topic = { } }) }) + if ($.isArray(nodes) && nodes.length > 1) { + self.fetchRelatives(nodes.slice(1), metacode_id) + } } var paramsString = metacode_id ? 'metacode=' + metacode_id + '&' : '' paramsString += 'network=' + topics_string + '&creators=' + creators_string $.ajax({ - type: 'Get', + type: 'GET', url: '/topics/' + topic.id + '/relatives.json?' + paramsString, success: successCallback, error: function () {} diff --git a/app/views/shared/_cheatsheet.html.erb b/app/views/shared/_cheatsheet.html.erb index 6468ccb6..e86b2977 100644 --- a/app/views/shared/_cheatsheet.html.erb +++ b/app/views/shared/_cheatsheet.html.erb @@ -26,9 +26,9 @@
    -
    Recenter Topics around chosen Topic: Alt + click on the topic OR Ctrl + E
    -
    Reveal the siblings for a Topic: Right-click and choose 'Reveal siblings' OR Ctrl + R
    -
    Center topic and reveal siblings: Ctrl + T
    +
    Recenter Topics around chosen Topic: Alt + click on the topic OR Alt + E
    +
    Reveal the siblings for a Topic: Right-click and choose 'Reveal siblings' OR Alt + R
    +
    Center topic and reveal siblings: Alt + T
    diff --git a/package.json b/package.json index 0ad44676..2da72637 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "metamaps-frontend", + "name": "metamaps", "version": "1.0.0", - "description": "Metamaps frontend - currently just tests", + "description": "Metamaps webpacked javascript code", "scripts": { "build": "webpack", "build:watch": "webpack --watch", @@ -17,22 +17,20 @@ "url": "https://github.com/metamaps/metamaps/issues" }, "homepage": "https://github.com/metamaps/metamaps#readme", - "devDependencies": { + "dependencies": { "babel-cli": "^6.11.4", "babel-loader": "^6.2.4", "babel-plugin-transform-class-properties": "^6.11.5", "babel-preset-es2015": "^6.9.0", "babel-preset-react": "^6.11.1", + "backbone": "^1.0.0", "chai": "^3.5.0", "jquery": "^1.12.1", "mocha": "^2.4.5", - "webpack": "^1.13.1" - }, - "dependencies": { - "backbone": "^1.0.0", "react": "^15.3.0", "react-dom": "^15.3.0", "requirejs": "^2.1.1", - "underscore": "^1.4.4" + "underscore": "^1.4.4", + "webpack": "^1.13.1" } }