Added Option To Download DMP as XML
This commit is contained in:
parent
623180d1c0
commit
b112748ba4
|
@ -27,6 +27,9 @@
|
|||
<button mat-menu-item (click)="viewVersions(this.dataManagementPlan.groupId, this.dataManagementPlan.label)">
|
||||
<mat-icon>library_books</mat-icon>{{'DMP-LISTING.ACTIONS.VIEW-VERSION' | translate}}
|
||||
</button>
|
||||
<button mat-menu-item (click)="downloadXml(this.dataManagementPlan.id)">
|
||||
<mat-icon>save_alt</mat-icon>{{'DMP-LISTING.ACTIONS.DOWNLOAD-XML' | translate}}
|
||||
</button>
|
||||
</mat-menu>
|
||||
<div>
|
||||
<button mat-icon-button type="button" [matMenuTriggerFor]="actionsMenu">
|
||||
|
|
|
@ -33,6 +33,7 @@ import { IBreadCrumbComponent } from '../../shared/components/breadcrumb/definit
|
|||
import { BreadcrumbItem } from '../../shared/components/breadcrumb/definition/breadcrumb-item';
|
||||
import { SingleAutoCompleteConfiguration } from '../../shared/components/autocompletes/single/single-auto-complete-configuration';
|
||||
import { MultipleAutoCompleteConfiguration } from '../../shared/components/autocompletes/multiple/multiple-auto-complete-configuration';
|
||||
import * as FileSaver from 'file-saver';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dmp-editor-component',
|
||||
|
@ -328,4 +329,31 @@ export class DataManagementPlanEditorComponent implements AfterViewInit, IBreadC
|
|||
viewVersions(rowId: String, rowLabel: String) {
|
||||
this.router.navigate(['/dmps/viewversions/' + rowId], { queryParams: { groupLabel: rowLabel } });
|
||||
}
|
||||
|
||||
downloadXml(id: string) {
|
||||
this.dataManagementPlanService.downloadXML(id).subscribe(response => {
|
||||
const blob = new Blob([response.body], { type: 'application/xml' });
|
||||
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
||||
|
||||
FileSaver.saveAs(blob, filename);
|
||||
});
|
||||
}
|
||||
|
||||
getFilenameFromContentDispositionHeader(header: string): string {
|
||||
const regex: RegExp = new RegExp(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g);
|
||||
|
||||
const matches = header.match(regex);
|
||||
let filename: string;
|
||||
for (let i = 0; i < matches.length; i++) {
|
||||
const match = matches[i];
|
||||
if (match.includes('filename="')) {
|
||||
filename = match.substring(10, match.length - 1);
|
||||
break;
|
||||
} else if (match.includes('filename=')) {
|
||||
filename = match.substring(9);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'rxjs/add/operator/map';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HostConfiguration } from './../../app.constants';
|
||||
import { BaseHttpService } from '../../utilities/cite-http-service-module/base-http.service';
|
||||
|
@ -20,7 +20,7 @@ export class DataManagementPlanService {
|
|||
private actionUrl: string;
|
||||
private headers: HttpHeaders;
|
||||
|
||||
constructor(private http: BaseHttpService) {
|
||||
constructor(private http: BaseHttpService, private httpClient: HttpClient) {
|
||||
|
||||
this.actionUrl = HostConfiguration.Server + 'dmps/';
|
||||
|
||||
|
@ -68,4 +68,8 @@ export class DataManagementPlanService {
|
|||
get(requestItem: RequestItem<DataManagementPlanCriteria>): Observable<DataManagementPlanListingModel[]> {
|
||||
return this.http.post<DataManagementPlanListingModel[]>(this.actionUrl + 'get', requestItem, { headers: this.headers });
|
||||
}
|
||||
|
||||
public downloadXML(id: string): Observable<HttpResponse<Blob>> {
|
||||
return this.httpClient.get(this.actionUrl + 'getXml/' + id, { responseType: 'blob', observe: 'response' });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,8 @@
|
|||
"DATASETS": "List All DMP Datasets",
|
||||
"NEW-VERSION": "New Version",
|
||||
"VIEW-VERSION": "All DMP Versions",
|
||||
"CLONE": "Clone"
|
||||
"CLONE": "Clone",
|
||||
"DOWNLOAD-XML": "Download XML"
|
||||
}
|
||||
},
|
||||
"DATASET-WIZARD": {
|
||||
|
|
Loading…
Reference in New Issue