Skip to content

Commit

Permalink
Revert "Fix XML model juggling in contact forms"
Browse files Browse the repository at this point in the history
This reverts commit 0150e72.

This is not the correct way to fix contact forms.
  • Loading branch information
alxndrsn committed Jun 30, 2017
1 parent 0150e72 commit bffc0f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medic-configurer-beta",
"version": "1.0.60",
"version": "1.0.59",
"description": "Configure Medic Mobile deployments",
"main": "index.js",
"scripts": {
Expand Down
14 changes: 7 additions & 7 deletions src/lib/convert-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = (project, subDirectory, options) => {
.then(() => info('Converting form', originalSourcePath, '…'))
.then(() => xls2xform(sourcePath, targetPath))
.then(() => getHiddenFields(`${fs.withoutExtension(originalSourcePath)}.properties.json`))
.then(hiddenFields => fixXml(sourcePath, targetPath, hiddenFields))
.then(hiddenFields => fixXml(targetPath, hiddenFields))
.then(() => trace('Converted form', originalSourcePath));
},
Promise.resolve());
Expand All @@ -46,8 +46,8 @@ const xls2xform = (sourcePath, targetPath) =>

// FIXME here we fix the form content in arcane ways. Seeing as we have out own
// fork of pyxform, we should probably be doing this fixing there.
const fixXml = (xlsPath, xmlPath, hiddenFields) => {
let xml = fs.read(xmlPath)
const fixXml = (path, hiddenFields) => {
let xml = fs.read(path)
// TODO This is not how you should modify XML
.replace(/ default="true\(\)"/g, '')

Expand All @@ -72,9 +72,9 @@ const fixXml = (xlsPath, xmlPath, hiddenFields) => {
// The ordering of elements in the <model> has an arcane affect on the
// order that docs are saved in the database when processing a form.
// Move the main doc's element down to the bottom.
xml = shiftThingsAroundInTheModel(xlsPath, xml);
xml = shiftThingsAroundInTheModel(path, xml);

fs.write(xmlPath, xml);
fs.write(path, xml);
};

function getHiddenFields(propsJson) {
Expand All @@ -93,8 +93,8 @@ function executableAvailable() {
}
}

const shiftThingsAroundInTheModel = (xlsPath, xml) => {
const baseName = fs.path.parse(xlsPath).name;
const shiftThingsAroundInTheModel = (path, xml) => {
const baseName = fs.path.parse(path).name;
let matchedBlock;

const matcher = new RegExp(`\\s*<${baseName}>[\\s\\S]*</${baseName}>\\s*(\\r|\\n)`);
Expand Down

0 comments on commit bffc0f9

Please sign in to comment.