Skip to content
This repository has been archived by the owner on Oct 6, 2021. It is now read-only.

Update export #43

Closed
wants to merge 4 commits into from
Closed

Update export #43

wants to merge 4 commits into from

Conversation

srbennett29
Copy link
Contributor

@srbennett29 srbennett29 commented Mar 10, 2020

Updated export capability to include:

  • Merging the separate Export buttons into a single "Export to..." drop-down button.
  • Updated the PDF export functionality to use a join query to get sentences from the database.
  • Updated the PDF export functionality to highlight found sentences in the PDF document.
  • Added Export to Word capability

Merging of the Export buttons into a single drop-down button required modification of the webapp/html/columns.html file.

Updating the PDF export functionality to use a join query required modification to the "PDF_export" method in the handlers/web_api.py file and creating a new method "build_sentences_for_export" in the service/data_svc.py file. The "build_sentences_for_export" method uses two join queries to retrieve the sentence and sentence hits data from the database and return the data to the "pdf_export" method.

Updating the PDF export functionality to highlight found sentences in the PDF document generated required modification to the "pdf_export" method in the handlers/web_api.py file to add a style attribute to the sentence object. This style attribute was interpreted by the PDF make library to bold the sentence rather than highlight the sentence in the PDF document.

Adding the Export to Word capability required the following steps:

  • Added the "Export to Word" option to the "Export to..." drop-down button
  • when the "Export to Word" option is selected, the jquery getJSON method is called to make a GET request to "/export/word/{file}",
  • this request is sent to the "word_export" method in the handlers/web_api.py file to query the database and create the JSON object containing the sentence data.
  • The JSON object is returned in the response and passed to the "exportToWord" method in the webapp/theme/scripts/basic.js file
  • The "exportToWord" method makes a jquery ajax POST request to "/export/word/doc"
    Note: This separate ajax POST request is required because the server method returns binary data not JSON data
  • this request is sent to the "export_to_word" method in the handlers/web_api.py file to build the docx Document object from the sentence data
  • The "export_to_word" method returns the Document object as a binary byte array in the response
  • The binary byte array returned to the "exportToWord" is passed to the "downloadWord" to be downloaded by the browser as a Word document
    Note: The two separate jquery ajax requests should be combined into a single request, but I did not want to dramatically change the way the application works, i.e. one method to get the JSON object data and another to generate the output, especially since the api is currently being revised.

To test, enter a report url and title, click "Submit", when the report appears in the "Needs Review" card, click "Analyze" to bring up the analysis/edit page.
On the analysis/edit page, click the highlighted sentences to see the techniques found for that sentence, and click the "Accept" button to confirm the technique.
After going through the report and confirming techniques found, click the "Export to.." drop-down button and select "Export to PDF" or "Export to Word" to generate and download the document

@MarkDavidson
Copy link
Contributor

Hi @srbennett29. Thank you for the substantive PR and please accept my apologies that it has taken so long to respond. TRAM has been re-architected and moved to https://github.com/center-for-threat-informed-defense/tram, which unfortunately means that not all of this PR aligns to the new code base. The new code includes includes many improvements but does not completely address the spirit of this PR.

For full disclosure, here is the current disposition of each proposed change:

Thank you again for your time and effort. I hope the new TRAM represents an improvement for you/

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

Successfully merging this pull request may close these issues.

2 participants