From c0a220abc9921a41b35f5746f0b03f712fc68154 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 6 Oct 2016 11:52:05 +0800 Subject: [PATCH] allow synapses to be imported by topic name as well as id --- frontend/src/Metamaps/Import.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/src/Metamaps/Import.js b/frontend/src/Metamaps/Import.js index 6788335f..91da38cf 100644 --- a/frontend/src/Metamaps/Import.js +++ b/frontend/src/Metamaps/Import.js @@ -253,12 +253,16 @@ const Import = { parsedSynapses.forEach(function (synapse) { // only createSynapseWithParameters once both topics are persisted + // if there isn't a cidMapping, check by topic name instead var topic1 = Metamaps.Topics.get(self.cidMappings[synapse.topic1]) + if (!topic1) topic1 = Metamaps.Topics.findWhere({ name: synapse.topic1 }) var topic2 = Metamaps.Topics.get(self.cidMappings[synapse.topic2]) + if (!topic1) topic1 = Metamaps.Topics.findWhere({ name: synapse.topic1 }) + if (!topic1 || !topic2) { console.error("One of the two topics doesn't exist!") console.error(synapse) - return true + return // next } // ensure imported topics have a chance to get a real id attr before creating synapses @@ -407,6 +411,7 @@ const Import = { normalizeKeys: function(obj) { return _.transform(obj, (result, val, key) => { let newKey = key.toLowerCase() + newKey = newKey.replace(/\s/g, '') // remove whitespace if (newKey === 'url') key = 'link' if (newKey === 'title') key = 'name' if (newKey === 'description') key = 'desc'