RED-5213 rss xml and json export
This commit is contained in:
parent
8163d0fcea
commit
38b62dfe27
@ -15,9 +15,12 @@
|
|||||||
<button color="primary" mat-flat-button type="submit" (click)="exportJSON()">
|
<button color="primary" mat-flat-button type="submit" (click)="exportJSON()">
|
||||||
{{ 'rss-dialog.actions.export-json' | translate }}
|
{{ 'rss-dialog.actions.export-json' | translate }}
|
||||||
</button>
|
</button>
|
||||||
<button color="primary" mat-flat-button type="submit" (click)="exportXML()">
|
<button color="primary" mat-flat-button type="button" (click)="exportXML()">
|
||||||
{{ 'rss-dialog.actions.export-xml' | translate }}
|
{{ 'rss-dialog.actions.export-xml' | translate }}
|
||||||
</button>
|
</button>
|
||||||
|
<!-- <button color="primary" mat-flat-button type="button" (click)="exportAllInDossier()">-->
|
||||||
|
<!-- {{ 'Export All' }}-->
|
||||||
|
<!-- </button>-->
|
||||||
<div class="all-caps-label cancel" mat-dialog-close translate="rss-dialog.actions.close"></div>
|
<div class="all-caps-label cancel" mat-dialog-close translate="rss-dialog.actions.close"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -3,9 +3,10 @@ import { BaseDialogComponent, SaveOptions } from '@iqser/common-ui';
|
|||||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||||
import { RssService } from '@services/files/rss.service';
|
import { RssService } from '@services/files/rss.service';
|
||||||
import { IFile, IRssEntry } from '@red/domain';
|
import { IFile, IRssEntry } from '@red/domain';
|
||||||
import { BehaviorSubject, Observable } from 'rxjs';
|
import { BehaviorSubject, firstValueFrom, Observable } from 'rxjs';
|
||||||
import { saveAs } from 'file-saver';
|
import { saveAs } from 'file-saver';
|
||||||
import { map, tap } from 'rxjs/operators';
|
import { map, tap } from 'rxjs/operators';
|
||||||
|
import { FilesMapService } from '@services/files/files-map.service';
|
||||||
|
|
||||||
interface RssData {
|
interface RssData {
|
||||||
file: IFile;
|
file: IFile;
|
||||||
@ -17,11 +18,11 @@ interface RssData {
|
|||||||
})
|
})
|
||||||
export class RssDialogComponent extends BaseDialogComponent {
|
export class RssDialogComponent extends BaseDialogComponent {
|
||||||
rssData$: Observable<IRssEntry>;
|
rssData$: Observable<IRssEntry>;
|
||||||
rssDataSubject$: BehaviorSubject<IRssEntry> = new BehaviorSubject<IRssEntry>(null);
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected readonly _dialogRef: MatDialogRef<RssDialogComponent>,
|
protected readonly _dialogRef: MatDialogRef<RssDialogComponent>,
|
||||||
private readonly _rssService: RssService,
|
private readonly _rssService: RssService,
|
||||||
|
private readonly _filesMapService: FilesMapService,
|
||||||
@Inject(MAT_DIALOG_DATA) readonly data: RssData,
|
@Inject(MAT_DIALOG_DATA) readonly data: RssData,
|
||||||
) {
|
) {
|
||||||
super(_dialogRef);
|
super(_dialogRef);
|
||||||
@ -37,20 +38,23 @@ export class RssDialogComponent extends BaseDialogComponent {
|
|||||||
result: mapped,
|
result: mapped,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
tap(entry => this.rssDataSubject$.next(entry)),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
exportJSON() {
|
exportJSON() {
|
||||||
const blob = new Blob([JSON.stringify(this.rssDataSubject$.value, null, 2)], { type: 'application/json' });
|
this._rssService.exportJSON(this.data.file.dossierId, this.data.file.fileId, this.data.file.filename).subscribe();
|
||||||
saveAs(blob, this.data.file.filename + '.rss.json');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exportXML() {
|
exportXML() {
|
||||||
this._rssService.getRSSDataAsXML(this.data.file.dossierId, this.data.file.fileId).subscribe(data => {
|
this._rssService.exportXML(this.data.file.dossierId, this.data.file.fileId, this.data.file.filename).subscribe();
|
||||||
const blob = new Blob([data], { type: 'application/xml' });
|
}
|
||||||
saveAs(blob, this.data.file.filename + '.rss.xml');
|
|
||||||
});
|
async exportAllInDossier() {
|
||||||
|
const allFilesInDossier = this._filesMapService.get(this.data.file.dossierId);
|
||||||
|
for (const file of allFilesInDossier) {
|
||||||
|
await firstValueFrom(this._rssService.exportJSON(file.dossierId, file.fileId, file.filename));
|
||||||
|
await firstValueFrom(this._rssService.exportXML(file.dossierId, file.fileId, file.filename));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
save(): void {
|
save(): void {
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { GenericService, QueryParam, RequiredParam, Validate } from '@iqser/common-ui';
|
import { GenericService, QueryParam, RequiredParam, Validate } from '@iqser/common-ui';
|
||||||
import { IRssData, IRssEntry } from '@red/domain';
|
import { IRssData, IRssEntry } from '@red/domain';
|
||||||
import { catchError, map } from 'rxjs/operators';
|
import { catchError, map, tap } from 'rxjs/operators';
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { HttpHeaders } from '@angular/common/http';
|
import { HttpHeaders } from '@angular/common/http';
|
||||||
|
import { saveAs } from 'file-saver';
|
||||||
|
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class RssService extends GenericService<void> {
|
export class RssService extends GenericService<void> {
|
||||||
@ -31,7 +32,6 @@ export class RssService extends GenericService<void> {
|
|||||||
let headers = new HttpHeaders();
|
let headers = new HttpHeaders();
|
||||||
headers = headers.set('accept', 'application/xml');
|
headers = headers.set('accept', 'application/xml');
|
||||||
|
|
||||||
console.log('headers', headers);
|
|
||||||
return this._http.get(`/${encodeURI('rss')}/${entityPath}`, {
|
return this._http.get(`/${encodeURI('rss')}/${entityPath}`, {
|
||||||
headers: headers,
|
headers: headers,
|
||||||
params: this._queryParams(queryParams),
|
params: this._queryParams(queryParams),
|
||||||
@ -39,4 +39,22 @@ export class RssService extends GenericService<void> {
|
|||||||
observe: 'body',
|
observe: 'body',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exportJSON(dossierId: string, fileId: string, name: string) {
|
||||||
|
return this.getRSSData(dossierId, fileId).pipe(
|
||||||
|
tap(data => {
|
||||||
|
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
|
||||||
|
saveAs(blob, name + '.rss.json');
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
exportXML(dossierId: string, fileId: string, name: string) {
|
||||||
|
return this.getRSSDataAsXML(dossierId, fileId).pipe(
|
||||||
|
tap(data => {
|
||||||
|
const blob = new Blob([data], { type: 'application/xml' });
|
||||||
|
saveAs(blob, name + '.rss.xml');
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user