Skip to content
Snippets Groups Projects
Commit 42e4fe8a authored by Bogdan Cochior's avatar Bogdan Cochior
Browse files

feat(mts): add files info to xml file

parent 9b7dc67b
No related branches found
No related tags found
2 merge requests!21Sprint #16 features,!15MTS integration
const convert = require('xml-js') const convert = require('xml-js')
const { set, get } = require('lodash') const { set, get, reduce } = require('lodash')
const PackageManager = require('./PackageManager') const PackageManager = require('./PackageManager')
const mts = require('./mts-json-template') const mts = require('./mts-json-template')
...@@ -116,20 +116,29 @@ class MTS { ...@@ -116,20 +116,29 @@ class MTS {
return jsonTemplate return jsonTemplate
} }
static setFigures({ supplementary = [] }, jsonTemplate) { static setFiles(files, jsonTemplate) {
const figs = supplementary.map((f, i) => ({ const jsonFiles = reduce(
label: { files,
_text: `Figure ${i + 1}`, (result, value, key) => {
value.map(v =>
result.push({
item_type: {
_text: key,
},
item_description: {
_text: key,
},
item_name: {
_text: v.name,
},
}),
)
return result
}, },
graphic: { [],
_attributes: { )
'xlink:href': f.name, set(jsonTemplate, 'article.front.files.file', jsonFiles)
'xmlns:xlink': 'http://www.w3.org/1999/xlink',
},
},
}))
set(jsonTemplate, 'article.body.fig', figs)
return jsonTemplate return jsonTemplate
} }
...@@ -171,6 +180,9 @@ class MTS { ...@@ -171,6 +180,9 @@ class MTS {
id: `aff${i + 1}`, id: `aff${i + 1}`,
}, },
country: {}, country: {},
'addr-line': {
_text: a.affiliation || '',
},
})) }))
set( set(
...@@ -186,6 +198,7 @@ class MTS { ...@@ -186,6 +198,7 @@ class MTS {
composeJson(fragment = {}) { composeJson(fragment = {}) {
const { const {
authors = [], authors = [],
files = [],
metadata = { title: 'untitled', abstract: '' }, metadata = { title: 'untitled', abstract: '' },
submitted = new Date(), submitted = new Date(),
} = fragment } = fragment
...@@ -195,7 +208,7 @@ class MTS { ...@@ -195,7 +208,7 @@ class MTS {
...this.setMetadata(metadata, this.jsonTemplate), ...this.setMetadata(metadata, this.jsonTemplate),
...this.constructor.setContributors(authors, this.jsonTemplate), ...this.constructor.setContributors(authors, this.jsonTemplate),
...this.constructor.setHistory(submitted, this.jsonTemplate), ...this.constructor.setHistory(submitted, this.jsonTemplate),
// ...this.constructor.setFigures(files, this.jsonTemplate), ...this.constructor.setFiles(files, this.jsonTemplate),
} }
} }
......
...@@ -142,6 +142,9 @@ const getJsonTemplate = (config = {}) => ({ ...@@ -142,6 +142,9 @@ const getJsonTemplate = (config = {}) => ({
}, },
'funding-group': {}, 'funding-group': {},
}, },
files: {
file: [],
},
}, },
}, },
}) })
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment