Skip to content

Commit

Permalink
Restructure forms to separate contact and app forms
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Jun 1, 2017
1 parent c3396d6 commit 92646d8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ This tool expects a project to be sctructured as follows:
rules.nools.js
schedules.json
forms/
contact-person-create.xlsx
app/
my_project_form.xlsx
my_project_form.properties.json
my_project_form/
xml
contact/
person-create.xlsx
person-create/
xml
my_project_form.xlsx
my_project_form.properties.json
my_project_form/
xml
translations/
messages-xx.properties
Expand Down Expand Up @@ -81,7 +86,6 @@ This tool expects a project to be sctructured as follows:

# TODO

* split app/ and contact/ forms into separate directories
* apply all necessary transforms to contact forms
* only upload things which have changed (this could be a separate mode - e.g. `update` vs `configure`)
* require manual confirmation of upload if url is *.app.medicmobile.org and either git is not available, or the working directory is dirty or has new files
Expand Down
3 changes: 2 additions & 1 deletion bin/medic-conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ if(args.length === 2) {
'convert-forms',
'backup-forms',
'delete-forms',
'upload-forms',
'upload-app-forms',
'upload-contact-forms',
'upload-resources',
'upload-custom-translations',
];
Expand Down
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.24",
"version": "1.0.25",
"description": "Configure Medic Mobile deployments",
"main": "index.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/cli/supported-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ module.exports = [
'compress-images',
'convert-forms',
'delete-forms',
'upload-app-forms',
'upload-app-settings',
'upload-forms',
'upload-contact-forms',
'upload-resources',
'upload-custom-translations',
];
3 changes: 3 additions & 0 deletions src/fn/upload-app-forms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const uploadForms = require('../lib/upload-forms');

module.exports = (project, couchUrl) => uploadForms(project, couchUrl, 'app');
5 changes: 5 additions & 0 deletions src/fn/upload-contact-forms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const uploadForms = require('../lib/upload-forms');

module.exports = (project, couchUrl) => uploadForms(project, couchUrl, 'contact', {
id_prefix: 'contact:',
});
8 changes: 5 additions & 3 deletions src/fn/upload-forms.js → src/lib/upload-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ const PouchDB = require('pouchdb');
const attachmentsFromDir = require('../lib/attachments-from-dir');
const insertOrReplace = require('../lib/insert-or-replace');

module.exports = (project, couchUrl) => {
module.exports = (project, couchUrl, subDirectory, options) => {
const db = new PouchDB(couchUrl);

const formsDir = `${project}/forms`;
if(!options) options = {};

const formsDir = `${project}/forms/${subDirectory}`;
return Promise.all(fs.readdir(formsDir)
.filter(name => name.endsWith('.xlsx'))
.map(xls => {
const baseFileName = fs.withoutExtension(xls);
const formDir = `${formsDir}/${baseFileName}`;
const expectedId = baseFileName.replace(/-/g, ':');
const expectedId = (options.id_prefix || '') + baseFileName.replace(/-/g, ':');

if(!fs.exists(formDir)) {
warn(`No form directory found corresponding to XML ${formDir}`);
Expand Down

0 comments on commit 92646d8

Please sign in to comment.