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
Implement initial integration with enketo-core to display complex emb… #563
Conversation
…edded surveys The form is displayed inline in the main app, so it can be manipulated much more easily. In particular: - both the form and the model are javascript objects passed in to a function so can be manipulated at will to customize the survey for a particular user. - The result is also retrieved in the form, so results can be reflected immediately in the UX The form is currently displayed as a view in the metrics tab, with its own state. I considered making it a popover instead, but wasn't sure that the smaller width would work for the survey. I might experiment with that in a future change. The main changes to the app itself are to the main.js to define the new state, and a new survey launcher `enketo_launch.js` that is the controller for the new state. The rest of the code is to check in the enketo javascript libraries. It is theoretically possible to install them via `npm install` and then use `rollup` or `webpack` to create the bundle. But we don't really have a gruntfile or other build mechanism to invoke the rollup/webpack, and ES6 imports don't necessarily play nice with angular 1. For example, when I tried using `import { Form } from `enketo-core`, angular complained about the import. Also, the resulting bundle file did not include an export for `Form` since rollup inlines functions where possible. I had to manually add `window.FormModule` to the javascript file to allow it to be used from the rest of the app. Given all this, I decided to check in enketo-core as a `manual_lib`. This change can be tested by applying the following patch, although it is pretty kludgy. Long-term, individual projects need to determine where they want to launch the test from. Also includes a couple of sample JSON files for testing. The input to the library is the enketo paper formatted JSON files. They can be obtained using the following process: - Create the form using kobotoolbox https://github.com/kobotoolbox/ or https://build.opendatakit.org/ This will let you download an xlsform - Convert xlsform -> xml form using http://xlsform.opendatakit.org/ - Convert xml form -> enketo paper format form + model using enketo-transformer. The curl option works fine - I used it with requests - Copy the json files into www/json - Launch them by passing the JSON file as a parameter while changing state, as in `metrics.js` below ``` diff --git a/www/js/metrics.js b/www/js/metrics.js index d80e81d7..e7e4a3d3 100644 --- a/www/js/metrics.js +++ b/www/js/metrics.js @@ -35,6 +35,13 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date $scope.onCurrentTrip(); }); + $scope.testSurvey = function() { + $state.go("root.main.enketosurvey", { + form_location: "json/enketo-survey-sample-full.json" + }); + } + + // If we want to share this function (see the pun?) between the control screen and the dashboard, we need to put it into a service/factory. // But it is not clear to me why it needs to be in the profile screen... var prepopulateMessage = { diff --git a/www/templates/main-metrics.html b/www/templates/main-metrics.html index 124e95d9..923e0d05 100644 --- a/www/templates/main-metrics.html +++ b/www/templates/main-metrics.html @@ -10,6 +10,9 @@ <button class="button button-icon" ng-click="doRefresh()"> <i class="icon ion-refresh"></i> </button> + <button class="button button-icon" ng-click="testSurvey()"> + TEST SURVEY + </button> </ion-nav-buttons> <ion-content class="has-header"> <div style="height: 40px; width: 100%; padding: 10px;" ng-if="uictrl.showVis"> <!-- visualization control --> ```
This fixes e-mission/e-mission-docs#376 |
Note that the embedded surveys share a limitation with all enketo smart paper based surveys on recent android and iOS. It looks like for the geopicker widget, maps are not displayed for picking a location - only the lat/lng fields can be typed into. This is true of the embedded survey, the IAB and chrome on android. I have filed enketo/enketo#209 for upstream to address it. While try other hacks if they can't fill it. I am not quite sure whether you really need the geowidget, given that you already have trajectories and places available for the user.
If not, you may want to use forms that don't have a geo/map component. |
See attached video of the current functionality |
This required some deep digging into the bowels of both enketo and ionic code, but it works now. Please see e-mission/e-mission-docs#376 for way more detail than can fit here :) At this point, the survey is displayed in the e-mission app in the same way as in a mobile browser, but returns values to the app on validation.
Not sure why this didn't show up in the devapp, but I guess the devapp process rewrites the index to be more promiscuous. The real apps do honor the CSP, so we couldn't load some logos and map tiles properly. e-mission/e-mission-docs#376 (comment) These fixes were discussed in e-mission/e-mission-docs#376 (comment) and fortunately, they work!
@asiripanich, I have merged these fixes to https://e-mission.eecs.berkeley.edu/#/client_setup?new_client=martanetworksp18&clear_usercache=true&clear_local_storage=true so you can get a sense of what the surveys may look like before they are merged to your channel. And it was good that I did, because I found and fixed e781d99 which was not visible in the devapp. To test the form, you can click on the "TEST SURVEY" button at the top of the metrics tab. The "TEST SURVEY" button is clearly just a placeholder. Now that you have this example, you might want to think about what surveys you want, and where you want to launch them from, so that @atton16 can implement the changes specific to your use case. |
Also, @asiripanich once you are done with deciding how to use this for your use case, can you please contribute documentation on how to do so? Please ensure that this is integrated into the existing documentation and not a separate throwaway file as in e-mission/e-mission-docs#47 This is a third kind of data input, so it will probably go in here, potentially with a link to more details as for the external surveys. |
I merged the changes from shankari:xlsform_survey_support and it appears that the css from
However, I have not yet test the core functionality of the new I will get back as soon as I get some results. |
@shankari Can you please give me a tips on how to do auto reload during the development?? It is difficult to force close the app and reconnect with the UI server every time I modified the code. |
Ran some tests on Android Emulator. I got these:
|
@atton16 all of these are changes to the visual appearance, not to the functionality. I suspect they are related to the new css tags that come with the survey - just like how all the links are now red instead of blue. It should be pretty easy to change them by editing the survey css to only apply to elements within the survey div. I generally don't mess with the css, since theoretically every channel can modify their own L&F. As I said in e-mission/e-mission-docs#376 (comment)
Not sure what you mean by this. Can you clarify? "x doesn't work" is not as helpful as "when I do x, y happens". Since this is functionality, if it is indeed broken, I will undertake to fix this.
Again, can you provide more details of how/why this is not working? It works just fine for me (see attached video). |
I tried this out on iOS and I see what you mean. Fortunately, stackoverflow comes to the rescue. It works now on both (see attached video). |
This fixes e-mission#563 (comment) using a suggestion from https://stackoverflow.com/a/37231467 Fix was trivial, we just had to add `overflow-scroll="true"` to the `ion-content` Fix documented in e-mission#563 (comment)
Oh, I can see that your The step looks simple enough with I have been doing a Modify-Force Exit-Launch-Connect loop for months and thought that this is normal. I am not certain what I might have missed at this point. |
@atton16 can we pull out the devapp questions into their own issue since they seem a bit involved and are not really related to this PR? |
Not sure what is wrong but I cannot open a new issue on this repo. Is is okay if I open a new issue on |
|
For the broken UI, after inserting two enketo-related css files, I did try to put all selectors under It turns out that it resolved all of the UI issues except the total shift up in iOS devices. I will try something else and come back again. |
how bad is the total shift up in iOS devices? |
@atton16 I am testing enketo/enketo#235 with iOS now and I see the displacement even on that branch, which does not have any of the enketo changes. Are you sure this is not just something in master - i.e. are you sure that it did not have this displacement before? |
@atton16 I take that back, the list view looks fine on enketo/enketo#235. And actually, on this branch as well. See screenshots below. The arrows are still messed up because I don't have your changes, but the screen is not displaced. IIRC, when I saw the displaced screen, there was an error during page load, which complicated the rendering; you may want to look at your debugger to see if you can find anything.
|
Can you send out a PR or a patch with your css changes? I can apply them to my branch, see if I still see the displacement, and if not, merge to master. Then you can always just recreate your branch from master if you are not able to get the spacing right. |
Wait, the gist has you making changes to the print view
As far as I know, |
Done enketo/enketo#308 |
I merged the css changes from enketo/enketo#308 and can still reproduce the issue with the displacement. But, and this is interesting, the displacement happens only when the survey is launched. See attached video - when the app is first launched, the UX is not displaced. Then when the survey is launched, there's the additional line at the bottom. |
I tried to compare the html before and after loading the survey and could not find substantial differences. I then loaded the form in a browser, and noticed that the page scrolled to hide the page navigation at the top. I wonder if this displacement is happening in javascript... |
ok so I added multiple breakpoints in the javascript, and the line that causes the displacement is
|
After some more breakpointing and digging deeper into the rabbit hole, I narrowed it down to this line. We scroll the page until |
It turned out to be due to the enketo paging module scrolling to show the page element that needs the focus. Since we are using ionic scrolling, it looks like it already scrolls to show the top element, which works. Please see the next 5-6 comments after e-mission#563 (comment) This doesn't _seem_ to break anything, but let me know if it does!
…e-mission-phone into xlsform_survey_support
Commenting out that line - e.g.
fixes the issue |
@asiripanich, updated https://e-mission.eecs.berkeley.edu/#/client_setup?new_client=martanetworksp18&clear_usercache=true&clear_local_storage=true |
Follow on to af94688 This time, it is to scroll to the location with errors
@shankari the survey looks good. Scrolling is no longer an issue. However, I found a UI bug that I haven't been able to replicate. The bug caused the back button to Dashboard disappear. |
Hm, was that in the devapp or in the test channel? If it is in the devapp, I am pretty sure I know the reason [1]. If in the test channel, yeah would be good to remember what you did to reproduce. $angularStateProvider (which is what we use for tabs) is pretty stable. Also, I currently have the survey as a second view in the dashboard tab since I wanted to get a Proof of Concept working. It can definitely be a second view in a different tab (e.g. diary/profile) or in a tab of its own. Are you even going to have the dashboard in your version of the app? I think we need to figure that out along with where the survey should be launched from, the contents of the survey,.... [1] if you edit a file and cause the app to reload when you are on the survey page, then the survey is the first page loaded in that view, and so there is no there is no back button to the "previous" dashboard page. |
@shankari I have just realised that you didn't merge this into main! what was your reason? :) after all these great efforts you put in. |
@asiripanich I didn't merge it into master because it is not complete. @atton16 picked this up and implemented additional changes on top. I think that merging the survey framework code into master is a great idea, but it needs to be cleaned up and made modular. |
…edded surveys
The form is displayed inline in the main app, so it can be manipulated much
more easily. In particular:
can be manipulated at will to customize the survey for a particular user.
immediately in the UX
The form is currently displayed as a view in the metrics tab, with its own
state. I considered making it a popover instead, but wasn't sure that the
smaller width would work for the survey. I might experiment with that in a
future change.
The main changes to the app itself are to the main.js to define the new state,
and a new survey launcher
enketo_launch.js
that is the controller for the newstate.
The rest of the code is to check in the enketo javascript libraries. It is
theoretically possible to install them via
npm install
and then userollup
or
webpack
to create the bundle. But we don't really have a gruntfile orother build mechanism to invoke the rollup/webpack, and ES6 imports don't
necessarily play nice with angular 1. For example, when I tried using
import { Form } from
enketo-core`, angular complained about the import.Also, the resulting bundle file did not include an export for
Form
sincerollup inlines functions where possible. I had to manually add
window.FormModule
to the javascript file to allow it to be used from the restof the app.
Given all this, I decided to check in enketo-core as a
manual_lib
.This change can be tested by applying the following patch, although it is
pretty kludgy. Long-term, individual projects need to determine where they want
to launch the test from.
Also includes a couple of sample JSON files for testing.
The input to the library is the enketo paper formatted JSON files.
They can be obtained using the following process:
enketo-transformer. The curl option works fine - I used it with requests
metrics.js
below