Skip to content

Commit

Permalink
Merge pull request #225 from OpenFn/form-sharing-archivedForms
Browse files Browse the repository at this point in the history
Form sharing updates for archived forms
  • Loading branch information
aleksa-krolls authored Aug 17, 2024
2 parents 95af4e0 + 004a26d commit 96abd5b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions form-sharing/3-updateSheetsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,21 @@ fn(state => {
//projectId(form.name), //for GRM only
//grmID(form.name), //for GRM only
form.deployment__active ? 'deployed' : 'archived', //deployment status //if we assume only deployed forms will be fetched
workspaceName(form.name), //openfn project space
form.url,
'ConSoSci', //openfn project space --> OLD dynamic mapping: //workspaceName(form.name),
`https://kf.kobotoolbox.org/#/forms/${form.url}/summary`, //form.url,
form.date_modified, //kobo_form_date_modified
form.date_created, //kobo_form_date_created
new Date().toISOString(), //row_date_modified
false, //auto_sync checkbox
//job code template
`{id: '${form.uid}', tag: '${createTagName(form.name)}', name: '${
form.name
}', owner: '${form.owner__username}', instance: '${instance(form.name)}'},`,
];

state.rowValuesToCreate = formsToCreate.map(form => sheetRowMap(form));
state.rowValuesToUpdate = formsToUpdate.map(form => ({
range: `wcs-bns-test!A${form.rowIndex + 2}:N${form.rowIndex + 2}`,
range: `wcs-bns-DEPLOYED!A${form.rowIndex + 2}:N${form.rowIndex + 2}`,
values: [sheetRowMap(form)],
}));

Expand All @@ -66,13 +70,14 @@ fn(state => {
return state;
});

//if new Kobo form shared, adding to the Google Sheet...
//if new Kobo form shared, adding to the "Deployed"" Sheet...
appendValues({
spreadsheetId: '1s7K3kxzm5AlpwiALattyc7D9_aIyqWmo2ubcQIUlqlY', //sheet id
range: 'wcs-bns-test!A:N', //range of columns in sheet
range: 'wcs-bns-DEPLOYED!A:O', //range of columns in sheet
values: state => state.rowValuesToCreate,
});

//updating rows in Sheet where forms are archived
each(
'$.rowValuesToUpdate[*]',
batchUpdateValues({
Expand All @@ -81,3 +86,10 @@ each(
values: state => state.data.values,
})
);

//also adding archived rows to "Archived" Sheet...
appendValues({
spreadsheetId: '1s7K3kxzm5AlpwiALattyc7D9_aIyqWmo2ubcQIUlqlY', //sheet id
range: 'wcs-bns-ARCHIVED!A:O', //range of columns in sheet
values: state => state.rowValuesToUpdate,
});
2 changes: 1 addition & 1 deletion form-sharing/4-upsertAsanaTask.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//This job will add a task to Asana if a new Kobo form was shared
//This job will add a task to Asana if a new Kobo form was shared
fn(state => {
const dueDate = new Date(new Date().getTime() + 5 * 24 * 60 * 60 * 1000)
.toISOString()
Expand Down

0 comments on commit 96abd5b

Please sign in to comment.