ok copy-paste mostly works. pasting on top of other topics is still awkward

This commit is contained in:
Devin Howard 2016-10-07 13:50:06 +08:00
parent d3c3f928d4
commit 26189edb74
2 changed files with 17 additions and 12 deletions

View file

@ -29,7 +29,7 @@ const Export = {
loadCopyData: function() { loadCopyData: function() {
if (!Active.Map) return // someday we can expand this 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 // deselect synapses not joined to a selected topic
Selected.Edges.slice(0).forEach(edge => { Selected.Edges.slice(0).forEach(edge => {

View file

@ -6,6 +6,7 @@ import _ from 'lodash'
import Active from './Active' import Active from './Active'
import AutoLayout from './AutoLayout' import AutoLayout from './AutoLayout'
import DataModel from './DataModel' import DataModel from './DataModel'
import Control from './Control'
import Map from './Map' import Map from './Map'
import Synapse from './Synapse' import Synapse from './Synapse'
import Topic from './Topic' import Topic from './Topic'
@ -78,6 +79,8 @@ const Import = {
if (topics.length > 0 || synapses.length > 0) { if (topics.length > 0 || synapses.length > 0) {
if (window.confirm('Are you sure you want to create ' + topics.length + if (window.confirm('Are you sure you want to create ' + topics.length +
' new topics and ' + synapses.length + ' new synapses?')) { ' new topics and ' + synapses.length + ' new synapses?')) {
Control.deselectAllNodes()
Control.deselectAllEdges()
self.importTopics(topics) self.importTopics(topics)
// window.setTimeout(() => self.importSynapses(synapses), 5000) // window.setTimeout(() => self.importSynapses(synapses), 5000)
self.importSynapses(synapses) self.importSynapses(synapses)
@ -122,10 +125,10 @@ const Import = {
if (noblanks.length === 0) { if (noblanks.length === 0) {
state = STATES.UNKNOWN state = STATES.UNKNOWN
break 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 state = STATES.TOPICS_NEED_HEADERS
break 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 state = STATES.SYNAPSES_NEED_HEADERS
break break
} }
@ -233,7 +236,11 @@ const Import = {
self.createTopicWithParameters( self.createTopicWithParameters(
topic.name, topic.metacode, topic.permission, 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(() => { $.when(topic1Promise, topic2Promise).done(() => {
self.createSynapseWithParameters( self.createSynapseWithParameters(
synapse.desc, synapse.category, synapse.permission, synapse.desc, synapse.category, synapse.permission,
topic1, topic2 topic1, topic2, {
success: synapse => {
Control.selectEdge(synapse.get('edge'))
}
}
) )
}) })
}) })
@ -369,6 +380,7 @@ const Import = {
importId, importId,
{ {
success: function(topic) { success: function(topic) {
Control.selectNode(topic.get('node'))
if (topic.get('name') !== 'Link') return if (topic.get('name') !== 'Link') return
$.get('/hacks/load_url_title', { $.get('/hacks/load_url_title', {
url url
@ -421,13 +433,6 @@ const Import = {
console.error(message) console.error(message)
}, },
// TODO investigate replacing with es6 (?) trim()
simplify: function(string) {
return string
.replace(/(^\s*|\s*$)/g, '')
.toLowerCase()
},
normalizeKey: function(key) { normalizeKey: function(key) {
let newKey = key.toLowerCase() let newKey = key.toLowerCase()
newKey = newKey.replace(/\s/g, '') // remove whitespace newKey = newKey.replace(/\s/g, '') // remove whitespace