Skip to content

Commit

Permalink
Moved the class module in ./scripts/modules/ to ./server/src/modules/;
Browse files Browse the repository at this point in the history
Updated path to modules in group-new.js
Create modules doc
Created translations dir in docs for language-specific translations.
  • Loading branch information
chrisekelley committed Dec 18, 2018
1 parent 9b00e97 commit 091251d
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 44 deletions.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ Welcome to the Tangerine Documentation site. This is an MDWiki hosted on Github

## V3
* [Icons](v3.x.x/icons.md)
* [Modules](modules.md)

42 changes: 42 additions & 0 deletions docs/modules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Tangy Modules

Modules provide two functions:
- forms added to the client when a new group is created
- data transformation for reporting

Steps to add a module
- Forms that need to be copied over to the client should be placed in server/src/modules/moduleName.
- Modify the code in server/src/routes/group-new
- Add new functionality to the client Angular code, if needed.

To modify the data transformation for reports, add an index.js file to your modules directory and follow this code example
to implement the flatFormReponse hook:

```
const DB = require('../../db.js')
const log = require('tangy-log').log
const clog = require('tangy-log').clog
module.exports = {
hooks: {
flatFormReponse: function(data) {
return new Promise((resolve, reject) => {
debugger;
let formResponse = data.formResponse
let flatFormResponse = data.flatFormResponse
if (formResponse.metadata && formResponse.metadata.studentRegistrationDoc && formResponse.metadata.studentRegistrationDoc.classId) {
let studentRegistrationDoc = formResponse.metadata.studentRegistrationDoc
flatFormResponse[`sr_classId`] = studentRegistrationDoc.classId;
flatFormResponse[`sr_student_name`] = studentRegistrationDoc.student_name;
flatFormResponse[`sr_student_id`] = studentRegistrationDoc.id;
flatFormResponse[`sr_age`] = studentRegistrationDoc.age;
flatFormResponse[`sr_gender`] = studentRegistrationDoc.gender;
}
resolve({flatFormResponse, formResponse})
})
}
}
}
```

This code will be automatically run when the TangyModules (server/src/modules/index.js) is run
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,9 @@
"You may not mark an item incorrect that is beyond the last item attempted.": "You may not mark an item incorrect that is beyond the last item attempted.",
"You may proceed.": "You may proceed.",
"Item Title": "Item Title",
"✓ Yay! You are up to date.": "✓ Yay! You are up to date."
"✓ Yay! You are up to date.": "✓ Yay! You are up to date.",
"open": "open",
"close": "close",
"save": "save",
"submit": "submit"
}
14 changes: 0 additions & 14 deletions scripts/modules/class/curricula.json

This file was deleted.

