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

Change census forms to post directly to census tables #19193

Merged
merged 6 commits into from Nov 16, 2017

Conversation

drewsamnick
Copy link
Contributor

These changes will allow us to bypass the pegasus FORMS table and write directly to the census tables.

There are a few parts:

  • New controller to expose the API for the ajax requests to post the data
  • Changes to the /yourschool and HoC census forms to post to the new API and to rename fields and values to be compatible.

This should have no impact to the HoC signup form.

@drewsamnick
Copy link
Contributor Author

@@ -123,8 +123,8 @@ $(document).ready(function () {
});

function checkShowCensusFollowUp() {
if ($("#twenty-hour-how-much").val() === "some" || $("#twenty-hour-how-much").val() === "all" || $("#ten-hour-how-much").val() === "some" ||
$("#ten-hour-how-much").val() === "all") {
if ($("#twenty-hour-how-much").val() === "SOME" || $("#twenty-hour-how-much").val() === "ALL" || $("#ten-hour-how-much").val() === "SOME" ||
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: break this long line up

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. From our styleguide:

Stick to an 80 character line length when possible, except for long URLs in comments or long regular expressions. Occasionally wiggling between 80 and 120 characters is OK in cases where it greatly improves the readability over a multiple line split.

@@ -63,14 +63,14 @@ class CensusForm extends Component {
checkShowFollowUp() {
const twentyHours = this.state.submission.twentyHours;
this.setState({
showFollowUp: (twentyHours === 'some' || twentyHours === 'all')
showFollowUp: (twentyHours === 'SOME' || twentyHours === 'ALL')
}, this.checkShowPledge);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like for HoC signup we also show the follow up questions if tenHours === "ALL". Is that also the case for /yourschool?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They actually have different checks. I'm already changing so much here that I didn't want to change this behavior also.

@@ -207,7 +221,7 @@ class CensusForm extends Component {
const { errors } = this.state;
if (!errors.email && !errors.topics && !errors.frequency && !errors.school && !errors.nces && !errors.role && !errors.hoc && !errors.afterSchool && !errors.tenHours && !errors.twentyHours && !errors.country) {
$.ajax({
url: "/forms/Census2017",
url: "/dashboardapi/v1/census/CensusYourSchool2017v4",
Copy link
Contributor

@Erin007 Erin007 Nov 16, 2017

Choose a reason for hiding this comment

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

should this match line 267 in apps/src/sites/hourofcode.com/pages/public/index.js? What are the different versions of the form?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The different form versions map to different models with different validation. They all write to the same table (census_submission) but with a different value for 'type'. This also allows us to map responses back to which version of the form was used.

@@ -207,7 +221,7 @@ class CensusForm extends Component {
const { errors } = this.state;
if (!errors.email && !errors.topics && !errors.frequency && !errors.school && !errors.nces && !errors.role && !errors.hoc && !errors.afterSchool && !errors.tenHours && !errors.twentyHours && !errors.country) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe tighten with something like:

if (Object.values(errors).every(error => !error)) {
  // Submit...

@@ -300,7 +314,7 @@ class CensusForm extends Component {
)}
</div>
<select
name="hoc_s"
name="how_many_do_hoc"
Copy link
Contributor

Choose a reason for hiding this comment

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

So we don't need the data type _s appended to the name because that's an expectation of Pegasus forms, but not of your new table?

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. I changed the naming in the forms to match the models and controller rather than making the models and controller match the existing form fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

The _s suffixes are for SOLR to understand the data types when we index Pegasus forms. We don't use SOLR on the dashboard side, so don't need it.

@@ -544,7 +558,7 @@ class CensusForm extends Component {
</div>
<input
type="text"
name="name_s"
name="submitter_name"
Copy link
Contributor

Choose a reason for hiding this comment

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

submitter_name and pledged are much clearer than the previous names - thanks for updating 🙂

assert_response 201, @response.body.to_s
response = JSON.parse(@response.body)
refute response['census_submission_id'].nil?, "census_submission_id expected in response: #{response}"
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth testing other variations of submissions beyond school? invalid email, etc?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or confirming schools with punctuation succeed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by "schools with punctuation"?

Copy link
Contributor

@Erin007 Erin007 left a comment

Choose a reason for hiding this comment

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

Looks good to me! A few questions, mostly for my own edification.

@drewsamnick drewsamnick merged commit 0d17472 into staging Nov 16, 2017
@@ -123,8 +123,8 @@ $(document).ready(function () {
});

function checkShowCensusFollowUp() {
if ($("#twenty-hour-how-much").val() === "some" || $("#twenty-hour-how-much").val() === "all" || $("#ten-hour-how-much").val() === "some" ||
$("#ten-hour-how-much").val() === "all") {
if ($("#twenty-hour-how-much").val() === "SOME" || $("#twenty-hour-how-much").val() === "ALL" || $("#ten-hour-how-much").val() === "SOME" ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. From our styleguide:

Stick to an 80 character line length when possible, except for long URLs in comments or long regular expressions. Occasionally wiggling between 80 and 120 characters is OK in cases where it greatly improves the readability over a multiple line split.

@@ -300,7 +314,7 @@ class CensusForm extends Component {
)}
</div>
<select
name="hoc_s"
name="how_many_do_hoc"
Copy link
Contributor

Choose a reason for hiding this comment

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

The _s suffixes are for SOLR to understand the data types when we index Pegasus forms. We don't use SOLR on the dashboard side, so don't need it.

].freeze

# POST /dashboardapi/v1/census/<form_version>
def new_submission
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Any reason we're not using the standard create action?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just lack of awareness on my part. I'll make this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants