I'm looking for a conceptual approach to a problem.
I'm building a web app that imports data from a source I don't control. The data quality is pretty high, but occasionally, the data does not make sense. So I want to expose the exceptions (based on data rules) to users in a modal so that they can accept the funky data or change it before committing.
The app has been developed so far to behave like this:
- while importing data, transactions are validated
- transactions that do not validate are accumulated in a php array (aka "exceptions_arr")
- in some cases intelligence in the code proposes a solution to "bad" data fields (based on related data) and adds these suggestions to the "exception" record (but does not replace the original imported data)
- then before completing the import, the exception records (and proposed fixes) are exposed to the user in a modal, one at a time
- for each record, the user decides: skip it, accept the original data or edit the record and save it (which will, of course, be validated again for security reasons)
Goal:
Create a user experience IN THE MODAL: display an exception, submit the user's decision and/or edits, record that data on the backend, send a confirming message, then serve up the next exception by replacing the body of the modal. Bonus if the underlying page is updated (with some counter stats) based on the decisions made.
Question: how to do this?
It's the looping through the exceptions that I'm having trouble with. My approach so far has been to: a) set and display the modal with an empty structure (done, no issues) b) create the tbody of the table with the first exception data (done, no issues) c) capture the appropriate data (none, old, proposed/edited) when the user submits his/her decision (done, no issues)
Current approach:
Currently I am POSTing the user's decision data to the host page via ajax, and handling the resulting user decision/POST just fine - once. The problem is that this POST back to the page that launched the modal blows away the accumulated exception_arr.
I have searched how to loop through the data one record at a time and halt the process when each exception is found (and pop open a fresh modal and collect the user's decision), but alas jquery/javascript/php code isn't easily halted and resumed. When the user decision is POSTed, the launching page still restarts (from the beginning).
Is using SESSION storage a good approach? Read all exceptions into the DOM and then process?