15 changes: 0 additions & 15 deletions scripts/modules/modules.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
<tangy-form has-summary linear-mode hide-closed-items id="class-registration" on-change="" >
<tangy-form-item id="class-registration" title="صف دراسي" hide-back-button hide-next-button on-open="
<tangy-form-item id="class-registration" title="Class Registration" hide-back-button hide-next-button on-open="
function fetchLocal(url) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest
xhr.responseType = 'json';
xhr.onload = function() {
if (xhr.status < 200 || xhr.status >= 300) {
reject({request: xhr});
if (xhr.status === 0) {
if (Array.isArray(xhr.response)) {
resolve(xhr.response)
} else {
reject({request: xhr});
}
} else {
reject({request: xhr});
}
} else {
resolve(new Response(xhr.responseText, {status: xhr.status}))
resolve(xhr.response)
}
}
xhr.open('GET', url)
xhr.send(null)
})
}
async function loadCurricula(that) {
let filePath = './assets/forms.json'
let data;
await fetchLocal(filePath)
.then(async function (datums) {
await datums.json().then(function(json) {
data = json
});
})
let data = await fetchLocal(filePath)
.catch(function (err) {
console.error('Augh, there was an error!', err.request.status);
});
let tcsEl = that.$.content.querySelector('tangy-checkboxes[name=\'curriculum\']')
let cbDiv = tcsEl.$.checkboxes;
cbDiv.innerHTML = ''
Expand All @@ -48,7 +49,6 @@
if (!that.value || (typeof that.value === 'object' && that.value.length < newValue.length)) {
that.value = newValue
}
}
let that = this;
loadCurricula(that);
Expand Down
File renamed without changes.
105 changes: 105 additions & 0 deletions server/src/modules/class/translation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"Accuracy": "Accuracy:",
"Accuracy Level:": "Accuracy Level:",
"An update is available. Be sure to first sync your data before installing the update. If you have not done this, click `Cancel`. If you are ready to install the update, click `Yes`": "An update is available. Be sure to first sync your data before installing the update. If you have not done this, click `Cancel`. If you are ready to install the update, click `Yes`",
"Applying Updates...": "Applying Updates...",
"Are you sure you want to start a form response?": "Are you sure you want to start a form response?",
"Are you sure you would like to exit the form?": "Are you sure you would like to exit the form?",
"Check for Update": "Check for Update",
"Checking For Updates...": "Checking For Updates...",
"Click a Picture": "Click a Picture",
"Click the play button to get started.": "Click the play button to get started.",
"Confirm New Password": "Confirm New Password",
"Confirm Password": "Confirm Password",
"Could Not Create User": "Could Not Create User",
"Could Not Load List Of Forms": "Could Not Load List Of Forms",
"Create Form": "Create Form",
"Date and Time": "Date and Time",
"Docs Not Uploaded": "Docs Not Uploaded",
"Docs Uploaded": "Docs Uploaded",
"Download CSV": "Download CSV",
"EXPORT DATA FOR ALL USERS": "EXPORT DATA FOR ALL USERS",
"Edit Item": "Edit Item",
"Enter your response to above question here": "Enter your response to above question here",
"Export Data": "Export Data",
"File Stored At": "File Stored At",
"Filter": "Filter",
"Form Name": "Form Name",
"Form Title": "Form Title",
"Item Listing": "Item Listing",
"Item Not Found": "Item Not Found",
"LAST ATTEMPTED": "LAST ATTEMPTED",
"LOGIN": "LOGIN",
"Last Successful Sync Timestamp": "Last Successful Sync Timestamp",
"Last attempted cannot be before an item marked.": "Last attempted cannot be before an item marked.",
"Latitude": "Latitude:",
"Loading": "Loading...",
"Login Unsuccesful": "Login Unsuccesful",
"Logout": "Logout",
"Longitude": "Longitude:",
"MARK": "MARK",
"Manage Profile": "Manage Profile",
"Meters": "Meters",
"My Forms": "My Forms",
"New Form": "New Form",
"New Item": "New Item",
"New Password": "New Password",
"No Data for": "No Data for",
"No Forms Currently Defined": "No Forms Currently Defined",
"No Update": "No Update",
"Observations": "Observations",
"Open": "Open",
"Password": "Password",
"Password Reset Unsuccesful": "Password Reset Unsuccesful",
"Percentage Complete": "Percentage Complete",
"RECOVER ACCOUNT": "RECOVER ACCOUNT",
"REGISTER": "REGISTER",
"RESET": "RESET",
"RESET PASSWORD": "RESET PASSWORD",
"Reports": "Reports",
"Response": "response",
"START": "START",
"STOP": "STOP",
"SYNC DATA FOR ALL USERS": "SYNC DATA FOR ALL USERS",
"Save": "Save",
"Save before switching or your changes will be deleted.": "Save before switching or your changes will be deleted.",
"School": "School",
"Searching...": "Searching...",
"Select Form Name": "Select Form Name",
"Select one or more": "Select one or more",
"Select only One": "Select only One",
"Select your Username": "Select your Username",
"Switch Editor": "Switch Editor",
"Sync": "Sync",
"Sync Successful": "Sync Successful",
"Sync Unsuccessful. Please Retry": "Sync Unsuccessful. Please Retry",
"Syncing Status By User": "",
"Syncing Status Summary": "Syncing Status Summary",
"Tangerine": "Tangerine",
"Tap any boxes that were incorrect during the test.": "Tap any boxes that were incorrect during the test.",
"Tap items to mark them incorrect.": "Tap items to mark them incorrect.",
"Tap the item last attempted.": "Tap the item last attempted.",
"Tips": "Tips",
"Total Docs Uploaded": "Total Docs Uploaded",
"Total Docs not Uploaded": "Total Docs not Uploaded",
"Total Percentage Complete": "Total Percentage Complete",
"Total Updates Applied": "Total Updates Applied",
"Try moving outside with a clear view of the sky": "Try moving outside with a clear view of the sky",
"Try standing away from trees or buildings": "Try standing away from trees or buildings",
"Try standing next to a window": "Try standing next to a window",
"Update App": "Update App",
"Update is Running. Please Wait ...": "Update is Running. Please Wait ...",
"Username": "Username",
"Username Available": "Username Available",
"Username Unavailable": "Username Unavailable",
"Visits": "Visits",
"Write Failed": "Write Failed",
"You may not mark an item incorrect that is beyond the last item attempted.": "You may not mark an item incorrect that is beyond the last item attempted.",
"You may proceed.": "You may proceed.",
"Item Title": "Item Title",
"✓ Yay! You are up to date.": "✓ Yay! You are up to date.",
"open": "open",
"close": "close",
"save": "save",
"submit": "submit"
}
2 changes: 1 addition & 1 deletion server/src/routes/group-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = async (req, res) => {
const exists = await fs.pathExists('/tangerine/client/app/src/assets/class-registration')
if (!exists) {
try {
await fs.copy('/tangerine/scripts/modules/class/', '/tangerine/client/app/src/assets/')
await fs.copy('/tangerine/server/src/modules/class/', '/tangerine/client/app/src/assets/')
console.log('Copied class module forms.')
} catch (err) {
console.error(err)
Expand Down

0 comments on commit 091251d

Please sign in to comment.