WIP: Ajouter la possibilité d'exporter l'estimation en PDF #1

Draft
tcornaut wants to merge 4 commits from feature/export-pdf into develop
2 changed files with 40 additions and 11 deletions
Showing only changes of commit 47020f7beb - Show all commits

View File

@ -12,14 +12,49 @@ const ExportTab: FunctionalComponent<ExportTabProps> = ({ project }) => {
route(`/pdf/${uuid}`);
};
const showFile = (blob:any) => {
var newBlob = new Blob([blob], {type: "application/pdf"})
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(newBlob);
return;
}
const data = window.URL.createObjectURL(newBlob);
var link = document.createElement('a');
link.href = data;
link.download=project.label+".pdf";
link.click();
setTimeout(function(){
window.URL.revokeObjectURL(data);
}, 100);
}
const options = {
projectURL: `//${window.location.host}/export/projects`,
}
const exportPdf = () => {
return fetch(`${options.projectURL}/${project.id}`, {
method: 'GET',
}).then(r => r.blob())
.then(showFile);
};
return (
<div>
<label class="label is-size-4">Format PDF</label>
<div class="field">
<button class="button is-primary"
onClick={displayPdf}>
Aperçu PDF
</button>
<button class="button is-default"
onClick={displayPdf}>
Aperçu PDF
</button>
</div>
<div class="field">
<a class="button is-primary"
onClick={exportPdf}>
Exporter PDF
</a>
</div>
<hr />
<label class="label is-size-4">Format JSON</label>

View File

@ -119,12 +119,6 @@ func handleExportProject(w http.ResponseWriter, r *http.Request) {
log.Fatal(err)
}
// Write buffer contents to file on disk
err = pdfg.WriteFile("./sample.pdf")
if err != nil {
log.Fatal(err)
}
rsp, err := writePDF(w, http.StatusOK, pdfg.Bytes())
if err != nil {
panic(errors.Wrap(err, "could not write pdf response"))
@ -307,7 +301,7 @@ func writeJSON(w http.ResponseWriter, statusCode int, data interface{}) error {
}
func writePDF(w http.ResponseWriter, statusCode int, data []byte) (int, error) {
w.Header().Set("Content-Disposition", "attachment; filename=foo.pdf")
w.Header().Set("Content-Disposition", "attachment; filename=estimation.pdf")
w.Header().Set("Content-Type", "application/pdf")
w.WriteHeader(statusCode)