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

[Survey module] Make public module #3609

Closed
wants to merge 49 commits into from

Conversation

jstirling91
Copy link
Contributor

This pull request creates a public module structure for the survey module. It redesigns the old version to use React using API like calls to retrieve, partially save and validate forms.

@@ -0,0 +1,60 @@
<?php
/**
* Implements the main LORIS user login page to handle authentication
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment and the one below should be updated

static function formatElement($element, $elName)
{
$tempElement = array(
"Type" => $element['type'],
Copy link
Contributor

Choose a reason for hiding this comment

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

How do you make sure the key 'type' exists in the array?
Is the function intended to "eat" LorisFormElement ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this class is designed so that it could hypothetically replace the current way we convert the instrument to JSON for the API. The inputted element is expected to be in the format outputted by LorisForm which as far as I know always has the type set.

Copy link
Contributor

@xlecours xlecours May 8, 2018

Choose a reason for hiding this comment

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

Could you type hint $element to \LorisFormElement?


}

?>
Copy link
Contributor

Choose a reason for hiding this comment

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

remove that line please.

*/
function getReactReview()
{
$DB = Database::singleton();
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use NDB_Factory->database()

import Page from './DirectEntryForm';

/*eslint-disable */
class DirectEntry extends React.Component {
Copy link
Contributor

Choose a reason for hiding this comment

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

The indentation should be 2 spaces

Copy link
Contributor Author

Choose a reason for hiding this comment

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

2 spaces is only used to reduce size of javascript files. Since this is compiled into a minified file I feel like 4 spaces is better suited as it aligns with our standards for php along with making this file easier to read

Copy link
Contributor

Choose a reason for hiding this comment

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

But 4 spaces do not align with our JSX standard and make files harder to read

// Since the Instrument data is set when the component is
// mounted we want to display nothing until it has been set
return (
<div></div>
Copy link
Contributor

Choose a reason for hiding this comment

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

A loading span would be nice.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am making a Loader Component I hope to make a pull request for soon.

</div>
)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

please add proptypes so that reviewData is described properly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Default props would also be useful.

render() {

let questions = this.props.reviewData.questions.map((element) => {
console.log(element);
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be removed

let questions = this.props.reviewData.questions.map((element) => {
console.log(element);
return (
<tr className='reviewPage'>
Copy link
Contributor

Choose a reason for hiding this comment

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

missing key prop


componentWillMount() {

$.ajax({
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be done in ComponentDidMount because ComponentWillMoiunt is done just before the first render and this.setState might not trigger a second rendering whit the new state. Otherwise, the method name is now UNSAFE_componentWillMount()

* @license Loris license
* @link https://www.github.com/aces/Loris/
*/
class DirectDataEntryMainPage
Copy link
Contributor

Choose a reason for hiding this comment

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

htdocs/survey.php still exists

Copy link
Collaborator

@HenriRabalais HenriRabalais left a comment

Choose a reason for hiding this comment

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

Need some clarifications and changes.


unset($Values['CommentID']);
unset($Values['UserID']);
// unset($Values['Testdate']);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this meant to be un-commented eventually, or should it be removed?


$this->tpl_data['Values'] = json_encode($Values);

echo json_encode($this->tpl_data);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the entirety of $this->tpl_data is being json_encoded, is the json_encode on 129 necessary? I believe json_encode works recursively.

dataType: 'json',
success: function(data) {
const InstrumentJSON = JSON.parse(data.InstrumentJSON);
const Values = JSON.parse(data.Values);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should these be parsed? Are they not already encoded before being returned by the ajax call and therefore already in the proper format to be set as JSON objects?

// Since the Instrument data is set when the component is
// mounted we want to display nothing until it has been set
return (
<div></div>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am making a Loader Component I hope to make a pull request for soon.

class ReviewPage extends React.Component {
constructor(props) {
super(props);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

If no functions need to be bound or state's set, then the constructor can be removed.

</div>
)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Default props would also be useful.

/**
* This is used by the Loris survey module to retrieve the email
* template for the current instrument. It is used in the survey_accounts
* page via AJAX to update the email template with the current page
Copy link
Contributor

Choose a reason for hiding this comment

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

missing ending dot


/**
* Handles a request by delegating to the appropriate
* handle method
Copy link
Contributor

@PapillonMcGill PapillonMcGill Jun 26, 2018

Choose a reason for hiding this comment

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

should have an ending dot to stay consistant with other comments

$values = array();

foreach ($temp->questions as $value) {
// $this->form->directValues[$value->SourceField] = $value->response;
Copy link
Contributor

Choose a reason for hiding this comment

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

To be deleted?

/**
* This file contains React component for Direct Data Entry
*
* @author Jordan Stirling (StiringApps ltd.)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about advertising in the codebase... but in any case you've got a typo here 😸

@johnsaigle
Copy link
Contributor

@jstirling91 in general we are trying to use return type declarations for new PHP code.

Would you be able to add these to your function signatures? Should be quick. given that they're already documented with return types.

@driusan driusan added the Needs Maintainer PR owner is no longer involved in it. PR is up for adoption by a new developer label Oct 16, 2018
@HenriRabalais
Copy link
Collaborator

@driusan @ridz1208
This seems to need a maintainer, but also considerable work before being merged (such as making sure we are using loris end-points and refactoring the jsx). It appears that a lot of the changes made here may already be deprecated. It may be best to simply close this PR and address this module in another PR.

@ridz1208
Copy link
Collaborator

@zaliqarosli lets talk about this one

@samirdas
Copy link
Contributor

This needs to be discussed with Dave, Rida, Tom Beaudry.

@sruthymathew123
Copy link
Contributor

Had a meeting with @driusan @thomasbeaudry & @driusan regarding how to handle this PR;
In light of that, I shared the latest survey module code and advised him some of the steps to refactor this PR.

@driusan driusan added Needs Work PR awaiting additional changes by the author or contains issues that the author needs to fix Needs Rebase PR contains conflicts with the current target branch or was issued to the wrong branch and removed Needs Maintainer PR owner is no longer involved in it. PR is up for adoption by a new developer labels Jan 28, 2019
@ridz1208
Copy link
Collaborator

ridz1208 commented Feb 1, 2019

See related Issue for status of this

@ridz1208 ridz1208 closed this Feb 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Rebase PR contains conflicts with the current target branch or was issued to the wrong branch Needs Work PR awaiting additional changes by the author or contains issues that the author needs to fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants