Adds export as Docx functionality on Datsets

This commit is contained in:
Diamantis Tziotzios 2019-03-26 16:45:27 +02:00
parent 1157a90d79
commit 1f643cda9a
5 changed files with 39 additions and 2 deletions

View File

@ -80,6 +80,21 @@ public class DatasetWizardController extends BaseController {
return this.datasetManager.getDocument(id, visibilityRuleService, contentType);
}
else if (contentType.equals("application/msword")){
File file = datasetManager.getWordDocument(this.environment, id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
InputStream resource = new FileInputStream(file);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(file.length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + file.getName() + ".docx");
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
byte[] content = IOUtils.toByteArray(resource);
return new ResponseEntity<>(content,
responseHeaders,
HttpStatus.OK);
}
else {
DatasetWizardModel dataset = this.datasetManager.getSingle(id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetWizardModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset));

View File

@ -45,6 +45,11 @@ export class DatasetWizardService {
return this.httpClient.get(this.actionUrl + 'getPDF/' + id, { responseType: 'blob', observe: 'response', headers: this.headers });
}
public downloadDOCX(id: string): Observable<HttpResponse<Blob>> {
let headerDocx: HttpHeaders = this.headers.set('Content-Type', 'application/msword')
return this.httpClient.get(this.actionUrl + id, { responseType: 'blob', observe: 'response', headers: headerDocx });
}
public downloadXML(id: string): Observable<HttpResponse<Blob>> {
let headerXml: HttpHeaders = this.headers.set('Content-Type', 'application/xml')
return this.httpClient.get(this.actionUrl + id, { responseType: 'blob', observe: 'response', headers: headerXml }); // + 'getXml/'

View File

@ -29,6 +29,8 @@
'DATASET-WIZARD.ACTIONS.SAVE-AND-FINALISE' | translate }}</button>
<button mat-raised-button color="primary" *ngIf="datasetWizardModel&&datasetWizardModel?.status == 1" class="downloadPDF"
(click)="downloadPDF();" type="button">{{ 'DATASET-WIZARD.ACTIONS.DOWNLOAD-PDF' | translate }}</button>
<button mat-raised-button color="primary" *ngIf="datasetWizardModel&&datasetWizardModel?.status == 1" class="downloadDOCX"
(click)="downloadDOCX();" type="button">{{ 'DATASET-WIZARD.ACTIONS.DOWNLOAD-DOCX' | translate }}</button>
<button mat-raised-button color="primary" *ngIf="datasetWizardModel&&datasetWizardModel?.status == 1" class="downloadXML"
(click)="downloadXML();" type="button">{{ 'DATASET-WIZARD.ACTIONS.DOWNLOAD-XML' | translate }}</button>
<div class="fill-space"></div>

View File

@ -2,11 +2,9 @@
.step-container {
margin-top: 1em;
}
.external-item-card {
margin-top: 1em;
}
.external-item-action-row,
.description-action-row {
margin-top: 1em;
@ -36,4 +34,9 @@
margin-bottom: 15px;
margin-right: 15px;
}
.downloadDOCX {
margin-top: 15px;
margin-bottom: 15px;
margin-right: 15px;
}
}

View File

@ -325,6 +325,18 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
});
}
downloadDOCX(): void {
this.datasetWizardService.downloadDOCX(this.itemId)
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
const blob = new Blob([response.body], { type: 'application/msword' });
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
FileSaver.saveAs(blob, filename);
});
}
downloadXML(): void {
this.datasetWizardService.downloadXML(this.itemId)
.pipe(takeUntil(this._destroyed))