-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature to download Bahmni form builder forms as a PDF (#76)
* [PrintForm] | Chiran, Natheesh | Add UI for form printer Co-authored-by: Chiranjeewee <[email protected]> * [PrintForm] | Chiranjeewee, Natheeshkumar, Rushikesh, Rachana, Pranav | Fix download url for pdf Co-authored-by: Rachana <[email protected]> | Chiranjeewee Koirala <[email protected]> | Natheeshkumar <[email protected]> | Pranav Sricharan <[email protected]> * [PrintForm] | Chiran, Natheesh | Fix download button status Co-authored-by: Chiranjeewee <[email protected]> * [PrintForm] | Sameera, Priya | Added a new button to download a pdf of a form * Removing extra files * added yarn.lock * Updated. yarn.lock * Fix. test failures * Fix. ESlint Indentation and spacing error --------- Co-authored-by: Natheeshkumar <[email protected]> Co-authored-by: Chiranjeewee <[email protected]> Co-authored-by: RishiHalle <[email protected]> Co-authored-by: Rachana <[email protected]> | Chiranjeewee Koirala <[email protected]> | Natheeshkumar <[email protected]> | Pranav Sricharan <[email protected]> Co-authored-by: praveenadayanand <[email protected]> Co-authored-by: SanoferSameera <[email protected]>
- Loading branch information
1 parent
e4b8159
commit 04352c7
Showing
10 changed files
with
421 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React, { Component } from 'react'; | ||
import FormBuilderHeader from 'form-builder/components/FormBuilderHeader.jsx'; | ||
import PdfList from 'form-builder/components/PdfList.jsx'; | ||
import { httpInterceptor } from 'common/utils/httpInterceptor'; | ||
import { formBuilderConstants } from 'form-builder/constants'; | ||
|
||
class FormPrinterContainer extends Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
selectedFile: '', | ||
downloadLink: '', | ||
importBtnStatus: '', | ||
status: 'Processing', | ||
}; | ||
this.onFileChange = this.onFileChange.bind(this); | ||
this.onFileUpload = this.onFileUpload.bind(this); | ||
} | ||
onFileChange(event) { | ||
event.preventDefault(); | ||
this.setState({ selectedFile: event.target.files[0] }); | ||
} | ||
|
||
onFileUpload(event) { | ||
let file = this.state.selectedFile; | ||
this.setState({ importBtnStatus: 'clicked' }); | ||
const self = this; | ||
const reader = new FileReader(); | ||
// eslint-disable-next-line | ||
reader.onload = function () { | ||
try { | ||
const formData = JSON.parse(reader.result); | ||
httpInterceptor.post(formBuilderConstants.jsonToPdfConvertionUrl, formData).then((response) => { | ||
let fileName = response.pdfName; | ||
let link = formBuilderConstants.pdfDownloadUrl + fileName; | ||
self.setState({ downloadLink: link }); | ||
self.setState({ status: 'Completed' }); | ||
}); | ||
} catch (error) { | ||
self.setState({ status: 'Error' }); | ||
} | ||
}; | ||
reader.readAsText(file); | ||
} | ||
|
||
|
||
render() { | ||
return ( | ||
<div> | ||
<div> | ||
<FormBuilderHeader /> | ||
</div> | ||
<div className="breadcrumb-wrap"> | ||
<div className="breadcrumb-inner"> | ||
<div style={{ display: 'flex', flexWrap: 'nowrap' }}> | ||
<label htmlFor="jsonName" style={{ paddingTop: '5px', marginRight: '10px' }}>Import JSON file:</label> | ||
<input type="text" id="jsonName" name="jsonName" value={this.state.selectedFile.name} readOnly /> | ||
<label htmlFor="files" className="button">Add</label> | ||
<input id="files" style={{ visibility: 'collapse' }} type="file" accept=".json" onChange={this.onFileChange} /> | ||
{this.state.selectedFile != '' && <button className="btn--highlight" onClick={this.onFileUpload}> | ||
Import | ||
</button>} | ||
|
||
</div> | ||
</div> | ||
|
||
{this.state.importBtnStatus != '' && <div> | ||
<div className="container-content-wrap"> | ||
<div className="container-content"> | ||
<div className="container-main form-list"> | ||
<h2 className="header-title">Generated PDF's</h2> | ||
<PdfList downloadLink={this.state.downloadLink} status={this.state.status} /> | ||
</div> | ||
</div> | ||
</div> | ||
</div>} | ||
|
||
</div> | ||
</div > | ||
); | ||
} | ||
} | ||
export default FormPrinterContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React, { Component } from 'react'; | ||
|
||
export default class FormList extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.downloadFile = this.downloadFile.bind(this); | ||
} | ||
downloadFile() { | ||
window.open(this.props.downloadLink); | ||
} | ||
render() { | ||
return ( | ||
<div> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Form Status</th> | ||
<th>Action</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
|
||
<tr > | ||
<td>{this.props.status}</td> | ||
<td> | ||
<button onClick={this.downloadFile} disabled={this.props.status != 'Completed'} >Download</button> | ||
</td> | ||
</tr> | ||
|
||
</tbody> | ||
</table> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.