topics imported with a link get Reference metacode

This commit is contained in:
Devin Howard 2016-10-01 12:14:38 +08:00
parent e093ca5a30
commit 1562d8fcfe

View file

@ -40,9 +40,9 @@ const Import = {
const topicsRegex = /("?Topics"?)([\s\S]*)/mi const topicsRegex = /("?Topics"?)([\s\S]*)/mi
const synapsesRegex = /("?Synapses"?)([\s\S]*)/mi const synapsesRegex = /("?Synapses"?)([\s\S]*)/mi
let topicsText = text.match(topicsRegex) let topicsText = text.match(topicsRegex) || ""
if (topicsText) topicsText = topicsText[2].replace(synapsesRegex, '') if (topicsText) topicsText = topicsText[2].replace(synapsesRegex, '')
let synapsesText = text.match(synapsesRegex) let synapsesText = text.match(synapsesRegex) || ""
if (synapsesText) synapsesText = synapsesText[2].replace(topicsRegex, '') if (synapsesText) synapsesText = synapsesText[2].replace(topicsRegex, '')
// merge default options and extra options passed in parserOpts argument // merge default options and extra options passed in parserOpts argument
@ -54,13 +54,19 @@ const Import = {
const topicsPromise = $.Deferred() const topicsPromise = $.Deferred()
parse(topicsText, csv_parser_options, (err, data) => { parse(topicsText, csv_parser_options, (err, data) => {
if (err) return topicsPromise.reject(err) if (err) {
console.warn(err)
return topicsPromise.resolve([])
}
topicsPromise.resolve(data.map(row => self.lowercaseKeys(row))) topicsPromise.resolve(data.map(row => self.lowercaseKeys(row)))
}) })
const synapsesPromise = $.Deferred() const synapsesPromise = $.Deferred()
parse(synapsesText, csv_parser_options, (err, data) => { parse(synapsesText, csv_parser_options, (err, data) => {
if (err) return synapsesPromise.reject(err) if (err) {
console.warn(err)
return synapsesPromise.resolve([])
}
synapsesPromise.resolve(data.map(row => self.lowercaseKeys(row))) synapsesPromise.resolve(data.map(row => self.lowercaseKeys(row)))
}) })
@ -240,6 +246,10 @@ const Import = {
} }
} }
if (topic.name && topic.link && !topic.metacode) {
topic.metacode = "Reference"
}
self.createTopicWithParameters( self.createTopicWithParameters(
topic.name, topic.metacode, topic.permission, topic.name, topic.metacode, topic.permission,
topic.desc, topic.link, x, y, topic.id topic.desc, topic.link, x, y, topic.id