This PR fixes the bug that was causing an empty filterLists object on exported documents. I identified that the issue was caused by these lines in the annotations controller:
if params[:document_id]
loadOptions[:uri] = request.base_url + '/documents/' + params[:document_id]
end
This PR updates the statement to use the URL from the user's browser. It uses regex to replace the json stuff at the end to get the main URL of the document:
if params[:document_id]
loadOptions[:uri] = request.url.sub(/\/annotations\/field\/.*.json$/, '')
end
There's probably a better way to do this than regex, but it works.
Testing
I've tested this myself with a local document, but we will need to test thoroughly on staging and probably again once it's deployed to production.
Add a document to an anthology.
Add a few annotations to the anthology, including tags and categories on some of them.
Click the button to take a snapshot of the document:
Click the "Download HTML" button just below that and Slack it to me.
What this PR does
This PR fixes the bug that was causing an empty
filterLists
object on exported documents. I identified that the issue was caused by these lines in the annotations controller:This constructs the URL that is used in the database query to fetch related annotations. The problem was that there may be multiple versions of a document, e.g. a version saved at https://studio.covecollective.org/documents/portrait-of-mr-wh-the-adf1eb34-30b4-4467-93f0-e3c88f72ee70 and an anthology version at https://studio.covecollective.org/anthologies/wh-team-draft/documents/portrait-of-mr-wh-the-adf1eb34-30b4-4467-93f0-e3c88f72ee70. The above lines of code would always construct the first URL, so it would fetch incorrect or missing data.
This PR updates the statement to use the URL from the user's browser. It uses regex to replace the json stuff at the end to get the main URL of the document:
There's probably a better way to do this than regex, but it works.
Testing
I've tested this myself with a local document, but we will need to test thoroughly on staging and probably again once it's deployed to production.