From 26189edb749ce93a864f67c8dd78cc426052db06 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 7 Oct 2016 13:50:06 +0800 Subject: [PATCH] ok copy-paste mostly works. pasting on top of other topics is still awkward --- frontend/src/Metamaps/Export.js | 2 +- frontend/src/Metamaps/Import.js | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/frontend/src/Metamaps/Export.js b/frontend/src/Metamaps/Export.js index dcabd2d9..4f8ab8b9 100644 --- a/frontend/src/Metamaps/Export.js +++ b/frontend/src/Metamaps/Export.js @@ -29,7 +29,7 @@ const Export = { loadCopyData: function() { if (!Active.Map) return // someday we can expand this - const topics = Selected.Nodes.map(node => node.id) + const topics = Selected.Nodes.map(node => node.getData('topic').id) // deselect synapses not joined to a selected topic Selected.Edges.slice(0).forEach(edge => { diff --git a/frontend/src/Metamaps/Import.js b/frontend/src/Metamaps/Import.js index d4051ddb..a7727c5d 100644 --- a/frontend/src/Metamaps/Import.js +++ b/frontend/src/Metamaps/Import.js @@ -6,6 +6,7 @@ import _ from 'lodash' import Active from './Active' import AutoLayout from './AutoLayout' import DataModel from './DataModel' +import Control from './Control' import Map from './Map' import Synapse from './Synapse' import Topic from './Topic' @@ -78,6 +79,8 @@ const Import = { if (topics.length > 0 || synapses.length > 0) { if (window.confirm('Are you sure you want to create ' + topics.length + ' new topics and ' + synapses.length + ' new synapses?')) { + Control.deselectAllNodes() + Control.deselectAllEdges() self.importTopics(topics) // window.setTimeout(() => self.importSynapses(synapses), 5000) self.importSynapses(synapses) @@ -122,10 +125,10 @@ const Import = { if (noblanks.length === 0) { state = STATES.UNKNOWN break - } else if (noblanks.length === 1 && self.simplify(line[0]) === 'topics') { + } else if (noblanks.length === 1 && self.normalizeKey(line[0]) === 'topics') { state = STATES.TOPICS_NEED_HEADERS break - } else if (noblanks.length === 1 && self.simplify(line[0]) === 'synapses') { + } else if (noblanks.length === 1 && self.normalizeKey(line[0]) === 'synapses') { state = STATES.SYNAPSES_NEED_HEADERS break } @@ -233,7 +236,11 @@ const Import = { self.createTopicWithParameters( topic.name, topic.metacode, topic.permission, - topic.desc, topic.link, coords.x, coords.y, topic.id + topic.desc, topic.link, coords.x, coords.y, topic.id, { + success: topic => { + Control.selectNode(topic.get('node')) + } + } ) }) }, @@ -270,7 +277,11 @@ const Import = { $.when(topic1Promise, topic2Promise).done(() => { self.createSynapseWithParameters( synapse.desc, synapse.category, synapse.permission, - topic1, topic2 + topic1, topic2, { + success: synapse => { + Control.selectEdge(synapse.get('edge')) + } + } ) }) }) @@ -369,6 +380,7 @@ const Import = { importId, { success: function(topic) { + Control.selectNode(topic.get('node')) if (topic.get('name') !== 'Link') return $.get('/hacks/load_url_title', { url @@ -421,13 +433,6 @@ const Import = { console.error(message) }, - // TODO investigate replacing with es6 (?) trim() - simplify: function(string) { - return string - .replace(/(^\s*|\s*$)/g, '') - .toLowerCase() - }, - normalizeKey: function(key) { let newKey = key.toLowerCase() newKey = newKey.replace(/\s/g, '') // remove whitespace