Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JotForm API client, translation, and question helper classes. #22474

Merged
merged 2 commits into from May 18, 2018

Conversation

aoby
Copy link
Contributor

@aoby aoby commented May 17, 2018

This PR contains a self-contained set of classes in dashboard/lib to interact with JotForm's API, parse questions and submissions, serialize to/from a question format we can store in the DB (as JSON) and use to process answers.

The JotForm answer data alone is insufficient until it's combined with the question data.

There is a bit of complexity with, and differences between, the various types of questions we want to support and how JotForm describes them, so I have created a Question class hierarchy that should make that easier to reason about and test. There are a number of extraneous fields in the JotForm question data that we don't need (formatting, redundant with other fields, etc) that are ignored and not mentioned in this PR. This also should help simplify things.

This will be used for workshop daily surveys and their facilitator-specific questions in a set of forthcoming additional PRs, and it's also flexible enough to be used in future JotForm-based forms with minimal additional code.

@@ -0,0 +1,61 @@
module Pd
module JotForm
class MatrixQuestion < QuestionWithOptions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give an example of a matrix question in a comment here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


# Hash includes other, in form {'0' => value1, '1' => value2, ..., 'other' => otherText}.
# Note "other" can be chosen and blank, in which case we use the other text from the question.
values_with_other = answer.map {|k, v| k == 'other' ? v.presence || other_text : v}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 'other' provided by jotform? Suggest making it a const up top

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is provided by JotForm, and it seems to be hardcoded, independent of the otherText which is the placeholder we can set. I'll add a const

options: %w(From To),
values: [1, 2, 3]
),
MatrixQuestion.new(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer this to look like the actual matrix questions - with the text
"I feel..."
and name "like this course is good", "like I learned a lot"...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

…none, referenced as parent in the sub questions.
Copy link

@clareconstantine clareconstantine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks well organized and thought out. :)

@aoby aoby merged commit 33afae1 into staging May 18, 2018
@aoby aoby deleted the jotform-translation branch May 18, 2018 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants